aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1590210 - 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/remote-repo/org/apache/maven/test/maven-artifact03/ test/remote...
Date Sat, 26 Apr 2014 01:29:08 GMT
Author: gawor
Date: Sat Apr 26 01:29:08 2014
New Revision: 1590210

URL: http://svn.apache.org/r1590210
Log:
ARIES-1103: Use version from bundle or subsystem manifest. Add in appropriate type too

Added:
    aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java
  (with props)
    aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java
  (with props)
    aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java
  (with props)
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.jar
  (with props)
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.pom
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.esa
  (with props)
    aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.pom
    aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/
    aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml
  (with props)
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
    aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub.java

Added: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java?rev=1590210&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java
(added)
+++ aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java
Sat Apr 26 01:29:08 2014
@@ -0,0 +1,43 @@
+/*
+ * 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.aries.plugin.esa;
+
+public class Constants {
+   
+    public static final String BUNDLE_VERSION = "Bundle-Version";
+    public static final String BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName";
+    public static final String FRAGMENT_HOST = "Fragment-Host";
+    
+    public static final String BUNDLE_TYPE = "osgi.bundle";
+    public static final String FRAGMENT_TYPE = "osgi.fragment";
+    public static final String APPLICATION_TYPE = "osgi.subsystem.application";
+
+    /*
+     * Subsystem manifest headers
+     */
+    public static final String SUBSYSTEM_MANIFESTVERSION = "Subsystem-ManifestVersion";
+    public static final String SUBSYSTEM_SYMBOLICNAME = "Subsystem-SymbolicName";
+    public static final String SUBSYSTEM_VERSION = "Subsystem-Version";
+    public static final String SUBSYSTEM_NAME = "Subsystem-Name";
+    public static final String SUBSYSTEM_DESCRIPTION = "Subsystem-Description";
+    public static final String SUBSYSTEM_CONTENT = "Subsystem-Content";
+    public static final String SUBSYSTEM_USEBUNDLE = "Use-Bundle";
+    public static final String SUBSYSTEM_TYPE = "Subsystem-Type";
+}

