Introduce feature generation (not complete yet)
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 14 Jun 2009 21:38:51 +0000 (21:38 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 14 Jun 2009 21:38:51 +0000 (21:38 +0000)
Build number in MANIFEST

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

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/Feature.java [new file with mode: 0644]
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/FeatureDescriptorMojo.java [new file with mode: 0644]
maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/Plugin.java [new file with mode: 0644]
maven-argeo-osgi-plugin/src/main/resources/META-INF/plexus/components.xml

index 42ee07e11bacf79f633f8a0049f609632375c9af..b6f1f98a893a65714d55cddfbe724b2c961f7068 100644 (file)
@@ -73,6 +73,14 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
         */
        protected boolean strictSymbolicName;
 
+       /**
+        * Build number (provided by the build number plugin in general).
+        * 
+        * @parameter expression="${buildNumber}"
+        * @required
+        */
+       protected String buildNumber;
+
        private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
 
        protected List analyze(boolean willGenerate) throws MojoExecutionException {
@@ -138,12 +146,13 @@ public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo {
                if (sIndex >= 0) {// SNAPSHOT
                        versionMain = versionMain(sIndex);
                        // buildId = "D_" + sdf.format(new Date());// D for dev
-                       buildId = "SNAPSHOT";
+                       buildId = "SNAPSHOT-r" + buildNumber;
                        isSnapshot = true;
                } else {
                        versionMain = project.getVersion();
                        // buildId = "R_" + sdf.format(new Date());// R for release
-                       buildId = "R" + sdf.format(new Date());
+                       //buildId = "R" + sdf.format(new Date());
+                       buildId = "r" + buildNumber;
                }
 
                if (!versionMain.equals(versionMfMain)) {
diff --git a/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/Feature.java b/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/Feature.java
new file mode 100644 (file)
index 0000000..e0d8e93
--- /dev/null
@@ -0,0 +1,34 @@
+package org.argeo.slc.maven.plugins.osgi;
+
+import java.util.List;
+
+public class Feature {
+       private String updateSite;
+       private String copyright;
+       private List plugins;
+
+       public String getUpdateSite() {
+               return updateSite;
+       }
+
+       public void setUpdateSite(String license) {
+               this.updateSite = license;
+       }
+
+       public String getCopyright() {
+               return copyright;
+       }
+
+       public void setCopyright(String copyright) {
+               this.copyright = copyright;
+       }
+
+       public List getPlugins() {
+               return plugins;
+       }
+
+       public void setPlugins(List plugins) {
+               this.plugins = plugins;
+       }
+
+}
diff --git a/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/FeatureDescriptorMojo.java b/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/FeatureDescriptorMojo.java
new file mode 100644 (file)
index 0000000..9507f69
--- /dev/null
@@ -0,0 +1,177 @@
+package org.argeo.slc.maven.plugins.osgi;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarInputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.License;
+import org.apache.maven.model.Organization;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.argeo.slc.maven.plugin.MavenDependencyManager;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+
+/**
+ * Generates a feature descriptor based on the pom
+ * 
+ * @goal featureDescriptor
+ * @phase process-resources
+ */
+public class FeatureDescriptorMojo extends AbstractOsgiMojo {
+       /** @component */
+       private MavenDependencyManager mavenDependencyManager;
+
+       /**
+        * The Maven project.
+        * 
+        * @parameter expression="${project}"
+        * @required
+        * @readonly
+        */
+       private MavenProject project;
+
+       /**
+        * The directory for the pom
+        * 
+        * @parameter expression="${basedir}"
+        * @required
+        */
+       private File baseDir;
+
+       /**
+        * Information about the feature
+        * 
+        * @parameter expression="${argeo-pde.feature}"
+        */
+       private Feature feature;
+
+       public void execute() throws MojoExecutionException {
+               File featureDesc = new File(baseDir, "feature.xml");
+               FileWriter fileWriter = null;
+               try {
+                       fileWriter = new FileWriter(featureDesc);
+                       PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter(
+                                       fileWriter);
+                       xmlWriter.startElement("feature");
+                       xmlWriter.addAttribute("id", project.getArtifactId());
+                       xmlWriter.addAttribute("label", project.getName());
+
+                       // Version
+                       String projectVersion = project.getVersion();
+                       int indexSnapshot = projectVersion.indexOf("-SNAPSHOT");
+                       if (indexSnapshot > -1)
+                               projectVersion = projectVersion.substring(0, indexSnapshot);
+                       projectVersion = projectVersion + ".qualifier";
+
+                       // project.
+                       xmlWriter.addAttribute("version", projectVersion);
+
+                       Organization organization = project.getOrganization();
+                       if (organization != null && organization.getName() != null)
+                               xmlWriter.addAttribute("provider-name", organization.getName());
+
+                       if (project.getDescription() != null || project.getUrl() != null) {
+                               xmlWriter.startElement("description");
+                               if (project.getUrl() != null)
+                                       xmlWriter.addAttribute("url", project.getUrl());
+                               if (project.getDescription() != null)
+                                       xmlWriter.writeText(project.getDescription());
+                               xmlWriter.endElement();// description
+                       }
+
+                       if (feature != null && feature.getCopyright() != null
+                                       || (organization != null && organization.getUrl() != null)) {
+                               xmlWriter.startElement("copyright");
+                               if (organization != null && organization.getUrl() != null)
+                                       xmlWriter.addAttribute("url", organization.getUrl());
+                               if (feature.getCopyright() != null)
+                                       xmlWriter.writeText(feature.getCopyright());
+                               xmlWriter.endElement();// copyright
+                       }
+
+                       if (feature != null && feature.getUpdateSite() != null) {
+                               xmlWriter.startElement("url");
+                               xmlWriter.startElement("update");
+                               xmlWriter.addAttribute("url", feature.getUpdateSite());
+                               xmlWriter.endElement();// update
+                               xmlWriter.endElement();// url
+                       }
+
+                       List licenses = project.getLicenses();
+                       if (licenses.size() > 0) {
+                               // take the first one
+                               License license = (License) licenses.get(0);
+                               xmlWriter.startElement("license");
+
+                               if (license.getUrl() != null)
+                                       xmlWriter.addAttribute("url", license.getUrl());
+                               if (license.getComments() != null)
+                                       xmlWriter.writeText(license.getComments());
+                               else if (license.getName() != null)
+                                       xmlWriter.writeText(license.getName());
+                               xmlWriter.endElement();// license
+                       }
+
+                       // deploymentRepository.pathOf(null);
+                       Set dependencies = mavenDependencyManager
+                                       .getTransitiveProjectDependencies(project, remoteRepos,
+                                                       local);
+                       for (Iterator it = dependencies.iterator(); it.hasNext();) {
+                               Artifact depArtifact = (Artifact) it.next();
+
+                               String symbolicName = null;
+                               String version = null;
+                               File artifactFile = depArtifact.getFile();
+                               JarInputStream jarInputStream = null;
+                               try {
+                                       jarInputStream = new JarInputStream(new FileInputStream(
+                                                       artifactFile));
+                                       symbolicName = jarInputStream.getManifest()
+                                                       .getMainAttributes()
+                                                       .getValue("Bundle-SymbolicName");
+                                       version = jarInputStream.getManifest().getMainAttributes()
+                                                       .getValue("Bundle-Version");
+                               } catch (Exception e) {
+                                       // probably not a jar, skipping
+                                       if (getLog().isDebugEnabled())
+                                               getLog().debug(
+                                                               "Skipping artifact " + depArtifact
+                                                                               + " because of " + e.getMessage());
+                                       continue;
+                               } finally {
+                                       IOUtils.closeQuietly(jarInputStream);
+                               }
+
+                               if (symbolicName != null && version != null) {
+                                       xmlWriter.startElement("plugin");
+                                       xmlWriter.addAttribute("id", symbolicName);
+                                       xmlWriter.addAttribute("version", version);
+                                       xmlWriter.addAttribute("unpack", "false");
+                                       xmlWriter.endElement();// plugin
+                               }
+                       }
+                       /*
+                        * List plugins = feature.getPlugins(); for (int i = 0; i <
+                        * plugins.size(); i++) { Plugin plugin = (Plugin) plugins.get(i);
+                        * xmlWriter.startElement("plugin"); xmlWriter.addAttribute("id",
+                        * plugin.getId()); xmlWriter.addAttribute("version",
+                        * plugin.getVersion()); xmlWriter.addAttribute("unpack",
+                        * plugin.getUnpack()); xmlWriter.endElement();// plugin }
+                        */
+                       xmlWriter.endElement();// feature
+               } catch (Exception e) {
+                       throw new MojoExecutionException("Cannot write feature descriptor",
+                                       e);
+               }
+               IOUtil.close(fileWriter);
+               getLog().info("FeatureDescriptorMojo done");
+       }
+}
diff --git a/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/Plugin.java b/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/Plugin.java
new file mode 100644 (file)
index 0000000..adcbcc9
--- /dev/null
@@ -0,0 +1,32 @@
+package org.argeo.slc.maven.plugins.osgi;
+
+public class Plugin {
+       private String id;
+       private String version;
+       private String unpack = "false";
+
+       public String getId() {
+               return id;
+       }
+
+       public void setId(String id) {
+               this.id = id;
+       }
+
+       public String getVersion() {
+               return version;
+       }
+
+       public void setVersion(String version) {
+               this.version = version;
+       }
+
+       public String getUnpack() {
+               return unpack;
+       }
+
+       public void setUnpack(String unpack) {
+               this.unpack = unpack;
+       }
+
+}
index d9ad3c56d56201853f04d8822a3d40390cbebc19..c4a3929373587d45d9dd6edb0f1a7d8b0661b84e 100644 (file)
                        <configuration>
                                <phases>
                                        <package>
-                                               org.argeo.slc.maven:maven-argeo-osgi-plugin:package-bundles
+                                               org.argeo.maven.plugins:maven-argeo-osgi-plugin:package-bundles
                                        </package>
                                        <install>
-                                               org.argeo.slc.maven:maven-argeo-osgi-plugin:install-bundles
+                                               org.argeo.maven.plugins:maven-argeo-osgi-plugin:install-bundles
                                        </install>
                                        <deploy>
-                                               org.argeo.slc.maven:maven-argeo-osgi-plugin:deploy-bundles
+                                               org.argeo.maven.plugins:maven-argeo-osgi-plugin:deploy-bundles
                                        </deploy>
                                </phases>
                        </configuration>