You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gc...@apache.org on 2012/07/31 12:24:01 UTC

svn commit: r1367481 - in /aries/trunk/esa-maven-plugin/src: main/java/org/apache/aries/plugin/esa/ test/java/org/apache/aries/plugin/esa/ test/java/org/apache/aries/plugin/esa/stubs/ test/resources/unit/basic-esa-start-order/

Author: gcc
Date: Tue Jul 31 10:24:00 2012
New Revision: 1367481

URL: http://svn.apache.org/viewvc?rev=1367481&view=rev
Log:
ARIES-876
Added support for start-order.  Putting the following in the plugin configuration will add a start-order value to
all contents based on the order in which they are presented to the plugin (which I'm hoping is the same order they
appear in the pom.xml :) )
   <startOrder>dependencies</startOrder>

Added:
    aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/BasicEsaStartOrder.java
    aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-start-order/
    aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-start-order/plugin-config.xml
Modified:
    aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java
    aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java

Modified: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java?rev=1367481&r1=1367480&r2=1367481&view=diff
==============================================================================
--- aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java (original)
+++ aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java Tue Jul 31 10:24:00 2012
@@ -58,7 +58,7 @@ public class EsaMojo
 
     private static final String[] DEFAULT_INCLUDES = {"**/**"};
 
-    /**
+    /*
      * Subsystem manifest headers
      */
     private static final String SUBSYSTEM_MANIFESTVERSION = "Subsystem-ManifestVersion";
@@ -192,6 +192,14 @@ public class EsaMojo
      */
     private String archiveContent;
 
+    /**
+     * Define the start order for content bundles.
+     *   none - no start orders are added
+     *   dependencies - start order based on pom dependency order
+     *
+     * @parameter expression="${startOrder}" default-value="none"
+     */
+    private String startOrder;
 
     private File buildDir;
 
@@ -403,23 +411,31 @@ public class EsaMojo
             Iterator<Artifact> iter = artifacts.iterator();
 
             FileUtils.fileAppend(fileName, SUBSYSTEM_CONTENT + ": ");
