[jboss-osgi-commits] JBoss-OSGI SVN: r97541 - in projects/jboss-osgi/projects/spi/tags: jboss-osgi-spi-1.0.3.SP1 and 2 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Dec 8 09:21:12 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-12-08 09:21:09 -0500 (Tue, 08 Dec 2009)
New Revision: 97541

Added:
   projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/
   projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/pom.xml
   projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/capability/EventAdminCapability.java
   projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
Removed:
   projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/pom.xml
   projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
Log:
[maven-release-plugin]  copy for tag jboss-osgi-spi-1.0.3.SP1

Copied: projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1 (from rev 97534, projects/jboss-osgi/projects/spi/trunk)


Property changes on: projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1
___________________________________________________________________
Name: svn:ignore
   + target

Name: svn:mergeinfo
   + 

Deleted: projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/pom.xml
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/pom.xml	2009-12-08 12:30:17 UTC (rev 97534)
+++ projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/pom.xml	2009-12-08 14:21:09 UTC (rev 97541)
@@ -1,131 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-  <!-- ====================================================================== -->
-  <!--                                                                        -->
-  <!--  JBoss, the OpenSource J2EE webOS                                      -->
-  <!--                                                                        -->
-  <!--  Distributable under LGPL license.                                     -->
-  <!--  See terms of license at http://www.gnu.org.                           -->
-  <!--                                                                        -->
-  <!-- ====================================================================== -->
-
-  <!-- $Id$ -->
-  
-<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/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-
-  <name>JBossOSGi SPI</name>
-
-  <groupId>org.jboss.osgi</groupId>
-  <artifactId>jboss-osgi-spi</artifactId>
-  <packaging>jar</packaging>
-
-  <version>1.0.4-SNAPSHOT</version>
-  
-  <!-- Parent -->
-  <parent>
-    <groupId>org.jboss.osgi</groupId>
-    <artifactId>jboss-osgi-parent</artifactId>
-    <version>1.0.4</version>
-  </parent>
-
-  <!-- Subversion -->
-  <scm>
-    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-osgi/projects/spi/trunk</connection>
-    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-osgi/projects/spi/trunk</developerConnection>
-    <url>http://fisheye.jboss.com/qsearch/JBossOSGi</url>
-  </scm>
-  
-  <!-- Properties -->
-  <properties>
-    <version.args4j>2.0.12</version.args4j>
-    <version.jboss.vfs>2.1.3.SP1</version.jboss.vfs>
-    <version.osgi>4.2.0</version.osgi>
-  </properties>
-  
-  <!-- Dependencies -->
-  <dependencies>
-
-    <!-- Compile Dependencies -->
-    <dependency>
-      <groupId>args4j</groupId>
-      <artifactId>args4j</artifactId>
-      <version>${version.args4j}</version>
-    </dependency> 
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-vfs</artifactId>
-      <version>${version.jboss.vfs}</version>
-    </dependency>
-
-    <!-- Provided Dependencies -->
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>${version.osgi}</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.compendium</artifactId>
-      <version>${version.osgi}</version>
-      <scope>provided</scope>
-    </dependency>
-  </dependencies>
-
-  <!-- Build -->
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>build-helper-maven-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>attach-artifacts</id>
-            <phase>package</phase>
-            <goals>
-              <goal>attach-artifact</goal>
-            </goals>
-            <configuration>
-              <artifacts>
-                <artifact>
-                  <!-- For some reason the distribution javadoc module needs this -->
-                  <file>target/${artifactId}-${version}-sources.jar</file>
-                  <classifier>sources</classifier>
-                  <type>jar</type>
-                </artifact>
-              </artifacts>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-
-  <!-- Repositories -->
-  <repositories>
-    <repository>
-      <id>repository.jboss.org</id>
-      <name>JBoss Repository</name>
-      <url>http://repository.jboss.org/maven2/</url>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-    </repository>
-    <repository>
-      <id>snapshots.jboss.org</id>
-      <name>JBoss Snapshots Repository</name>
-      <url>http://snapshots.jboss.org/maven2/</url>
-      <releases>
-        <enabled>false</enabled>
-      </releases>
-      <snapshots>
-        <enabled>true</enabled>
-      </snapshots>
-    </repository>
-  </repositories>
-</project>

