Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.maven / src / main / java / org / gvsig / installer / maven / GeneratePackageInfoMojo.java @ 37822

History | View | Annotate | Download (7.33 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.File;
25
import java.net.URL;
26

    
27
import org.apache.maven.plugin.AbstractMojo;
28
import org.apache.maven.plugin.MojoExecutionException;
29
import org.apache.maven.plugin.MojoFailureException;
30
import org.apache.maven.plugin.logging.Log;
31

    
32
import org.gvsig.installer.lib.api.InstallerLocator;
33
import org.gvsig.installer.lib.api.InstallerManager;
34
import org.gvsig.installer.lib.api.PackageInfo;
35
import org.gvsig.installer.lib.api.creation.MakePluginPackageService;
36
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException;
37
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
38
import org.gvsig.tools.locator.LocatorException;
39

    
40
/**
41
 * Maven mojo to launch the gvSIG installer to generate a file with the package
42
 * info.
43
 * <p>
44
 * 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"
45
 * >gvSIG plugin naming standard</a> for information about installers naming and
46
 * versioning.
47
 * </p>
48
 * 
49
 * @see InstallerManager
50
 * 
51
 * @author gvSIG Team
52
 * @version $Id$
53
 * 
54
 * @goal write-info
55
 */
56
public class GeneratePackageInfoMojo extends AbstractMojo {
57

    
58
        /**
59
         * Location of the gvSIG plugins folder.
60
         * 
61
         * @parameter
62
         * @required
63
         */
64
        private File pluginsFolder;
65

    
66
        /**
67
         * Plugin project artifactId or code, used as gvSIG plugin name.
68
         * 
69
         * @parameter expression="${project.artifactId}"
70
         * @required
71
         */
72
        private String artifactId;
73

    
74
        /**
75
         * Plugin project packaging, to check it is of jar type.
76
         * 
77
         * @parameter expression="${project.packaging}"
78
         * @required
79
         */
80
        private String packaging;
81

    
82
        /**
83
         * Plugin project name.
84
         * 
85
         * @parameter expression="${project.name}"
86
         * @required
87
         */
88
        private String name;
89

    
90
        /**
91
         * Plugin project description.
92
         * 
93
         * @parameter expression="${project.description}"
94
         * @required
95
         */
96
        private String description;
97

    
98
        /**
99
         * Plugin project version.
100
         * 
101
         * @parameter expression="${project.version}"
102
         * @required
103
         */
104
        private String version;
105

    
106
        /**
107
         * Plugin build number.
108
         * 
109
         * @parameter
110
         * @required
111
         */
112
        private int buildNumber;
113

    
114
        /**
115
         * Plugin state. One of: devel, pilot, prototype, alpha[num], beta[num],
116
         * RC[num], final.
117
         * 
118
         * Defaults to "devel".
119
         * 
120
         * @parameter
121
         */
122
        private String state;
123

    
124
        /**
125
         * If the plugin is a gvSIG official one.
126
         * 
127
         * @parameter
128
         * @required
129
         */
130
        private boolean official;
131

    
132
        /**
133
         * The supported operating system. Examples: lin (linux), win (windows),
134
         * osx_10_4, osx_10_5, osx_10_6.
135
         * 
136
         * Defaults to all.
137
         * 
138
         * @parameter
139
         */
140
        private String operatingSystem;
141

    
142
        /**
143
         * The supported architecture. Examples: x86 (32 bits), x86_64 (64 bits).
144
         * 
145
         * Defaults to all.
146
         * 
147
         * @parameter
148
         */
149
        private String architecture;
150

    
151
        /**
152
         * Minimum Java VM version supported. Example: j1_5, j1_6.
153
         * 
154
         * Defaults to j1_5.
155
         * 
156
         * @parameter
157
         */
158
        private String javaVM;
159

    
160
        /**
161
         * The minimum gvSIG version supported.
162
         * 
163
         * @parameter
164
         * @required
165
         */
166
        private String gvSIGVersion;
167

    
168
        /**
169
         * Installabe type. Only <strong>plugin</strong> is supported.
170
         * 
171
         * @parameter default="${plugin}"
172
         */
173
        private String installableType = "plugin";
174

    
175
        /**
176
         * If the mojo execution is disabled. Useful for projects that inherit the
177
         * maven plugin configuration but don't generate installer.
178
         * 
179
         * @parameter
180
         */
181
        private boolean disabled = false;
182

    
183
        /**
184
         * Plugin project folder where to store the package info.
185
         * 
186
         * @parameter expression="${basedir}"
187
         * @required
188
         */
189
        private File packageInfoFolder;
190

    
191
        /**
192
         * Dependencies with other packages
193
         * 
194
         * @parameter
195
         */
196
        private String pkgdependencies;
197

    
198
        /**
199
         * Owner of the package.
200
         * 
201
         * @parameter
202
         */
203
        private String owner;
204

    
205
        /**
206
         * URL of the plugin sources.
207
         * 
208
         * @parameter
209
         */
210
        private URL sourcesURL;
211

    
212
        /**
213
         * URL of the project's web.
214
         * 
215
         * @parameter
216
         */
217
        private URL webURL;
218

    
219
        public void execute() throws MojoExecutionException, MojoFailureException {
220
                Log log = getLog();
221

    
222
                if (disabled) {
223
                        log.info("Package info generation disabled.");
224
                        return;
225
                }
226

    
227
                if (!"jar".equals(packaging)) {
228
                        log
229
                                        .info("Running on a project with packaging of type "
230
                                                        + packaging
231
                                                        + ". Do nothing, as we only create installers for projects "
232
                                                        + "with jar packaging");
233
                        return;
234
                }
235

    
236
                log.info("Generating the package info for the plugin: " + artifactId
237
                                + " with the following information:");
238
                log.info("\tPlugin name: " + name);
239
                log.info("\tPlugin description: " + description);
240
                log.info("\tPlugin version: " + version);
241
                log.info("\tPlugin build number: " + buildNumber);
242
                log.info("\tPlugin state: " + state);
243
                log.info("\tPlugin official: " + official);
244
                log.info("\tPlugin operatingSystem: " + operatingSystem);
245
                log.info("\tPlugin architecture: " + architecture);
246
                log.info("\tPlugin javaVM: " + javaVM);
247
                log.info("\tPlugin gvSIGVersion: " + gvSIGVersion);
248
                log.info("\tgvSIG Plugin's folder: " + pluginsFolder);
249
                log.info("\tPackage info folder: " + packageInfoFolder);
250
                log.info("\tDependencies: " + pkgdependencies);
251
                log.info("\tOwner: " + owner);
252
                log.info("\tSources URL: " + sourcesURL);
253
                log.info("\tWeb URL: " + webURL);
254

    
255
                try {
256
                        new DefaultLibrariesInitializer().fullInitialize();
257

    
258
                        InstallerManager manager = InstallerLocator.getInstallerManager();
259

    
260
                        MakePluginPackageService makePluginService = manager
261
                                        .getMakePluginPackageService();
262

    
263
                        // Get and fill the package info data
264
                        PackageInfo info = makePluginService
265
                                        .getPluginPackageInfo(artifactId);
266

    
267
                        // info.setCode(artifactId);
268
                        info.setDescription(description);
269
                        info.setName(name);
270
                        info.setOfficial(official);
271
                        info.setState(state);
272
                        info.setType(installableType);
273
                        info.setVersion(version);
274
                        info.setBuild(buildNumber);
275
                        info.setOperatingSystem(operatingSystem);
276
                        info.setArchitecture(architecture);
277
                        info.setJavaVM(javaVM);
278
                        info.setGvSIGVersion(gvSIGVersion);
279
                        info.setDependencies(pkgdependencies);
280
                        info.setOwner(owner);
281
                        info.setSourcesURL(sourcesURL);
282
                        info.setWebURL(webURL);
283

    
284
                        makePluginService.writePackageInfo(info, packageInfoFolder);
285

    
286
                } catch (LocatorException e) {
287
                        throw new MojoExecutionException(
288
                                        "Error getting a reference to the InstallerManager", e);
289
                } catch (MakePluginPackageServiceException e) {
290
                        throw new MojoExecutionException(
291
                                        "Error getting a MakePluginPackageService for the "
292
                                                        + " plugin folder: " + pluginsFolder, e);
293
                }
294

    
295
                log.info("Package info file created successfully");
296
        }
297
}