Propchange: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/Constants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java?rev=1590210&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java
(added)
+++ aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java
Sat Apr 26 01:29:08 2014
@@ -0,0 +1,172 @@
+/*
+ * 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.aries.plugin.esa;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
+import org.apache.maven.shared.osgi.Maven2OsgiConverter;
+
+import aQute.lib.osgi.Analyzer;
+
+public class ContentInfo {
+   
+    /**
+     * Coverter for maven pom values to OSGi manifest values (pulled in from the maven-bundle-plugin)
+     */
+    private static Maven2OsgiConverter maven2OsgiConverter = new DefaultMaven2OsgiConverter();
+    
+    private String symbolicName;
+    private String type;
+    private String version;
+    
+    public String getSymbolicName() {
+        return symbolicName;
+    }
+    
+    public String getType() {
+        return type;
+    }
+    
+    public String getVersion() {
+        return version;
+    }
+    
+    public String getContentLine() {
+        String line = symbolicName;
+        if (type != null) {
+            line += ";type=\"" + type + "\"";
+        }
+        if (version != null) {
+            line += ";version=\"" + version + "\"";
+        }
+        return line;
+    }
+    
+    public static ContentInfo create(Artifact artifact, Log log) {
+        ZipFile zip = null;
+        try {
+            zip = new ZipFile(artifact.getFile());
+            ZipEntry entry = zip.getEntry("META-INF/MANIFEST.MF");
+            if (entry != null) {
+                Manifest mf = getManifest(zip, entry);
+                return handleManifest(artifact, mf);
+            } else {
+                // no manifest.mf
+                entry = zip.getEntry("OSGI-INF/SUBSYSTEM.MF");
+                if (entry != null) {
+                    Manifest mf = getManifest(zip, entry);
+                    return handleSubsystem(artifact, mf);
+                } else {
+                    // and no subsystem.mf
+                    return handleUnknown(artifact);
+                }
+            }
+        } catch (Exception e) {
+            log.warn("Error creating content information", e);
+            return null;
+        } finally {
+            if (zip != null) {
+               try { zip.close(); } catch (IOException ignore) {}
+            }
+        }
+    }
+
+    private static ContentInfo handleUnknown(Artifact artifact) {
+        ContentInfo info = new ContentInfo();
+        info.symbolicName = maven2OsgiConverter.getBundleSymbolicName(artifact);
+        info.version = Analyzer.cleanupVersion(artifact.getVersion());  
+        return info;
+    }
+
+    private static ContentInfo handleSubsystem(Artifact artifact, Manifest mf) {
+        ContentInfo info = new ContentInfo();
+        
+        Attributes mainAttributes = mf.getMainAttributes();
+        
+        String subsystemSymbolicName = mainAttributes.getValue(Constants.SUBSYSTEM_SYMBOLICNAME);
+        if (subsystemSymbolicName != null) {
+            Map<String, ?> header = Analyzer.parseHeader(subsystemSymbolicName, null);
+            info.symbolicName = (String) header.keySet().iterator().next(); 
+        }
+        
+        String subsystemVersion = mainAttributes.getValue(Constants.SUBSYSTEM_VERSION);
+        if (subsystemVersion != null) {
+            info.version = subsystemVersion;
+        }
+        
+        String subsystemType = mainAttributes.getValue(Constants.SUBSYSTEM_TYPE);
+        if (subsystemType == null) {
+            info.type = Constants.APPLICATION_TYPE;
+        } else {
+            Map<String, ?> header = Analyzer.parseHeader(subsystemType, null);
+            info.type = (String) header.keySet().iterator().next(); 
+        }
+        
+        return info;
+    }
+
+    private static ContentInfo handleManifest(Artifact artifact, Manifest mf) {
+        Attributes mainAttributes = mf.getMainAttributes();
+        
+        String bundleSymbolicName = mainAttributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+        if (bundleSymbolicName == null) {
+            // not a bundle
+            return handleUnknown(artifact);
+        } else {
+            ContentInfo info = new ContentInfo();
+            
+            Map<String, ?> header = Analyzer.parseHeader(bundleSymbolicName, null);
+            info.symbolicName = (String) header.keySet().iterator().next();         
+        
+            String bundleVersion = mainAttributes.getValue(Constants.BUNDLE_VERSION);
+            if (bundleVersion != null) {
+                info.version = bundleVersion;
+            }
+        
+            if (mainAttributes.getValue(Constants.FRAGMENT_HOST) != null) {
+                info.type = Constants.FRAGMENT_TYPE;
+            }
+            
+            return info;
+        }
+    }
+   
+    private static Manifest getManifest(ZipFile zip, ZipEntry entry) throws IOException {
       
+        InputStream in = null;
+        try {
+            in = zip.getInputStream(entry);
+            Manifest mf = new Manifest(in);
+            return mf;
+        } finally {
+            if (in != null) {
+                try { in.close(); } catch (IOException ignore) {}
+            }
+        }
+    }
+}

Propchange: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1590210&r1=1590209&r2=1590210&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 Sat
Apr 26 01:29:08 2014
@@ -28,9 +28,6 @@ import org.codehaus.plexus.archiver.Arch
 import org.codehaus.plexus.archiver.zip.ZipArchiver;
 import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
-import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
-import org.apache.maven.shared.osgi.Maven2OsgiConverter;
-import aQute.lib.osgi.Analyzer;
 import java.io.File;
 import java.io.IOException;
 import java.util.Iterator;
@@ -58,35 +55,18 @@ public class EsaMojo
 
     private static final String[] DEFAULT_INCLUDES = {"**/**"};
 
