1 package org.apache.maven.plugins.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.LinkedHashSet;
24 import java.util.Set;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo;
29 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
30 import org.apache.maven.project.MavenProject;
31 import org.apache.maven.project.ProjectBuildingRequest;
32 import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
33 import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
34 import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
35 import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;
36 import org.apache.maven.shared.artifact.filter.collection.TypeFilter;
37 import org.apache.maven.shared.artifact.resolve.ArtifactResult;
38 import org.apache.maven.shared.dependencies.DependableCoordinate;
39 import org.apache.maven.shared.dependencies.resolve.DependencyResolverException;
40
41
42
43
44 public abstract class AbstractResolveMojo
45 extends AbstractDependencyFilterMojo
46 {
47
48
49
50
51
52
53 @Parameter( property = "outputFile" )
54 protected File outputFile;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 @Parameter( property = "appendOutput", defaultValue = "false" )
72 protected boolean appendOutput;
73
74
75
76
77
78
79 @Parameter( property = "excludeReactor", defaultValue = "true" )
80 protected boolean excludeReactor;
81
82
83
84
85 @Parameter
86 protected boolean useJvmChmod = true;
87
88
89
90
91 @Parameter
92 protected boolean ignorePermissions;
93
94
95
96
97 protected FilterArtifacts getPluginArtifactsFilter()
98 {
99 if ( excludeReactor )
100 {
101 final StringBuilder exAids = new StringBuilder();
102 if ( this.excludeArtifactIds != null )
103 {
104 exAids.append( this.excludeArtifactIds );
105 }
106
107 for ( final MavenProject rp : reactorProjects )
108 {
109 if ( !"maven-plugin".equals( rp.getPackaging() ) )
110 {
111 continue;
112 }
113
114 if ( exAids.length() > 0 )
115 {
116 exAids.append( "," );
117 }
118
119 exAids.append( rp.getArtifactId() );
120 }
121
122 this.excludeArtifactIds = exAids.toString();
123 }
124
125 final FilterArtifacts filter = new FilterArtifacts();
126
127
128 filter.addFilter( new org.apache.maven.shared.artifact.filter.collection.ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ),
129 DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) );
130
131
132 filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ),
133 DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) );
134
135 filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ),
136 DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) );
137
138 filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ),
139 DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) );
140
141 filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ),
142 DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) );
143
144 return filter;
145 }
146
147
148
149
150
151
152
153
154 protected Set<Artifact> resolveArtifactDependencies( final DependableCoordinate artifact )
155 throws DependencyResolverException
156 {
157 ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
158
159 Iterable<ArtifactResult> artifactResults =
160 getDependencyResolver().resolveDependencies( buildingRequest, artifact, null );
161
162 Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
163
164 for ( final ArtifactResult artifactResult : artifactResults )
165 {
166 artifacts.add( artifactResult.getArtifact() );
167 }
168
169 return artifacts;
170
171 }
172 }