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.ArrayList;
23 import java.util.List;
24
25 import org.apache.tools.ant.Task;
26 import org.apache.tools.ant.types.DataType;
27 import org.apache.tools.ant.types.Reference;
28
29
30
31 public class Artifacts
32 extends DataType
33 implements ArtifactContainer
34 {
35
36 private List<ArtifactContainer> containers = new ArrayList<ArtifactContainer>();
37
38 protected Artifacts getRef()
39 {
40 return (Artifacts) getCheckedRef();
41 }
42
43 public void validate( Task task )
44 {
45 if ( isReference() )
46 {
47 getRef().validate( task );
48 }
49 else
50 {
51 for ( ArtifactContainer container : containers )
52 {
53 container.validate( task );
54 }
55 }
56 }
57
58 public void setRefid( Reference ref )
59 {
60 if ( !containers.isEmpty() )
61 {
62 throw noChildrenAllowed();
63 }
64 super.setRefid( ref );
65 }
66
67 public void addArtifact( Artifact artifact )
68 {
69 checkChildrenAllowed();
70 containers.add( artifact );
71 }
72
73 public void addArtifacts( Artifacts artifacts )
74 {
75 checkChildrenAllowed();
76 if ( artifacts == this )
77 {
78 throw circularReference();
79 }
80 containers.add( artifacts );
81 }
82
83 public List<Artifact> getArtifacts()
84 {
85 if ( isReference() )
86 {
87 return getRef().getArtifacts();
88 }
89 List<Artifact> artifacts = new ArrayList<Artifact>();
90 for ( ArtifactContainer container : containers )
91 {
92 artifacts.addAll( container.getArtifacts() );
93 }
94 return artifacts;
95 }
96
97 }