-    /*
-     * Subsystem manifest headers
-     */
-    private static final String SUBSYSTEM_MANIFESTVERSION = "Subsystem-ManifestVersion";
-    private static final String SUBSYSTEM_SYMBOLICNAME = "Subsystem-SymbolicName";
-    private static final String SUBSYSTEM_VERSION = "Subsystem-Version";
-    private static final String SUBSYSTEM_NAME = "Subsystem-Name";
-    private static final String SUBSYSTEM_DESCRIPTION = "Subsystem-Description";
-    private static final String SUBSYSTEM_CONTENT = "Subsystem-Content";
-    private static final String SUBSYSTEM_USEBUNDLE = "Use-Bundle";
-    private static final String SUBSYSTEM_TYPE = "Subsystem-Type";
-
     private static final Set<String> SKIP_INSTRUCTIONS = new HashSet<String>();
 
     static {
-        SKIP_INSTRUCTIONS.add(SUBSYSTEM_MANIFESTVERSION);
-        SKIP_INSTRUCTIONS.add(SUBSYSTEM_SYMBOLICNAME);
-        SKIP_INSTRUCTIONS.add(SUBSYSTEM_VERSION);
-        SKIP_INSTRUCTIONS.add(SUBSYSTEM_NAME);
-        SKIP_INSTRUCTIONS.add(SUBSYSTEM_DESCRIPTION);
-        SKIP_INSTRUCTIONS.add(SUBSYSTEM_CONTENT);
+        SKIP_INSTRUCTIONS.add(Constants.SUBSYSTEM_MANIFESTVERSION);
+        SKIP_INSTRUCTIONS.add(Constants.SUBSYSTEM_SYMBOLICNAME);
+        SKIP_INSTRUCTIONS.add(Constants.SUBSYSTEM_VERSION);
+        SKIP_INSTRUCTIONS.add(Constants.SUBSYSTEM_NAME);
+        SKIP_INSTRUCTIONS.add(Constants.SUBSYSTEM_DESCRIPTION);
+        SKIP_INSTRUCTIONS.add(Constants.SUBSYSTEM_CONTENT);
     }
 
     /**
-     * Coverter for maven pom values to OSGi manifest values (pulled in from the maven-bundle-plugin)
-     */
-    private Maven2OsgiConverter maven2OsgiConverter = new DefaultMaven2OsgiConverter();
-    
-    /**
      * Single directory for extra files to include in the esa.
      *
      * @parameter expression="${basedir}/src/main/esa"
@@ -249,8 +229,7 @@ public class EsaMojo
                 
                 artifacts = selectArtifacts(artifacts);
                 int cnt = 0;
-                for (Artifact artifact : artifacts) {
-
+                for (Artifact artifact : artifacts) {                    
                     if (!artifact.isOptional() /*&& filter.include(artifact)*/) {
                         getLog().info("Copying artifact[" + artifact.getGroupId() + ", "
+ artifact.getId() + ", " +
                                 artifact.getScope() + "]");
@@ -414,15 +393,15 @@ public class EsaMojo
         try {
             // TODO: add support for dependency version ranges. Need to pick
             // them up from the pom and convert them to OSGi version ranges.
-            FileUtils.fileAppend(fileName, SUBSYSTEM_MANIFESTVERSION + ": " + "1" + "\n");
-            FileUtils.fileAppend(fileName, SUBSYSTEM_SYMBOLICNAME + ": "
+            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_MANIFESTVERSION + ": " + "1"
+ "\n");
+            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_SYMBOLICNAME + ": "
                     + getSubsystemSymbolicName(project.getArtifact()) + "\n");
-            FileUtils.fileAppend(fileName, SUBSYSTEM_VERSION + ": "
+            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_VERSION + ": "
                     + getSubsystemVersion() + "\n");
-            FileUtils.fileAppend(fileName, SUBSYSTEM_NAME + ": " + getSubsystemName() + "\n");
+            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_NAME + ": " + getSubsystemName()
+ "\n");
             String description = getSubsystemDescription();
             if (description != null) {
-                FileUtils.fileAppend(fileName, SUBSYSTEM_DESCRIPTION + ": " + description
+ "\n");
+                FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_DESCRIPTION + ": " + description
+ "\n");
             }
 
             // Write the SUBSYSTEM-CONTENT
@@ -435,31 +414,22 @@ public class EsaMojo
             artifacts = selectArtifacts(artifacts);
             Iterator<Artifact> iter = artifacts.iterator();
 