Copied: projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/pom.xml (from rev 97540, projects/jboss-osgi/projects/spi/trunk/pom.xml)
===================================================================
--- projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/pom.xml	                        (rev 0)
+++ projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/pom.xml	2009-12-08 14:21:09 UTC (rev 97541)
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+  <!-- ====================================================================== -->
+  <!--                                                                        -->
+  <!--  JBoss, the OpenSource J2EE webOS                                      -->
+  <!--                                                                        -->
+  <!--  Distributable under LGPL license.                                     -->
+  <!--  See terms of license at http://www.gnu.org.                           -->
+  <!--                                                                        -->
+  <!-- ====================================================================== -->
+
+  <!-- $Id$ -->
+  
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <name>JBossOSGi SPI</name>
+
+  <groupId>org.jboss.osgi</groupId>
+  <artifactId>jboss-osgi-spi</artifactId>
+  <packaging>jar</packaging>
+
+  <version>1.0.3.SP1</version>
+  
+  <!-- Parent -->
+  <parent>
+    <groupId>org.jboss.osgi</groupId>
+    <artifactId>jboss-osgi-parent</artifactId>
+    <version>1.0.4</version>
+  </parent>
+
+  <!-- Subversion -->
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1</developerConnection>
+    <url>http://fisheye.jboss.com/qsearch/JBossOSGi/tags/jboss-osgi-spi-1.0.3.SP1</url>
+  </scm>
+  
+  <!-- Properties -->
+  <properties>
+    <version.args4j>2.0.12</version.args4j>
+    <version.jboss.vfs>2.1.3.SP1</version.jboss.vfs>
+    <version.osgi>4.2.0</version.osgi>
+  </properties>
+  
+  <!-- Dependencies -->
+  <dependencies>
+
+    <!-- Compile Dependencies -->
+    <dependency>
+      <groupId>args4j</groupId>
+      <artifactId>args4j</artifactId>
+      <version>${version.args4j}</version>
+    </dependency> 
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-vfs</artifactId>
+      <version>${version.jboss.vfs}</version>
+    </dependency>
+
+    <!-- Provided Dependencies -->
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${version.osgi}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>${version.osgi}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <!-- Build -->
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-artifacts</id>
+            <phase>package</phase>
+            <goals>
+              <goal>attach-artifact</goal>
+            </goals>
+            <configuration>
+              <artifacts>
+                <artifact>
+                  <!-- For some reason the distribution javadoc module needs this -->
+                  <file>target/${artifactId}-${version}-sources.jar</file>
+                  <classifier>sources</classifier>
+                  <type>jar</type>
+                </artifact>
+              </artifacts>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <!-- Repositories -->
+  <repositories>
+    <repository>
+      <id>repository.jboss.org</id>
+      <name>JBoss Repository</name>
+      <url>http://repository.jboss.org/maven2/</url>
+      <snapshots>
+        <enabled>false</enabled>
+      </snapshots>
+    </repository>
+    <repository>
+      <id>snapshots.jboss.org</id>
+      <name>JBoss Snapshots Repository</name>
+      <url>http://snapshots.jboss.org/maven2/</url>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+      <snapshots>
+        <enabled>true</enabled>
+      </snapshots>
+    </repository>
+  </repositories>
+</project>

