]> git.argeo.org Git - gpl/argeo-slc.git/blob - maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/UpdateManifestsMojo.java
Add update manifest feature
[gpl/argeo-slc.git] / maven / maven-argeo-osgi-plugin / src / main / java / org / argeo / slc / maven / plugins / osgi / UpdateManifestsMojo.java
1 package org.argeo.slc.maven.plugins.osgi;
2
3 import java.io.File;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.OutputStream;
7 import java.util.jar.Attributes;
8 import java.util.jar.Manifest;
9
10 import org.apache.commons.io.IOUtils;
11 import org.apache.maven.plugin.MojoExecutionException;
12 import org.apache.maven.plugin.MojoFailureException;
13
14 /**
15 * Update the manifests based on the POM
16 *
17 * @goal update-manifests
18 * @phase package
19 * @author mbaudier
20 *
21 */
22 public class UpdateManifestsMojo extends AbstractBundlesPackagerMojo {
23
24 public void execute() throws MojoExecutionException, MojoFailureException {
25 if (!PACKAGING_BUNDLE.equals(project.getPackaging())) {
26 getLog().info(
27 "Project is not of packaging type " + PACKAGING_BUNDLE
28 + ", skipping...");
29 }
30
31 int sIndex = snapshotIndex();
32 String versionMf = null;
33 if (sIndex >= 0) {// SNAPSHOT
34 versionMf = versionMain(sIndex) + ".SNAPSHOT";
35 } else {
36 throw new MojoExecutionException("Can only modify on SNAPSHOT");
37 }
38
39 File[] bundleDirs = getBundleDirectory().listFiles(bundleFileFilter());
40 for (int i = 0; i < bundleDirs.length; i++) {
41 OutputStream out = null;
42 try {
43 File dir = bundleDirs[i];
44 File originalMf = manifestFileFromDir(dir);
45 Manifest manifest = readManifest(originalMf);
46 manifest.getMainAttributes().putValue("Bundle-Version",
47 versionMf);
48 manifest.getMainAttributes().put(
49 Attributes.Name.MANIFEST_VERSION, "1.0");
50
51 out = new FileOutputStream(originalMf);
52 manifest.write(out);
53 getLog().info(
54 "Update MANIFEST of bundle " + dir + " with version "
55 + versionMf);
56 } catch (IOException e) {
57 throw new MojoExecutionException(
58 "Could not modify manifets. WARNING: some manifests may already have been modified! Check your sources.",
59 e);
60 } finally {
61 IOUtils.closeQuietly(out);
62 }
63 }
64
65 }
66 }