-            FileUtils.fileAppend(fileName, SUBSYSTEM_CONTENT + ": ");
-            int order = 1;
-            if (iter.hasNext()) {
-                Artifact artifact = iter.next(); 
-                String entry = new String(
-                        maven2OsgiConverter.getBundleSymbolicName(artifact)
-                        + ";version=\""
-                        + Analyzer.cleanupVersion(artifact.getVersion())
-                        + "\"");
-                if ("dependencies".equals(startOrder)) {
-                    entry += ";start-order=\"" + order + "\"";                  
-                }
-                FileUtils.fileAppend(fileName, entry);
-            }
+            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_CONTENT + ": ");
+            int order = 0;
             while (iter.hasNext()) {
                 Artifact artifact = iter.next();
                 order++;
-                String entry = new String(",\n "
-                        + maven2OsgiConverter.getBundleSymbolicName(artifact)
-                        + ";version=\""
-                        + Analyzer.cleanupVersion(artifact.getVersion())
-                        + "\"");
+                ContentInfo info = ContentInfo.create(artifact, getLog());
+                if (info == null) {
+                    continue;
+                }
+                String entry = info.getContentLine();
                 if ("dependencies".equals(startOrder)) {
                     entry += ";start-order=\"" + order + "\"";                  
                 }
+                if (iter.hasNext()) {
+                    entry += ",\n ";
+                }
                 FileUtils.fileAppend(fileName, entry);
             }
 
