View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.resolver.internal.ant.types;
20  
21  import org.apache.maven.resolver.internal.ant.AntRepoSys;
22  import org.apache.tools.ant.BuildException;
23  import org.apache.tools.ant.Project;
24  import org.apache.tools.ant.types.DataType;
25  import org.apache.tools.ant.types.Reference;
26  
27  /**
28   */
29  public class Proxy extends DataType {
30  
31      private String host;
32  
33      private int port;
34  
35      private String type;
36  
37      private String nonProxyHosts;
38  
39      private Authentication authentication;
40  
41      @Override
42      public void setProject(Project project) {
43          super.setProject(project);
44  
45          AntRepoSys.getInstance(project).addProxy(this);
46      }
47  
48      protected Proxy getRef() {
49          return (Proxy) getCheckedRef();
50      }
51  
52      public void setRefid(Reference ref) {
53          if (host != null || port != 0 || type != null || nonProxyHosts != null) {
54              throw tooManyAttributes();
55          }
56          if (authentication != null) {
57              throw noChildrenAllowed();
58          }
59          super.setRefid(ref);
60      }
61  
62      public String getHost() {
63          if (isReference()) {
64              return getRef().getHost();
65          }
66          return host;
67      }
68  
69      public void setHost(String host) {
70          checkAttributesAllowed();
71          this.host = host;
72      }
73  
74      public int getPort() {
75          if (isReference()) {
76              return getRef().getPort();
77          }
78          return port;
79      }
80  
81      public void setPort(int port) {
82          checkAttributesAllowed();
83          if (port <= 0 || port > 0xFFFF) {
84              throw new BuildException("The port number must be within the range 1 - 65535");
85          }
86          this.port = port;
87      }
88  
89      public String getType() {
90          if (isReference()) {
91              return getRef().getType();
92          }
93          return type;
94      }
95  
96      public void setType(String type) {
97          checkAttributesAllowed();
98          this.type = type;
99      }
100 
101     public String getNonProxyHosts() {
102         if (isReference()) {
103             return getRef().getNonProxyHosts();
104         }
105         return nonProxyHosts;
106     }
107 
108     public void setNonProxyHosts(String nonProxyHosts) {
109         checkAttributesAllowed();
110         this.nonProxyHosts = nonProxyHosts;
111     }
112 
113     public Authentication getAuthentication() {
114         if (isReference()) {
115             return getRef().getAuthentication();
116         }
117         return authentication;
118     }
119 
120     public void addAuthentication(Authentication authentication) {
121         checkChildrenAllowed();
122         if (this.authentication != null) {
123             throw new BuildException("You must not specify multiple <authentication> elements");
124         }
125         this.authentication = authentication;
126     }
127 
128     public void setAuthRef(Reference ref) {
129         if (authentication == null) {
130             authentication = new Authentication();
131             authentication.setProject(getProject());
132         }
133         authentication.setRefid(ref);
134     }
135 }