+            int order = 1;
             if (iter.hasNext()) {
-                Artifact artifact = iter.next();
-                FileUtils.fileAppend(fileName, maven2OsgiConverter
-                        .getBundleSymbolicName(artifact)
+                Artifact artifact = iter.next(); 
+                String entry = new String(
+                		maven2OsgiConverter.getBundleSymbolicName(artifact)
                         + ";version=\""
                         + Analyzer.cleanupVersion(artifact.getVersion())
-//                      + maven2OsgiConverter.getVersion(artifact.getVersion())
                         + "\"");
+                if ("dependencies".equals(startOrder)) {
+                	entry += ";start-order=\"" + order + "\"";                	
+                }
+                FileUtils.fileAppend(fileName, entry);
             }
             while (iter.hasNext()) {
                 Artifact artifact = iter.next();
-                FileUtils.fileAppend(fileName, ",\n "
+                order++;
+                String entry = new String(",\n "
                         + maven2OsgiConverter.getBundleSymbolicName(artifact)
                         + ";version=\""
                         + Analyzer.cleanupVersion(artifact.getVersion())
-//                      + maven2OsgiConverter.getVersion(artifact.getVersion())
                         + "\"");
+                if ("dependencies".equals(startOrder)) {
+                	entry += ";start-order=\"" + order + "\"";                	
+                }
+                FileUtils.fileAppend(fileName, entry);
             }
 
             FileUtils.fileAppend(fileName, "\n");

Modified: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java?rev=1367481&r1=1367480&r2=1367481&view=diff
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java (original)
+++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/EsaMojoTest.java Tue Jul 31 10:24:00 2012
@@ -207,7 +207,7 @@ public class EsaMojoTest
         
         String line;
         while ((line = br.readLine()) != null) {
-            if (line.contains(new String(header))) {
+            if (line.contains(header)) {
                 assertEquals(exactEntry, line);
                 foundHeader = true;
             }
@@ -215,6 +215,27 @@ public class EsaMojoTest
         assertTrue("Found " + header + ":", foundHeader);
         
     }
+    
+    private void testForLine(ZipFile esa, String exactEntry) throws Exception {
+        
+        Enumeration entries = esa.getEntries();
+
+
+        // Test Use-Bundle & Subsytem-Type inclusion
+        ZipEntry entry = esa.getEntry("OSGI-INF/SUBSYSTEM.MF");
+        BufferedReader br = new BufferedReader(new InputStreamReader(esa.getInputStream(entry)));
+
+        Boolean foundEntry=false;
+        
+        String line;
+        while ((!foundEntry) && ((line = br.readLine()) != null)) {
+            if (line.equals(exactEntry)) {
+                foundEntry = true;
+            }
+        }
+        assertTrue("Found " + exactEntry + ":", foundEntry);
+        
+    }
 
     public void testSubsystemManifestGeneration()
         throws Exception
@@ -270,6 +291,54 @@ public class EsaMojoTest
         testForHeader(esa, "Subsystem-Type", "Subsystem-Type: feature");
     }
 
+    public void testSubsystemStartOrder()
+        throws Exception
+    {
+        File testPom = new File( getBasedir(),
+                                 "target/test-classes/unit/basic-esa-start-order/plugin-config.xml" );
+
+        EsaMojo mojo = ( EsaMojo ) lookupMojo( "esa", testPom );
+
+        assertNotNull( mojo );
+
+        String finalName = ( String ) getVariableValueFromObject( mojo, "finalName" );
+
+        String workDir = ( String ) getVariableValueFromObject( mojo, "workDirectory" );
+
+        String outputDir = ( String ) getVariableValueFromObject( mojo, "outputDirectory" );
+
+        mojo.execute();
+
+
+        //check the generated esa file
+        File esaFile = new File( outputDir, finalName + ".esa" );
+
+        assertTrue( esaFile.exists() );
+
+        //expected files/directories inside the esa file
+        List expectedFiles = new ArrayList();
+
+        expectedFiles.add( "OSGI-INF/SUBSYSTEM.MF" );
+        expectedFiles.add( "OSGI-INF/" );
+        expectedFiles.add( "maven-artifact01-1.0-SNAPSHOT.jar" );
+        expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" );
+
+        ZipFile esa = new ZipFile( esaFile );
+        
+        Enumeration entries = esa.getEntries();
+
+        assertTrue( entries.hasMoreElements() );
+
+        int missing = getSizeOfExpectedFiles(entries, expectedFiles);
+        assertEquals("Missing files: " + expectedFiles,  0, missing);
+
+        // Test for the Use-Bundle header
+        testForHeader(esa, "Subsystem-Content", "Subsystem-Content: maven-artifact02-1.0-SNAPSHOT;version=\"1.0.0.SNAPSHOT\";start-order=\"1\",");
+ 
+        // Test for the Subsystem-Content header
+        testForLine(esa, " maven-artifact01-1.0-SNAPSHOT;version=\"1.0.0.SNAPSHOT\";start-order=\"2\"");
+    }
+
 
     public void testArchiveContentConfigurationNoBundles()
         throws Exception

Added: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/BasicEsaStartOrder.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/BasicEsaStartOrder.java?rev=1367481&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/BasicEsaStartOrder.java (added)
+++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/BasicEsaStartOrder.java Tue Jul 31 10:24:00 2012
@@ -0,0 +1,31 @@
+package org.apache.aries.plugin.esa.stubs;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+public class BasicEsaStartOrder
+    extends EsaMavenProjectStub
+{
+    public File getFile()
+    {
+        return new File( getBasedir(), "src/test/resources/unit/basic-esa-start-order/plugin-config.xml" );
+    }
+}

Added: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-start-order/plugin-config.xml
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-start-order/plugin-config.xml?rev=1367481&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-start-order/plugin-config.xml (added)
+++ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-start-order/plugin-config.xml Tue Jul 31 10:24:00 2012
@@ -0,0 +1,41 @@
+<!--
+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.
+-->
+
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>esa-maven-plugin</artifactId>
+		<configuration>
+		  <esaSourceDirectory>${basedir}/src/test/resources/unit/basic-esa-start-order/src/main/esa</esaSourceDirectory>
+          <generateManifest>true</generateManifest>
+          <startOrder>dependencies</startOrder>
+          <instructions>
+          </instructions>
+          <includeEmptyDirs>true</includeEmptyDirs>
+		  <workDirectory>${basedir}/target/unit/basic-esa-start-order/target/esa-test-start-order</workDirectory>
+          <sharedResources>${basedir}/target/unit/basic-esa-start-order/target/maven-shared-archive-resources</sharedResources>
+		  <outputDirectory>${basedir}/target/unit/basic-esa-start-order/target</outputDirectory>
+		  <finalName>test-esa-start-order</finalName>
+		  <project implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub4" />
+		</configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>