Copied: projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/capability/EventAdminCapability.java (from rev 97539, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/capability/EventAdminCapability.java)
===================================================================
--- projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/capability/EventAdminCapability.java	                        (rev 0)
+++ projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/capability/EventAdminCapability.java	2009-12-08 14:21:09 UTC (rev 97541)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.capability;
+
+//$Id$
+
+import org.osgi.service.event.EventAdmin;
+
+/**
+ * Adds the OSGi compedium EventAdmin capability. 
+ * 
+ * It is ignored if the {@link EventAdmin} is already registered.
+ * 
+ * Installed bundles: org.apache.felix.eventadmin.jar
+ * 
+ * [TODO] Add to SPI
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Dec-2009
+ */
+public class EventAdminCapability extends Capability
+{
+   public EventAdminCapability()
+   {
+      super(EventAdmin.class.getName());
+      
+      addDependency(new LogServiceCapability());
+      
+      addBundle("bundles/org.apache.felix.eventadmin.jar");
+   }
+}
\ No newline at end of file

Deleted: projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-12-08 12:30:17 UTC (rev 97534)
+++ projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-12-08 14:21:09 UTC (rev 97541)
@@ -1,271 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.spi.util;
-
-//$Id$
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
-
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Version;
-
-/**
- * Primitive access to bundle meta data and root virtual file.
- * 
- * The bundle info can be constructed from various locations.
- * If that succeeds, there is a valid OSGi Manifest. 
- * 
- * @author thomas.diesler at jboss.com
- * @since 16-Oct-2009
- */
-public class BundleInfo implements Serializable
-{
-   private static final long serialVersionUID = -2363297020450715134L;
-
-   private URL rootURL;
-   private String location;
-   private String symbolicName;
-   private String version;
-
-   private transient VirtualFile rootFile;
-   private transient Manifest manifest;
-
-   public static BundleInfo createBundleInfo(String location)
-   {
-      if (location == null)
-         throw new IllegalArgumentException("Location cannot be null");
-
-      URL url = getRealLocation(location);
-      if (url == null)
-         throw new IllegalArgumentException("Cannot obtain root url from: " + location);
-      
-      return new BundleInfo(toVirtualFile(url), location);
-   }
-
-   public static BundleInfo createBundleInfo(URL url)
-   {
-      if (url == null)
-         throw new IllegalArgumentException("Null root url");
-      
-      return new BundleInfo(toVirtualFile(url), url.toExternalForm());
-   }
-
-   public static BundleInfo createBundleInfo(VirtualFile root)
-   {
-      return new BundleInfo(root, null);
-   }
-
-   public static BundleInfo createBundleInfo(VirtualFile root, String location)
-   {
-      return new BundleInfo(root, location);
-   }
-
-   private BundleInfo(VirtualFile rootFile, String location)
-   {
-      if (rootFile == null)
-         throw new IllegalArgumentException("Root file cannot be null");
-
-      this.rootFile = rootFile;
-      this.rootURL = toURL(rootFile);
-
-      // Derive the location from the root
-      if (location == null)
-         location = rootURL.toExternalForm();
-      
-      this.location = location;
-
-      symbolicName = getManifestHeader(Constants.BUNDLE_SYMBOLICNAME);
-      if (symbolicName == null)
-         throw new IllegalArgumentException("Cannot obtain Bundle-SymbolicName for: " + rootFile);
-
-      version = getManifestHeader(Constants.BUNDLE_VERSION);
-      version = Version.parseVersion(version).toString();
-   }
-
-   /**
-    * Get the manifest header for the given key.
-    */
-   public String getManifestHeader(String key)
-   {
-      Attributes attribs = getManifest().getMainAttributes();
-      String value = attribs.getValue(key);
-      return value;
-   }
-
-   /**
-    * Get the bundle location
-    */
-   public String getLocation()
-   {
-      return location;
-   }
-
-   /**
-    * Get the bundle root file
-    */
-   public VirtualFile getRoot()
-   {
-      if (rootFile == null)
-         rootFile = toVirtualFile(rootURL);
-      
-      return rootFile;
-   }
-
-   /**
-    * Get the bundle root url
-    */
-   public URL getRootURL()
-   {
-      return toURL(getRoot());
-   }
-
-   /**
-    * Get the bundle symbolic name
-    */
-   public String getSymbolicName()
-   {
-      return symbolicName;
-   }
-
-   /**
-    * Get the bundle version
-    */
-   public Version getVersion()
-   {
-      return Version.parseVersion(version);
-   }
-
-   private Manifest getManifest()
-   {
-      if (manifest == null)
-      {
-         try
-         {
-            manifest = VFSUtils.getManifest(getRoot());
-         }
-         catch (Exception ex)
-         {
-            throw new IllegalArgumentException("Cannot get manifest from: " + rootURL, ex);
-         }
-      }
-      return manifest;
-   }
-
-   private static URL getRealLocation(String location)
-   {
-      // Try location as URL
-      URL url = null;
-      try
-      {
-         url = new URL(location);
-      }
-      catch (MalformedURLException ex)
-      {
-         // ignore
-      }
-
-      // Try location as File
-      if (url == null)
-      {
-         try
-         {
-            File file = new File(location);
-            if (file.exists())
-               url = file.toURI().toURL();
-         }
-         catch (MalformedURLException e)
-         {
-            // ignore
-         }
-      }
-      
-      // Try to prefix the location with the test archive directory
-      if (url == null)
-      {
-         String prefix = System.getProperty("test.archive.directory", "target/test-libs");
-         if (new File(prefix).exists())
-            return getRealLocation(prefix + File.separator + location);
-      }
-         
-      return url;
-   }
-
-   private static VirtualFile toVirtualFile(URL url)
-   {
-      try
-      {
-         return VFS.getRoot(url);
-      }
-      catch (IOException e)
-      {
-         throw new IllegalArgumentException("Invalid root url: " + url, e);
-      }
-   }
-
-   private static URL toURL(VirtualFile file)
-   {
-      try
-      {
-         return file.toURL();
-      }
-      catch (Exception e)
-      {
-         throw new IllegalArgumentException("Invalid root file: " + file);
-      }
-   }
-
-   private String toEqualString()
-   {
-      return "[" + symbolicName + "-" + version + ",url=" + rootURL + "]";
-   }
-
-   @Override
-   public boolean equals(Object obj)
-   {
-      if (!(obj instanceof BundleInfo))
-         return false;
-
-      BundleInfo other = (BundleInfo)obj;
-      return toEqualString().equals(other.toEqualString());
-   }
-
-   @Override
-   public int hashCode()
-   {
-      return toEqualString().hashCode();
-   }
-
-   @Override
-   public String toString()
-   {
-      return toEqualString();
-   }
-}
\ No newline at end of file

