You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2010/03/18 14:36:29 UTC

svn commit: r924768 - in /servicemix/maven-plugins/jbi-maven-plugin/trunk/src: main/java/org/apache/servicemix/maven/plugin/jbi/ test/java/org/apache/servicemix/maven/plugin/jbi/

Author: gertv
Date: Thu Mar 18 13:36:28 2010
New Revision: 924768

URL: http://svn.apache.org/viewvc?rev=924768&view=rev
Log:
SM-1938: Shared library JAR should not be added to the component-class-path

Added:
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformationTest.java
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriterTest.java
Modified:
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformation.java
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java
    servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java

Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformation.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformation.java?rev=924768&r1=924767&r2=924768&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformation.java (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformation.java Thu Mar 18 13:36:28 2010
@@ -24,6 +24,11 @@ package org.apache.servicemix.maven.plug
  */
 public class DependencyInformation {
 
+    /**
+     * Artifact type for a JBI Shared Library
+     */
+    public static final String SHARED_LIBRARY_TYPE = "jbi-shared-library";
+
     private String filename;
 
     private String component;
@@ -83,4 +88,11 @@ public class DependencyInformation {
     public void setVersion(String version) {
         this.version = version;
     }
+
+    /**
+     * Is this dependency a JBI Shared Library?
+     */
+    public boolean isSharedLibrary() {
+        return SHARED_LIBRARY_TYPE.equals(type);
+    }
 }

Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java?rev=924768&r1=924767&r2=924768&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java Thu Mar 18 13:36:28 2010
@@ -34,6 +34,8 @@ import org.apache.maven.project.MavenPro
 import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.util.FileUtils;
 
+import static org.apache.servicemix.maven.plugin.jbi.DependencyInformation.*;
+
 /**
  * A Mojo used to build the jbi.xml file.
  * 
@@ -241,7 +243,7 @@ public class GenerateComponentDescriptor
                                     + artifact.getArtifactId() + " assuming jar");
                 }
                 String type = project != null ? project.getPackaging() : artifact.getType();
-                if ("jbi-shared-library".equals(type)) {
+                if (SHARED_LIBRARY_TYPE.equals(type)) {
                     // exclude children, but not the shared library itself
                     excludeBranch(listener.getNode(artifact), excludes);
                     excludes.remove(artifact);
@@ -269,62 +271,6 @@ public class GenerateComponentDescriptor
             info.setType(type);
             uris.add(info);
         }
-//
-//        DependencyNode node = buildDependencyTree(filter);
-//        Set<Artifact> includes = new HashSet<Artifact>();
-//        Set<Artifact> excludes = new HashSet<Artifact>();
-//        for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
-//            Artifact artifact = (Artifact) iter.next();
-//            //if (filter.include(artifact)) {
-//                MavenProject project = null;
-//                try {
-//                    project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
-//                } catch (ProjectBuildingException e) {
-//                    getLog().warn("Unable to determine packaging for dependency : "
-//                                    + artifact.getArtifactId() + " assuming jar");
-//                }
-//                String type = project != null ? project.getPackaging() : artifact.getType();
-//                if ("jbi-shared-library".equals(type)) {
-//                    // exclude children, but not the shared library itself
-//                    excludeBranch(findNode(node, artifact), excludes, false);
-//                    includes.add(artifact);
-//                } else if ("jar".equals(type) || "bundle".equals(type) || "jbi-component".equals(type)) {
-//                    includes.add(artifact);
-//                }
-//            //}
-//        }
-//        for (Artifact artifact : excludes) {
-//            System.out.println("Excludes: " + artifact);
-//        }
-//        includes.removeAll(excludes);
-//        Set<Artifact> newIncludes = new HashSet<Artifact>();
-//        for (Artifact artifact : includes) {
-//            DependencyNode n = findNode(node, artifact);
-//            if (n != null) {
-//                Artifact a = n.getArtifact();
-//                if (filter.include(a)) {
-//                    newIncludes.add(artifact);
-//                }
-//            }
-//        }
-//        //pruneTree(node, filter, excludes);
-//        for (Artifact artifact : newIncludes) {
-//            MavenProject project = null;
-//            try {
-//                project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
-//            } catch (ProjectBuildingException e) {
-//                getLog().warn("Unable to determine packaging for dependency : "
-//                                + artifact.getArtifactId() + " assuming jar");
-//            }
-//            String type = project != null ? project.getPackaging() : artifact.getType();
-//            info = new DependencyInformation();
-//            info.setFilename(LIB_DIRECTORY + "/" + artifact.getFile().getName());
-//            info.setVersion(artifact.getVersion());
-//            info.setName(artifact.getArtifactId());
-//            info.setType(type);
-//            uris.add(info);
-//        }
-//
 
         JbiComponentDescriptorWriter writer = new JbiComponentDescriptorWriter(encoding);
         writer.write(descriptor, component, bootstrap, type, name, description,

Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java?rev=924768&r1=924767&r2=924768&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java Thu Mar 18 13:36:28 2010
@@ -78,9 +78,11 @@ public class JbiComponentDescriptorWrite
         writer.startElement("component-class-path");
         for (Iterator it = uris.iterator(); it.hasNext();) {
             DependencyInformation info = (DependencyInformation) it.next();
-            writer.startElement("path-element");
-            writer.writeText(info.getFilename());
-            writer.endElement();
+            if (!info.isSharedLibrary()) {
+                writer.startElement("path-element");
+                writer.writeText(info.getFilename());
+                writer.endElement();
+            }
         }
         writer.endElement();
 
@@ -100,7 +102,7 @@ public class JbiComponentDescriptorWrite
 
         for (Iterator it = uris.iterator(); it.hasNext();) {
             DependencyInformation info = (DependencyInformation) it.next();
-            if ("jbi-shared-library".equals(info.getType())) {
+            if (info.isSharedLibrary()) {
                 writer.startElement("shared-library");
                 writer.addAttribute("version", info.getVersion());
                 writer.writeText(info.getName());

Added: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformationTest.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformationTest.java?rev=924768&view=auto
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformationTest.java (added)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/DependencyInformationTest.java Thu Mar 18 13:36:28 2010
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.maven.plugin.jbi;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link org.apache.servicemix.maven.plugin.jbi.DependencyInformation}
+ */
+public class DependencyInformationTest extends TestCase {
+
+    public void testIsSharedLibrary() {
+        DependencyInformation dep = new DependencyInformation();
+
+        dep.setType("jar");
+        assertFalse(dep.isSharedLibrary());
+
+        dep.setType(DependencyInformation.SHARED_LIBRARY_TYPE);
+        assertTrue(dep.isSharedLibrary());
+    }
+}

Added: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriterTest.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriterTest.java?rev=924768&view=auto
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriterTest.java (added)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/test/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriterTest.java Thu Mar 18 13:36:28 2010
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.maven.plugin.jbi;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+
+import junit.framework.TestCase;
+import org.xml.sax.InputSource;
+
+/**
+ * Test cases for {@link org.apache.servicemix.maven.plugin.jbi.JbiComponentDescriptorWriter}
+ */
+public class JbiComponentDescriptorWriterTest extends TestCase {
+
+    private static final String VERSION = "1.0";
+
+    private static final NamespaceContext NAMESPACES = new NamespaceContext() {
+
+        public String getNamespaceURI(String prefix) {
+            return "http://java.sun.com/xml/ns/jbi";
+        }
+
+        public String getPrefix(String namespaceURI) {
+            return "jbi";
+        }
+
+        public Iterator getPrefixes(String namespaceURI) {
+            return Arrays.asList("jbi").iterator();
+        }
+    };
+
+    private JbiComponentDescriptorWriter writer;
+    private File file;
+    private XPathFactory factory = XPathFactory.newInstance();
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        writer = new JbiComponentDescriptorWriter(GenerateComponentDescriptorMojo.UTF_8);
+        file = File.createTempFile(getClass().getName(), ".xml");
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        if (!file.delete()) {
+            file.deleteOnExit();
+        }
+    }
+
+    public void testWrite() throws Exception {
+        List<DependencyInformation> deps = new ArrayList<DependencyInformation>();
+        deps.add(createJarDependency("simple-jar", "lib/simple-jar.jar"));
+        deps.add(createSharedLibraryDependency("simple-sl"));
+
+        writer.write(file,
+                     "org.apache.servicemix.test.Component",
+                     "org.apache.servicemix.test.Bootstrap",
+                     "binding-component",
+                     "servicemix-test",
+                     "ServiceMix :: A Test Component",
+                     "parent-first",
+                     "parent-first",
+                     deps);
+
+
+        assertEquals("Should have a reference to the SL in the shared-library element",
+                     "simple-sl", xpath("/jbi:jbi/jbi:component/jbi:shared-library"));
+        assertEquals("1.0", xpath("/jbi:jbi/jbi:component/jbi:shared-library/@version"));
+
+        assertEquals("Only the JAR should be on the component-class-path", "1",
+                     xpath("count(/jbi:jbi/jbi:component/jbi:component-class-path/jbi:path-element)"));
+        assertEquals("lib/simple-jar.jar",
+                     xpath("/jbi:jbi/jbi:component/jbi:component-class-path/jbi:path-element"));
+    }
+
+    private String xpath(String expression) throws Exception {
+        XPath xpath = factory.newXPath();
+        xpath.setNamespaceContext(NAMESPACES);
+
+        InputSource source = new InputSource(new FileReader(file));
+
+        return xpath.evaluate(expression, source);
+    }
+
+    private DependencyInformation createJarDependency(String name, String filename) {
+        DependencyInformation dep = createDependency(name, "jar");
+        dep.setFilename(filename);
+        return dep;
+    }    
+
+    private DependencyInformation createSharedLibraryDependency(String name) {
+        return createDependency(name, DependencyInformation.SHARED_LIBRARY_TYPE);
+    }
+
+    private DependencyInformation createDependency(String name, String type) {
+        DependencyInformation dep = new DependencyInformation();
+        dep.setName(name);
+        dep.setType(type);
+        dep.setVersion(VERSION);
+        return dep;
+    }
+}