Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.maven / src / main / java / org / gvsig / installer / maven / GeneratePackageInfoMojo.java @ 40395

History | View | Annotate | Download (7.65 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
         */
111
        private int buildNumber = -1;
112

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

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

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

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

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

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

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

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

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

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

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

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

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

    
218
        /**
219
         * addon categories.
220
         * 
221
         * @parameter
222
         */
223
        private String categories;
224

    
225
        public void execute() throws MojoExecutionException, MojoFailureException {
226
                Log log = getLog();
227

    
228
                if (disabled) {
229
                        log.info("Package info generation disabled.");
230
                        return;
231
                }
232
                if( buildNumber == -1 ) {
233
                        log.info("Skip package info generation, undefined buildNumber property.");
234
                        return;
235
                }
236

    
237
                if (!"jar".equals(packaging)) {
238
                        log
239
                                        .info("Running on a project with packaging of type "
240
                                                        + packaging
241
                                                        + ". Do nothing, as we only create installers for projects "
242
                                                        + "with jar packaging");
243
                        return;
244
                }
245

    
246
                log.info("Generating the package info for the plugin: " + artifactId
247
                                + " with the following information:");
248
                log.info("\tPlugin name: " + name);
249
                log.info("\tPlugin description: " + description);
250
                log.info("\tPlugin version: " + version);
251
                log.info("\tPlugin build number: " + buildNumber);
252
                log.info("\tPlugin state: " + state);
253
                log.info("\tPlugin official: " + official);
254
                log.info("\tPlugin operatingSystem: " + operatingSystem);
255
                log.info("\tPlugin architecture: " + architecture);
256
                log.info("\tPlugin javaVM: " + javaVM);
257
                log.info("\tPlugin gvSIGVersion: " + gvSIGVersion);
258
                log.info("\tgvSIG Plugin's folder: " + pluginsFolder);
259
                log.info("\tPackage info folder: " + packageInfoFolder);
260
                log.info("\tDependencies: " + pkgdependencies);
261
                log.info("\tOwner: " + owner);
262
                log.info("\tSources URL: " + sourcesURL);
263
                log.info("\tWeb URL: " + webURL);
264
                log.info("\tCategories: " + categories);
265

    
266
                try {
267
                        new DefaultLibrariesInitializer().fullInitialize();
268

    
269
                        InstallerManager manager = InstallerLocator.getInstallerManager();
270
                        
271
                        manager.setDefaultLocalAddonRepository(pluginsFolder);
272
                        MakePluginPackageService makePluginService = manager.getMakePluginPackageService();
273

    
274
                        // Get and fill the package info data
275
                        PackageInfo info = makePluginService.getPluginPackageInfo(artifactId);
276

    
277
                        // info.setCode(artifactId);
278
                        info.setDescription(description);
279
                        info.setName(name);
280
                        info.setOfficial(official);
281
                        info.setState(state);
282
                        info.setType(installableType);
283
                        info.setVersion(version);
284
                        info.setBuild(buildNumber);
285
                        info.setOperatingSystem(operatingSystem);
286
                        info.setArchitecture(architecture);
287
                        info.setJavaVM(javaVM);
288
                        info.setGvSIGVersion(gvSIGVersion);
289
                        info.setDependencies(pkgdependencies);
290
                        info.setOwner(owner);
291
                        info.setSourcesURL(sourcesURL);
292
                        info.setWebURL(webURL);
293
                        info.addCategoriesAsString(categories);
294

    
295
                        makePluginService.writePackageInfo(info, packageInfoFolder);
296

    
297
                } catch (LocatorException e) {
298
                        throw new MojoExecutionException(
299
                                        "Error getting a reference to the InstallerManager", e);
300
                } catch (MakePluginPackageServiceException e) {
301
                        throw new MojoExecutionException(
302
                                        "Error getting a MakePluginPackageService for the "
303
                                                        + " plugin folder: " + pluginsFolder, e);
304
                }
305

    
306
                log.info("Package info file created successfully");
307
        }
308
}