1 package org.apache.maven.plugin.dependency;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Set;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
27 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
28 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
29 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
30 import org.apache.maven.plugins.annotations.Component;
31 import org.apache.maven.plugins.annotations.Parameter;
32 import org.apache.maven.project.MavenProject;
33 import org.apache.maven.project.MavenProjectBuilder;
34 import org.apache.maven.project.ProjectBuildingException;
35 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
36 import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
37 import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
38 import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
39 import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;
40 import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
41 import org.apache.maven.shared.artifact.filter.collection.TypeFilter;
42
43
44
45
46
47 public abstract class AbstractResolveMojo
48 extends AbstractDependencyFilterMojo
49 {
50
51
52
53 @Component
54 protected MavenProjectBuilder mavenProjectBuilder;
55
56
57
58
59
60
61
62 @Parameter( property = "outputFile" )
63 protected File outputFile;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 @Parameter( property = "appendOutput", defaultValue = "false" )
83 protected boolean appendOutput;
84
85
86
87
88
89
90
91 @Parameter( property = "excludeReactor", defaultValue = "true" )
92 protected boolean excludeReactor;
93
94 protected FilterArtifacts getPluginArtifactsFilter()
95 {
96 if ( excludeReactor )
97 {
98 final StringBuilder exAids = new StringBuilder();
99 if ( this.excludeArtifactIds != null )
100 {
101 exAids.append( this.excludeArtifactIds );
102 }
103
104 for ( final MavenProject rp : reactorProjects )
105 {
106 if ( !"maven-plugin".equals( rp.getPackaging() ) )
107 {
108 continue;
109 }
110
111 if ( exAids.length() > 0 )
112 {
113 exAids.append( "," );
114 }
115
116 exAids.append( rp.getArtifactId() );
117 }
118
119 this.excludeArtifactIds = exAids.toString();
120 }
121
122 final FilterArtifacts filter = new FilterArtifacts();
123
124 filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ),
125 DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) );
126
127 filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ),
128 DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) );
129
130 filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ),
131 DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) );
132
133 filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ),
134 DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) );
135
136 filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ),
137 DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) );
138
139 return filter;
140 }
141
142 protected Set<Artifact> resolveDependencyArtifacts( final MavenProject theProject )
143 throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException
144 {
145 final Set<Artifact> artifacts =
146 theProject.createArtifacts( this.factory, Artifact.SCOPE_TEST,
147 new ScopeArtifactFilter( Artifact.SCOPE_TEST ) );
148
149 for ( final Artifact artifact : artifacts )
150 {
151
152 this.resolver.resolve( artifact, this.remoteRepos, this.getLocal() );
153 }
154 return artifacts;
155 }
156
157
158
159
160
161
162
163
164
165
166
167
168 protected Set<Artifact> resolveArtifactDependencies( final Artifact artifact )
169 throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException,
170 InvalidDependencyVersionException
171 {
172 final Artifact pomArtifact =
173 this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "",
174 "pom" );
175
176 final MavenProject pomProject =
177 mavenProjectBuilder.buildFromRepository( pomArtifact, this.remoteRepos, this.getLocal() );
178
179 return resolveDependencyArtifacts( pomProject );
180 }
181 }