Add some variables.
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 28 Apr 2009 12:42:35 +0000 (12:42 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 28 Apr 2009 12:42:35 +0000 (12:42 +0000)
Use SNAPSHOT instead of qualifier.

git-svn-id: https://svn.argeo.org/slc/trunk/maven@2388 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

maven-argeo-osgi-plugin/pom.xml
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/DeployBundlesMojo.java
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/EquinoxExecMojo.java
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/InstallBundlesMojo.java
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/PackageBundlesMojo.java

index b7f2b6699a7ce0a61fde4846f0065649a9037411..26160740be086e2fdc739c7cb850a89146708ca9 100644 (file)
@@ -7,7 +7,7 @@
                <relativePath>..</relativePath>\r
        </parent>\r
        <artifactId>maven-argeo-osgi-plugin</artifactId>\r
-       <version>0.1.7</version>\r
+       <version>0.1.8</version>\r
        <packaging>maven-plugin</packaging>\r
        <name>Argeo OSGi Plugin</name>\r
 \r
index f3b15fe768b618211b21aaba3db547727e582d76..acc894107424a2716f26c101ff28286df1022bd8 100644 (file)
@@ -4,7 +4,9 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
@@ -46,7 +48,25 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
         */
        protected String bundlesPomArtifactId;
 
-       protected List analyze() throws MojoExecutionException {
+       /**
+        * Whether should fail if MANIFEST version are not in line with pom version.
+        * 
+        * @parameter expression="${strictManifestVersion}" default-value="false"
+        * @required
+        */
+       protected boolean strictManifestVersion;
+
+       /**
+        * Whether should fail if symbolic name does not match artifact id.
+        * 
+        * @parameter expression="${strictSymbolicName}" default-value="false"
+        * @required
+        */
+       protected boolean strictSymbolicName;
+
+       private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
+
+       protected List analyze(boolean willGenerate) throws MojoExecutionException {
                List list = new ArrayList();
 
                File[] bundleDirs = bundlesDirectory.listFiles(new FileFilter() {
@@ -58,87 +78,113 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
                        }
                });
                for (int i = 0; i < bundleDirs.length; i++) {
+
                        File dir = bundleDirs[i];
-                       File manifestFile = manifestFileFromDir(dir);
-                       String artifactId = dir.getName();
-                       File destFile = new File(packagedBundlesDir.getPath()
-                                       + File.separator + artifactId + ".jar");
+                       BundlePackage bundlePackage;
                        try {
-                               String manifestStr = FileUtils.readFileToString(manifestFile);
-                               char lastChar = manifestStr.charAt(manifestStr.length() - 1);
-                               if (lastChar != '\n')
-                                       throw new RuntimeException(
-                                                       "Manifest "
-                                                                       + manifestFile
-                                                                       + " is not valid, it does not end with and endline character.");
-
-                               Manifest manifest = readManifest(manifestFile);
-                               // Symbolic name
-                               String symbolicNameMf = manifest.getMainAttributes().getValue(
-                                               "Bundle-SymbolicName");
-                               if (!artifactId.equals(symbolicNameMf))
-                                       getLog().warn(
-                                                       "Symbolic name " + symbolicNameMf
-                                                                       + " does not match with directory name "
-                                                                       + artifactId);
-
-                               // Version
-                               String versionMf = manifest.getMainAttributes().getValue(
-                                               "Bundle-Version");
-                               int qIndex = versionMf.lastIndexOf(".qualifier");
-                               String versionMfMain;
-                               if (qIndex >= 0)
-                                       versionMfMain = versionMf.substring(0, qIndex);
-                               else
-                                       versionMfMain = versionMf;
-
-                               int sIndex = project.getVersion().lastIndexOf("-SNAPSHOT");
-                               String versionMain;
-                               boolean isSnapshot = false;
-                               if (sIndex >= 0) {// SNAPSHOT
-                                       versionMain = project.getVersion().substring(0, sIndex);
-                                       isSnapshot = true;
-                               } else {
-                                       versionMain = project.getVersion();
-                               }
-
-                               if (!versionMain.equals(versionMfMain))
-                                       getLog()
-                                                       .warn(
-                                                                       "Main manifest version "
-                                                                                       + versionMfMain
-                                                                                       + " of bundle "
-                                                                                       + artifactId
-                                                                                       + " do not match with main project version "
-                                                                                       + versionMain);
-
-                               String newVersionMf;
-                               String newVersionArt;
-                               if (isSnapshot) {
-                                       newVersionMf = versionMfMain + ".SNAPSHOT";
-                                       newVersionArt = versionMfMain + "-SNAPSHOT";
-                               } else {
-                                       newVersionMf = versionMfMain;
-                                       newVersionArt = versionMfMain;
-                               }
-
-                               manifest.getMainAttributes().putValue("Bundle-Version",
-                                               newVersionMf);
-                               manifest.getMainAttributes().put(
-                                               Attributes.Name.MANIFEST_VERSION, "1.0");
-
-                               Artifact artifact = artifactFactory.createBuildArtifact(project
-                                               .getGroupId(), artifactId, newVersionArt, "jar");
-                               BundlePackage bundlePackage = new BundlePackage(artifact, dir,
-                                               new Manifest(manifest), destFile);
-                               list.add(bundlePackage);
+                               bundlePackage = processBundleDir(dir, willGenerate);
                        } catch (Exception e) {
                                throw new MojoExecutionException("Could not analyze " + dir, e);
                        }
+                       list.add(bundlePackage);
+
                }
                return list;
        }
 
+       protected BundlePackage processBundleDir(File dir, boolean willGenerate)
+                       throws Exception {
+               File manifestFile = manifestFileFromDir(dir);
+               String artifactId = dir.getName();
+               File destFile = new File(packagedBundlesDir.getPath() + File.separator
+                               + artifactId + ".jar");
+
+               String manifestStr = FileUtils.readFileToString(manifestFile);
+               char lastChar = manifestStr.charAt(manifestStr.length() - 1);
+               if (lastChar != '\n')
+                       throw new RuntimeException("Manifest " + manifestFile
+                                       + " is not valid,"
+                                       + " it does not end with and endline character.");
+
+               Manifest manifest = readManifest(manifestFile);
+               // Symbolic name
+               String symbolicNameMf = manifest.getMainAttributes().getValue(
+                               "Bundle-SymbolicName");
+               if (!artifactId.equals(symbolicNameMf)) {
+                       String msg = "Symbolic name " + symbolicNameMf
+                                       + " does not match with directory name " + artifactId;
+                       if (strictSymbolicName)
+                               throw new RuntimeException(msg);
+                       else
+                               getLog().warn(msg);
+               }
+
+               // Version
+               String versionMf = manifest.getMainAttributes().getValue(
+                               "Bundle-Version");
+               int qIndex = versionMf.lastIndexOf(".SNAPSHOT");
+               String versionMfMain;
+               if (qIndex >= 0)
+                       versionMfMain = versionMf.substring(0, qIndex);
+               else
+                       versionMfMain = versionMf;
+
+               int sIndex = project.getModel().getVersion().lastIndexOf("-SNAPSHOT");
+               String versionMain;
+               String buildId;
+               boolean isSnapshot = false;
+               if (sIndex >= 0) {// SNAPSHOT
+                       versionMain = project.getVersion().substring(0, 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 = "";
+               }
+
+               if (!versionMain.equals(versionMfMain)) {
+                       String msg = "Main manifest version " + versionMfMain
+                                       + " of bundle " + artifactId
+                                       + " do not match with main project version " + versionMain;
+                       if (strictManifestVersion)
+                               throw new RuntimeException(msg);
+                       else
+                               getLog().warn(msg);
+               }
+
+               String newVersionMf = versionMfMain + "." + buildId;
+               String newVersionArt;
+               if (isSnapshot) {
+                       newVersionArt = versionMfMain + "-SNAPSHOT";
+               } else {
+                       newVersionArt = versionMfMain;
+               }
+
+               //boolean debug = true;
+               boolean debug = getLog().isDebugEnabled();
+               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);
+               }
+
+               manifest.getMainAttributes().putValue("Bundle-Version", newVersionMf);
+               manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION,
+                               "1.0");
+
+               Artifact artifact = artifactFactory.createBuildArtifact(project
+                               .getGroupId(), artifactId, newVersionArt, "jar");
+               return new BundlePackage(artifact, dir, new Manifest(manifest),
+                               destFile);
+       }
+
        protected File manifestFileFromDir(File dir) {
                return new File(dir + File.separator + "META-INF" + File.separator
                                + "MANIFEST.MF");
index 75b52b010d8a56801e70397e1e296952e2242c17..0483b40f419d915c821cd7e286a47a722900757b 100644 (file)
@@ -19,7 +19,7 @@ public class DeployBundlesMojo extends AbstractBundlesPackagerMojo {
        private ArtifactDeployer deployer;
 
        public void execute() throws MojoExecutionException, MojoFailureException {
-               List bundlePackages = analyze();
+               List bundlePackages = analyze(false);
                for (int i = 0; i < bundlePackages.size(); i++) {
                        AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages
                                        .get(i);
index c483c5250a3fd412845d4a5c3881ee1d668925c4..ea75a22838a001497edb694eb11666a981d19647 100644 (file)
@@ -55,8 +55,23 @@ public class EquinoxExecMojo extends AbstractOsgiMojo {
         */
        protected String[] jvmArgs;
 
+       /**
+        * JVM arguments to append
+        * 
+        * @parameter alias="${jvmArgsToAppend}"
+        */
+       protected String[] jvmArgsToAppend;
+
        protected String[] defaultJvmArgs = { "-Xmx128m" };
 
+       /**
+        * Debug port (0 deactivate)
+        * 
+        * @parameter expression="${debug}" default-value="0"
+        * @required
+        */
+       protected String debug;
+
        /**
         * Equinox args
         * 
@@ -64,6 +79,13 @@ public class EquinoxExecMojo extends AbstractOsgiMojo {
         */
        protected String[] args;
 
+       /**
+        * Equinox args to append
+        * 
+        * @parameter alias="${argsToAppend}"
+        */
+       protected String[] argsToAppend;
+
        protected String[] defaultArgs = { "-console", "-configuration", "conf",
                        "-data", "data" };
 
@@ -140,8 +162,20 @@ public class EquinoxExecMojo extends AbstractOsgiMojo {
 
                        // Build command
                        List cmdList = new ArrayList();
+                       // JVM
                        cmdList.add(jvm);
+                       // JVM arguments
                        cmdList.addAll(Arrays.asList(jvmArgs));
+
+                       if (!"0".equals(debug))
+                               cmdList
+                                               .add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="
+                                                               + debug);
+
+                       if (jvmArgsToAppend != null)
+                               cmdList.addAll(Arrays.asList(jvmArgsToAppend));
+
+                       // System properties
                        if (!systemProperties.containsKey("osgi.bundles"))
                                cmdList.add("-Dosgi.bundles="
                                                + osgiBootArtifact.getFile().getCanonicalPath()
@@ -160,9 +194,15 @@ public class EquinoxExecMojo extends AbstractOsgiMojo {
                                }
                                cmdList.add("-D" + key + "=" + strValue);
                        }
+
+                       // Equinox jar
                        cmdList.add("-jar");
                        cmdList.add(equinoxArtifact.getFile().getCanonicalPath());
+
+                       // Program arguments
                        cmdList.addAll(Arrays.asList(args));
+                       if (argsToAppend != null)
+                               cmdList.addAll(Arrays.asList(argsToAppend));
 
                        String[] cmd = (String[]) cmdList.toArray(new String[0]);
 
index d46ff5d40c6016fb6116ba200f156103b779be1b..d3b4dfa5678427564671cedc666382b57229160a 100644 (file)
@@ -19,7 +19,7 @@ public class InstallBundlesMojo extends AbstractBundlesPackagerMojo {
        private ArtifactInstaller installer;
 
        public void execute() throws MojoExecutionException, MojoFailureException {
-               List bundlePackages = analyze();
+               List bundlePackages = analyze(false);
                for (int i = 0; i < bundlePackages.size(); i++) {
                        AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages
                                        .get(i);
index ec61d5a8761c52e6030b6fcd01d26c6be66fd7ba..abb5fcf1bb20cd3789c011653916c5406cab6ae7 100644 (file)
@@ -44,7 +44,7 @@ public class PackageBundlesMojo extends AbstractBundlesPackagerMojo {
                bundlesPom.append("\t<packaging>pom</packaging>\n");
                bundlesPom.append("\t<dependencies>\n");
 
-               List bundlePackages = analyze();
+               List bundlePackages = analyze(true);
 
                for (int i = 0; i < bundlePackages.size(); i++) {
                        AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages