You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2014/10/03 16:27:05 UTC
svn commit: r1629208 - in /aries/trunk/esa-maven-plugin/src:
main/java/org/apache/aries/plugin/esa/ContentInfo.java
test/java/org/apache/aries/plugin/esa/EsaMojoTest.java
Author: davidb
Date: Fri Oct 3 14:27:05 2014
New Revision: 1629208
URL: http://svn.apache.org/r1629208
Log:
[ARIES-1255] esa-maven-plugin generates Subsystem-Content with version range for composite subsystems
This patch restricts the version range for Subsystem-Content entried that are derived from Maven Artifacts to be exactly the Maven version [a.b.c, a.b.c] as this maps to the Maven dependency model.
Previously the dependency was modeled as version="a.b.c" which actually is the same as [a.b.c, infinity].
Modified:
aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.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/ContentInfo.java
URL: http://svn.apache.org/viewvc/aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java?rev=1629208&r1=1629207&r2=1629208&view=diff
==============================================================================
--- aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java (original)
+++ aries/trunk/esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/ContentInfo.java Fri Oct 3 14:27:05 2014
@@ -27,47 +27,47 @@ import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import aQute.lib.osgi.Analyzer;
+
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 + "\"";
+ line += ";version=\"[" + version + "," + version + "]\"";
}
return line;
}
-
+
public static ContentInfo create(Artifact artifact, Log log) {
ZipFile zip = null;
try {
@@ -100,64 +100,64 @@ public class ContentInfo {
private static ContentInfo handleUnknown(Artifact artifact) {
ContentInfo info = new ContentInfo();
info.symbolicName = maven2OsgiConverter.getBundleSymbolicName(artifact);
- info.version = Analyzer.cleanupVersion(artifact.getVersion());
+ 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();
+ info.symbolicName = 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();
+ info.type = 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();
-
+ info.symbolicName = 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 {
+
+ private static Manifest getManifest(ZipFile zip, ZipEntry entry) throws IOException {
InputStream in = null;
try {
in = zip.getInputStream(entry);
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=1629208&r1=1629207&r2=1629208&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 Fri Oct 3 14:27:05 2014
@@ -26,17 +26,15 @@ 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 aQute.lib.osgi.Analyzer;
+
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>
@@ -60,13 +58,13 @@ public class EsaMojoTest
{
testBasicEsa( "target/test-classes/unit/basic-esa-test/plugin-config.xml", null );
}
-
+
public void testBasicEsaPgkType()
throws Exception
{
testBasicEsa( "target/test-classes/unit/basic-esa-test-with-pgk-type/plugin-config.xml", "maven-esa-test-1.0-SNAPSHOT.jar" );
}
-
+
private void testBasicEsa(String path, String extraExpectedFiles)
throws Exception
{
@@ -221,19 +219,19 @@ public class EsaMojoTest
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 {
-
+
Enumeration entries = esa.getEntries();
@@ -242,7 +240,7 @@ public class EsaMojoTest
BufferedReader br = new BufferedReader(new InputStreamReader(esa.getInputStream(entry)));
Boolean foundHeader=false;
-
+
String line;
while ((line = br.readLine()) != null) {
if (line.contains(header)) {
@@ -251,7 +249,7 @@ public class EsaMojoTest
}
}
assertTrue("Found " + header + ":", foundHeader);
-
+
}
public void testSubsystemManifestGeneration()
@@ -293,7 +291,7 @@ public class EsaMojoTest
expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" );
ZipFile esa = new ZipFile( esaFile );
-
+
Enumeration entries = esa.getEntries();
assertTrue( entries.hasMoreElements() );
@@ -341,7 +339,7 @@ public class EsaMojoTest
expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" );
ZipFile esa = new ZipFile( esaFile );
-
+
Enumeration entries = esa.getEntries();
assertTrue( entries.hasMoreElements() );
@@ -351,19 +349,19 @@ public class EsaMojoTest
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.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version"));
// start-order is actually a directive, shows up here as the name+":"
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("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version"));
assertEquals("2", attributes.get("start-order:"));
assertNull(attributes.get("type"));
}
@@ -498,7 +496,7 @@ public class EsaMojoTest
expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" );
ZipFile esa = new ZipFile( esaFile );
-
+
Enumeration entries = esa.getEntries();
assertTrue( entries.hasMoreElements() );
@@ -511,7 +509,7 @@ public class EsaMojoTest
// Test for the MyHeader header
testForHeader(esa, "MyHeader", "MyHeader: myValue");
-
+
// Test for the Subsystem-Name header
testForHeader(esa, "Subsystem-Name", "Subsystem-Name: myName");
}
@@ -559,30 +557,30 @@ public class EsaMojoTest
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.0.0.SNAPSHOT,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"));
+ assertEquals("[1.0.0.SNAPSHOT,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("[1.1.0.SNAPSHOT.NNN,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("[1.2.0.SNAPSHOT,1.2.0.SNAPSHOT]", attributes.get("version"));
assertEquals("feature", attributes.get("type"));
}
-
+
private int getSizeOfExpectedFiles( Enumeration entries, List expectedFiles )
{
while( entries.hasMoreElements() )