aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1102801 - in /aries/trunk/spi-fly: spi-fly-examples/spi-fly-example-client2-bundle/src/main/java/org/apache/aries/spifly/examples/client2/impl/Activator.java spi-fly-static-tool/src/main/java/org/apache/aries/spifly/statictool/Main.java
Date Fri, 13 May 2011 15:59:27 GMT
Author: davidb
Date: Fri May 13 15:59:26 2011
New Revision: 1102801

URL: http://svn.apache.org/viewvc?rev=1102801&view=rev
Log:
Add support for jars embedded in the consumer via Bundle-ClassPath

Modified:
    aries/trunk/spi-fly/spi-fly-examples/spi-fly-example-client2-bundle/src/main/java/org/apache/aries/spifly/examples/client2/impl/Activator.java
    aries/trunk/spi-fly/spi-fly-static-tool/src/main/java/org/apache/aries/spifly/statictool/Main.java

Modified: aries/trunk/spi-fly/spi-fly-examples/spi-fly-example-client2-bundle/src/main/java/org/apache/aries/spifly/examples/client2/impl/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-examples/spi-fly-example-client2-bundle/src/main/java/org/apache/aries/spifly/examples/client2/impl/Activator.java?rev=1102801&r1=1102800&r2=1102801&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-examples/spi-fly-example-client2-bundle/src/main/java/org/apache/aries/spifly/examples/client2/impl/Activator.java
(original)
+++ aries/trunk/spi-fly/spi-fly-examples/spi-fly-example-client2-bundle/src/main/java/org/apache/aries/spifly/examples/client2/impl/Activator.java
Fri May 13 15:59:26 2011
@@ -1,3 +1,21 @@
+/**
+ * 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.spifly.examples.client2.impl;
 
 import java.util.ServiceLoader;

Modified: aries/trunk/spi-fly/spi-fly-static-tool/src/main/java/org/apache/aries/spifly/statictool/Main.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static-tool/src/main/java/org/apache/aries/spifly/statictool/Main.java?rev=1102801&r1=1102800&r2=1102801&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static-tool/src/main/java/org/apache/aries/spifly/statictool/Main.java
(original)
+++ aries/trunk/spi-fly/spi-fly-static-tool/src/main/java/org/apache/aries/spifly/statictool/Main.java
Fri May 13 15:59:26 2011
@@ -40,6 +40,7 @@ import org.apache.aries.spifly.weaver.TC
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
+import org.osgi.framework.Constants;
 
 public class Main {
     private static final String MODIFIED_BUNDLE_SUFFIX = "_spifly.jar";
@@ -78,7 +79,8 @@ public class Main {
         Manifest manifest = unJar(jarFile, tempDir);
         String consumerHeader = manifest.getMainAttributes().getValue(SpiFlyConstants.SPI_CONSUMER_HEADER);
         if (consumerHeader != null) {
-            weaveDir(tempDir, consumerHeader);
+            String bcp = manifest.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH);
+            weaveDir(tempDir, consumerHeader, bcp);
 
             manifest.getMainAttributes().remove(new Attributes.Name(SpiFlyConstants.SPI_CONSUMER_HEADER));
             manifest.getMainAttributes().putValue(SpiFlyConstants.PROCESSED_SPI_CONSUMER_HEADER,
consumerHeader);
@@ -151,7 +153,7 @@ public class Main {
         return new File(s);
     }
 
-    private static void weaveDir(File dir, String consumerHeader) throws IOException {
+    private static void weaveDir(File dir, String consumerHeader, String bundleClassPath)
throws IOException {
         String dirName = dir.getAbsolutePath();
 
         DirTree dt = new DirTree(dir);
@@ -185,6 +187,30 @@ public class Main {
                 os.close();
             }
         }
+
+        if (bundleClassPath != null) {
+            for (String entry : bundleClassPath.split(",")) {
+                File jarFile = new File(dir, entry.trim());
+                if (jarFile.isFile()) {
+                    weaveBCPJar(jarFile, consumerHeader);
+                }
+            }
+        }
+    }
+
+    private static void weaveBCPJar(File jarFile, String consumerHeader) throws IOException
{
+        File tempDir = new File(System.getProperty("java.io.tmpdir") + File.separator + jarFile.getName()
+ "_" + System.currentTimeMillis());
+        try {
+            Manifest manifest = unJar(jarFile, tempDir);
+            weaveDir(tempDir, consumerHeader, null);
+            if (!jarFile.delete()) {
+                throw new IOException("Could not replace file: " + jarFile);
+            }
+
+            jar(jarFile, tempDir, manifest);
+        } finally {
+            delTree(tempDir);
+        }
     }
 
     static Manifest unJar(File jarFile, File tempDir) throws IOException {



Mime
View raw message