View Javadoc
1   package org.apache.maven.resolver.internal.ant.types;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.resolver.internal.ant.AntRepoSys;
26  import org.apache.tools.ant.Project;
27  import org.apache.tools.ant.types.DataType;
28  import org.apache.tools.ant.types.Reference;
29  
30  /**
31   */
32  public class Authentication
33      extends DataType
34  {
35  
36      private String username;
37  
38      private String password;
39  
40      private String privateKeyFile;
41  
42      private String passphrase;
43  
44      private List<String> servers = new ArrayList<String>();
45  
46      @Override
47      public void setProject( Project project )
48      {
49          super.setProject( project );
50  
51          AntRepoSys.getInstance( project ).addAuthentication( this );
52      }
53  
54      protected Authentication getRef()
55      {
56          return (Authentication) getCheckedRef();
57      }
58  
59      public void setRefid( Reference ref )
60      {
61          if ( username != null || password != null || privateKeyFile != null || passphrase != null )
62          {
63              throw tooManyAttributes();
64          }
65          super.setRefid( ref );
66      }
67  
68      public String getUsername()
69      {
70          if ( isReference() )
71          {
72              return getRef().getUsername();
73          }
74          return username;
75      }
76  
77      public void setUsername( String username )
78      {
79          checkAttributesAllowed();
80          this.username = username;
81      }
82  
83      public String getPassword()
84      {
85          if ( isReference() )
86          {
87              return getRef().getPassword();
88          }
89          return password;
90      }
91  
92      public void setPassword( String password )
93      {
94          checkAttributesAllowed();
95          this.password = password;
96      }
97  
98      public String getPrivateKeyFile()
99      {
100         if ( isReference() )
101         {
102             return getRef().getPrivateKeyFile();
103         }
104         return privateKeyFile;
105     }
106 
107     public void setPrivateKeyFile( String privateKeyFile )
108     {
109         checkAttributesAllowed();
110         this.privateKeyFile = privateKeyFile;
111     }
112 
113     public String getPassphrase()
114     {
115         if ( isReference() )
116         {
117             return getRef().getPassphrase();
118         }
119         return passphrase;
120     }
121 
122     public void setPassphrase( String passphrase )
123     {
124         checkAttributesAllowed();
125         this.passphrase = passphrase;
126     }
127 
128     public List<String> getServers()
129     {
130         if ( isReference() )
131         {
132             return getRef().getServers();
133         }
134         return servers;
135     }
136 
137     public void setServers( String servers )
138     {
139         checkAttributesAllowed();
140         this.servers.clear();
141         String[] split = servers.split( "[;:]" );
142         for ( String server : split )
143         {
144             server = server.trim();
145             if ( server.length() > 0 )
146             {
147                 this.servers.add( server );
148             }
149         }
150     }
151 
152 }