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.repository.ArtifactRepository;
25 import org.apache.maven.model.Dependency;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.project.MavenProject;
28
29 import java.io.File;
30 import java.util.List;
31 import java.util.Properties;
32
33
34
35
36
37
38
39
40
41 public class BuildRemotePomMojo
42 extends AbstractPomMojo
43 {
44
45
46
47
48
49
50 private File propertiesFile;
51
52
53
54
55
56
57
58
59 private ArtifactRepository localRepository;
60
61
62
63
64
65
66
67
68 private List remoteRepositories;
69
70
71
72
73
74
75 private ArtifactFactory factory;
76
77
78
79
80
81
82 private Dependency[] dependencies;
83
84
85
86
87
88
89 public void execute()
90 throws MojoExecutionException
91 {
92 Properties props = new Properties();
93
94 getLog().info( "[MAVEN-CORE-IT-LOG] Building remote POMs" );
95
96 if ( dependencies != null )
97 {
98 for ( int i = 0; i < dependencies.length; i++ )
99 {
100 Dependency dependency = dependencies[i];
101
102 Artifact artifact =
103 factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
104 dependency.getVersion(), dependency.getType(),
105 dependency.getClassifier() );
106
107 String id = artifact.getId();
108
109 getLog().info( "[MAVEN-CORE-IT-LOG] Building " + id );
110
111 try
112 {
113 MavenProject project = builder.buildFromRepository( artifact, remoteRepositories, localRepository );
114
115 dump( props, id + ".", project );
116 }
117 catch ( Exception e )
118 {
119 getLog().warn( "Failed to build remote POM for " + artifact.getId(), e );
120 }
121
122 put( props, id + ".file", artifact.getFile() );
123 put( props, id + ".version", artifact.getVersion() );
124 }
125 }
126
127 store( props, propertiesFile );
128 }
129
130 }