@@ -486,29 +456,29 @@ public class EsaMojo
     // The maven2OsgiConverter assumes the artifact is a jar so we need our own
     // This uses the same fallback scheme as the converter
     private String getSubsystemSymbolicName(Artifact artifact) {
-        if (instructions.containsKey(SUBSYSTEM_SYMBOLICNAME)) {
-            return instructions.get(SUBSYSTEM_SYMBOLICNAME).toString();
+        if (instructions.containsKey(Constants.SUBSYSTEM_SYMBOLICNAME)) {
+            return instructions.get(Constants.SUBSYSTEM_SYMBOLICNAME).toString();
         }
         return artifact.getGroupId() + "." + artifact.getArtifactId();
     }
     
     private String getSubsystemVersion() {
-        if (instructions.containsKey(SUBSYSTEM_VERSION)) {
-            return instructions.get(SUBSYSTEM_VERSION).toString();
+        if (instructions.containsKey(Constants.SUBSYSTEM_VERSION)) {
+            return instructions.get(Constants.SUBSYSTEM_VERSION).toString();
         }
         return aQute.lib.osgi.Analyzer.cleanupVersion(project.getVersion());
     }
     
     private String getSubsystemName() {
-        if (instructions.containsKey(SUBSYSTEM_NAME)) {
-            return instructions.get(SUBSYSTEM_NAME).toString();
+        if (instructions.containsKey(Constants.SUBSYSTEM_NAME)) {
+            return instructions.get(Constants.SUBSYSTEM_NAME).toString();
         }
         return project.getName();
     }
     
     private String getSubsystemDescription() {
-        if (instructions.containsKey(SUBSYSTEM_DESCRIPTION)) {
-            return instructions.get(SUBSYSTEM_DESCRIPTION).toString();
+        if (instructions.containsKey(Constants.SUBSYSTEM_DESCRIPTION)) {
+            return instructions.get(Constants.SUBSYSTEM_DESCRIPTION).toString();
         }
         return project.getDescription();
     }

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=1590210&r1=1590209&r2=1590210&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
Sat Apr 26 01:29:08 2014
@@ -21,17 +21,23 @@ package org.apache.aries.plugin.esa;
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Iterator;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
 
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.codehaus.plexus.archiver.zip.ZipEntry;
 import org.codehaus.plexus.archiver.zip.ZipFile;
 import org.codehaus.plexus.util.FileUtils;
 
+import aQute.lib.osgi.Analyzer;
+
 /**
  * @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
  */
@@ -209,6 +215,22 @@ public class EsaMojoTest
         int missing = getSizeOfExpectedFiles(entries, expectedFiles);
         assertEquals("Missing files: " + expectedFiles,  0, missing);
     }
+
+    private Manifest getSubsystemManifest(ZipFile esa) throws Exception {
+        ZipEntry entry = esa.getEntry("OSGI-INF/SUBSYSTEM.MF");
+
+        InputStream in = esa.getInputStream(entry);
+        Manifest mf = new Manifest(in);
+        
+        return mf;
+    }
+          
+    private Map<String, Map<String, String>> getHeader(Manifest mf, String header)
{
+        Attributes attributes = mf.getMainAttributes();
+        String value = attributes.getValue(header);
+        assertNotNull("Header " + header + " not found", value);
+        return Analyzer.parseHeader(value, null);
+    }
     
     private void testForHeader(ZipFile esa, String header, String exactEntry) throws Exception
{
         
@@ -231,27 +253,6 @@ 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
@@ -348,11 +349,22 @@ public class EsaMojoTest
         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\"");
+        Manifest mf = getSubsystemManifest(esa);
+        Map<String, Map<String, String>> header = getHeader(mf, "Subsystem-Content");
+        
+        Map<String, String> attributes = null;
+        
+        attributes = header.get("maven-artifact01-1.0-SNAPSHOT");
+        assertNotNull(attributes);
+        assertEquals("1.0.0.SNAPSHOT", attributes.get("version"));
+        assertEquals("1", attributes.get("start-order"));
+        assertNull(attributes.get("type"));
+        
+        attributes = header.get("maven-artifact02-1.0-SNAPSHOT");
+        assertNotNull(attributes);
+        assertEquals("1.0.0.SNAPSHOT", attributes.get("version"));
+        assertEquals("2", attributes.get("start-order"));
+        assertNull(attributes.get("type"));
     }
 
 
@@ -503,6 +515,73 @@ public class EsaMojoTest
         testForHeader(esa, "Subsystem-Name", "Subsystem-Name: myName");
     }
 
+    public void testSubsystemContentType()
+        throws Exception
+    {
+        File testPom = new File(getBasedir(),
+                "target/test-classes/unit/basic-esa-content-type/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");
+        expectedFiles.add("maven-artifact03-1.1-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);
+
+        Manifest mf = getSubsystemManifest(esa);
+        Map<String, Map<String, String>> header = getHeader(mf, "Subsystem-Content");
+        
+        Map<String, String> attributes = null;
+        
+        attributes = header.get("maven-artifact01-1.0-SNAPSHOT");
+        assertNotNull(attributes);
+        assertEquals("1.0.0.SNAPSHOT", attributes.get("version"));
+        assertNull(attributes.get("type"));
+        
+        attributes = header.get("maven-artifact02-1.0-SNAPSHOT");
+        assertNotNull(attributes);
+        assertEquals("1.0.0.SNAPSHOT", attributes.get("version"));
+        assertNull(attributes.get("type"));
+        
+        attributes = header.get("maven-artifact03");
+        assertNotNull(attributes);
+        assertEquals("1.1.0.SNAPSHOT.NNN", attributes.get("version"));
+        assertEquals("osgi.fragment", attributes.get("type"));
+        
+        attributes = header.get("maven-artifact04");
+        assertNotNull(attributes);
+        assertEquals("1.2.0.SNAPSHOT", attributes.get("version"));
+        assertEquals("feature", attributes.get("type"));
+    }
+    
     private int getSizeOfExpectedFiles( Enumeration entries, List expectedFiles )
     {
         while( entries.hasMoreElements() )

Modified: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub.java?rev=1590210&r1=1590209&r2=1590210&view=diff
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub.java
(original)
+++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub.java
Sat Apr 26 01:29:08 2014
@@ -22,7 +22,7 @@ package org.apache.aries.plugin.esa.stub
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -110,7 +110,7 @@ public class EsaMavenProjectStub
     
     public Set getArtifacts()
     {   
-        Set artifacts = new HashSet();
+        Set artifacts = new LinkedHashSet();
  
         artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT",
false ) );
         artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT",
false ) );
@@ -134,6 +134,11 @@ public class EsaMavenProjectStub
     
     protected Artifact createArtifact( String groupId, String artifactId, String version,
boolean optional )
     {
+        return createArtifact(groupId, artifactId, version, "jar", optional);
+    }
+    
+    protected Artifact createArtifact( String groupId, String artifactId, String version,
String type, boolean optional )
+    {
         Artifact artifact = new EsaArtifactStub();
         
         artifact.setGroupId( groupId );
@@ -146,7 +151,7 @@ public class EsaMavenProjectStub
         
         artifact.setFile( new File ( getBasedir() + "/src/test/remote-repo/" + artifact.getGroupId().replace(
'.', '/' ) + 
                           "/" + artifact.getArtifactId() + "/" + artifact.getVersion() +

-                          "/" + artifact.getArtifactId() + "-" + artifact.getVersion() +
".jar" ) ) ;
+                          "/" + artifact.getArtifactId() + "-" + artifact.getVersion() +
"." + type ) ) ;
         
         return artifact;
     }

