Revision 37599 branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.maven/src/main/java/org/gvsig/installer/maven/AbstractGeneratePackageMojo.java

View differences:

AbstractGeneratePackageMojo.java
45 45
 * Abstract Maven mojo to launch the gvSIG installer to generate a package of a
46 46
 * gvSIG plugin.
47 47
 * <p>
48
 * Look at the <a href=
49
 * "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"
48
 * 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"
50 49
 * >gvSIG plugin naming standard</a> for information about installers naming and
51 50
 * versioning.
52 51
 * </p>
......
58 57
 */
59 58
public abstract class AbstractGeneratePackageMojo extends AbstractMojo {
60 59

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

  
69
    /**
70
     * Location of the folder where to create the package file.
71
     * 
72
     * @parameter
73
     * @required
74
     */
75
    private File packageFolder;
68
	/**
69
	 * Location of the folder where to create the package file.
70
	 * 
71
	 * @parameter
72
	 * @required
73
	 */
74
	private File packageFolder;
76 75

  
77
    /**
78
     * Name of the package file. If not provided, the
79
     * official gvSIG name will be used, as provided by
80
     * the org.gvsig.installer.lib.api.InstallerManager.
81
     * 
82
     * @parameter
83
     */
84
    private String packageFileName;
76
	/**
77
	 * Name of the package file. If not provided, the official gvSIG name will
78
	 * be used, as provided by the org.gvsig.installer.lib.api.InstallerManager.
79
	 * 
80
	 * @parameter
81
	 */
82
	private String packageFileName;
85 83

  
86
    /**
87
     * Plugin project artifactId or code, used as gvSIG plugin name.
88
     * 
89
     * @parameter expression="${project.artifactId}"
90
     * @required
91
     */
92
    private String artifactId;
84
	/**
85
	 * Plugin project artifactId or code, used as gvSIG plugin name.
86
	 * 
87
	 * @parameter expression="${project.artifactId}"
88
	 * @required
89
	 */
90
	private String artifactId;
93 91

  
94
    /**
95
     * Plugin project packaging, to check it is of jar type.
96
     * 
97
     * @parameter expression="${project.packaging}"
98
     * @required
99
     */
100
    private String packaging;
92
	/**
93
	 * Plugin project packaging, to check it is of jar type.
94
	 * 
95
	 * @parameter expression="${project.packaging}"
96
	 * @required
97
	 */
98
	private String packaging;
101 99

  
102
    /**
103
     * If the mojo execution is disabled. Useful for projects that inherit
104
     * the maven plugin configuration but don't generate installer.
105
     * 
106
     * @parameter
107
     */
108
    private boolean disabled = false;
100
	/**
101
	 * If the mojo execution is disabled. Useful for projects that inherit the
102
	 * maven plugin configuration but don't generate installer.
103
	 * 
104
	 * @parameter
105
	 */
106
	private boolean disabled = false;
109 107

  
110
    public void execute() throws MojoExecutionException, MojoFailureException {
111
        String packageName;
112
        MakePluginPackageService makePluginService;
113
        File packageBundleFile = null;
108
	public void execute() throws MojoExecutionException, MojoFailureException {
109
		String packageName;
110
		MakePluginPackageService makePluginService;
111
		File packageBundleFile = null;
114 112

  
115
        Log log = getLog();
113
		Log log = getLog();
116 114

  
117
        if (disabled) {
118
            log.info(getPackageTypeName() + " generation disabled.");
119
            return;
120
        }
115
		if (disabled) {
116
			log.info(getPackageTypeName() + " generation disabled.");
117
			return;
118
		}
121 119

  
122
        if (!"jar".equals(packaging)) {
123
            log.info("Running on a project with packaging of type " + packaging
124
                + ". Do nothing, as we only create installers for projects "
125
                + "with jar packaging");
126
            return;
127
        }
120
		if (!"jar".equals(packaging)) {
121
			log
122
					.info("Running on a project with packaging of type "
123
							+ packaging
124
							+ ". Do nothing, as we only create installers for projects "
125
							+ "with jar packaging");
126
			return;
127
		}
128 128

  
129
        log.info("Generating a " + getPackageTypeName() + " for the plugin: "
130
            + artifactId + " with the following information:");
131
        log.info("\tgvSIG Plugin's folder: " + pluginsFolder);
132
        log.info("\tPackage file destination folder: " + packageFolder);
129
		log.info("Generating a " + getPackageTypeName() + " for the plugin: "
130
				+ artifactId + " with the following information:");
131
		log.info("\tgvSIG Plugin's folder: " + pluginsFolder);
132
		log.info("\tPackage file destination folder: " + packageFolder);
133 133

  
134
        try {
135
            new DefaultLibrariesInitializer().fullInitialize();
134
		try {
135
			new DefaultLibrariesInitializer().fullInitialize();
136 136

  
137
            InstallerManager manager = InstallerLocator.getInstallerManager();
137
			InstallerManager manager = InstallerLocator.getInstallerManager();
138 138

  
139
            makePluginService =
140
                manager.getMakePluginPackageService(pluginsFolder);
141
        } catch (LocatorException e) {
142
            throw new MojoExecutionException(
143
                "Error getting a reference to the InstallerManager", e);
144
        } catch (MakePluginPackageServiceException e) {
145
            throw new MojoExecutionException(
146
                "Error getting a MakePluginPackageService for the "
147
                    + " plugin folder: " + pluginsFolder, e);
148
        }
139
			makePluginService = manager
140
					.getMakePluginPackageService(pluginsFolder);
141
		} catch (LocatorException e) {
142
			throw new MojoExecutionException(
143
					"Error getting a reference to the InstallerManager", e);
144
		} catch (MakePluginPackageServiceException e) {
145
			throw new MojoExecutionException(
146
					"Error getting a MakePluginPackageService for the "
147
							+ " plugin folder: " + pluginsFolder, e);
148
		}
149 149

  
150
        // Get and fill the package info data
151
        PackageInfo info = makePluginService.getPluginPackageInfo(artifactId);
150
		// Get and fill the package info data
151
		PackageInfo info = makePluginService.getPluginPackageInfo(artifactId);
152 152

  
153
        log.info("Creating package of the package info:");
154
        log.info(info.toString());
153
		log.info("Creating package of the package info:");
154
		log.info(info.toString());
155 155

  
156
        // Create the package bundle file
157
        packageName =
158
            packageFileName == null ? getPackageFileName(info)
159
                : packageFileName;
160
        if (!packageFolder.exists()) {
161
            packageFolder.mkdirs();
162
        }
163
        packageBundleFile = new File(packageFolder, packageName);
156
		// Create the package bundle file
157
		packageName = packageFileName == null ? getPackageFileName(info)
158
				: packageFileName;
159
		if (!packageFolder.exists()) {
160
			packageFolder.mkdirs();
161
		}
162
		packageBundleFile = new File(packageFolder, packageName);
164 163

  
165
        try {
166
            FileOutputStream fos = new FileOutputStream(packageBundleFile);
167
            BufferedOutputStream bos = new BufferedOutputStream(fos);
164
		try {
165
			FileOutputStream fos = new FileOutputStream(packageBundleFile);
166
			BufferedOutputStream bos = new BufferedOutputStream(fos);
168 167

  
169
            createPackage(makePluginService, info, bos);
168
			createPackage(makePluginService, info, bos);
170 169

  
171
            bos.flush();
172
            bos.close();
173
            fos.close();
174
        } catch (FileNotFoundException e) {
175
            throw new MojoExecutionException("Error creating the "
176
                + getPackageTypeName() + " file: " + packageBundleFile, e);
177
        } catch (MakePluginPackageServiceException e) {
178
            throw new MojoExecutionException(
179
                "Error creating the package file: " + packageName
180
                    + ", for the plugin: " + artifactId, e);
181
        } catch (IOException e) {
182
            throw new MojoExecutionException("I/O error writing the "
183
                + getPackageTypeName() + " file: " + packageBundleFile, e);
184
        }
170
			bos.flush();
171
			bos.close();
172
			fos.close();
173
		} catch (FileNotFoundException e) {
174
			throw new MojoExecutionException("Error creating the "
175
					+ getPackageTypeName() + " file: " + packageBundleFile, e);
176
		} catch (MakePluginPackageServiceException e) {
177
			throw new MojoExecutionException(
178
					"Error creating the package file: " + packageName
179
							+ ", for the plugin: " + artifactId, e);
180
		} catch (IOException e) {
181
			throw new MojoExecutionException("I/O error writing the "
182
					+ getPackageTypeName() + " file: " + packageBundleFile, e);
183
		}
185 184

  
186
        log.info(getPackageTypeName() + " file created successfully as: "
187
            + packageName);
188
    }
185
		log.info(getPackageTypeName() + " file created successfully as: "
186
				+ packageName);
187
	}
189 188

  
190
    /**
191
     * Returns the name of the package file to create.
192
     * 
193
     * @param info
194
     *            package information
195
     * @return the name of the file to create
196
     */
197
    protected abstract String getPackageFileName(PackageInfo info);
189
	/**
190
	 * Returns the name of the package file to create.
191
	 * 
192
	 * @param info
193
	 *            package information
194
	 * @return the name of the file to create
195
	 */
196
	protected abstract String getPackageFileName(PackageInfo info);
198 197

  
199
    /**
200
     * Returns the name of the package type to create.
201
     * 
202
     * @return the name of the package type to create
203
     */
204
    protected abstract String getPackageTypeName();
198
	/**
199
	 * Returns the name of the package type to create.
200
	 * 
201
	 * @return the name of the package type to create
202
	 */
203
	protected abstract String getPackageTypeName();
205 204

  
206
    /**
207
     * Creates the package file into the given {@link OutputStream}.
208
     * 
209
     * @param makePluginService
210
     *            to use to create the package
211
     * @param info
212
     *            the information of the package to create
213
     * @param os
214
     *            where to create the package file
215
     * @throws MakePluginPackageServiceException
216
     *             if there is an error creating the package file
217
     */
218
    protected abstract void createPackage(
219
        MakePluginPackageService makePluginService, PackageInfo info,
220
        OutputStream os) throws MakePluginPackageServiceException;
205
	/**
206
	 * Creates the package file into the given {@link OutputStream}.
207
	 * 
208
	 * @param makePluginService
209
	 *            to use to create the package
210
	 * @param info
211
	 *            the information of the package to create
212
	 * @param os
213
	 *            where to create the package file
214
	 * @throws MakePluginPackageServiceException
215
	 *             if there is an error creating the package file
216
	 */
217
	protected abstract void createPackage(
218
			MakePluginPackageService makePluginService, PackageInfo info,
219
			OutputStream os) throws MakePluginPackageServiceException;
221 220
}

Also available in: Unified diff