Author: mnuttall
Date: Thu Jul  1 15:55:55 2010
New Revision: 959704

URL: http://svn.apache.org/viewvc?rev=959704&view=rev
Log:
ARIES-344: BundleConverter interface returns one-use-only inputstream

Added:
    
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConversion.java
    
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WabConversion.java
Modified:
    
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConverter.java
    
incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java
    
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WarToWabConverter.java
    
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
    
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterService.java

Added: 
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConversion.java
URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConversion.java?rev=959704&view=auto
==============================================================================
--- 
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConversion.java
 (added)
+++ 
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConversion.java
 Thu Jul  1 15:55:55 2010
@@ -0,0 +1,45 @@
+/*
+ * 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 WARRANTIESOR 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.application.management;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.aries.application.ApplicationMetadataFactory;
+
+/**
+ * A BundleConversion represents a .JAR file which has been converted in to 
+ * an well-formed OSGi bundle, or a .WAR file which has been converted into a 
.WAB 
+ * file
+ */
+public interface BundleConversion {
+
+       /**
+        * @return The InputStream to the converted bundle.
+        */
+       public InputStream getInputStream() throws IOException;
+       
+       /** 
+        * @param The ApplicationMetadataFactory used to parse the content of 
+        * the converted bundle into a BundleInfo object
+        * @return The bundle information for the converted bundle.
+        */
+       public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws 
IOException;
+}

Modified: 
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConverter.java
URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConverter.java?rev=959704&r1=959703&r2=959704&view=diff
==============================================================================
--- 
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConverter.java
 (original)
+++ 
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleConverter.java
 Thu Jul  1 15:55:55 2010
@@ -38,6 +38,6 @@ public interface BundleConverter {
    * @return valid input stream or null if this converter does not support 
conversion of
    *         this artifact type.  
    */
-  public InputStream convert (IDirectory parentEba, IFile fileInEba) throws 
ConversionException;
+  public BundleConversion convert (IDirectory parentEba, IFile fileInEba) 
throws ConversionException;
 
 }

Modified: 
incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java
URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java?rev=959704&r1=959703&r2=959704&view=diff
==============================================================================
--- 
incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java
 (original)
+++ 
incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java
 Thu Jul  1 15:55:55 2010
@@ -22,9 +22,15 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.apache.aries.application.ApplicationMetadataFactory;
 import org.apache.aries.application.filesystem.IDirectory;
 import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.management.BundleConversion;
 import org.apache.aries.application.management.BundleConverter;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.utils.management.SimpleBundleInfo;
+import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.aries.web.converter.WabConversion;
 import org.apache.aries.web.converter.WarToWabConverter;
 import org.apache.aries.web.converter.WarToWabConverter.InputStreamProvider;
 import org.slf4j.Logger;
@@ -44,14 +50,26 @@ public class WabConverterService impleme
         this.wabConverter = wabConverter;
     }
 
