svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.maven / src / main / java / org / gvsig / installer / maven / GenerateInstallerMojo.java @ 33696
History | View | Annotate | Download (8.88 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.installer.maven; |
23 |
|
24 |
import java.io.BufferedOutputStream; |
25 |
import java.io.File; |
26 |
import java.io.FileNotFoundException; |
27 |
import java.io.FileOutputStream; |
28 |
import java.io.IOException; |
29 |
|
30 |
import org.apache.maven.plugin.AbstractMojo; |
31 |
import org.apache.maven.plugin.MojoExecutionException; |
32 |
import org.apache.maven.plugin.MojoFailureException; |
33 |
import org.apache.maven.plugin.logging.Log; |
34 |
|
35 |
import org.gvsig.installer.lib.api.InstallerLocator; |
36 |
import org.gvsig.installer.lib.api.InstallerManager; |
37 |
import org.gvsig.installer.lib.api.PackageInfo; |
38 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageService; |
39 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException; |
40 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
41 |
import org.gvsig.tools.locator.LocatorException; |
42 |
|
43 |
/**
|
44 |
* Maven mojo to launch the gvSIG installer to generate a installation
|
45 |
* bundle of a gvSIG plugin.
|
46 |
* <p>
|
47 |
* Look at the <a href=
|
48 |
* "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"
|
49 |
* >gvSIG plugin naming standard</a> for information about installers naming and
|
50 |
* versioning.
|
51 |
* </p>
|
52 |
*
|
53 |
* @see InstallerManager
|
54 |
*
|
55 |
* @author gvSIG Team
|
56 |
* @version $Id$
|
57 |
*
|
58 |
* @goal generate-installer
|
59 |
*
|
60 |
* @phase install
|
61 |
*/
|
62 |
public class GenerateInstallerMojo extends AbstractMojo { |
63 |
|
64 |
/**
|
65 |
* Location of the gvSIG plugins folder.
|
66 |
*
|
67 |
* @parameter
|
68 |
* @required
|
69 |
*/
|
70 |
private File pluginsFolder; |
71 |
|
72 |
/**
|
73 |
* Location of the folder where to create the package bundle file.
|
74 |
*
|
75 |
* @parameter
|
76 |
* @required
|
77 |
*/
|
78 |
private File bundleFolder; |
79 |
|
80 |
/**
|
81 |
* Name of the package bundle file. If not provided, the
|
82 |
* official gvSIG name will be used, as provided by
|
83 |
* the org.gvsig.installer.lib.api.InstallerManager.
|
84 |
*
|
85 |
* @parameter
|
86 |
*/
|
87 |
private String bundleFileName; |
88 |
|
89 |
/**
|
90 |
* Plugin project artifactId or code, used as gvSIG plugin name.
|
91 |
*
|
92 |
* @parameter expression="${project.artifactId}"
|
93 |
* @required
|
94 |
*/
|
95 |
private String artifactId; |
96 |
|
97 |
/**
|
98 |
* Plugin project packaging, to check it is of jar type.
|
99 |
*
|
100 |
* @parameter expression="${project.packaging}"
|
101 |
* @required
|
102 |
*/
|
103 |
private String packaging; |
104 |
|
105 |
/**
|
106 |
* Plugin project name.
|
107 |
*
|
108 |
* @parameter expression="${project.name}"
|
109 |
* @required
|
110 |
*/
|
111 |
private String name; |
112 |
|
113 |
/**
|
114 |
* Plugin project description.
|
115 |
*
|
116 |
* @parameter expression="${project.description}"
|
117 |
* @required
|
118 |
*/
|
119 |
private String description; |
120 |
|
121 |
/**
|
122 |
* Plugin project version.
|
123 |
*
|
124 |
* @parameter expression="${project.version}"
|
125 |
* @required
|
126 |
*/
|
127 |
private String version; |
128 |
|
129 |
/**
|
130 |
* Plugin build number.
|
131 |
*
|
132 |
* @parameter
|
133 |
* @required
|
134 |
*/
|
135 |
private int buildNumber; |
136 |
|
137 |
/**
|
138 |
* Plugin state.
|
139 |
* One of: devel, pilot, prototype, alpha[num], beta[num], RC[num], final.
|
140 |
*
|
141 |
* Defaults to "devel".
|
142 |
*
|
143 |
* @parameter
|
144 |
*/
|
145 |
private String state; |
146 |
|
147 |
/**
|
148 |
* If the plugin is a gvSIG official one.
|
149 |
*
|
150 |
* @parameter
|
151 |
* @required
|
152 |
*/
|
153 |
private boolean official; |
154 |
|
155 |
/**
|
156 |
* The supported operating system.
|
157 |
* Examples: lin (linux), win (windows), osx_10_4, osx_10_5, osx_10_6.
|
158 |
*
|
159 |
* Defaults to all.
|
160 |
*
|
161 |
* @parameter
|
162 |
*/
|
163 |
private String operatingSystem; |
164 |
|
165 |
/**
|
166 |
* The supported architecture.
|
167 |
* Examples: x86 (32 bits), x86_64 (64 bits).
|
168 |
*
|
169 |
* Defaults to all.
|
170 |
*
|
171 |
* @parameter
|
172 |
*/
|
173 |
private String architecture; |
174 |
|
175 |
/**
|
176 |
* Minimum Java VM version supported.
|
177 |
* Example: j1_5, j1_6.
|
178 |
*
|
179 |
* Defaults to j1_5.
|
180 |
*
|
181 |
* @parameter
|
182 |
*/
|
183 |
private String javaVM; |
184 |
|
185 |
/**
|
186 |
* The minimum gvSIG version supported.
|
187 |
*
|
188 |
* @parameter
|
189 |
* @required
|
190 |
*/
|
191 |
private String gvSIGVersion; |
192 |
|
193 |
/**
|
194 |
* Installabe type. Only <strong>plugin</strong> is supported.
|
195 |
*
|
196 |
* @parameter default="${plugin}"
|
197 |
*/
|
198 |
private String installableType = "plugin"; |
199 |
|
200 |
/**
|
201 |
* If the mojo execution is disabled. Useful for projects that inherit
|
202 |
* the maven plugin configuration but don't generate installer.
|
203 |
*
|
204 |
* @parameter
|
205 |
*/
|
206 |
private boolean disabled = false; |
207 |
|
208 |
public void execute() throws MojoExecutionException, MojoFailureException { |
209 |
Log log = getLog(); |
210 |
|
211 |
if (disabled) {
|
212 |
log.info("Installer generation disabled.");
|
213 |
return;
|
214 |
} |
215 |
|
216 |
if (!"jar".equals(packaging)) { |
217 |
log.info("Running on a project with packaging of type " + packaging
|
218 |
+ ". Do nothing, as we only create installers for projects "
|
219 |
+ "with jar packaging");
|
220 |
return;
|
221 |
} |
222 |
|
223 |
log.info("Generating a installable for the plugin: " + artifactId
|
224 |
+ " with the following information:");
|
225 |
log.info("\tPlugin name: " + name);
|
226 |
log.info("\tPlugin description: " + description);
|
227 |
log.info("\tPlugin version: " + version);
|
228 |
log.info("\tPlugin build number: " + buildNumber);
|
229 |
log.info("\tPlugin state: " + state);
|
230 |
log.info("\tPlugin official: " + official);
|
231 |
log.info("\tPlugin operatingSystem: " + operatingSystem);
|
232 |
log.info("\tPlugin architecture: " + architecture);
|
233 |
log.info("\tPlugin javaVM: " + javaVM);
|
234 |
log.info("\tPlugin gvSIGVersion: " + gvSIGVersion);
|
235 |
log.info("\tgvSIG Plugin's folder: " + pluginsFolder);
|
236 |
log.info("\tBundle installation file to create: " + bundleFolder);
|
237 |
|
238 |
File packageBundleFile = null; |
239 |
|
240 |
try {
|
241 |
new DefaultLibrariesInitializer().fullInitialize();
|
242 |
|
243 |
InstallerManager manager = InstallerLocator.getInstallerManager(); |
244 |
|
245 |
MakePluginPackageService makePluginService = |
246 |
manager.getMakePluginPackageService(pluginsFolder); |
247 |
|
248 |
// Get and fill the package info data
|
249 |
PackageInfo info = |
250 |
makePluginService.getPluginPackageInfo(artifactId); |
251 |
|
252 |
info.setBuild(buildNumber); |
253 |
// info.setCode(artifactId);
|
254 |
info.setDescription(description); |
255 |
info.setName(name); |
256 |
info.setOfficial(official); |
257 |
info.setState(state); |
258 |
info.setType(installableType); |
259 |
info.setVersion(version); |
260 |
info.setOperatingSystem(operatingSystem); |
261 |
info.setArchitecture(architecture); |
262 |
info.setJavaVM(javaVM); |
263 |
info.setGvSIGVersion(gvSIGVersion); |
264 |
|
265 |
// Create the package bundle file
|
266 |
String packageBundleFileName =
|
267 |
bundleFileName == null ? manager.getPackageBundleFileName(info)
|
268 |
: bundleFileName; |
269 |
|
270 |
if (!bundleFolder.exists()) {
|
271 |
bundleFolder.mkdirs(); |
272 |
} |
273 |
packageBundleFile = new File(bundleFolder, packageBundleFileName); |
274 |
|
275 |
FileOutputStream fos = new FileOutputStream(packageBundleFile); |
276 |
BufferedOutputStream bos = new BufferedOutputStream(fos); |
277 |
|
278 |
makePluginService.createPluginPackage(info, bos); |
279 |
|
280 |
bos.flush(); |
281 |
bos.close(); |
282 |
fos.close(); |
283 |
} catch (LocatorException e) {
|
284 |
throw new MojoExecutionException( |
285 |
"Error getting a reference to the InstallerManager", e);
|
286 |
} catch (MakePluginPackageServiceException e) {
|
287 |
throw new MojoExecutionException( |
288 |
"Error getting a MakePluginPackageService for the "
|
289 |
+ "plugin folder: " + pluginsFolder, e);
|
290 |
} catch (FileNotFoundException e) { |
291 |
throw new MojoExecutionException( |
292 |
"Error creating the bundle installation file: "
|
293 |
+ packageBundleFile, e); |
294 |
} catch (IOException e) { |
295 |
throw new MojoExecutionException( |
296 |
"I/O error writing the bundle installation file: "
|
297 |
+ packageBundleFile, e); |
298 |
} |
299 |
|
300 |
log.info("Bundle installation file created successfully");
|
301 |
} |
302 |
} |