servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r594352 - in /incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main: java/org/apache/servicemix/maven/plugin/jbi/ resources/META-INF/plexus/
Date Mon, 12 Nov 2007 23:56:56 GMT
Author: gnodet
Date: Mon Nov 12 15:56:55 2007
New Revision: 594352

URL: http://svn.apache.org/viewvc?rev=594352&view=rev
Log:
SM-1135: Put mandatory osgi entries in the JBI artifacts so that those artifacts can be deployed
as bundles

Modified:
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java?rev=594352&r1=594351&r2=594352&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java
(original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java
Mon Nov 12 15:56:55 2007
@@ -27,6 +27,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
@@ -46,6 +48,8 @@
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.servicemix.maven.plugin.jbi.JbiResolutionListener.Node;
+import org.codehaus.plexus.archiver.jar.Manifest;
+import org.codehaus.plexus.archiver.jar.ManifestException;
 
 public abstract class AbstractJbiMojo extends AbstractMojo {
 
@@ -55,6 +59,10 @@
 
     public static final String LIB_DIRECTORY = "lib";
 
+    private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+(\\.\\d+(\\.\\d+)?)?)-");
+
+    private static final String[] VERSION_COMPLETERS = new String[] {".0.0", ".0" };
+
     /**
      * Maven ProjectHelper
      * 
@@ -297,4 +305,34 @@
                     "Error during setting up classpath", e);
         }
     }
+
+    protected Manifest createManifest() throws ManifestException {
+        Manifest manifest = new Manifest();
+        manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Bundle-Name",
project.getName()));
+        manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Bundle-SymbolicName",
project.getArtifactId()));
+        manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Bundle-Version",
fixBundleVersion(project.getVersion())));
+        return manifest;
+    }
+
+    private static String fixBundleVersion(String version) {
+        // Maven uses a '-' to separate the version qualifier, while
+        // OSGi uses a '.', so we need to convert the first '-' to a
+        // '.' and fill in any missing minor or micro version
+        // components if necessary.
+        final Matcher matcher = VERSION_PATTERN.matcher(version);
+        if (!matcher.lookingAt()) {
+            return version;
+        }
+        // Leave extra space for worst-case additional insertion:
+        final StringBuffer sb = new StringBuffer(version.length() + 4);
+        sb.append(matcher.group(1));
+        if (null == matcher.group(3)) {
+            final int count = null != matcher.group(2) ? 2 : 1;
+            sb.append(VERSION_COMPLETERS[count - 1]);
+        }
+        sb.append('.');
+        sb.append(version.substring(matcher.end(), version.length()));
+        return sb.toString();
+    }
+
 }

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java?rev=594352&r1=594351&r2=594352&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
(original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
Mon Nov 12 15:56:55 2007
@@ -33,6 +33,7 @@
 import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.jar.Manifest;
 import org.codehaus.plexus.archiver.jar.ManifestException;
 import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
@@ -129,6 +130,8 @@
             archiver.setArchiver(jarArchiver);
             archiver.setOutputFile(installerFile);
             jarArchiver.addDirectory(workDirectory);
+            Manifest manifest = createManifest();
+            jarArchiver.addConfiguredManifest(manifest);
             if (jbiSourceDirectory.isDirectory()) {
                 jarArchiver.addDirectory(jbiSourceDirectory, null,
                         DirectoryScanner.DEFAULTEXCLUDES);

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java?rev=594352&r1=594351&r2=594352&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java
(original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java
Mon Nov 12 15:56:55 2007
@@ -21,6 +21,8 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -29,6 +31,8 @@
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingException;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -45,50 +49,94 @@
 public class GenerateServiceAssemblyMojo extends AbstractJbiMojo {
 
     /**
+     * The Zip archiver.
+     *
+     * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
+     * @required
+     */
+    private JarArchiver jarArchiver;
+
+    /**
      * Directory where the application.xml file will be auto-generated.
      * 
-     * @parameter expression="${project.build.directory}/classes"
+     * @parameter expression="${project.build.directory}/sus"
      * @required
      */
     private File workDirectory;
 
+    /**
+     * The directory for the generated JBI component.
+     *
+     * @parameter expression="${project.build.directory}"
+     * @required
+     */
+    private File outputDirectory;
+
+    /**
+     * The name of the generated war.
+     *
+     * @parameter expression="${project.build.finalName}.zip"
+     * @required
+     */
+    private String finalName;
+
+    /**
+     * The maven archive configuration to use.
+     *
+     * @parameter
+     */
+    private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
     public void execute() throws MojoExecutionException, MojoFailureException {
         try {
             injectDependentServiceUnits();
+
+            createArchive(new File(outputDirectory, finalName));
+
+            projectHelper.attachArtifact(project, "zip", null, new File(outputDirectory,
finalName));
         } catch (Exception e) {
             throw new MojoExecutionException("Failed to inject dependencies", e);
         }
     }
 
-    private void injectDependentServiceUnits() throws JbiPluginException,
-            ArtifactResolutionException, ArtifactNotFoundException {
+    private void createArchive(File installerFile) throws JbiPluginException {
+        try {
+            // generate war file
+            getLog().info("Generating service assembly " + installerFile.getAbsolutePath());
+            MavenArchiver archiver = new MavenArchiver();
+            archiver.setArchiver(jarArchiver);
+            archiver.setOutputFile(installerFile);
+            jarArchiver.addDirectory(workDirectory);
+            jarArchiver.addConfiguredManifest(createManifest());
+            jarArchiver.addDirectory(workDirectory, null, DirectoryScanner.DEFAULTEXCLUDES);
+            archiver.createArchive(getProject(), archive);
+
+        } catch (Exception e) {
+            throw new JbiPluginException("Error creating shared library: "
+                    + e.getMessage(), e);
+        }
+    }
+
+    private void injectDependentServiceUnits() throws JbiPluginException, ArtifactResolutionException,
ArtifactNotFoundException {
         Set artifacts = project.getArtifacts();
         for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
             Artifact artifact = (Artifact) iter.next();
-
             // TODO: utilise appropriate methods from project builder
-            ScopeArtifactFilter filter = new ScopeArtifactFilter(
-                    Artifact.SCOPE_RUNTIME);
-            if (!artifact.isOptional() && filter.include(artifact)
-                    && (artifact.getDependencyTrail().size() == 2)) {
+            ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+            if (!artifact.isOptional() && filter.include(artifact) && (artifact.getDependencyTrail().size()
== 2)) {
                 MavenProject project = null;
                 try {
-                    project = projectBuilder.buildFromRepository(artifact,
-                            remoteRepos, localRepo);
+                    project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
                 } catch (ProjectBuildingException e) {
-                    getLog().warn(
-                            "Unable to determine packaging for dependency : "
+                    getLog().warn("Unable to determine packaging for dependency : "
                                     + artifact.getArtifactId()
                                     + " assuming jar");
                 }
-                if ((project != null)
-                        && (project.getPackaging().equals("jbi-service-unit"))) {
+                if (project != null && project.getPackaging().equals("jbi-service-unit"))
{
                     try {
                         String path = artifact.getFile().getAbsolutePath();
-                        path = path.substring(0, path.lastIndexOf('.'))
-                                + ".zip";
-                        FileUtils.copyFileToDirectory(new File(path),
-                                workDirectory);
+                        path = path.substring(0, path.lastIndexOf('.')) + ".zip";
+                        FileUtils.copyFileToDirectory(new File(path), workDirectory);
                     } catch (IOException e) {
                         throw new JbiPluginException(e);
                     }

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java?rev=594352&r1=594351&r2=594352&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java
(original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java
Mon Nov 12 15:56:55 2007
@@ -128,6 +128,7 @@
             archiver.setArchiver(jarArchiver);
             archiver.setOutputFile(installerFile);
             jarArchiver.addDirectory(workDirectory);
+            jarArchiver.addConfiguredManifest(createManifest());
             if (jbiSourceDirectory.isDirectory()) {
                 jarArchiver.addDirectory(jbiSourceDirectory, null,
                         DirectoryScanner.DEFAULTEXCLUDES);

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=594352&r1=594351&r2=594352&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
(original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
Mon Nov 12 15:56:55 2007
@@ -106,8 +106,7 @@
           <process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
           <test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
           <test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
-          <package>org.apache.servicemix.tooling:jbi-maven-plugin:jbi-service-assembly,
-          		   org.apache.maven.plugins:maven-jar-plugin:jar</package>
+          <package>org.apache.servicemix.tooling:jbi-maven-plugin:jbi-service-assembly</package>
           <install>org.apache.maven.plugins:maven-install-plugin:install</install>
           <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
         </phases>



Mime
View raw message