Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHristo Iliev2011-02-28 03:16:37 -0500
committerHristo Iliev2011-02-28 03:16:37 -0500
commit335a868a608cc366130b8adb608f73fb96b135ec (patch)
treea45a53ff308bc3474cf7e1bd4cba07dbedaefa0f /org.eclipse.virgo.kernel.artifact
parent06e1ac345dc2d49d033dbf0211bd61a45c218321 (diff)
downloadorg.eclipse.virgo.kernel-335a868a608cc366130b8adb608f73fb96b135ec.tar.gz
org.eclipse.virgo.kernel-335a868a608cc366130b8adb608f73fb96b135ec.tar.xz
org.eclipse.virgo.kernel-335a868a608cc366130b8adb608f73fb96b135ec.zip
bug 335190: PAR and Bundle bridges now fallback to file name to determine identity. Illegal version causes exceptionbug335190-bridge-identity
Diffstat (limited to 'org.eclipse.virgo.kernel.artifact')
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridge.java46
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java38
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java36
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java43
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-manifest.jarbin0 -> 452 bytes
-rw-r--r--org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-symbolic-name.jarbin0 -> 774 bytes
6 files changed, 113 insertions, 50 deletions
diff --git a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridge.java b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridge.java
index d7298b8d..9106e42d 100644
--- a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridge.java
+++ b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridge.java
@@ -40,9 +40,9 @@ import org.eclipse.virgo.util.osgi.manifest.FragmentHost.Extension;
* either as a JAR file, or a directory.
* <p />
* <strong>Concurrent Semantics</strong><br />
- *
+ *
* This class is thread-safe
- *
+ *
*/
public final class BundleBridge implements ArtifactBridge {
@@ -53,9 +53,9 @@ public final class BundleBridge implements ArtifactBridge {
public static final String RAW_HEADER_PREFIX = "RAW_HEADER:";
public static final String BRIDGE_TYPE = "bundle";
-
+
private final HashGenerator hashGenerator;
-
+
public BundleBridge(HashGenerator hashGenerator) {
this.hashGenerator = hashGenerator;
}
@@ -72,17 +72,47 @@ public final class BundleBridge implements ArtifactBridge {
BundleManifest bundleManifest;
try {
- bundleManifest = BundleManifestUtils.readBundleManifest(artifactFile, JAR_SUFFIX, WAR_SUFFIX);
+ bundleManifest = BundleManifestUtils.readBundleManifest(artifactFile, JAR_SUFFIX, WAR_SUFFIX);
} catch (RuntimeException re) {
throw new RuntimeException(String.format("Error occurred while parsing the manifest of file '%s'.", artifactFile.getPath()), re);
} catch (Exception e) {
throw new ArtifactGenerationException("Error occurred while parsing the manifest.", BRIDGE_TYPE, e);
}
-
- if (bundleManifest == null) {
- return null;
+
+ ArtifactDescriptor descriptor = null;
+
+ if (bundleManifest != null) {
+ descriptor = createArtifactDescriptorFromManifest(artifactFile, bundleManifest);
}
+ if (descriptor == null) {
+ descriptor = createArtifactDescriptorFromFile(artifactFile);
+ }
+
+ return descriptor;
+ }
+
+ private ArtifactDescriptor createArtifactDescriptorFromFile(File artifactFile) {
+ String fileName = artifactFile.getName();
+
+ if (fileName.endsWith(JAR_SUFFIX) || fileName.endsWith(WAR_SUFFIX)) {
+ String name = fileName.substring(0, fileName.length() - JAR_SUFFIX.length());
+
+ ArtifactDescriptorBuilder artifactDescriptorBuilder = new ArtifactDescriptorBuilder();
+ artifactDescriptorBuilder.setUri(artifactFile.toURI());
+ artifactDescriptorBuilder.setName(name);
+ artifactDescriptorBuilder.setType(BRIDGE_TYPE);
+ artifactDescriptorBuilder.setVersion(Version.emptyVersion);
+
+ this.hashGenerator.generateHash(artifactDescriptorBuilder, artifactFile);
+
+ return artifactDescriptorBuilder.build();
+ }
+
+ return null;
+ }
+
+ private ArtifactDescriptor createArtifactDescriptorFromManifest(File artifactFile, BundleManifest bundleManifest) throws ArtifactGenerationException {
try {
ArtifactDescriptorBuilder artifactDescriptorBuilder = new ArtifactDescriptorBuilder();
diff --git a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java
index 0219e9cc..35791e57 100644
--- a/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java
+++ b/org.eclipse.virgo.kernel.artifact/src/main/java/org/eclipse/virgo/kernel/artifact/par/ParBridge.java
@@ -25,16 +25,17 @@ import org.eclipse.virgo.repository.builder.ArtifactDescriptorBuilder;
import org.eclipse.virgo.repository.builder.AttributeBuilder;
import org.eclipse.virgo.util.common.StringUtils;
import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
+import org.osgi.framework.Version;
/**
* An <code>ArtifactBridge</code> for PAR files.
- *
+ *
* <p />
- *
+ *
* <strong>Concurrent Semantics</strong><br />
- *
+ *
* Thread-safe.
- *
+ *
*/
public final class ParBridge implements ArtifactBridge {
@@ -50,6 +51,8 @@ public final class ParBridge implements ArtifactBridge {
public static final String BRIDGE_TYPE = "par";
+ public static final String PAR_SUFFIX = ".par";
+
private final HashGenerator hashGenerator;
public ParBridge(HashGenerator hashGenerator) {
@@ -61,7 +64,7 @@ public final class ParBridge implements ArtifactBridge {
BundleManifest manifest;
try {
- manifest = BundleManifestUtils.readBundleManifest(artifactFile, ".par");
+ manifest = BundleManifestUtils.readBundleManifest(artifactFile, PAR_SUFFIX);
} catch (IOException ioe) {
throw new ArtifactGenerationException("Failed to read manifest from " + artifactFile, ioe);
}
@@ -69,8 +72,25 @@ public final class ParBridge implements ArtifactBridge {
if (manifest != null) {
return createDescriptorFromManifest(manifest, artifactFile);
} else {
- return null;
+ return createDescriptorFromFile(artifactFile);
+ }
+ }
+
+ private ArtifactDescriptor createDescriptorFromFile(File artifactFile) throws ArtifactGenerationException {
+ String fileName = artifactFile.getName();
+
+ if (fileName.endsWith(PAR_SUFFIX)) {
+ String symbolicName = fileName.substring(0, fileName.length() - PAR_SUFFIX.length());
+
+ ArtifactDescriptorBuilder builder = new ArtifactDescriptorBuilder();
+ builder.setType(BRIDGE_TYPE).setName(symbolicName).setVersion(Version.emptyVersion).setUri(artifactFile.toURI());
+
+ this.hashGenerator.generateHash(builder, artifactFile);
+
+ return builder.build();
}
+
+ return null;
}
private ArtifactDescriptor createDescriptorFromManifest(BundleManifest manifest, File artifactFile) throws ArtifactGenerationException {
@@ -88,7 +108,7 @@ public final class ParBridge implements ArtifactBridge {
applyAttributeIfPresent(HEADER_APPLICATION_NAME, manifest, builder);
applyAttributeIfPresent(HEADER_APPLICATION_DESCRIPTION, manifest, builder);
-
+
this.hashGenerator.generateHash(builder, artifactFile);
return builder.build();
@@ -102,7 +122,7 @@ public final class ParBridge implements ArtifactBridge {
}
}
- private Version getApplicationVersion(BundleManifest manifest) throws ArtifactGenerationException {
+ private Version getApplicationVersion(BundleManifest manifest) {
String versionString = manifest.getHeader(HEADER_APPLICATION_VERSION);
Version version;
@@ -112,7 +132,7 @@ public final class ParBridge implements ArtifactBridge {
try {
version = new Version(versionString);
} catch (IllegalArgumentException iae) {
- throw new ArtifactGenerationException("Version '" + versionString + "' is ill-formed", iae);
+ throw new IllegalArgumentException("Version '" + versionString + "' is ill-formed", iae);
}
}
return version;
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
index 8d606dba..ef06b0a2 100644
--- a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
@@ -37,21 +37,21 @@ import org.osgi.framework.Version;
* Unit tests for {@link org.eclipse.virgo.kernel.artifact.bundle.BundleBridge BundleBridge}. Uses a combination of real bundle files and
* static test data.
* </p>
- *
+ *
* <strong>Concurrent Semantics</strong><br />
- *
+ *
* Threadsafe test case
- *
+ *
*/
public class BundleBridgeTests {
-
+
//Test Data
-
+
private final static String ARTEFACT_ATTRIBUTE_NAME = "name";
private final static String ARTEFACT_ATTRIBUTE_VERSION = "version";
//End Test Data
-
+
private static BundleBridge BUNDLE_BRIDGE;
private static final StubBundleArtefactBridge STUB_ARTEFACT_DEFINITION = new StubBundleArtefactBridge();
@@ -162,7 +162,7 @@ public class BundleBridgeTests {
public void webBundleWar() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = BUNDLE_BRIDGE.generateArtifactDescriptor(new File("src/test/resources/wars/test.war"));
assertNotNull(descriptor);
- assertEquals("bundle", descriptor.getType());
+ assertEquals(BundleBridge.BRIDGE_TYPE, descriptor.getType());
assertEquals("com.springsource.server.admin.web", descriptor.getName());
assertEquals(new Version(2, 0, 0), descriptor.getVersion());
}
@@ -171,14 +171,32 @@ public class BundleBridgeTests {
public void explodedBundle() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = BUNDLE_BRIDGE.generateArtifactDescriptor(new File("src/test/resources/bundle.jar"));
assertNotNull(descriptor);
- assertEquals("bundle", descriptor.getType());
+ assertEquals(BundleBridge.BRIDGE_TYPE, descriptor.getType());
assertEquals("exploded.bundle", descriptor.getName());
assertEquals(new Version(1, 0, 0), descriptor.getVersion());
}
+ @Test
+ public void noSymbolicName() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = BUNDLE_BRIDGE.generateArtifactDescriptor(new File("src/test/resources/jars/no-symbolic-name.jar"));
+ assertNotNull(descriptor);
+ assertEquals(BundleBridge.BRIDGE_TYPE, descriptor.getType());
+ assertEquals("no-symbolic-name", descriptor.getName());
+ assertEquals(new Version(0, 0, 0), descriptor.getVersion());
+ }
+
+ @Test
+ public void noManifest() throws ArtifactGenerationException {
+ ArtifactDescriptor descriptor = BUNDLE_BRIDGE.generateArtifactDescriptor(new File("src/test/resources/jars/no-manifest.jar"));
+ assertNotNull(descriptor);
+ assertEquals(BundleBridge.BRIDGE_TYPE, descriptor.getType());
+ assertEquals("no-manifest", descriptor.getName());
+ assertEquals(Version.emptyVersion, descriptor.getVersion());
+ }
+
private Set<ArtifactDescriptor> generateArtefacts(File directory) throws ArtifactGenerationException {
Set<ArtifactDescriptor> artefacts = new HashSet<ArtifactDescriptor>();
-
+
for (File fileInDir : directory.listFiles()) {
if(!fileInDir.getName().endsWith(".jar") && !fileInDir.getName().contains("sources")){
ArtifactDescriptor artefact = BUNDLE_BRIDGE.generateArtifactDescriptor(fileInDir);
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java
index 459889f3..8a47a352 100644
--- a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/par/ParBridgeTests.java
@@ -22,56 +22,51 @@ import java.io.File;
import org.junit.Test;
import org.osgi.framework.Version;
-
import org.eclipse.virgo.kernel.artifact.StubHashGenerator;
import org.eclipse.virgo.kernel.artifact.par.ParBridge;
import org.eclipse.virgo.repository.ArtifactDescriptor;
import org.eclipse.virgo.repository.ArtifactGenerationException;
-
-/**
- *
- */
public class ParBridgeTests {
-
+
private final ParBridge parBridge = new ParBridge(new StubHashGenerator());
-
+
@Test
public void descriptorGeneration() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/basic.par"));
assertDescriptor(descriptor, "par", "basic", new Version(1,2,3), "Basic Par", "A basic PAR file for the unit tests");
}
-
+
@Test
public void generationWithNoManifest() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-manifest.par"));
- assertNull(descriptor);
+ assertDescriptor(descriptor, "par", "no-manifest", Version.emptyVersion, null, null);
}
-
+
@Test
public void generationWithNoApplicationSymbolicName() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-asn.par"));
assertNull(descriptor);
}
-
+
@Test
public void generationWithNoApplicationVersion() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-version.par"));
assertDescriptor(descriptor, "par", "basic", Version.emptyVersion, "Basic Par", "A basic PAR file for the unit tests");
}
-
+
@Test
public void generationWithNoName() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-name.par"));
assertDescriptor(descriptor, "par", "basic", new Version(1,2,3), null, "A basic PAR file for the unit tests");
}
-
+
@Test
public void generationWithNoDescription() throws ArtifactGenerationException {
ArtifactDescriptor descriptor = this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/no-description.par"));
assertDescriptor(descriptor, "par", "basic", new Version(1,2,3), "Basic Par", null);
}
-
+
@Test
public void generationWithIllegalApplicationSymbolicName() throws Exception {
try {
@@ -79,24 +74,24 @@ public class ParBridgeTests {
fail("Illegal Application-SymbolicName did not throw an ArtifactGenerationException");
} catch (ArtifactGenerationException age) {
assertEquals("Application-SymbolicName '.@$%' contains illegal characters", age.getMessage());
- }
+ }
}
-
+
@Test
public void generationWithIllegalApplicationVersion() throws Exception {
try {
this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/illegal-version.par"));
- fail("Illegal Application-Version did not throw an ArtifactGenerationException");
- } catch (ArtifactGenerationException age) {
- assertEquals("Version 'alpha' is ill-formed", age.getMessage());
- }
+ fail("Illegal Application-Version did not throw an IllegalArgumentException");
+ } catch (IllegalArgumentException iae) {
+ assertEquals("Version 'alpha' is ill-formed", iae.getMessage());
+ }
}
-
+
@Test(expected=ArtifactGenerationException.class)
public void generationWithMissingPar() throws ArtifactGenerationException {
- this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/not-there.par"));
+ this.parBridge.generateArtifactDescriptor(new File("src/test/resources/pars/not-there.par"));
}
-
+
private void assertDescriptor(ArtifactDescriptor descriptor, String type, String symbolicName, Version version, String name, String description) {
assertNotNull(descriptor);
assertEquals(type, descriptor.getType());
@@ -107,7 +102,7 @@ public class ParBridgeTests {
} else {
assertTrue(descriptor.getAttribute("Application-Name").isEmpty());
}
-
+
if (description != null) {
assertEquals(description, descriptor.getAttribute("Application-Description").iterator().next().getValue());
} else {
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-manifest.jar b/org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-manifest.jar
new file mode 100644
index 00000000..f63054be
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-manifest.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-symbolic-name.jar b/org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-symbolic-name.jar
new file mode 100644
index 00000000..7ab5fb31
--- /dev/null
+++ b/org.eclipse.virgo.kernel.artifact/src/test/resources/jars/no-symbolic-name.jar
Binary files differ

Back to the top