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 2011/03/04 16:29:11 UTC
svn commit: r1078002 - in /aries/trunk/spi-fly: ./ spi-fly-core/
spi-fly-static-support-bundle/ spi-fly-static/ spi-fly-static/src/
spi-fly-static/src/main/ spi-fly-static/src/main/java/
spi-fly-static/src/main/java/org/ spi-fly-static/src/main/java/or...
Author: davidb
Date: Fri Mar 4 15:29:10 2011
New Revision: 1078002
URL: http://svn.apache.org/viewvc?rev=1078002&view=rev
Log:
Start of a static weaving tool.
Added:
aries/trunk/spi-fly/spi-fly-static/
aries/trunk/spi-fly/spi-fly-static-support-bundle/
aries/trunk/spi-fly/spi-fly-static-support-bundle/pom.xml
aries/trunk/spi-fly/spi-fly-static/pom.xml
aries/trunk/spi-fly/spi-fly-static/src/
aries/trunk/spi-fly/spi-fly-static/src/main/
aries/trunk/spi-fly/spi-fly-static/src/main/java/
aries/trunk/spi-fly/spi-fly-static/src/main/java/org/
aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/
aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/
aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/spifly/
aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/spifly/statictool/
aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/spifly/statictool/Main.java
aries/trunk/spi-fly/spi-fly-static/src/test/
aries/trunk/spi-fly/spi-fly-static/src/test/java/
aries/trunk/spi-fly/spi-fly-static/src/test/java/org/
aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/
aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/
aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/
aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/
aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/DirTree.java
aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/MainTest.java
aries/trunk/spi-fly/spi-fly-static/src/test/resources/
aries/trunk/spi-fly/spi-fly-static/src/test/resources/testjar.jar (with props)
Modified:
aries/trunk/spi-fly/pom.xml
aries/trunk/spi-fly/spi-fly-core/pom.xml
Modified: aries/trunk/spi-fly/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/pom.xml?rev=1078002&r1=1078001&r2=1078002&view=diff
==============================================================================
--- aries/trunk/spi-fly/pom.xml (original)
+++ aries/trunk/spi-fly/pom.xml Fri Mar 4 15:29:10 2011
@@ -56,5 +56,7 @@
<modules>
<module>spi-fly-deps</module>
<module>spi-fly-core</module>
+ <module>spi-fly-static</module>
+ <module>spi-fly-static-support-bundle</module>
</modules>
</project>
Modified: aries/trunk/spi-fly/spi-fly-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/pom.xml?rev=1078002&r1=1078001&r2=1078002&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/pom.xml (original)
+++ aries/trunk/spi-fly/spi-fly-core/pom.xml Fri Mar 4 15:29:10 2011
@@ -27,7 +27,7 @@
</parent>
<artifactId>org.apache.aries.spifly.core</artifactId>
- <packaging>bundle</packaging>
+ <packaging>jar</packaging>
<name>Apache Aries SPI Fly Core</name>
<description>
This bundle contains an extender that facilitates the use
Added: aries/trunk/spi-fly/spi-fly-static-support-bundle/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static-support-bundle/pom.xml?rev=1078002&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static-support-bundle/pom.xml (added)
+++ aries/trunk/spi-fly/spi-fly-static-support-bundle/pom.xml Fri Mar 4 15:29:10 2011
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ 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.
+ -->
+<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>
+ <parent>
+ <groupId>org.apache.aries.spifly</groupId>
+ <artifactId>spifly</artifactId>
+ <version>0.4-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.apache.aries.spifly.static.support.bundle</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Aries SPI Fly Static Weaving runtime support Bundle</name>
+ <description>
+ This bundle contains support classes used at runtime by bundles
+ woven using the static weaving done through the org.apache.aries.spifly.static
+ component.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.spifly</groupId>
+ <artifactId>org.apache.aries.spifly.core</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Export-Package>org.apache.aries.spifly</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: aries/trunk/spi-fly/spi-fly-static/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static/pom.xml?rev=1078002&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static/pom.xml (added)
+++ aries/trunk/spi-fly/spi-fly-static/pom.xml Fri Mar 4 15:29:10 2011
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ 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.
+ -->
+<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>
+ <parent>
+ <groupId>org.apache.aries.spifly</groupId>
+ <artifactId>spifly</artifactId>
+ <version>0.4-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.apache.aries.spifly.static</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Aries SPI Fly Static Weaving Tool</name>
+ <description>
+ This tool does the weaving to support SPI ServiceLoader statically.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.spifly</groupId>
+ <artifactId>org.apache.aries.spifly.core</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.aries.spifly.statictool.Main</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/spifly/statictool/Main.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/spifly/statictool/Main.java?rev=1078002&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/spifly/statictool/Main.java (added)
+++ aries/trunk/spi-fly/spi-fly-static/src/main/java/org/apache/aries/spifly/statictool/Main.java Fri Mar 4 15:29:10 2011
@@ -0,0 +1,104 @@
+/**
+ * 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.statictool;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.apache.aries.spifly.Streams;
+
+public class Main {
+ public static void usage() {
+ System.err.println();
+ System.err.println("Usage: java " + Main.class.getName() + " bundle1.jar bundle2.jar ...");
+ System.exit(-1);
+ }
+
+ public static void main(String ... args) throws Exception {
+ for (String arg : args) {
+ weaveJar(arg);
+ }
+ }
+
+ private static void weaveJar(String jarPath) throws IOException {
+ File jarFile = new File(jarPath);
+ File tempdir = new File(System.getProperty("java.io.tmpdir") + File.separator + jarFile.getName() + "_" + System.currentTimeMillis());
+ unJar(jarFile, tempdir);
+ }
+
+ static void unJar(File jarFile, File tempDir) throws IOException {
+ ensureDirectory(tempDir);
+
+ JarInputStream jis = new JarInputStream(new FileInputStream(jarFile));
+ JarEntry je = null;
+ while((je = jis.getNextJarEntry()) != null) {
+ if (je.isDirectory()) {
+ File outDir = new File(tempDir, je.getName());
+ ensureDirectory(outDir);
+
+ continue;
+ }
+
+ File outFile = new File(tempDir, je.getName());
+ File outDir = outFile.getParentFile();
+ ensureDirectory(outDir);
+
+ OutputStream out = new FileOutputStream(outFile);
+ try {
+ Streams.pump(jis, out);
+ } finally {
+ out.flush();
+ out.close();
+ jis.closeEntry();
+ }
+ outFile.setLastModified(je.getTime());
+ }
+
+ Manifest manifest = jis.getManifest();
+ if (manifest != null) {
+ File mf = new File(tempDir, "META-INF/MANIFEST.MF");
+ File mfDir = mf.getParentFile();
+ ensureDirectory(mfDir);
+
+ OutputStream out = new FileOutputStream(mf);
+ try {
+ manifest.write(out);
+ } finally {
+ out.flush();
+ out.close();
+ }
+ }
+
+ jis.close();
+ }
+
+ private static void ensureDirectory(File outDir) throws IOException {
+ if (!outDir.isDirectory())
+ if (!outDir.mkdirs())
+ throw new IOException("Unable to create directory " + outDir.getAbsolutePath());
+ }
+}
+
Added: aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/DirTree.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/DirTree.java?rev=1078002&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/DirTree.java (added)
+++ aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/DirTree.java Fri Mar 4 15:29:10 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.statictool;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DirTree {
+ List<File> fileList = new ArrayList<File>();
+
+ public DirTree(File f) {
+ String[] names = f.list();
+
+ if (names == null) {
+ fileList.add(f);
+ return;
+ }
+
+ for (String name : names) {
+ File curFile = new File(f, name);
+
+ if (curFile.isDirectory()) {
+ fileList.addAll(new DirTree(curFile).getFiles());
+ } else {
+ fileList.add(curFile);
+ }
+ }
+ fileList.add(f);
+ }
+
+ public List<File> getFiles() {
+ return fileList;
+ }
+}
Added: aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/MainTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/MainTest.java?rev=1078002&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/MainTest.java (added)
+++ aries/trunk/spi-fly/spi-fly-static/src/test/java/org/apache/aries/spifly/statictool/MainTest.java Fri Mar 4 15:29:10 2011
@@ -0,0 +1,85 @@
+/**
+ * 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.statictool;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.aries.spifly.Streams;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MainTest {
+ @Test
+ public void testUnJar() throws Exception {
+ URL jarURL = getClass().getResource("/testjar.jar");
+ File jarFile = new File(jarURL.getFile());
+ File tempDir = new File(System.getProperty("java.io.tmpdir") + "/testjar_" + System.currentTimeMillis());
+
+ try {
+ Main.unJar(jarFile, tempDir);
+
+ assertStreams(new File(tempDir, "META-INF/MANIFEST.MF"),
+ "jar:" + jarURL + "!/META-INF/MANIFEST.MF");
+
+ assertStreams(new File(tempDir, "A text File with no content"),
+ "jar:" + jarURL + "!/A text File with no content");
+ assertStreams(new File(tempDir, "dir/Main.class"),
+ "jar:" + jarURL + "!/dir/Main.class");
+ assertStreams(new File(tempDir, "dir/dir 2/a.txt"),
+ "jar:" + jarURL + "!/dir/dir 2/a.txt");
+ assertStreams(new File(tempDir, "dir/dir 2/b.txt"),
+ "jar:" + jarURL + "!/dir/dir 2/b.txt");
+
+ Assert.assertTrue(new File(tempDir, "dir/dir.3").exists());
+ } finally {
+ deleteTree(tempDir);
+ }
+ }
+
+ private void assertStreams(File file, String url) throws Exception {
+ InputStream is1 = new FileInputStream(file);
+ InputStream is2 = new URL(url).openStream();
+ try {
+ byte[] bytes1 = Streams.suck(is1);
+ byte[] bytes2 = Streams.suck(is2);
+ Assert.assertArrayEquals("Files not equal", bytes1, bytes2);
+ } finally {
+ is1.close();
+ is2.close();
+ }
+ }
+
+ public static void deleteTree(File dir) throws IOException {
+ if (!dir.isDirectory())
+ return;
+
+ for (File f : new DirTree(dir).getFiles()) {
+ if (!f.delete()) {
+ throw new IOException("Unable to delete file " + f.getAbsolutePath() +
+ " The file may still be in use.");
+ }
+ }
+ }
+}
+
+
Added: aries/trunk/spi-fly/spi-fly-static/src/test/resources/testjar.jar
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static/src/test/resources/testjar.jar?rev=1078002&view=auto
==============================================================================
Binary file - no diff available.
Propchange: aries/trunk/spi-fly/spi-fly-static/src/test/resources/testjar.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream