You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/03/31 10:54:28 UTC

svn commit: r642930 - in /servicemix/smx4/features/trunk/war/deployer: ./ src/main/java/org/apache/servicemix/war/deployer/ src/main/java/org/apache/servicemix/war/deployer/impl/ src/main/resources/ src/main/resources/META-INF/ src/main/resources/META-...

Author: gnodet
Date: Mon Mar 31 01:54:24 2008
New Revision: 642930

URL: http://svn.apache.org/viewvc?rev=642930&view=rev
Log:
Fix war deployer

Added:
    servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/IOUtils.java
    servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/WarDeploymentListener.java
      - copied, changed from r642270, servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/WarDeploymentListener.java
    servicemix/smx4/features/trunk/war/deployer/src/main/resources/
    servicemix/smx4/features/trunk/war/deployer/src/main/resources/META-INF/
    servicemix/smx4/features/trunk/war/deployer/src/main/resources/META-INF/spring/
    servicemix/smx4/features/trunk/war/deployer/src/main/resources/META-INF/spring/war-deployer.xml
Removed:
    servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/
Modified:
    servicemix/smx4/features/trunk/war/deployer/pom.xml

Modified: servicemix/smx4/features/trunk/war/deployer/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/war/deployer/pom.xml?rev=642930&r1=642929&r2=642930&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/war/deployer/pom.xml (original)
+++ servicemix/smx4/features/trunk/war/deployer/pom.xml Mon Mar 31 01:54:24 2008
@@ -58,11 +58,6 @@
             <version>${junit.version}</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>biz.aQute</groupId>
-            <artifactId>bndlib</artifactId>
-            <version>${bnd.version}</version>
-        </dependency>
     </dependencies>
 
     <build>
@@ -73,10 +68,7 @@
                 <configuration>
                     <instructions>
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
-                        <Bundle-Activator>${pom.artifactId}.impl.Activator</Bundle-Activator>
-                        <Export-Package>${pom.artifactId}*</Export-Package>
                         <Import-Package>*</Import-Package>
-                        <Private-Package>aQute.*</Private-Package>
                     </instructions>
                 </configuration>
             </plugin>

