svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.maven / src / main / java / org / gvsig / installer / maven / GeneratePackageInfoMojo.java @ 40560
History | View | Annotate | Download (7.76 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.installer.maven; |
25 |
|
26 |
import java.io.File; |
27 |
import java.net.URL; |
28 |
|
29 |
import org.apache.maven.plugin.AbstractMojo; |
30 |
import org.apache.maven.plugin.MojoExecutionException; |
31 |
import org.apache.maven.plugin.MojoFailureException; |
32 |
import org.apache.maven.plugin.logging.Log; |
33 |
|
34 |
import org.gvsig.installer.lib.api.InstallerLocator; |
35 |
import org.gvsig.installer.lib.api.InstallerManager; |
36 |
import org.gvsig.installer.lib.api.PackageInfo; |
37 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageService; |
38 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException; |
39 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
40 |
import org.gvsig.tools.locator.LocatorException; |
41 |
|
42 |
/**
|
43 |
* Maven mojo to launch the gvSIG installer to generate a file with the package
|
44 |
* info.
|
45 |
* <p>
|
46 |
* Look at the <a href="http://www.gvsig.org/web/projects/gvsig-desktop/docs/devel/gvsig-devel-guide/2.0.0/anexos/proyectos-oficiales-en-gvsig/nombrado-de-binarios-para-un-plugin-de-gvsig"
|
47 |
* >gvSIG plugin naming standard</a> for information about installers naming and
|
48 |
* versioning.
|
49 |
* </p>
|
50 |
*
|
51 |
* @see InstallerManager
|
52 |
*
|
53 |
* @author gvSIG Team
|
54 |
* @version $Id$
|
55 |
*
|
56 |
* @goal write-info
|
57 |
*/
|
58 |
public class GeneratePackageInfoMojo extends AbstractMojo { |
59 |
|
60 |
/**
|
61 |
* Location of the gvSIG plugins folder.
|
62 |
*
|
63 |
* @parameter
|
64 |
* @required
|
65 |
*/
|
66 |
private File pluginsFolder; |
67 |
|
68 |
/**
|
69 |
* Plugin project artifactId or code, used as gvSIG plugin name.
|
70 |
*
|
71 |
* @parameter expression="${project.artifactId}"
|
72 |
* @required
|
73 |
*/
|
74 |
private String artifactId; |
75 |
|
76 |
/**
|
77 |
* Plugin project packaging, to check it is of jar type.
|
78 |
*
|
79 |
* @parameter expression="${project.packaging}"
|
80 |
* @required
|
81 |
*/
|
82 |
private String packaging; |
83 |
|
84 |
/**
|
85 |
* Plugin project name.
|
86 |
*
|
87 |
* @parameter expression="${project.name}"
|
88 |
* @required
|
89 |
*/
|
90 |
private String name; |
91 |
|
92 |
/**
|
93 |
* Plugin project description.
|
94 |
*
|
95 |
* @parameter expression="${project.description}"
|
96 |
* @required
|
97 |
*/
|
98 |
private String description; |
99 |
|
100 |
/**
|
101 |
* Plugin project version.
|
102 |
*
|
103 |
* @parameter expression="${project.version}"
|
104 |
* @required
|
105 |
*/
|
106 |
private String version; |
107 |
|
108 |
/**
|
109 |
* Plugin build number.
|
110 |
*
|
111 |
* @parameter
|
112 |
*/
|
113 |
private int buildNumber = -1; |
114 |
|
115 |
/**
|
116 |
* Plugin state. One of: devel, pilot, prototype, alpha[num], beta[num],
|
117 |
* RC[num], final.
|
118 |
*
|
119 |
* Defaults to "devel".
|
120 |
*
|
121 |
* @parameter
|
122 |
*/
|
123 |
private String state; |
124 |
|
125 |
/**
|
126 |
* If the plugin is a gvSIG official one.
|
127 |
*
|
128 |
* @parameter
|
129 |
* @required
|
130 |
*/
|
131 |
private boolean official; |
132 |
|
133 |
/**
|
134 |
* The supported operating system. Examples: lin (linux), win (windows),
|
135 |
* osx_10_4, osx_10_5, osx_10_6.
|
136 |
*
|
137 |
* Defaults to all.
|
138 |
*
|
139 |
* @parameter
|
140 |
*/
|
141 |
private String operatingSystem; |
142 |
|
143 |
/**
|
144 |
* The supported architecture. Examples: x86 (32 bits), x86_64 (64 bits).
|
145 |
*
|
146 |
* Defaults to all.
|
147 |
*
|
148 |
* @parameter
|
149 |
*/
|
150 |
private String architecture; |
151 |
|
152 |
/**
|
153 |
* Minimum Java VM version supported. Example: j1_5, j1_6.
|
154 |
*
|
155 |
* Defaults to j1_5.
|
156 |
*
|
157 |
* @parameter
|
158 |
*/
|
159 |
private String javaVM; |
160 |
|
161 |
/**
|
162 |
* The minimum gvSIG version supported.
|
163 |
*
|
164 |
* @parameter
|
165 |
* @required
|
166 |
*/
|
167 |
private String gvSIGVersion; |
168 |
|
169 |
/**
|
170 |
* Installabe type. Only <strong>plugin</strong> is supported.
|
171 |
*
|
172 |
* @parameter default="${plugin}"
|
173 |
*/
|
174 |
private String installableType = "plugin"; |
175 |
|
176 |
/**
|
177 |
* If the mojo execution is disabled. Useful for projects that inherit the
|
178 |
* maven plugin configuration but don't generate installer.
|
179 |
*
|
180 |
* @parameter
|
181 |
*/
|
182 |
private boolean disabled = false; |
183 |
|
184 |
/**
|
185 |
* Plugin project folder where to store the package info.
|
186 |
*
|
187 |
* @parameter expression="${basedir}"
|
188 |
* @required
|
189 |
*/
|
190 |
private File packageInfoFolder; |
191 |
|
192 |
/**
|
193 |
* Dependencies with other packages
|
194 |
*
|
195 |
* @parameter
|
196 |
*/
|
197 |
private String pkgdependencies; |
198 |
|
199 |
/**
|
200 |
* Owner of the package.
|
201 |
*
|
202 |
* @parameter
|
203 |
*/
|
204 |
private String owner; |
205 |
|
206 |
/**
|
207 |
* URL of the plugin sources.
|
208 |
*
|
209 |
* @parameter
|
210 |
*/
|
211 |
private URL sourcesURL; |
212 |
|
213 |
/**
|
214 |
* URL of the project's web.
|
215 |
*
|
216 |
* @parameter
|
217 |
*/
|
218 |
private URL webURL; |
219 |
|
220 |
/**
|
221 |
* addon categories.
|
222 |
*
|
223 |
* @parameter
|
224 |
*/
|
225 |
private String categories; |
226 |
|
227 |
public void execute() throws MojoExecutionException, MojoFailureException { |
228 |
Log log = getLog(); |
229 |
|
230 |
if (disabled) {
|
231 |
log.info("Package info generation disabled.");
|
232 |
return;
|
233 |
} |
234 |
if( buildNumber == -1 ) { |
235 |
log.info("Skip package info generation, undefined buildNumber property.");
|
236 |
return;
|
237 |
} |
238 |
|
239 |
if (!"jar".equals(packaging)) { |
240 |
log |
241 |
.info("Running on a project with packaging of type "
|
242 |
+ packaging |
243 |
+ ". Do nothing, as we only create installers for projects "
|
244 |
+ "with jar packaging");
|
245 |
return;
|
246 |
} |
247 |
packageInfoFolder = new File(packageInfoFolder, "target") ; |
248 |
|
249 |
log.info("Generating the package info for the plugin: " + artifactId
|
250 |
+ " with the following information:");
|
251 |
log.info("\tPlugin name: " + name);
|
252 |
log.info("\tPlugin description: " + description);
|
253 |
log.info("\tPlugin version: " + version);
|
254 |
log.info("\tPlugin build number: " + buildNumber);
|
255 |
log.info("\tPlugin state: " + state);
|
256 |
log.info("\tPlugin official: " + official);
|
257 |
log.info("\tPlugin operatingSystem: " + operatingSystem);
|
258 |
log.info("\tPlugin architecture: " + architecture);
|
259 |
log.info("\tPlugin javaVM: " + javaVM);
|
260 |
log.info("\tPlugin gvSIGVersion: " + gvSIGVersion);
|
261 |
log.info("\tgvSIG Plugin's folder: " + pluginsFolder);
|
262 |
log.info("\tPackage info folder: " + packageInfoFolder);
|
263 |
log.info("\tDependencies: " + pkgdependencies);
|
264 |
log.info("\tOwner: " + owner);
|
265 |
log.info("\tSources URL: " + sourcesURL);
|
266 |
log.info("\tWeb URL: " + webURL);
|
267 |
log.info("\tCategories: " + categories);
|
268 |
|
269 |
try {
|
270 |
new DefaultLibrariesInitializer().fullInitialize();
|
271 |
|
272 |
InstallerManager manager = InstallerLocator.getInstallerManager(); |
273 |
|
274 |
manager.setDefaultLocalAddonRepository(pluginsFolder); |
275 |
MakePluginPackageService makePluginService = manager.getMakePluginPackageService(); |
276 |
|
277 |
// Get and fill the package info data
|
278 |
PackageInfo info = makePluginService.getPluginPackageInfo(artifactId); |
279 |
|
280 |
// info.setCode(artifactId);
|
281 |
info.setDescription(description); |
282 |
info.setName(name); |
283 |
info.setOfficial(official); |
284 |
info.setState(state); |
285 |
info.setType(installableType); |
286 |
info.setVersion(version); |
287 |
info.setBuild(buildNumber); |
288 |
info.setOperatingSystem(operatingSystem); |
289 |
info.setArchitecture(architecture); |
290 |
info.setJavaVM(javaVM); |
291 |
info.setGvSIGVersion(gvSIGVersion); |
292 |
info.setDependencies(pkgdependencies); |
293 |
info.setOwner(owner); |
294 |
info.setSourcesURL(sourcesURL); |
295 |
info.setWebURL(webURL); |
296 |
info.addCategoriesAsString(categories); |
297 |
|
298 |
makePluginService.writePackageInfo(info, packageInfoFolder); |
299 |
|
300 |
} catch (LocatorException e) {
|
301 |
throw new MojoExecutionException( |
302 |
"Error getting a reference to the InstallerManager", e);
|
303 |
} catch (MakePluginPackageServiceException e) {
|
304 |
throw new MojoExecutionException( |
305 |
"Error getting a MakePluginPackageService for the "
|
306 |
+ " plugin folder: " + pluginsFolder, e);
|
307 |
} |
308 |
|
309 |
log.info("Package info file created successfully");
|
310 |
} |
311 |
} |