Copied: projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java (from rev 97539, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java)
===================================================================
--- projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	                        (rev 0)
+++ projects/jboss-osgi/projects/spi/tags/jboss-osgi-spi-1.0.3.SP1/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-12-08 14:21:09 UTC (rev 97541)
@@ -0,0 +1,271 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.util;
+
+//$Id$
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+/**
+ * Primitive access to bundle meta data and root virtual file.
+ * 
+ * The bundle info can be constructed from various locations.
+ * If that succeeds, there is a valid OSGi Manifest. 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 16-Oct-2009
+ */
+public class BundleInfo implements Serializable
+{
+   private static final long serialVersionUID = -2363297020450715134L;
+
+   private URL rootURL;
+   private String location;
+   private String symbolicName;
+   private String version;
+
+   private transient VirtualFile rootFile;
+   private transient Manifest manifest;
+
+   public static BundleInfo createBundleInfo(String location)
+   {
+      if (location == null)
+         throw new IllegalArgumentException("Location cannot be null");
+
+      URL url = getRealLocation(location);
+      if (url == null)
+         throw new IllegalArgumentException("Cannot obtain root url from: " + location);
+      
+      return new BundleInfo(toVirtualFile(url), location);
+   }
+
+   public static BundleInfo createBundleInfo(URL url)
+   {
+      if (url == null)
+         throw new IllegalArgumentException("Null root url");
+      
+      return new BundleInfo(toVirtualFile(url), url.toExternalForm());
+   }
+
+   public static BundleInfo createBundleInfo(VirtualFile root)
+   {
+      return new BundleInfo(root, null);
+   }
+
+   public static BundleInfo createBundleInfo(VirtualFile root, String location)
+   {
+      return new BundleInfo(root, location);
+   }
+
+   private BundleInfo(VirtualFile rootFile, String location)
+   {
+      if (rootFile == null)
+         throw new IllegalArgumentException("Root file cannot be null");
+
+      this.rootFile = rootFile;
+      this.rootURL = toURL(rootFile);
+
+      // Derive the location from the root
+      if (location == null)
+         location = rootURL.toExternalForm();
+      
+      this.location = location;
+
+      symbolicName = getManifestHeader(Constants.BUNDLE_SYMBOLICNAME);
+      if (symbolicName == null)
+         throw new IllegalArgumentException("Cannot obtain Bundle-SymbolicName for: " + rootFile);
+
+      version = getManifestHeader(Constants.BUNDLE_VERSION);
+      version = Version.parseVersion(version).toString();
+   }
+
+   /**
+    * Get the manifest header for the given key.
+    */
+   public String getManifestHeader(String key)
+   {
+      Attributes attribs = getManifest().getMainAttributes();
+      String value = attribs.getValue(key);
+      return value;
+   }
+
+   /**
+    * Get the bundle location
+    */
+   public String getLocation()
+   {
+      return location;
+   }
+
+   /**
+    * Get the bundle root file
+    */
+   public VirtualFile getRoot()
+   {
+      if (rootFile == null)
+         rootFile = toVirtualFile(rootURL);
+      
+      return rootFile;
+   }
+
+   /**
+    * Get the bundle root url
+    */
+   public URL getRootURL()
+   {
+      return toURL(getRoot());
+   }
+
+   /**
+    * Get the bundle symbolic name
+    */
+   public String getSymbolicName()
+   {
+      return symbolicName;
+   }
+
+   /**
+    * Get the bundle version
+    */
+   public Version getVersion()
+   {
+      return Version.parseVersion(version);
+   }
+
+   private Manifest getManifest()
+   {
+      if (manifest == null)
+      {
+         try
+         {
+            manifest = VFSUtils.getManifest(getRoot());
+         }
+         catch (Exception ex)
+         {
+            throw new IllegalArgumentException("Cannot get manifest from: " + rootURL, ex);
+         }
+      }
+      return manifest;
+   }
+
+   private static URL getRealLocation(String location)
+   {
+      // Try location as URL
+      URL url = null;
+      try
+      {
+         url = new URL(location);
+      }
+      catch (MalformedURLException ex)
+      {
+         // ignore
+      }
+
+      // Try location as File
+      if (url == null)
+      {
+         try
+         {
+            File file = new File(location);
+            if (file.exists())
+               url = file.toURI().toURL();
+         }
+         catch (MalformedURLException e)
+         {
+            // ignore
+         }
+      }
+      
+      // Try to prefix the location with the test archive directory
+      if (url == null)
+      {
+         String prefix = System.getProperty("test.archive.directory", "target/test-libs");
+         if (location.startsWith(prefix) == false && new File(prefix).exists())
+            return getRealLocation(prefix + File.separator + location);
+      }
+         
+      return url;
+   }
+
+   private static VirtualFile toVirtualFile(URL url)
+   {
+      try
+      {
+         return VFS.getRoot(url);
+      }
+      catch (IOException e)
+      {
+         throw new IllegalArgumentException("Invalid root url: " + url, e);
+      }
+   }
+
+   private static URL toURL(VirtualFile file)
+   {
+      try
+      {
+         return file.toURL();
+      }
+      catch (Exception e)
+      {
+         throw new IllegalArgumentException("Invalid root file: " + file);
+      }
+   }
+
+   private String toEqualString()
+   {
+      return "[" + symbolicName + "-" + version + ",url=" + rootURL + "]";
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (!(obj instanceof BundleInfo))
+         return false;
+
+      BundleInfo other = (BundleInfo)obj;
+      return toEqualString().equals(other.toEqualString());
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return toEqualString().hashCode();
+   }
+
+   @Override
+   public String toString()
+   {
+      return toEqualString();
+   }
+}
\ No newline at end of file



More information about the jboss-osgi-commits mailing list