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.plugin.AbstractMojo;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.project.MavenProject;
27
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.LinkedHashSet;
31 import java.util.Set;
32
33
34
35
36
37
38
39
40 public class InjectMojo
41 extends AbstractMojo
42 {
43
44
45
46
47
48
49
50 private String[] artifacts;
51
52
53
54
55
56 private Collection pluginArtifacts;
57
58
59
60
61
62
63
64
65 private MavenProject project;
66
67
68
69
70
71
72 private ArtifactFactory factory;
73
74
75
76
77
78
79 public void execute()
80 throws MojoExecutionException
81 {
82 Set artifactKeys = new LinkedHashSet();
83
84 if ( artifacts != null )
85 {
86 artifactKeys.addAll( Arrays.asList( artifacts ) );
87 }
88
89 Set dependencyArtifacts = project.getDependencyArtifacts();
90
91 if ( dependencyArtifacts != null )
92 {
93 dependencyArtifacts = new LinkedHashSet( dependencyArtifacts );
94 }
95 else
96 {
97 dependencyArtifacts = new LinkedHashSet();
98 }
99
100 for ( Object pluginArtifact : pluginArtifacts )
101 {
102 Artifact artifact = (Artifact) pluginArtifact;
103
104 String artifactKey = artifact.getGroupId() + ':' + artifact.getArtifactId();
105
106 if ( artifactKeys.remove( artifactKey ) )
107 {
108 artifact =
109 factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
110 Artifact.SCOPE_COMPILE, artifact.getType() );
111
112 getLog().info( "[MAVEN-CORE-IT-LOG] Injecting dependency artifact " + artifact );
113
114 dependencyArtifacts.add( artifact );
115 }
116 }
117
118 project.setDependencyArtifacts( dependencyArtifacts );
119
120 getLog().info( "[MAVEN-CORE-IT-LOG] Set dependency artifacts to " + dependencyArtifacts );
121
122 if ( !artifactKeys.isEmpty() )
123 {
124 getLog().warn( "[MAVEN-CORE-IT-LOG] These artifacts were not found " + artifactKeys );
125 }
126 }
127
128 }