1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.felix.obrplugin;
20
21
22 import java.io.File;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.factory.ArtifactFactory;
26 import org.apache.maven.plugin.AbstractMojo;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugins.annotations.Component;
29 import org.apache.maven.plugins.annotations.Parameter;
30 import org.apache.maven.project.MavenProject;
31
32
33
34
35
36
37
38 public abstract class AbstractFileMojo extends AbstractMojo
39 {
40
41
42
43 @Parameter( property = "groupId" )
44 private String groupId;
45
46
47
48
49 @Parameter( property = "artifactId" )
50 private String artifactId;
51
52
53
54
55 @Parameter( property = "version" )
56 private String version;
57
58
59
60
61 @Parameter( property = "packaging" )
62 private String packaging;
63
64
65
66
67 @Parameter( property = "classifier" )
68 private String classifier;
69
70
71
72
73 @Parameter( property = "pomFile" )
74 private File pomFile;
75
76
77
78
79 @Parameter( property = "file" )
80 protected File file;
81
82
83
84
85 @Parameter( property = "obrXml" )
86 protected String obrXml;
87
88
89
90
91 @Component
92 private ArtifactFactory m_factory;
93
94
95
96
97
98
99 public MavenProject getProject() throws MojoExecutionException
100 {
101 final MavenProject project;
102 if ( pomFile != null && pomFile.exists() )
103 {
104 project = PomHelper.readPom( pomFile );
105
106 groupId = project.getGroupId();
107 artifactId = project.getArtifactId();
108 version = project.getVersion();
109 packaging = project.getPackaging();
110 }
111 else
112 {
113 project = PomHelper.buildPom( groupId, artifactId, version, packaging );
114 }
115
116 if ( groupId == null || artifactId == null || version == null || packaging == null )
117 {
118 throw new MojoExecutionException( "Missing group, artifact, version, or packaging information" );
119 }
120
121 Artifact bundle = m_factory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );
122 project.setArtifact( bundle );
123
124 return project;
125 }
126 }