You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2012/07/05 14:27:08 UTC
svn commit: r1357577 - in
/ace/sandbox/marrs/ace-client-repository-helper-bundle: ./ .settings/ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/ace/ src/main/java/org/apache/ace/client/
src/main/java/...
Author: marrs
Date: Thu Jul 5 12:27:07 2012
New Revision: 1357577
URL: http://svn.apache.org/viewvc?rev=1357577&view=rev
Log:
One last project seemed to be missing.
Added:
ace/sandbox/marrs/ace-client-repository-helper-bundle/
ace/sandbox/marrs/ace-client-repository-helper-bundle/.classpath
ace/sandbox/marrs/ace-client-repository-helper-bundle/.project
ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/
ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.core.resources.prefs
ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.jdt.core.prefs
ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.m2e.core.prefs
ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.pde.core.prefs
ace/sandbox/marrs/ace-client-repository-helper-bundle/pom.xml
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/Activator.java
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/test/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/test/java/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/test/java/org/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/test/java/org/apache/
ace/sandbox/marrs/ace-client-repository-helper-bundle/src/test/java/org/apache/ace/
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/.classpath
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/.classpath?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/.classpath (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/.classpath Thu Jul 5 12:27:07 2012
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/.project
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/.project?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/.project (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/.project Thu Jul 5 12:27:07 2012
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ace-client-repository-helper-bundle</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.core.resources.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.core.resources.prefs?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.core.resources.prefs (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.core.resources.prefs Thu Jul 5 12:27:07 2012
@@ -0,0 +1,5 @@
+#Mon Feb 27 09:47:16 CET 2012
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
+encoding/<project>=UTF-8
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.jdt.core.prefs?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.jdt.core.prefs (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.jdt.core.prefs Thu Jul 5 12:27:07 2012
@@ -0,0 +1,6 @@
+#Mon Feb 27 09:47:16 CET 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.m2e.core.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.m2e.core.prefs?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.m2e.core.prefs (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.m2e.core.prefs Thu Jul 5 12:27:07 2012
@@ -0,0 +1,5 @@
+#Mon Feb 27 09:46:19 CET 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.pde.core.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.pde.core.prefs?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.pde.core.prefs (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/.settings/org.eclipse.pde.core.prefs Thu Jul 5 12:27:07 2012
@@ -0,0 +1,3 @@
+#Mon Feb 27 09:47:17 CET 2012
+BUNDLE_ROOT_PATH=target/classes
+eclipse.preferences.version=1
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/pom.xml
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/pom.xml?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/pom.xml (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/pom.xml Thu Jul 5 12:27:07 2012
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-pom</artifactId>
+ <version>0.8.1-SNAPSHOT</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+
+ <version>0.8.1-SNAPSHOT</version>
+ <artifactId>org.apache.ace.client.repository.helper.bundle</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache ACE :: Client :: Repository :: Helper :: Bundle</name>
+ <description>Artifact recognizer and helper for bundles.</description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/ace/trunk/ace-client-repository-helper-bundle</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/ace/trunk/ace-client-repository-helper-bundle</developerConnection>
+ <url>http://svn.apache.org/repos/asf/ace/trunk/ace-client-repository-helper-bundle</url>
+ </scm>
+
+ <properties>
+ <import.package>
+ org.apache.ace.client.repository;version=${project.version},
+ org.apache.ace.client.repository.helper;version=${project.version},
+ org.apache.ace.client.repository.object;version=${project.version},
+ *
+ </import.package>
+ <private.package>
+ org.apache.ace.client.repository.helper.bundle.impl,
+ org.apache.ace.util
+ </private.package>
+ <bundle.activator>org.apache.ace.client.repository.helper.bundle.impl.Activator</bundle.activator>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>org.apache.ace.client.repository.api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.dependencymanager</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/Activator.java?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/Activator.java (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/Activator.java Thu Jul 5 12:27:07 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.ace.client.repository.helper.bundle.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.ace.client.repository.helper.ArtifactHelper;
+import org.apache.ace.client.repository.helper.ArtifactRecognizer;
+import org.apache.ace.client.repository.helper.bundle.BundleHelper;
+import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Activator class for the Bundle ArtifactHelper.
+ */
+public class Activator extends DependencyActivatorBase {
+
+ @Override
+ public synchronized void init(BundleContext context, DependencyManager manager) throws Exception {
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put(ArtifactObject.KEY_MIMETYPE, BundleHelper.MIMETYPE);
+ BundleHelperImpl helperImpl = new BundleHelperImpl();
+ manager.add(createComponent()
+ .setInterface(ArtifactHelper.class.getName(), props)
+ .setImplementation(helperImpl));
+ manager.add(createComponent()
+ .setInterface(ArtifactRecognizer.class.getName(), null)
+ .setImplementation(helperImpl));
+ manager.add(createComponent()
+ .setInterface(BundleHelper.class.getName(), null)
+ .setImplementation(helperImpl));
+ }
+
+ @Override
+ public synchronized void destroy(BundleContext context, DependencyManager manager) throws Exception {
+ // Nothing to do
+ }
+}
\ No newline at end of file
Added: ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java?rev=1357577&view=auto
==============================================================================
--- ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java (added)
+++ ace/sandbox/marrs/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java Thu Jul 5 12:27:07 2012
@@ -0,0 +1,282 @@
+/*
+ * 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.ace.client.repository.helper.bundle.impl;
+
+import java.io.IOException;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.apache.ace.client.repository.RepositoryUtil;
+import org.apache.ace.client.repository.helper.ArtifactHelper;
+import org.apache.ace.client.repository.helper.ArtifactPreprocessor;
+import org.apache.ace.client.repository.helper.ArtifactRecognizer;
+import org.apache.ace.client.repository.helper.ArtifactResource;
+import org.apache.ace.client.repository.helper.bundle.BundleHelper;
+import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.ace.util.VersionRange;
+import org.osgi.framework.Version;
+
+/**
+ * BundleHelperImpl provides the Artifact Repository with Helper and Recognizer services.
+ */
+public class BundleHelperImpl implements ArtifactRecognizer, BundleHelper {
+ /** A custom <code>Comparator</code>, used to sort bundles in increasing version */
+ private static final Comparator <ArtifactObject> BUNDLE_COMPARATOR = new Comparator<ArtifactObject>() {
+ public int compare(ArtifactObject left, ArtifactObject right) {
+ Version vLeft = new Version(left.getAttribute(BundleHelper.KEY_VERSION));
+ Version vRight = new Version(right.getAttribute(BundleHelper.KEY_VERSION));
+ return vRight.compareTo(vLeft);
+ }
+ };
+
+ /*
+ * From ArtifactHelper
+ */
+ public boolean canUse(ArtifactObject object) {
+ if (object == null) {
+ return false;
+ }
+ return (object.getMimetype().equals(MIMETYPE));
+ }
+
+ public <TYPE extends ArtifactObject> String getAssociationFilter(TYPE obj, Map<String, String> properties) {
+ /*
+ * Creates an endpoint filter for an association. If there is a KEY_ASSOCIATION_VERSIONSTATEMENT, a filter
+ * will be created that matches exactly the given range.
+ */
+ if ((properties != null) && properties.containsKey(KEY_ASSOCIATION_VERSIONSTATEMENT)) {
+ String versions = properties.get(KEY_ASSOCIATION_VERSIONSTATEMENT);
+ VersionRange versionRange = null;
+ try {
+ versionRange = VersionRange.parse(versions);
+ }
+ catch (IllegalArgumentException iae) {
+ throw new IllegalArgumentException("version " + ((versions != null) ? versions + " " : "(null) ") + "cannot be parsed into a valid version range statement.");
+ }
+
+ StringBuilder bundleStatement = new StringBuilder("(&(" + KEY_SYMBOLICNAME + "=" + RepositoryUtil.escapeFilterValue(obj.getAttribute(KEY_SYMBOLICNAME)) + ")");
+
+ bundleStatement.append("(" + KEY_VERSION + ">=" + versionRange.getLow() + ")");
+ if (!versionRange.isLowInclusive()) {
+ bundleStatement.append("(!(" + KEY_VERSION + "=" + versionRange.getLow() + "))");
+ }
+
+ if (versionRange.getHigh() != null) {
+ bundleStatement.append("(" + KEY_VERSION + "<=" + versionRange.getHigh() + ")");
+ if (!versionRange.isHighInclusive()) {
+ bundleStatement.append("(!(" + KEY_VERSION + "=" + versionRange.getHigh() + "))");
+ }
+ }
+
+ bundleStatement.append(")");
+
+ return bundleStatement.toString();
+ }
+ else
+ {
+ if (obj.getAttribute(KEY_VERSION) != null) {
+ return "(&(" + KEY_SYMBOLICNAME + "=" + RepositoryUtil.escapeFilterValue(obj.getAttribute(KEY_SYMBOLICNAME)) + ")(" + KEY_VERSION + "=" + RepositoryUtil.escapeFilterValue(obj.getAttribute(KEY_VERSION)) + "))";
+ }
+ else {
+ return "(&(" + KEY_SYMBOLICNAME + "=" + RepositoryUtil.escapeFilterValue(obj.getAttribute(KEY_SYMBOLICNAME)) + ")(!(" + KEY_VERSION + "=*)))";
+ }
+ }
+ }
+
+ public <TYPE extends ArtifactObject> int getCardinality(TYPE obj, Map<String, String> properties) {
+ /* Normally, all objects that match the filter given by the previous version should be part of the
+ * association. However, when a version statement has been given, only one should be used. */
+ if ((properties != null) && properties.containsKey(BundleHelper.KEY_ASSOCIATION_VERSIONSTATEMENT)) {
+ return 1;
+ }
+ else {
+ return Integer.MAX_VALUE;
+ }
+ }
+
+ public Comparator<ArtifactObject> getComparator() {
+ return BUNDLE_COMPARATOR;
+ }
+
+ public Map<String, String> checkAttributes(Map<String, String> attributes) {
+ return normalizeVersion(attributes);
+ }
+
+ /**
+ * For the filter to work correctly, we need to make sure the version statement is an
+ * OSGi version.
+ */
+ private static Map<String, String> normalizeVersion(Map<String, String> input) {
+ String version = input.get(KEY_VERSION);
+ if (version != null) {
+ try {
+ Version theVersion = new Version(version);
+ input.put(KEY_VERSION, theVersion.toString());
+ }
+ catch (IllegalArgumentException iae) {
+ throw new IllegalArgumentException("The version statement in the bundle cannot be parsed to a valid version.", iae);
+ }
+ }
+
+ return input;
+ }
+
+ /*
+ * From BundleHelper
+ */
+ public String[] getDefiningKeys() {
+ return new String[] {KEY_SYMBOLICNAME, KEY_VERSION};
+ }
+
+ public String[] getMandatoryAttributes() {
+ return new String[] {KEY_SYMBOLICNAME};
+ }
+
+ public String getResourceProcessorPIDs(ArtifactObject object) {
+ ensureBundle(object);
+ return object.getAttribute(KEY_RESOURCE_PROCESSOR_PID);
+ }
+
+ public String getSymbolicName(ArtifactObject object) {
+ ensureBundle(object);
+ return object.getAttribute(KEY_SYMBOLICNAME);
+ }
+
+ public String getName(ArtifactObject object) {
+ ensureBundle(object);
+ return object.getAttribute(KEY_NAME);
+ }
+
+ public String getVersion(ArtifactObject object) {
+ ensureBundle(object);
+ return object.getAttribute(KEY_VERSION);
+ }
+
+ public String getVendor(ArtifactObject object) {
+ ensureBundle(object);
+ return object.getAttribute(KEY_VENDOR);
+ }
+
+ public boolean isResourceProcessor(ArtifactObject object) {
+ ensureBundle(object);
+ return object.getAttribute(KEY_RESOURCE_PROCESSOR_PID) != null;
+ }
+
+ private void ensureBundle(ArtifactObject object) {
+ if ((object == null) || !object.getMimetype().equals(MIMETYPE)) {
+ throw new IllegalArgumentException("This ArtifactObject cannot be handled by a BundleHelper.");
+ }
+ }
+
+ /*
+ * From ArtifactRecognizer
+ */
+ public boolean canHandle(String mimetype) {
+ return MIMETYPE.equals(mimetype);
+ }
+
+ public Map<String, String> extractMetaData(ArtifactResource artifact) throws IllegalArgumentException {
+ /*
+ * Opens the URL as a Jar input stream, gets the manifest, and extracts headers from there.
+ */
+ JarInputStream jis = null;
+ try {
+ jis = new JarInputStream(artifact.openStream());
+
+ Attributes manifestAttributes = jis.getManifest().getMainAttributes();
+ Map<String, String> result = new HashMap<String, String>();
+
+ for (String key : new String[] {KEY_NAME, KEY_SYMBOLICNAME, KEY_VERSION, KEY_VENDOR, KEY_RESOURCE_PROCESSOR_PID}) {
+ String value = manifestAttributes.getValue(key);
+ if (value != null) {
+ result.put(key, value);
+ }
+ }
+
+ if (result.get(KEY_VERSION) == null) {
+ result.put(KEY_VERSION, "0.0.0");
+ }
+
+ result.put(ArtifactHelper.KEY_MIMETYPE, MIMETYPE);
+ result.put(ArtifactObject.KEY_PROCESSOR_PID, "");
+ String name = manifestAttributes.getValue(KEY_NAME);
+ String version = manifestAttributes.getValue(KEY_VERSION);
+ if (name == null) {
+ name = manifestAttributes.getValue(KEY_SYMBOLICNAME);
+ }
+ result.put(ArtifactObject.KEY_ARTIFACT_NAME, name + (version == null ? "" : "-" + version));
+
+ return result;
+ }
+ catch (Exception e) {
+ throw new IllegalArgumentException("Error extracting metadata from artifact.", e);
+ }
+ finally {
+ try {
+ jis.close();
+ }
+ catch (IOException e) {
+ // Too bad.
+ }
+ }
+ }
+
+ public String recognize(ArtifactResource artifact) {
+ /*
+ * Tries to find out whether this artifact is a bundle by (a) trying to open it as a
+ * jar, (b) trying to extract the manifest, and (c) checking whether that manifest
+ * contains a Bundle-SymbolicName header.
+ */
+ JarInputStream jis = null;
+ try {
+ jis = new JarInputStream(artifact.openStream());
+
+ Manifest manifest = jis.getManifest();
+
+ Attributes mainAttributes = manifest.getMainAttributes();
+ if (mainAttributes.getValue(KEY_SYMBOLICNAME) != null) {
+ return MIMETYPE;
+ }
+ }
+ catch (Exception e) {
+ return null;
+ }
+ finally {
+ try {
+ jis.close();
+ }
+ catch (Exception e) {
+ // Too bad.
+ }
+ }
+ return null;
+ }
+
+ public ArtifactPreprocessor getPreprocessor() {
+ return null;
+ }
+
+ public String getExtension(ArtifactResource artifact) {
+ return ".jar";
+ }
+}
\ No newline at end of file