1 package org.apache.maven.plugin.coreit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.factory.ArtifactFactory;
24 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
25 import org.apache.maven.artifact.repository.ArtifactRepository;
26 import org.apache.maven.artifact.resolver.ArtifactCollector;
27 import org.apache.maven.model.Dependency;
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31
32 import java.util.Collections;
33 import java.util.LinkedHashSet;
34 import java.util.List;
35 import java.util.Set;
36
37
38
39
40
41
42
43
44 public class CollectMojo
45 extends AbstractMojo
46 {
47
48
49
50
51
52
53
54
55 private ArtifactRepository localRepository;
56
57
58
59
60
61
62
63
64 private List remoteRepositories;
65
66
67
68
69
70
71 private ArtifactCollector collector;
72
73
74
75
76
77
78 private ArtifactFactory factory;
79
80
81
82
83
84
85 private ArtifactMetadataSource metadataSource;
86
87
88
89
90
91
92 private Dependency[] dependencies;
93
94
95
96
97
98
99 public void execute()
100 throws MojoExecutionException, MojoFailureException
101 {
102 getLog().info( "[MAVEN-CORE-IT-LOG] Collecting artifacts" );
103
104 try
105 {
106 Artifact origin = factory.createArtifact( "it", "it", "0.1", null, "pom" );
107
108 Set artifacts = new LinkedHashSet();
109
110 if ( dependencies != null )
111 {
112 for ( Dependency dependency : dependencies )
113 {
114 Artifact artifact =
115 factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
116 dependency.getVersion(), dependency.getType(),
117 dependency.getClassifier() );
118
119 artifacts.add( artifact );
120
121 getLog().info( "[MAVEN-CORE-IT-LOG] Collecting " + artifact.getId() );
122 }
123 }
124
125 collector.collect( artifacts, origin, localRepository, remoteRepositories, metadataSource, null,
126 Collections.EMPTY_LIST );
127 }
128 catch ( Exception e )
129 {
130 throw new MojoExecutionException( "Failed to collect artifacts: " + e.getMessage(), e );
131 }
132 }
133
134 }