1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 getCheckedRef(Proxy.class);
50 }
51
52 @Override
53 public void setRefid(Reference ref) {
54 if (host != null || port != 0 || type != null || nonProxyHosts != null) {
55 throw tooManyAttributes();
56 }
57 if (authentication != null) {
58 throw noChildrenAllowed();
59 }
60 super.setRefid(ref);
61 }
62
63 public String getHost() {
64 if (isReference()) {
65 return getRef().getHost();
66 }
67 return host;
68 }
69
70 public void setHost(String host) {
71 checkAttributesAllowed();
72 this.host = host;
73 }
74
75 public int getPort() {
76 if (isReference()) {
77 return getRef().getPort();
78 }
79 return port;
80 }
81
82 public void setPort(int port) {
83 checkAttributesAllowed();
84 if (port <= 0 || port > 0xFFFF) {
85 throw new BuildException("The port number must be within the range 1 - 65535");
86 }
87 this.port = port;
88 }
89
90 public String getType() {
91 if (isReference()) {
92 return getRef().getType();
93 }
94 return type;
95 }
96
97 public void setType(String type) {
98 checkAttributesAllowed();
99 this.type = type;
100 }
101
102 public String getNonProxyHosts() {
103 if (isReference()) {
104 return getRef().getNonProxyHosts();
105 }
106 return nonProxyHosts;
107 }
108
109 public void setNonProxyHosts(String nonProxyHosts) {
110 checkAttributesAllowed();
111 this.nonProxyHosts = nonProxyHosts;
112 }
113
114 public Authentication getAuthentication() {
115 if (isReference()) {
116 return getRef().getAuthentication();
117 }
118 return authentication;
119 }
120
121 public void addAuthentication(Authentication authentication) {
122 checkChildrenAllowed();
123 if (this.authentication != null) {
124 throw new BuildException("You must not specify multiple <authentication> elements");
125 }
126 this.authentication = authentication;
127 }
128
129 public void setAuthRef(Reference ref) {
130 if (authentication == null) {
131 authentication = new Authentication();
132 authentication.setProject(getProject());
133 }
134 authentication.setRefid(ref);
135 }
136 }