Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2031 / extensions / org.gvsig.installer / org.gvsig.installer.maven / src / main / java / org / gvsig / installer / maven / GeneratePackageInfoMojo.java @ 36096

History | View | Annotate | Download (7.76 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

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

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

    
39
/**
40
 * Maven mojo to launch the gvSIG installer to generate a file with the
41
 * package info.
42
 * <p>
43
 * Look at the <a href=
44
 * "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.
116
     * One of: devel, pilot, prototype, alpha[num], beta[num], 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.
134
     * Examples: lin (linux), win (windows), 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.
144
     * 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.
154
     * Example: j1_5, j1_6.
155
     * 
156
     * Defaults to j1_5.
157
     * 
158
     * @parameter
159
     */
160
    private String javaVM;
161

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

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

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

    
185
    /**
186
     * Plugin project folder where to store the package info.
187
     * 
188
     * @parameter expression="${basedir}"
189
     * @required
190
     */
191
    private File packageInfoFolder;
192
    
193
    /**
194
     * Dependencies with other packages
195
     * 
196
     * @parameter default="${project.properties.package.info.pkgdependencies}" 
197
     */
198
    private String pkgdependencies;
199

    
200
    
201
    public void execute() throws MojoExecutionException, MojoFailureException {
202
        Log log = getLog();
203

    
204
        if (disabled) {
205
            log.info("Package info generation disabled.");
206
            return;
207
        }
208

    
209
        if (!"jar".equals(packaging)) {
210
            log.info("Running on a project with packaging of type " + packaging
211
                + ". Do nothing, as we only create installers for projects "
212
                + "with jar packaging");
213
            return;
214
        }
215

    
216
        log.info("Generating the package info for the plugin: " + artifactId
217
            + " with the following information:");
218
        log.info("\tPlugin name: " + name);
219
        log.info("\tPlugin description: " + description);
220
        log.info("\tPlugin version: " + version);
221
        log.info("\tPlugin build number: " + buildNumber);
222
        log.info("\tPlugin state: " + state);
223
        log.info("\tPlugin official: " + official);
224
        log.info("\tPlugin operatingSystem: " + operatingSystem);
225
        log.info("\tPlugin architecture: " + architecture);
226
        log.info("\tPlugin javaVM: " + javaVM);
227
        log.info("\tPlugin gvSIGVersion: " + gvSIGVersion);
228
        log.info("\tgvSIG Plugin's folder: " + pluginsFolder);
229
        log.info("\tPackage info folder: " + packageInfoFolder);
230
        log.info("\tDependencies: " + pkgdependencies);
231

    
232
        try {
233
            new DefaultLibrariesInitializer().fullInitialize();
234

    
235
            InstallerManager manager = InstallerLocator.getInstallerManager();
236

    
237
            MakePluginPackageService makePluginService =
238
                manager.getMakePluginPackageService(pluginsFolder);
239

    
240
            // Get and fill the package info data
241
            PackageInfo info =
242
                makePluginService.getPluginPackageInfo(artifactId);
243

    
244
            // info.setCode(artifactId);
245
            info.setDescription(description);
246
            info.setName(name);
247
            info.setOfficial(official);
248
            info.setState(state);
249
            info.setType(installableType);
250
            info.setVersion(version);
251
            info.setBuild(buildNumber);
252
            info.setOperatingSystem(operatingSystem);
253
            info.setArchitecture(architecture);
254
            info.setJavaVM(javaVM);
255
            info.setGvSIGVersion(gvSIGVersion);
256
            info.setDependencies(pkgdependencies);
257

    
258
            makePluginService.writePackageInfo(info, packageInfoFolder);
259

    
260
        } catch (LocatorException e) {
261
            throw new MojoExecutionException(
262
                "Error getting a reference to the InstallerManager", e);
263
        } catch (MakePluginPackageServiceException e) {
264
            throw new MojoExecutionException(
265
                "Error getting a MakePluginPackageService for the "
266
                    + " plugin folder: " + pluginsFolder, e);
267
        }
268

    
269
        log.info("Package info file created successfully");
270
    }
271
}