1 package org.apache.maven.resolver.internal.ant.types;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.apache.maven.resolver.internal.ant.AntRepoSys;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Project;
28 import org.apache.tools.ant.Task;
29 import org.apache.tools.ant.types.DataType;
30 import org.apache.tools.ant.types.Reference;
31 import org.eclipse.aether.repository.RepositoryPolicy;
32
33
34
35 public class RemoteRepository
36 extends DataType
37 implements RemoteRepositoryContainer
38 {
39
40 private String id;
41
42 private String url;
43
44 private String type;
45
46 private Policy releasePolicy;
47
48 private Policy snapshotPolicy;
49
50 private boolean releases = true;
51
52 private boolean snapshots = false;
53
54 private String checksums;
55
56 private String updates;
57
58 private Authentication authentication;
59
60 @Override
61 public void setProject( Project project )
62 {
63 super.setProject( project );
64
65
66 AntRepoSys.getInstance( project );
67 }
68
69 protected RemoteRepository getRef()
70 {
71 return (RemoteRepository) getCheckedRef();
72 }
73
74 public void validate( Task task )
75 {
76 if ( isReference() )
77 {
78 getRef().validate( task );
79 }
80 else
81 {
82 if ( url == null || url.length() <= 0 )
83 {
84 throw new BuildException( "You must specify the 'url' for a remote repository" );
85 }
86 if ( id == null || id.length() <= 0 )
87 {
88 throw new BuildException( "You must specify the 'id' for a remote repository" );
89 }
90 }
91 }
92
93 public void setRefid( Reference ref )
94 {
95 if ( id != null || url != null || type != null || checksums != null || updates != null )
96 {
97 throw tooManyAttributes();
98 }
99 if ( releasePolicy != null || snapshotPolicy != null || authentication != null )
100 {
101 throw noChildrenAllowed();
102 }
103 super.setRefid( ref );
104 }
105
106 public String getId()
107 {
108 if ( isReference() )
109 {
110 return getRef().getId();
111 }
112 return id;
113 }
114
115 public void setId( String id )
116 {
117 this.id = id;
118 }
119
120 public String getUrl()
121 {
122 if ( isReference() )
123 {
124 return getRef().getUrl();
125 }
126 return url;
127 }
128
129 public void setUrl( String url )
130 {
131 checkAttributesAllowed();
132 this.url = url;
133 }
134
135 public String getType()
136 {
137 if ( isReference() )
138 {
139 return getRef().getType();
140 }
141 return ( type != null ) ? type : "default";
142 }
143
144 public void setType( String type )
145 {
146 checkAttributesAllowed();
147 this.type = type;
148 }
149
150 public Policy getReleasePolicy()
151 {
152 if ( isReference() )
153 {
154 return getRef().getReleasePolicy();
155 }
156 return releasePolicy;
157 }
158
159 public void addReleases( Policy policy )
160 {
161 checkChildrenAllowed();
162 if ( this.releasePolicy != null )
163 {
164 throw new BuildException( "You must not specify multiple <releases> elements" );
165 }
166 this.releasePolicy = policy;
167 }
168
169 public Policy getSnapshotPolicy()
170 {
171 if ( isReference() )
172 {
173 return getRef().getSnapshotPolicy();
174 }
175 return snapshotPolicy;
176 }
177
178 public void addSnapshots( Policy policy )
179 {
180 checkChildrenAllowed();
181 if ( this.snapshotPolicy != null )
182 {
183 throw new BuildException( "You must not specify multiple <snapshots> elements" );
184 }
185 this.snapshotPolicy = policy;
186 }
187
188 public boolean isReleases()
189 {
190 if ( isReference() )
191 {
192 return getRef().isReleases();
193 }
194 return releases;
195 }
196
197 public void setReleases( boolean releases )
198 {
199 checkAttributesAllowed();
200 this.releases = releases;
201 }
202
203 public boolean isSnapshots()
204 {
205 if ( isReference() )
206 {
207 return getRef().isSnapshots();
208 }
209 return snapshots;
210 }
211
212 public void setSnapshots( boolean snapshots )
213 {
214 checkAttributesAllowed();
215 this.snapshots = snapshots;
216 }
217
218 public String getUpdates()
219 {
220 if ( isReference() )
221 {
222 return getRef().getUpdates();
223 }
224 return ( updates != null ) ? updates : RepositoryPolicy.UPDATE_POLICY_DAILY;
225 }
226
227 public void setUpdates( String updates )
228 {
229 checkAttributesAllowed();
230 checkUpdates( updates );
231 this.updates = updates;
232 }
233
234 protected static void checkUpdates( String updates )
235 {
236 if ( !RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( updates )
237 && !RepositoryPolicy.UPDATE_POLICY_DAILY.equals( updates )
238 && !RepositoryPolicy.UPDATE_POLICY_NEVER.equals( updates )
239 && !updates.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) )
240 {
241 throw new BuildException( "'" + updates + "' is not a permitted update policy" );
242 }
243 }
244
245 public String getChecksums()
246 {
247 if ( isReference() )
248 {
249 return getRef().getChecksums();
250 }
251 return ( checksums != null ) ? checksums : RepositoryPolicy.CHECKSUM_POLICY_WARN;
252 }
253
254 public void setChecksums( String checksums )
255 {
256 checkAttributesAllowed();
257 checkChecksums( checksums );
258 this.checksums = checksums;
259 }
260
261 protected static void checkChecksums( String checksums )
262 {
263 if ( !RepositoryPolicy.CHECKSUM_POLICY_FAIL.equals( checksums )
264 && !RepositoryPolicy.CHECKSUM_POLICY_WARN.equals( checksums )
265 && !RepositoryPolicy.CHECKSUM_POLICY_IGNORE.equals( checksums ) )
266 {
267 throw new BuildException( "'" + checksums + "' is not a permitted checksum policy" );
268 }
269 }
270
271 public Authentication getAuthentication()
272 {
273 if ( isReference() )
274 {
275 return getRef().getAuthentication();
276 }
277 return authentication;
278 }
279
280 public void addAuthentication( Authentication authentication )
281 {
282 checkChildrenAllowed();
283 if ( this.authentication != null )
284 {
285 throw new BuildException( "You must not specify multiple <authentication> elements" );
286 }
287 this.authentication = authentication;
288 }
289
290 public void setAuthRef( Reference ref )
291 {
292 checkAttributesAllowed();
293 if ( authentication == null )
294 {
295 authentication = new Authentication();
296 authentication.setProject( getProject() );
297 }
298 authentication.setRefid( ref );
299 }
300
301 public List<RemoteRepository> getRepositories()
302 {
303 return Collections.singletonList( this );
304 }
305
306
307
308 public static class Policy
309 {
310
311 private boolean enabled = true;
312
313 private String checksumPolicy;
314
315 private String updatePolicy;
316
317 public boolean isEnabled()
318 {
319 return enabled;
320 }
321
322 public void setEnabled( boolean enabled )
323 {
324 this.enabled = enabled;
325 }
326
327 public String getChecksums()
328 {
329 return checksumPolicy;
330 }
331
332 public void setChecksums( String checksumPolicy )
333 {
334 checkChecksums( checksumPolicy );
335 this.checksumPolicy = checksumPolicy;
336 }
337
338 public String getUpdates()
339 {
340 return updatePolicy;
341 }
342
343 public void setUpdates( String updatePolicy )
344 {
345 checkUpdates( updatePolicy );
346 this.updatePolicy = updatePolicy;
347 }
348
349 }
350
351 }