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