Added: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java?rev=1590210&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java
(added)
+++ aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java
Sat Apr 26 01:29:08 2014
@@ -0,0 +1,44 @@
+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;
+import java.util.HashSet;
+import java.util.Set;
+
+public class EsaMavenProjectStub9
+    extends EsaMavenProjectStub
+{
+    public File getFile()
+    {
+        return new File( getBasedir(), "src/test/resources/unit/basic-esa-content-type/plugin-config.xml"
);
+    }
+    
+    public Set getArtifacts()
+    {   
+        Set artifacts = new HashSet();
+ 
+        artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT",
false ) );
+        artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT",
false ) );
+        artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact03", "1.1-SNAPSHOT",
false ) );
+        artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact04", "1.2-SNAPSHOT",
"esa", true ) );
+        return artifacts;
+    }
+}

Propchange: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: aries/trunk/esa-maven-plugin/src/test/java/org/apache/aries/plugin/esa/stubs/EsaMavenProjectStub9.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.jar?rev=1590210&view=auto
==============================================================================
Binary file - no diff available.

Propchange: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.jar
------------------------------------------------------------------------------
    svn:mime-type = application/java-archive

Added: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.pom
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.pom?rev=1590210&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.pom
(added)
+++ aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact03/1.1-SNAPSHOT/maven-artifact03-1.1-SNAPSHOT.pom
Sat Apr 26 01:29:08 2014
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.test</groupId>
+  <artifactId>maven-artifact03</artifactId>
+  <version>1.1-SNAPSHOT</version>
+</project>

Added: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.esa
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.esa?rev=1590210&view=auto
==============================================================================
Binary file - no diff available.

Propchange: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.esa
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.pom
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.pom?rev=1590210&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.pom
(added)
+++ aries/trunk/esa-maven-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact04/1.2-SNAPSHOT/maven-artifact04-1.2-SNAPSHOT.pom
Sat Apr 26 01:29:08 2014
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.test</groupId>
+  <artifactId>maven-artifact04</artifactId>
+  <version>1.2-SNAPSHOT</version>
+  <packaging>esa</packaging>
+</project>

Added: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml?rev=1590210&view=auto
==============================================================================
--- aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml
(added)
+++ aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml
Sat Apr 26 01:29:08 2014
@@ -0,0 +1,34 @@
+<!-- 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-content-type/src/main/esa</esaSourceDirectory>
+					<generateManifest>true</generateManifest>
+					<addMavenDescriptor>false</addMavenDescriptor>
+					<includeEmptyDirs>true</includeEmptyDirs>
+					<workDirectory>${basedir}/target/unit/basic-esa-content-type/target/esa-test-content-type
+					</workDirectory>
+					<sharedResources>${basedir}/target/unit/basic-esa-content-type/target/maven-shared-archive-resources
+					</sharedResources>
+					<outputDirectory>${basedir}/target/unit/basic-esa-content-type/target
+					</outputDirectory>
+					<finalName>test-esa-content-type</finalName>
+					<project implementation="org.apache.aries.plugin.esa.stubs.EsaMavenProjectStub9"
/>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Propchange: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: aries/trunk/esa-maven-plugin/src/test/resources/unit/basic-esa-content-type/plugin-config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message