X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=maven%2Fmaven-argeo-osgi-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fmaven%2Fplugins%2Fosgi%2FAbstractBundlesPackagerMojo.java;h=42ee07e11bacf79f633f8a0049f609632375c9af;hb=059c8746edde7073bcb18af43da7195bd8958d81;hp=53f686099bce229a4b6b3087b90dc48964fd7062;hpb=27c9c497496706fce1a3a81fb05688b9d81c92d4;p=gpl%2Fargeo-slc.git
diff --git a/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java
index 53f686099..42ee07e11 100644
--- a/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java
+++ b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java
@@ -3,7 +3,6 @@ package org.argeo.slc.maven.plugins.osgi;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -13,16 +12,12 @@ import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.ProjectArtifactMetadata;
/**
+ * Base class for MoJo analyzing a set of bundles directories.
+ *
* @author mbaudier
*
*/
@@ -61,6 +56,15 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
*/
protected boolean strictManifestVersion;
+ /**
+ * Whether the manifest should be updated with the release version.
+ *
+ * @parameter expression="${updateManifestWhenReleasing}"
+ * default-value="true"
+ * @required
+ */
+ protected boolean updateManifestWhenReleasing;
+
/**
* Whether should fail if symbolic name does not match artifact id.
*
@@ -74,14 +78,7 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
protected List analyze(boolean willGenerate) throws MojoExecutionException {
List list = new ArrayList();
- File[] bundleDirs = bundlesDirectory.listFiles(new FileFilter() {
- public boolean accept(File file) {
- if (!file.isDirectory())
- return false;
-
- return manifestFileFromDir(file).exists();
- }
- });
+ File[] bundleDirs = bundlesDirectory.listFiles(bundleFileFilter());
for (int i = 0; i < bundleDirs.length; i++) {
File dir = bundleDirs[i];
@@ -134,19 +131,19 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
else
versionMfMain = versionMf;
- int sIndex = project.getModel().getVersion().lastIndexOf("-SNAPSHOT");
+ int sIndex = snapshotIndex();
String versionMain;
String buildId;
boolean isSnapshot = false;
if (sIndex >= 0) {// SNAPSHOT
- versionMain = project.getVersion().substring(0, sIndex);
+ versionMain = versionMain(sIndex);
// buildId = "D_" + sdf.format(new Date());// D for dev
buildId = "SNAPSHOT";
isSnapshot = true;
} else {
versionMain = project.getVersion();
// buildId = "R_" + sdf.format(new Date());// R for release
- buildId = "";
+ buildId = "R" + sdf.format(new Date());
}
if (!versionMain.equals(versionMfMain)) {
@@ -172,11 +169,6 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
if (debug && willGenerate) {
getLog().info("\n## " + artifactId);
getLog().info("project.getVersion()=" + project.getVersion());
- // getLog().info(
- // "project.getModel().getVersion()="
- // + project.getModel().getVersion());
- // getLog().info("versionMf=" + versionMf);
- // getLog().info("buildId=" + buildId);
getLog().info("newVersionMf=" + newVersionMf);
}
@@ -220,20 +212,21 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
pom.append("\t" + artifactId + "\n");
pom.append("\t" + packaging + "\n");
return pom;
-
+
// TODO: use the Model object e.g.: (from install plugin)
-// Model model = new Model();
-// model.setModelVersion( "4.0.0" );
-// model.setGroupId( groupId );
-// model.setArtifactId( artifactId );
-// model.setVersion( version );
-// model.setPackaging( packaging );
-// model.setDescription( "POM was created from install:install-file" );
-// fw = new FileWriter( tempFile );
-// tempFile.deleteOnExit();
-// new MavenXpp3Writer().write( fw, model );
-// ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, tempFile );
-// artifact.addMetadata( metadata );
+ // Model model = new Model();
+ // model.setModelVersion( "4.0.0" );
+ // model.setGroupId( groupId );
+ // model.setArtifactId( artifactId );
+ // model.setVersion( version );
+ // model.setPackaging( packaging );
+ // model.setDescription( "POM was created from install:install-file" );
+ // fw = new FileWriter( tempFile );
+ // tempFile.deleteOnExit();
+ // new MavenXpp3Writer().write( fw, model );
+ // ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact,
+ // tempFile );
+ // artifact.addMetadata( metadata );
}
@@ -243,6 +236,37 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
return pom.toString();
}
+ protected Manifest readManifest(File file) throws IOException {
+ Manifest manifest = new Manifest();
+ FileInputStream in = new FileInputStream(file);
+ manifest.read(in);
+ in.close();
+ return manifest;
+ }
+
+ protected int snapshotIndex() {
+ return project.getModel().getVersion().lastIndexOf("-SNAPSHOT");
+ }
+
+ protected String versionMain(int sIndex) {
+ return project.getVersion().substring(0, sIndex);
+ }
+
+ protected File getBundleDirectory() {
+ return bundlesDirectory;
+ }
+
+ protected FileFilter bundleFileFilter() {
+ return new FileFilter() {
+ public boolean accept(File file) {
+ if (!file.isDirectory())
+ return false;
+
+ return manifestFileFromDir(file).exists();
+ }
+ };
+ }
+
protected static class BundlePackage {
private final Artifact artifact;
private final File bundleDir;
@@ -281,13 +305,11 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
public File getPomFile() {
return new File(getPackageFile().getPath() + ".pom.xml");
}
- }
- protected Manifest readManifest(File file) throws IOException {
- Manifest manifest = new Manifest();
- FileInputStream in = new FileInputStream(file);
- manifest.read(in);
- in.close();
- return manifest;
+ public String toString() {
+ return "Bundle: " + bundleDir;
+ }
+
}
+
}