-    public InputStream convert(IDirectory parentEba, final IFile 
toBeConverted) {
+    public BundleConversion convert(IDirectory parentEba, final IFile 
toBeConverted) {
         if (toBeConverted.getName().endsWith(WAR_FILE_EXTENSION)) {
             try {
-                return wabConverter.convert(new InputStreamProvider() {
+               final WabConversion conversion = wabConverter.convert(new 
InputStreamProvider() {
                     public InputStream getInputStream() throws IOException {
                         return toBeConverted.open();
                     }
                 }, toBeConverted.getName(), new Properties());
+                               
+                return new BundleConversion() {
+
+                                       public BundleInfo 
getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
+                                               return new 
SimpleBundleInfo(amf, BundleManifest.fromBundle(conversion.getWAB()), 
toBeConverted.toString());
+                                       }
+
+                                       public InputStream getInputStream() 
throws IOException {
+                                               return conversion.getWAB();
+                                       }
+                       
+                };
             } catch (IOException e) {
                 LOGGER.error("Encountered an exception while converting " + 
toBeConverted.getName() 
                         + " in " + parentEba.getName(), e);

Added: 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WabConversion.java
URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WabConversion.java?rev=959704&view=auto
==============================================================================
--- 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WabConversion.java
 (added)
+++ 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WabConversion.java
 Thu Jul  1 15:55:55 2010
@@ -0,0 +1,37 @@
+/*
+ * 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 WARRANTIESOR 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.web.converter;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Manifest;
+
+public interface WabConversion {
+
+       /**
+        * @return The WAB Manifest of the converted WAB
+        */
+       public Manifest getWABManifest() throws IOException;
+       
+       /**
+        * @return The InputStream to read the bytes of the converted WAB
+        */
+       public InputStream getWAB() throws IOException;
+}

Modified: 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WarToWabConverter.java
URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WarToWabConverter.java?rev=959704&r1=959703&r2=959704&view=diff
==============================================================================
--- 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WarToWabConverter.java
 (original)
+++ 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/WarToWabConverter.java
 Thu Jul  1 15:55:55 2010
@@ -21,7 +21,6 @@ package org.apache.aries.web.converter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
-import java.util.jar.Manifest;
 
 /**
  * Service interface for WAR to WAB conversion
@@ -37,16 +36,6 @@ public interface WarToWabConverter {
 
   public static final String WEB_CONTEXT_PATH = "Web-ContextPath";
 
-  
-  /**
-   * Generate the new manifest for the converted war file.
-   * @param input
-   * @param name The name of the war file
-   * @param properties Properties to influence the conversion as defined in 
RFC66 (see also {...@link #convert} method)
-   * @return
-   */
-  Manifest generateManifest(InputStreamProvider input, String name, Properties 
properties) throws IOException;
-  
   /**
    * Generate the converter WAB file. This file includes all the files from 
the input
    * and has the new manifest.
@@ -69,5 +58,5 @@ public interface WarToWabConverter {
    * (if it exists) and also the results of the scan of the WAR file.
    * @return
    */
-  InputStream convert(InputStreamProvider input, String name, Properties 
properties) throws IOException;
+  WabConversion convert(InputStreamProvider input, String name, Properties 
properties) throws IOException;
 }

Modified: 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java?rev=959704&r1=959703&r2=959704&view=diff
==============================================================================
--- 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
 (original)
+++ 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
 Thu Jul  1 15:55:55 2010
@@ -38,11 +38,13 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.zip.ZipEntry;
 
+import org.apache.aries.web.converter.WabConversion;
+import org.apache.aries.web.converter.WarToWabConverter;
 import org.apache.aries.web.converter.WarToWabConverter.InputStreamProvider;
 import org.objectweb.asm.ClassReader;
 import org.osgi.framework.Constants;
 
-public class WarToWabConverterImpl {
+public class WarToWabConverterImpl implements WabConversion {
   private static final String DEFAULT_BUNDLE_VERSION = "1.0";
   private static final String DEFAULT_BUNDLE_MANIFESTVERSION = "2";
   private static final String INITIAL_CLASSPATH_ENTRY = "WEB-INF/classes";

Modified: 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterService.java
URL: 
http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterService.java?rev=959704&r1=959703&r2=959704&view=diff
==============================================================================
--- 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterService.java
 (original)
+++ 
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterService.java
 Thu Jul  1 15:55:55 2010
@@ -19,22 +19,15 @@
 package org.apache.aries.web.converter.impl;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Properties;
-import java.util.jar.Manifest;
 
+import org.apache.aries.web.converter.WabConversion;
 import org.apache.aries.web.converter.WarToWabConverter;
 
 public class WarToWabConverterService implements WarToWabConverter {
 
-  public InputStream convert(InputStreamProvider input, String name, 
Properties properties) throws IOException {
-    WarToWabConverterImpl converter = new WarToWabConverterImpl(input, name, 
properties);
-    return converter.getWAB();
-  }
-
-  public Manifest generateManifest(InputStreamProvider input, String name, 
Properties properties) throws IOException {
-    WarToWabConverterImpl converter = new WarToWabConverterImpl(input, name, 
properties);
-    return converter.getWABManifest();
+  public WabConversion convert(InputStreamProvider input, String name, 
Properties properties) throws IOException {
+    return new WarToWabConverterImpl(input, name, properties);
   }
 
 }


Reply via email to