1 package org
.argeo
.slc
.maven
.plugins
.osgi
;
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
;
10 import org
.apache
.commons
.io
.IOUtils
;
11 import org
.apache
.maven
.plugin
.MojoExecutionException
;
12 import org
.apache
.maven
.plugin
.MojoFailureException
;
15 * Update the manifests based on the POM
17 * @goal update-manifests
22 public class UpdateManifestsMojo
extends AbstractBundlesPackagerMojo
{
24 public void execute() throws MojoExecutionException
, MojoFailureException
{
25 if (!PACKAGING_BUNDLE
.equals(project
.getPackaging())) {
27 "Project is not of packaging type " + PACKAGING_BUNDLE
31 int sIndex
= snapshotIndex();
32 String versionMf
= null;
33 if (sIndex
>= 0) {// SNAPSHOT
34 versionMf
= versionMain(sIndex
) + ".SNAPSHOT";
36 throw new MojoExecutionException("Can only modify on SNAPSHOT");
39 File
[] bundleDirs
= getBundleDirectory().listFiles(bundleFileFilter());
40 for (int i
= 0; i
< bundleDirs
.length
; i
++) {
41 OutputStream out
= null;
43 File dir
= bundleDirs
[i
];
44 File originalMf
= manifestFileFromDir(dir
);
45 Manifest manifest
= readManifest(originalMf
);
46 manifest
.getMainAttributes().putValue("Bundle-Version",
48 manifest
.getMainAttributes().put(
49 Attributes
.Name
.MANIFEST_VERSION
, "1.0");
51 out
= new FileOutputStream(originalMf
);
54 "Update MANIFEST of bundle " + dir
+ " with version "
56 } catch (IOException e
) {
57 throw new MojoExecutionException(
58 "Could not modify manifets. WARNING: some manifests may already have been modified! Check your sources.",
61 IOUtils
.closeQuietly(out
);