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