Added: servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/IOUtils.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/IOUtils.java?rev=642930&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/IOUtils.java (added)
+++ servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/IOUtils.java Mon Mar 31 01:54:24 2008
@@ -0,0 +1,76 @@
+/**
+ * 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.servicemix.war.deployer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public final class IOUtils {
+
+    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+    private IOUtils() {
+    }
+
+    public static int copy(final InputStream input, final OutputStream output) throws IOException {
+        return copy(input, output, DEFAULT_BUFFER_SIZE);
+    }
+
+    public static int copy(final InputStream input,
+                           final OutputStream output,
+                           int bufferSize)
+        throws IOException {
+        int avail = input.available();
+        if (avail > 262144) {
+            avail = 262144;
+        }
+        if (avail > bufferSize) {
+            bufferSize = avail;
+        }
+        final byte[] buffer = new byte[bufferSize];
+        int n = 0;
+        n = input.read(buffer);
+        int total = 0;
+        while (-1 != n) {
+            output.write(buffer, 0, n);
+            total += n;
+            n = input.read(buffer);
+        }
+        return total;
+    }
+
+
+    public static int copyAndClose(final InputStream input, final OutputStream output) throws IOException {
+        return copyAndClose(input, output, DEFAULT_BUFFER_SIZE);
+    }
+
+    public static int copyAndClose(final InputStream input, final OutputStream output, final int bufferSize) throws IOException {
+        try {
+            return copy(input, output, bufferSize);
+        } finally {
+            try {
+                input.close();
+            } finally {
+                output.close();
+            }
+        }
+    }
+
+}

Copied: servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/WarDeploymentListener.java (from r642270, servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/WarDeploymentListener.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/WarDeploymentListener.java?p2=servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/WarDeploymentListener.java&p1=servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/WarDeploymentListener.java&r1=642270&r2=642930&rev=642930&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/WarDeploymentListener.java (original)
+++ servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/WarDeploymentListener.java Mon Mar 31 01:54:24 2008
@@ -14,17 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicemix.war.deployer.impl;
+package org.apache.servicemix.war.deployer;
 
 import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
+import java.io.FileOutputStream;
+import java.net.URL;
 import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -61,18 +55,9 @@
 
 	public File handle(File artifact, File tmpDir) {
 		try {
-            final Properties instructions = getInstructions();
-            generateClassPathInstruction(instructions, artifact);
-
+            URL war = new URL("war:" + artifact.toURL().toString());
             File outFile = new File(tmpDir, artifact.getName());
-
-            BndUtils.createBundle(
-                artifact,
-                outFile,
-                instructions,
-                tmpDir.toURI().toString()
-            );
-
+            IOUtils.copyAndClose(war.openStream(), new FileOutputStream(outFile));
             return outFile;
 
         } catch (Exception e) {
@@ -80,125 +65,5 @@
 			return null;
 		}
 	}
-
-    private static List<String> extractJarListFromWar(File artifact) throws IOException {
-        JarFile jarFile = null;
-        try {
-            jarFile = new JarFile(artifact);
-            final List<String> list = new ArrayList<String>();
-            Enumeration entries = jarFile.entries();
-            while( entries.hasMoreElements() ) {
-                JarEntry entry = (JarEntry) entries.nextElement();
-                String name = entry.getName();
-                if( !name.startsWith( "WEB-INF/lib/" ) ) {
-                    continue;
-                }
-                if( !name.endsWith( ".jar" ) ) {
-                    continue;
-                }
-                list.add( name );
-            }
-            return list;
-        } finally {
-            if (jarFile != null) {
-                try {
-                    jarFile.close();
-                } catch (IOException e) {
-                    // Ignore
-                }
-            }
-        }
-    }
-
-    /**
-     * Creates a set of default instructions.
-     */
-    protected Properties getInstructions() {
-        final Properties instructions = new Properties();
-        // war file to be processed
-        // default import packages
-        instructions.setProperty(
-            "Import-Package",
-            "javax.*; resolution:=optional,"
-            + "org.xml.*; resolution:=optional,"
-            + "org.w3c.*; resolution:=optional"
-        );
-        // default no export packages
-        instructions.setProperty(
-            "Export-Package",
-            "!*"
-        );
-        // remove unnecessary headers
-        instructions.setProperty(
-            "-removeheaders",
-            "Private-Package,"
-            + "Ignore-Package"
-        );
-        return instructions;
-    }
-
-    /**
-     * Generates the Bundle-ClassPath header by merging the Original classpath with:<br/>
-     * .<br/>
-     * WEB-INF/classes<br/>
-     * all jars found in WEB-INF/lib
-     *
-     * @param instructions instructions
-     *
-     * @throws java.io.IOException re-thrown from extractJarListFromWar()
-     */
-    private static void generateClassPathInstruction(final Properties instructions, final File jarFile) throws IOException {
-        final List<String> bundleClassPath = new ArrayList<String>();
-        // first take the bundle class path if present
-        bundleClassPath.addAll(toList(instructions.getProperty("Bundle-ClassPath"), ","));
-        // then get the list of jars in WEB-INF/lib
-        bundleClassPath.addAll(extractJarListFromWar(jarFile));
-        // check if we have a "WEB-INF/classpath" entry
-        if (!bundleClassPath.contains("WEB-INF/classes")) {
-            bundleClassPath.add(0, "WEB-INF/classes");
-        }
-        // check if we have a "." entry
-        if (!bundleClassPath.contains( "." )) {
-            bundleClassPath.add(0, ".");
-        }
-        // set back the new bundle classpath
-        instructions.setProperty( "Bundle-ClassPath", join( bundleClassPath, "," ) );
-    }
-
-    /**
-     * Splits a delimiter separated string into a list.
-     *
-     * @param separatedString string to be split
-     * @param delimiter       delimiter
-     *
-     * @return list composed out of the string segments
-     */
-    protected static List<String> toList(final String separatedString, final String delimiter) {
-        final List<String> list = new ArrayList<String>();
-        if (separatedString != null) {
-            list.addAll(Arrays.asList(separatedString.split(delimiter)));
-        }
-        return list;
-    }
-
-    /**
-     * Joins elements from a collection into a delimiter separated string.
-     *
-     * @param strings   collection of ellements
-     * @param delimiter delimiter
-     *
-     * @return string composed from the collection elements delimited by the delimiter
-     */
-    protected static String join(final Collection<String> strings, final String delimiter) {
-        final StringBuffer buffer = new StringBuffer();
-        final Iterator<String> iter = strings.iterator();
-        while (iter.hasNext()) {
-            buffer.append(iter.next());
-            if (iter.hasNext()) {
-                buffer.append(delimiter);
-            }
-        }
-        return buffer.toString();
-    }
 
 }

Added: servicemix/smx4/features/trunk/war/deployer/src/main/resources/META-INF/spring/war-deployer.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/war/deployer/src/main/resources/META-INF/spring/war-deployer.xml?rev=642930&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/war/deployer/src/main/resources/META-INF/spring/war-deployer.xml (added)
+++ servicemix/smx4/features/trunk/war/deployer/src/main/resources/META-INF/spring/war-deployer.xml Mon Mar 31 01:54:24 2008
@@ -0,0 +1,37 @@
+<?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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+  http://www.springframework.org/schema/beans
+  http://www.springframework.org/schema/beans/spring-beans.xsd
+  http://www.springframework.org/schema/util
+  http://www.springframework.org/schema/util/spring-util.xsd
+  http://www.springframework.org/schema/osgi
+  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+    <!-- The WAR deployment listener -->
+    <bean id="warDeployer" class="org.apache.servicemix.war.deployer.WarDeploymentListener" />
+
+    <osgi:service ref="warDeployer" interface="org.apache.servicemix.kernel.filemonitor.DeploymentListener" />
+
+</beans>
\ No newline at end of file