incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r898199 - in /incubator/aries/trunk/application: ./ application-converters/ application-converters/.settings/ application-converters/src/ application-converters/src/main/ application-converters/src/main/java/ application-converters/src/main...
Date Tue, 12 Jan 2010 07:17:29 GMT
Author: mahrwald
Date: Tue Jan 12 07:17:28 2010
New Revision: 898199

URL: http://svn.apache.org/viewvc?rev=898199&view=rev
Log:
ARIES-114 Initial move

Added:
    incubator/aries/trunk/application/application-converters/   (with props)
    incubator/aries/trunk/application/application-converters/.classpath
    incubator/aries/trunk/application/application-converters/.project
    incubator/aries/trunk/application/application-converters/.settings/
    incubator/aries/trunk/application/application-converters/.settings/org.eclipse.jdt.core.prefs
    incubator/aries/trunk/application/application-converters/.settings/org.maven.ide.eclipse.prefs
    incubator/aries/trunk/application/application-converters/pom.xml
    incubator/aries/trunk/application/application-converters/src/
    incubator/aries/trunk/application/application-converters/src/main/
    incubator/aries/trunk/application/application-converters/src/main/java/
    incubator/aries/trunk/application/application-converters/src/main/java/org/
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/Activator.java
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/ClassPathBuilder.java
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/JSPImportParser.java
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/PackageFinder.java
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java
    incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WarToWabConverter.java
    incubator/aries/trunk/application/application-converters/src/test/
    incubator/aries/trunk/application/application-converters/src/test/java/
    incubator/aries/trunk/application/application-converters/src/test/java/org/
    incubator/aries/trunk/application/application-converters/src/test/java/org/apache/
    incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/
    incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/
    incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/
    incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/JSPImportParserTest.java
    incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/WabConverterTest.java
    incubator/aries/trunk/application/application-converters/src/test/resources/
    incubator/aries/trunk/application/application-converters/src/test/resources/JSPs/
    incubator/aries/trunk/application/application-converters/src/test/resources/JSPs/helloImport.jsp
Modified:
    incubator/aries/trunk/application/pom.xml

Propchange: incubator/aries/trunk/application/application-converters/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jan 12 07:17:28 2010
@@ -0,0 +1 @@
+target

Added: incubator/aries/trunk/application/application-converters/.classpath
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/.classpath?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/.classpath (added)
+++ incubator/aries/trunk/application/application-converters/.classpath Tue Jan 12 07:17:28 2010
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="src" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: incubator/aries/trunk/application/application-converters/.project
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/.project?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/.project (added)
+++ incubator/aries/trunk/application/application-converters/.project Tue Jan 12 07:17:28 2010
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.aries.application.converters</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.wst.common.project.facet.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+	</natures>
+</projectDescription>

Added: incubator/aries/trunk/application/application-converters/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/.settings/org.eclipse.jdt.core.prefs?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/aries/trunk/application/application-converters/.settings/org.eclipse.jdt.core.prefs Tue Jan 12 07:17:28 2010
@@ -0,0 +1,5 @@
+#Sun Jan 10 13:09:12 GMT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5

Added: incubator/aries/trunk/application/application-converters/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/.settings/org.maven.ide.eclipse.prefs?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/.settings/org.maven.ide.eclipse.prefs (added)
+++ incubator/aries/trunk/application/application-converters/.settings/org.maven.ide.eclipse.prefs Tue Jan 12 07:17:28 2010
@@ -0,0 +1,9 @@
+#Sun Jan 10 13:09:12 GMT 2010
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1

Added: incubator/aries/trunk/application/application-converters/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/pom.xml?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/pom.xml (added)
+++ incubator/aries/trunk/application/application-converters/pom.xml Tue Jan 12 07:17:28 2010
@@ -0,0 +1,103 @@
+
+	<!--
+		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>
+	<parent>
+		<artifactId>application</artifactId>
+		<groupId>org.apache.aries.application</groupId>
+		<version>1.0.0-incubating-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+
+	<artifactId>org.apache.aries.application.converters</artifactId>
+	<packaging>bundle</packaging>
+	<name>Apache Aries Application Converters</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>asm</groupId>
+			<artifactId>asm-all</artifactId>
+			<version>3.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.aries.application</groupId>
+			<artifactId>org.apache.aries.application.api</artifactId>
+			<version>1.0.0-incubating-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.testsupport</groupId>
+			<artifactId>test-war-javaee_5</artifactId>
+			<version>2.2</version>
+			<type>war</type>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.aries.testsupport</groupId>
+			<artifactId>org.apache.aries.testsupport.unit</artifactId>
+			<version>1.0.0-incubating-SNAPSHOT</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Bundle-SymbolicName>${pom.groupId}.converters
+						</Bundle-SymbolicName>
+						<Bundle-Activator>org.apache.aries.application.converters.Activator
+						</Bundle-Activator>
+						<Export-Package>
+							org.apache.aries.application;version="${pom.version}",
+							org.apache.aries.application.filesystem;version="${pom.version}"
+						</Export-Package>
+						<_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))
+						</_versionpolicy>
+						<_removeheaders>Ignore-Package,Include-Resource,Private-Package,Bundle-DocURL
+						</_removeheaders>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<configuration>
+					<systemProperties>
+						<property>
+							<name>maven.repo.local</name>
+							<value>${localRepository}</value>
+						</property>
+					</systemProperties>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>
\ No newline at end of file

Added: incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/Activator.java?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/Activator.java (added)
+++ incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/Activator.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.converters;
+
+import org.apache.aries.application.management.BundleConverter;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+  public void start(BundleContext context) throws Exception {
+    context.registerService(BundleConverter.class.getName(), new WabConverterService(), null);
+  }
+
+  public void stop(BundleContext context) throws Exception {}
+
+}

Added: incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/ClassPathBuilder.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/ClassPathBuilder.java?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/ClassPathBuilder.java (added)
+++ incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/ClassPathBuilder.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,95 @@
+/*
+ * 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.converters;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.jar.Manifest;
+
+public class ClassPathBuilder
+{
+  private Map<String, Manifest> manifests;
+  
+  /**
+   * This class takes a map of <jarFileName, manifest> pairs which are contained in 
+   * a particular jar file.
+   * The updatePath method then uses this list to analyse the contents of the manifests
+   * and looks for any dependencies in the other manifests in the jar.
+   * @param manifests
+   */
+  public ClassPathBuilder(Map<String, Manifest> manifests)
+  {
+    this.manifests = manifests;
+  }
+
+  /**
+   * We take a full qualified jar file name and search its manifest for any other classpath
+   * dependencies within the other manifest in the parent jar file.
+   * @param jarFile
+   * @param classPath
+   * @return
+   * @throws IOException
+   */
+  public ArrayList<String> updatePath(String jarFile, ArrayList<String> classPath) throws IOException
+  {
+      // Get the classpath entries from this manifest and merge them into ours
+      Manifest manifest = manifests.get(jarFile);
+      
+      if (manifest == null)
+        return classPath;
+      
+      String dependencies = manifest.getMainAttributes().getValue("Class-Path");
+      if (dependencies == null)
+        dependencies = manifest.getMainAttributes().getValue("Class-path");
+            
+      if (dependencies != null)
+      {
+        // Search through the entries in the classpath
+        StringTokenizer tok = new StringTokenizer(dependencies, ";");
+        while (tok.hasMoreTokens()) {
+          String path = jarFile.substring(0, jarFile.lastIndexOf('/'));;
+          String entry = tok.nextToken();
+          
+          // Resolve the path to its canonical form
+          path = new File("/"+path+"/"+entry).getCanonicalPath().replace('\\','/');
+          path = path.substring(path.indexOf('/')+1);
+     
+          // If we havent already located this dependency before then we add this to our
+          // list of dependencies
+          if (entry.endsWith(".jar") && 
+              manifests.keySet().contains(path) && 
+              !classPath.contains(path) && 
+              !path.startsWith("WEB-INF/lib"))
+          {
+            classPath.add(path);
+            
+            // Recursively search the new classpath entry for more dependencies
+            classPath = updatePath(path, classPath);
+            
+          }
+        }
+      }
+
+    return classPath;
+  }
+
+}

Added: incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/JSPImportParser.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/JSPImportParser.java?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/JSPImportParser.java (added)
+++ incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/JSPImportParser.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.converters;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class JSPImportParser {
+
+  /**
+   * 
+   * @param is
+   *          An input stream of character-based text. We expect this to be JSP
+   *          source code.
+   * @return Each java package found within valid JSP import tags
+   * @throws IOException
+   */
+  public static Collection<String> getImports (InputStream is) throws IOException {
+    Collection<String> importedPackages = new LinkedList<String>();
+    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+    String line = null;
+    do { 
+      line = reader.readLine();
+      // searchMatchedGroupForImports could take (line): I've not done that because 
+      // the entry trace, once working, will print out lots of useless information.  
+      if (line != null) { 
+        Matcher hasJSPimport = lineWithJSPimport.matcher(line);
+        if (hasJSPimport.find()) {
+          Collection<String> foundImports = searchMatchedGroupForImports (hasJSPimport.group());
+          for (String found : foundImports) { 
+            if (!importedPackages.contains(found)) { 
+              importedPackages.add(found);
+            }
+          }
+        }
+      }
+    } while (line != null);
+    
+    return importedPackages;
+  }
+  
+  private static final Pattern lineWithJSPimport = Pattern.compile("<%@\\s*page\\s*import.*%>");
+  private static final Pattern stanzaEnd = Pattern.compile("%>");
+  private static final Pattern imports = Pattern.compile("import\\s*=\\s*\"(.*?)\"");
+  
+  /**
+   * 
+   * @param groupExtent a block of text known to contain a JSP import
+   * @return Each package found within valid JSP import tags
+   */
+  private static LinkedList<String> searchMatchedGroupForImports (String groupExtent) {
+    LinkedList<String> packagesFound = new LinkedList<String>();
+    String importStanzas[] = stanzaEnd.split(groupExtent);
+    for (String s: importStanzas){ 
+      Matcher oneImport = imports.matcher(s);
+      if (oneImport.find()) {
+        String thisStanzasImports = oneImport.group();
+        String allPackages = thisStanzasImports.substring(thisStanzasImports.indexOf("\"")+1, 
+            thisStanzasImports.lastIndexOf("\""));
+        String [] imports = allPackages.split(",");
+        for (String p : imports) { 
+          String thisPackage = p.substring(0,p.lastIndexOf('.')).trim();
+          
+          if (!!!thisPackage.startsWith("java."))
+            packagesFound.add(thisPackage);
+        }
+      }
+    }
+
+    return packagesFound;
+  }
+}

Added: incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/PackageFinder.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/PackageFinder.java?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/PackageFinder.java (added)
+++ incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/PackageFinder.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,454 @@
+/*
+ * 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.converters;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Attribute;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.signature.SignatureReader;
+import org.objectweb.asm.signature.SignatureVisitor;
+
+public class PackageFinder implements AnnotationVisitor, SignatureVisitor, ClassVisitor,
+    FieldVisitor, MethodVisitor
+{
+  private Set<String> packages = new HashSet<String>();
+  private Set<String> exemptPackages = new HashSet<String>();
+
+  // stored value of the signature class name
+  private String signatureOuterClass = null;
+
+  public Set<String> getImportPackages()
+  {
+    // Remove entries that will be imported by default
+    for (Iterator<String> i = packages.iterator(); i.hasNext();) {
+      if (i.next().startsWith("java.")) i.remove();
+    }
+    
+    return packages;
+  }
+  
+  public Set<String> getExemptPackages()
+  {
+    return exemptPackages;
+  }
+
+  private String getPackageName(String name)
+  {
+    String packageName = null;
+    if (name != null) {
+      int index = name.lastIndexOf('/');
+      if (index > 0) packageName = name.substring(0, index);
+    }
+    return packageName;
+  }
+
+  private String canonizePackage(String rawPackage)
+  {
+    String result = rawPackage.replace('/', '.');
+
+    // handle arrays
+    return result.replaceFirst("^\\[+L", "");
+  }
+  
+  private void addPackage(String packageName)
+  {
+    if (packageName != null) {
+      packages.add(canonizePackage(packageName));
+    }
+  }
+  
+  private void addExemptPackage(String packageName)
+  {
+    if (packageName != null) 
+      exemptPackages.add(canonizePackage(packageName));
+  }
+
+  private void addPackages(String[] packageNames)
+  {
+    if (packageNames != null) {
+      for (String s : packageNames)
+        if (s != null) {
+          packages.add(canonizePackage(s));
+        }
+    }
+  }
+
+  private String getResolvedPackageName(String name)
+  {
+    String resolvedName = null;
+    if (name != null) resolvedName = getPackageName(name);
+    return resolvedName;
+  }
+
+  private String[] getResolvedPackageNames(String[] names)
+  {
+    String[] resolvedNames = null;
+    if (names != null) {
+      resolvedNames = new String[names.length];
+      int i = 0;
+      for (String s : names)
+        resolvedNames[i++] = getResolvedPackageName(s);
+    }
+    return resolvedNames;
+  }
+
+  private String getDescriptorInfo(String descriptor)
+  {
+    String type = null;
+    if (descriptor != null) type = getType(Type.getType(descriptor));
+    return type;
+  }
+
+  private String[] getMethodDescriptorInfo(String descriptor)
+  {
+    String[] descriptors = null;
+    if (descriptor != null) {
+      Type[] types = Type.getArgumentTypes(descriptor);
+      descriptors = new String[types.length + 1];
+      descriptors[0] = getType(Type.getReturnType(descriptor));
+      int i = 1;
+      for (Type t : types)
+        descriptors[i++] = getType(t);
+    }
+    return descriptors;
+  }
+
+  private String getType(Type t)
+  {
+    String type = null;
+    switch (t.getSort())
+    {
+      case Type.ARRAY:
+        type = getType(t.getElementType());
+        break;
+      case Type.OBJECT:
+        type = getPackageName(t.getInternalName());
+        break;
+    }
+    return type;
+  }
+
+  private void addSignaturePackages(String signature)
+  {
+    if (signature != null) new SignatureReader(signature).accept(this);
+  }
+
+  private void addResolvedSignaturePackages(String signature)
+  {
+    if (signature != null) new SignatureReader(signature).acceptType(this);
+  }
+
+  //
+  // ClassVisitor methods
+  //
+
+  public void visit(int arg0, int arg1, String name, String signature, String parent,
+      String[] interfaces)
+  {
+    // We dont want to import our own packages so we add this classes package name to the
+    // list of exempt packages.
+    addExemptPackage(getPackageName(name));
+
+    if (signature == null) {
+      addPackage(getResolvedPackageName(parent));
+      addPackages(getResolvedPackageNames(interfaces));
+    } else addSignaturePackages(signature);
+  }
+
+  public AnnotationVisitor visitAnnotation(String descriptor, boolean visible)
+  {
+    addPackage(getDescriptorInfo(descriptor));
+    return this;
+  }
+
+  public void visitAttribute(Attribute arg0)
+  {
+    // No-op
+  }
+
+  public FieldVisitor visitField(int access, String name, String descriptor, String signature,
+      Object value)
+  {
+    if (signature == null) addPackage(getDescriptorInfo(descriptor));
+    else addResolvedSignaturePackages(signature);
+
+    if (value instanceof Type) addPackage(getType((Type) value));
+    return this;
+  }
+
+  public void visitInnerClass(String arg0, String arg1, String arg2, int arg3)
+  {
+    // no-op
+  }
+
+  public MethodVisitor visitMethod(int access, String name, String descriptor, String signature,
+      String[] exceptions)
+  {
+    if (signature == null) addPackages(getMethodDescriptorInfo(descriptor));
+    else addSignaturePackages(signature);
+
+    addPackages(getResolvedPackageNames(exceptions));
+    return this;
+
+  }
+
+  public void visitOuterClass(String arg0, String arg1, String arg2)
+  {
+    // no-op
+  }
+
+  public void visitSource(String arg0, String arg1)
+  {
+    // no-op
+  }
+
+  public void visitEnd()
+  {
+    // no-op
+  }
+
+  // 
+  // MethodVisitor methods
+  //
+
+  public AnnotationVisitor visitAnnotationDefault()
+  {
+    return this;
+  }
+
+  public void visitCode()
+  {
+    // no-op
+  }
+
+  public void visitFieldInsn(int opcode, String owner, String name, String descriptor)
+  {
+    addPackage(getResolvedPackageName(owner));
+    addPackage(getDescriptorInfo(descriptor));
+  }
+
+  public void visitFrame(int arg0, int arg1, Object[] arg2, int arg3, Object[] arg4)
+  {
+    // no-op
+  }
+
+  public void visitIincInsn(int arg0, int arg1)
+  {
+    // no-op
+  }
+
+  public void visitInsn(int arg0)
+  {
+    // no-op
+  }
+
+  public void visitIntInsn(int arg0, int arg1)
+  {
+    // no-op
+  }
+
+  public void visitJumpInsn(int arg0, Label arg1)
+  {
+    // no-op
+  }
+
+  public void visitLabel(Label arg0)
+  {
+    // no-op
+  }
+
+  public void visitLdcInsn(Object type)
+  {
+    if (type instanceof Type) addPackage(getType((Type) type));
+  }
+
+  public void visitLineNumber(int arg0, Label arg1)
+  {
+    // no-op
+  }
+
+  public void visitLocalVariable(String name, String descriptor, String signature, Label start,
+      Label end, int index)
+  {
+    addResolvedSignaturePackages(signature);
+  }
+
+  public void visitLookupSwitchInsn(Label arg0, int[] arg1, Label[] arg2)
+  {
+    // no-op
+  }
+
+  public void visitMaxs(int arg0, int arg1)
+  {
+    // no-op
+  }
+
+  public void visitMethodInsn(int opcode, String owner, String name, String descriptor)
+  {
+    addPackage(getResolvedPackageName(owner));
+    addPackages(getMethodDescriptorInfo(descriptor));
+  }
+
+  public void visitMultiANewArrayInsn(String descriptor, int arg1)
+  {
+    addPackage(getDescriptorInfo(descriptor));
+  }
+
+  public AnnotationVisitor visitParameterAnnotation(int arg0, String descriptor, boolean arg2)
+  {
+    addPackage(getDescriptorInfo(descriptor));
+    return this;
+  }
+
+  public void visitTableSwitchInsn(int arg0, int arg1, Label arg2, Label[] arg3)
+  {
+    //no-op
+  }
+
+  public void visitTryCatchBlock(Label arg0, Label arg1, Label arg2, String type)
+  {
+    addPackage(getResolvedPackageName(type));
+  }
+
+  public void visitTypeInsn(int arg0, String type)
+  {
+    addPackage(getResolvedPackageName(type));
+  }
+
+  public void visitVarInsn(int arg0, int arg1)
+  {
+    // no-op
+  }
+
+  //
+  // AnnotationVisitor Methods
+  //
+
+  public void visit(String arg0, Object value)
+  {
+    if (value instanceof Type) {
+      addPackage(getType((Type) value));
+    }
+  }
+
+  public AnnotationVisitor visitAnnotation(String arg0, String descriptor)
+  {
+    addPackage(getDescriptorInfo(descriptor));
+    return this;
+  }
+
+  public AnnotationVisitor visitArray(String arg0)
+  {
+    return this;
+  }
+
+  public void visitEnum(String name, String desc, String value)
+  {
+    addPackage(getDescriptorInfo(desc));
+  }
+
+  // 
+  // SignatureVisitor methods
+  //
+
+  public SignatureVisitor visitArrayType()
+  {
+    return this;
+  }
+
+  public void visitBaseType(char arg0)
+  {
+    // no-op
+  }
+
+  public SignatureVisitor visitClassBound()
+  {
+    return this;
+  }
+
+  public void visitClassType(String name)
+  {
+    signatureOuterClass = name;
+    addPackage(getResolvedPackageName(name));
+  }
+
+  public void visitInnerClassType(String name)
+  {
+    addPackage(getResolvedPackageName(signatureOuterClass + "$" + name));
+  }
+
+  public SignatureVisitor visitExceptionType()
+  {
+    return this;
+  }
+
+  public void visitFormalTypeParameter(String arg0)
+  {
+    // no-op
+  }
+
+  public SignatureVisitor visitInterface()
+  {
+    return this;
+  }
+
+  public SignatureVisitor visitParameterType()
+  {
+    return this;
+  }
+
+  public SignatureVisitor visitReturnType()
+  {
+    return this;
+  }
+
+  public SignatureVisitor visitSuperclass()
+  {
+    return this;
+  }
+
+  public void visitTypeArgument()
+  {
+    // no-op
+  }
+
+  public SignatureVisitor visitTypeArgument(char arg0)
+  {
+    return this;
+  }
+
+  public void visitTypeVariable(String arg0)
+  {
+    // no-op
+  }
+
+  public SignatureVisitor visitInterfaceBound()
+  {
+    return this;
+  }
+
+}

Added: 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=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java (added)
+++ incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WabConverterService.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,24 @@
+package org.apache.aries.application.converters;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.management.BundleConverter;
+
+public class WabConverterService implements BundleConverter {
+
+  public InputStream convert(IDirectory parentEba, IFile toBeConverted) {
+    try {
+      //TODO find the real name of the WAR file
+      WarToWabConverter converter = new WarToWabConverter(toBeConverted, new Properties());
+      return converter.getWAB();
+    } catch (IOException e) {
+      // TODO what to do with the Exception
+      return null;
+    }
+  }
+
+}

Added: incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WarToWabConverter.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WarToWabConverter.java?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WarToWabConverter.java (added)
+++ incubator/aries/trunk/application/application-converters/src/main/java/org/apache/aries/application/converters/WarToWabConverter.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,406 @@
+/*
+ * 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.converters;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+
+import org.apache.aries.application.filesystem.IFile;
+import org.objectweb.asm.ClassReader;
+import org.osgi.framework.Constants;
+
+public class WarToWabConverter {
+  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/";
+  private static final String CLASSPATH_LIB_PREFIX = "WEB-INF/lib/";
+  private static final String DEFAULT_IMPORT_PACKAGE_LIST = "javax.servlet;version=2.5,"
+      + "javax.servlet.http;version=2.5,"
+      + "javax.el;version=2.1,"
+      + "javax.servlet.jsp;version=2.1,"
+      + "javax.servlet.jsp.el;version=2.1,"
+      + "javax.servlet.jsp.tagext;version=2.1";
+
+  private static final String DEFAULT_WEB_CONTEXT_PATH = "/";
+  private static final String DEFAULT_WEB_JSP_EXTRACT_LOCATION = "/";
+
+  // TODO: These constants should be in the framework but at the time of write
+  // they
+  // do not exist. When they do we need to point at their values instead.
+  public static final String WEB_CONTEXT_PATH = "Web-ContextPath";
+  public static final String WEB_JSP_EXTRACT_LOCATION = "Web-JSPExtractLocation";
+
+  private Properties properties;
+
+  // InputStream for the new WAB file
+  private byte[] wabFile;
+  private String warName;
+  
+  private boolean converted = false;
+
+  // State used for updating the manifest
+  private ArrayList<String> fileNames;
+  private Set<String> importPackages;
+  private Set<String> exemptPackages;
+  private Map<String, Manifest> manifests; 
+  private ArrayList<String> classPath;
+  
+  private IFile warFile;
+
+  public WarToWabConverter(IFile warFile, Properties properties) throws IOException {
+    this.properties = properties;
+    fileNames = new ArrayList<String>();
+    classPath = new ArrayList<String>();
+    importPackages = new HashSet<String>();
+    exemptPackages = new HashSet<String>();
+    this.warFile = warFile;
+    this.warName = warFile.getName();
+  }
+  
+  private void convert() throws IOException {
+
+    ZipEntry entry;
+    JarInputStream jarInput = null;
+
+    Manifest manifest;
+    try {
+      jarInput = new JarInputStream(warFile.open());
+      scanForDependencies(jarInput);
+
+      // Add the new properties to the manifest byte stream
+      manifest = jarInput.getManifest();
+      manifest = updateManifest(manifest);
+    } 
+    finally {
+      try { if (jarInput != null) jarInput.close(); } catch (IOException e) { e.printStackTrace(); }
+    }
+
+    // Create a new jar file in memory with the new manifest and the old data
+    ByteArrayOutputStream output = new ByteArrayOutputStream();
+    JarOutputStream jarOutput = null;
+    jarInput = null;
+
+    // Copy across all entries from the original jar
+    int val;
+    try {
+      jarOutput = new JarOutputStream(output, manifest);
+      jarInput = new JarInputStream(warFile.open());
+      while ((entry = jarInput.getNextEntry()) != null) {
+        jarOutput.putNextEntry(entry);
+        while ((val = jarInput.read()) != -1)
+          jarOutput.write(val);
+      }
+    }
+    finally {
+      if (jarOutput != null)
+        jarOutput.close();
+      if (jarInput != null)
+        jarInput.close();
+    }
+
+    // Create a stream to the in-memory jar
+    wabFile = output.toByteArray();
+  }
+
+  private void scanRecursive(final JarInputStream jarInput, boolean topLevel) throws IOException 
+  {
+    ZipEntry entry;
+    
+    while ((entry = jarInput.getNextEntry()) != null) {
+      fileNames.add(entry.getName());
+      if (entry.getName().endsWith(".class")) {
+        PackageFinder pkgFinder = new PackageFinder();
+        new ClassReader(jarInput).accept(pkgFinder, ClassReader.SKIP_DEBUG);
+
+        importPackages.addAll(pkgFinder.getImportPackages());
+        exemptPackages.addAll(pkgFinder.getExemptPackages());
+      } else if (entry.getName().endsWith(".jsp")) { 
+        Collection<String> thisJSPsImports = JSPImportParser.getImports(jarInput);
+        importPackages.addAll(thisJSPsImports);
+      } else if (entry.getName().endsWith(".jar")) {
+        
+        JarInputStream newJar = new JarInputStream(new InputStream() {
+          @Override
+          public int read() throws IOException
+          {
+            return jarInput.read();
+          }
+        });
+        
+        // discard return, we only care about the top level jars
+        scanRecursive(newJar,false);
+        
+        // do not add jar embedded in already embedded jars
+        if (topLevel) {
+          manifests.put(entry.getName(), newJar.getManifest());
+        }
+      }
+    }
+  }
+  
+  /**
+   * 
+   * Read in the filenames inside the war (used for manifest update) Also
+   * analyse the bytecode of any .class files in order to find any required
+   * imports
+   */
+  private void scanForDependencies(final JarInputStream jarInput) throws IOException 
+  {
+    manifests = new HashMap<String, Manifest>();
+    
+    scanRecursive(jarInput, true);
+
+    // Process manifests from jars in order to work out classpath dependencies
+    ClassPathBuilder classPathBuilder = new ClassPathBuilder(manifests);
+    for (String fileName : manifests.keySet())
+      if (fileName.startsWith("WEB-INF/lib")) {
+        classPath.add(fileName);
+        classPath = classPathBuilder.updatePath(fileName, classPath);
+      }
+        
+    // Remove packages that are part of the classes we searched through
+    for (String s : exemptPackages)
+      if (importPackages.contains(s))
+        importPackages.remove(s);
+  }
+
+  protected Manifest updateManifest(Manifest manifest) throws IOException
+  {
+    // If for some reason no manifest was generated, we start our own so that we don't null pointer later on
+    if (manifest == null) {
+      manifest = new Manifest();
+      manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1");
+    }
+    
+    // Compare the manifest and the supplied properties
+
+    //
+    // Bundle-Version
+    //
+
+    if (manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION) == null
+        && !properties.containsKey(Constants.BUNDLE_VERSION)) {
+      properties.put(Constants.BUNDLE_VERSION, DEFAULT_BUNDLE_VERSION);
+    }
+
+    //
+    // Bundle-ManifestVersion
+    //
+
+    if (manifest.getMainAttributes().getValue(Constants.BUNDLE_MANIFESTVERSION) == null
+        && !properties.containsKey(Constants.BUNDLE_MANIFESTVERSION)) {
+      properties.put(Constants.BUNDLE_MANIFESTVERSION,
+          DEFAULT_BUNDLE_MANIFESTVERSION);
+    }
+
+    //
+    // Bundle-SymbolicName
+    //
+
+    if (manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) == null
+        && !properties.containsKey(Constants.BUNDLE_SYMBOLICNAME)) {
+      properties.put(Constants.BUNDLE_SYMBOLICNAME, warName + "_"
+          + manifest.hashCode());
+    }
+
+    // 
+    // Bundle-ClassPath
+    //
+
+    ArrayList<String> classpath = new ArrayList<String>();
+
+    // Set initial entry into classpath
+    classpath.add(0, INITIAL_CLASSPATH_ENTRY);
+
+    // Add any files from the WEB-INF/lib directory + their dependencies
+    classpath.addAll(classPath);
+    
+    for (String s : fileNames)
+      if (s.startsWith(CLASSPATH_LIB_PREFIX) && !classpath.contains(s))
+        classpath.add(s);
+
+    // Get the list from the URL and add to classpath (removing duplicates)
+    mergePathList(properties.getProperty(Constants.BUNDLE_CLASSPATH),
+        classpath, ";");
+
+    // Get the existing list from the manifest file and add to classpath
+    // (removing duplicates)
+    mergePathList(manifest.getMainAttributes().getValue(
+        Constants.BUNDLE_CLASSPATH), classpath, ";");
+
+    // Construct the classpath string and set it into the properties
+    StringBuffer classPathValue = new StringBuffer();
+    for (String entry : classpath) {
+      classPathValue.append(";");
+      classPathValue.append(entry);
+    }
+
+    if (!classpath.isEmpty())
+      properties.put(Constants.BUNDLE_CLASSPATH, classPathValue.toString()
+          .substring(1));
+
+    ArrayList<String> packages = new ArrayList<String>() {
+      @Override
+      public boolean contains(Object elem) {
+        // Check for exact match of export list
+        if (super.contains(elem))
+          return true;
+
+        if (!!!(elem instanceof String))
+          return false;
+
+        String expPackageStmt = (String) elem;
+        String expPackage = expPackageStmt.split("\\s*;\\s*")[0];
+        
+        Pattern p = Pattern.compile("^\\s*"+Pattern.quote(expPackage)+"((;|\\s).*)?\\s*$");
+        for (String s : this) {
+          Matcher m = p.matcher(s);
+          if (m.matches()) {
+            return true;
+          }
+        }
+
+        return false;
+      }
+
+    };
+    
+    //
+    // Import-Package
+    //
+    packages.clear();
+
+    // Get the list from the URL and add to classpath (removing duplicates)
+    mergePathList(properties.getProperty(Constants.IMPORT_PACKAGE), packages,
+        ",");
+
+    // Get the existing list from the manifest file and add to classpath
+    // (removing duplicates)
+    mergePathList(manifest.getMainAttributes().getValue(
+        Constants.IMPORT_PACKAGE), packages, ",");
+
+    // Add the default set of packages
+    mergePathList(DEFAULT_IMPORT_PACKAGE_LIST, packages, ",");
+
+    // Analyse the bytecode of any .class files in the jar to find any other
+    // required imports
+    if (!!!importPackages.isEmpty()) {
+      StringBuffer generatedImports = new StringBuffer();
+      for (String entry : importPackages) {
+        generatedImports.append(',');
+        generatedImports.append(entry);
+        generatedImports.append(";resolution:=optional");
+      }      
+      
+      mergePathList(generatedImports.substring(1), packages, ",");
+    }
+
+    // Construct the string and set it into the properties
+    StringBuffer importValues = new StringBuffer();
+    for (String entry : packages) {
+      importValues.append(",");
+      importValues.append(entry);
+    }
+    if (!packages.isEmpty())
+      properties.put(Constants.IMPORT_PACKAGE, importValues.toString()
+          .substring(1));
+
+    //
+    // Web-ContextPath
+    //
+
+    String webCPath = manifest.getMainAttributes().getValue(WEB_CONTEXT_PATH);
+    if (webCPath != null)
+    {
+      if (!webCPath.startsWith(DEFAULT_WEB_CONTEXT_PATH))
+      {
+          webCPath = DEFAULT_WEB_CONTEXT_PATH + webCPath;
+          properties.put(WEB_CONTEXT_PATH, webCPath);
+      }
+    }
+    else if ( !properties.containsKey(WEB_CONTEXT_PATH)) {
+      properties.put(WEB_CONTEXT_PATH, DEFAULT_WEB_CONTEXT_PATH);
+    }
+
+    //
+    // Web-JSPExtractLocation
+    //
+
+    if (manifest.getMainAttributes().getValue(WEB_JSP_EXTRACT_LOCATION) == null
+        && !properties.containsKey(WEB_JSP_EXTRACT_LOCATION)) {
+      properties
+          .put(WEB_JSP_EXTRACT_LOCATION, DEFAULT_WEB_JSP_EXTRACT_LOCATION);
+    }
+
+    // Take the properties map and add them to the manifest file
+    for (Object s : properties.keySet())
+      manifest.getMainAttributes().put(new Attributes.Name((String) s), properties.get(s));
+    
+    return manifest;
+  }
+
+  // pathlist = A "delim" delimitted list of path entries
+  public static void mergePathList(String pathlist, ArrayList<String> classpath,
+      String delim) {
+    if (pathlist != null) {
+      StringTokenizer tok = new StringTokenizer(pathlist, delim);
+      while (tok.hasMoreTokens()) {
+        String token = tok.nextToken().trim();
+        if (!classpath.contains(token))
+          classpath.add(token);
+      }
+    }
+  }
+
+  public InputStream getWAB() throws IOException {
+    if (!!!converted) {
+      convert();
+      converted = true;
+    }
+    
+    return new ByteArrayInputStream(wabFile);
+  }
+
+  public int getWabLength() throws IOException {
+    if (!!!converted) {
+      convert();
+      converted = true;
+    }
+
+    return wabFile.length;
+  }
+
+}

Added: incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/JSPImportParserTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/JSPImportParserTest.java?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/JSPImportParserTest.java (added)
+++ incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/JSPImportParserTest.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.converters;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.util.Collection;
+
+import org.junit.Test;
+
+public class JSPImportParserTest {
+
+  @Test
+  public void testJSPImportParser () throws Exception { 
+    InputStream helloImport = getClass().getClassLoader().getResourceAsStream("JSPs/helloImport.jsp");
+    Collection<String> imports = JSPImportParser.getImports(helloImport);
+    assertTrue("Four imports expected", imports.size() == 4);
+    assertTrue(imports.contains("javax.jms"));
+    assertTrue(imports.contains("javax.mystuff"));
+    assertTrue(imports.contains("javax.transaction"));
+    assertTrue(imports.contains("a.b"));
+    assertFalse(imports.contains("java.util"));
+  }
+}

Added: incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/WabConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/WabConverterTest.java?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/WabConverterTest.java (added)
+++ incubator/aries/trunk/application/application-converters/src/test/java/org/apache/aries/application/converters/WabConverterTest.java Tue Jan 12 07:17:28 2010
@@ -0,0 +1,119 @@
+/*
+ * 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.converters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.unittest.mocks.Skeleton;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+/**
+ * These tests do not cover the complete functionality (as yet). Rather this gives a place for adding
+ * smaller tests for individual units of work that don't need to be tested by converting a whole WAR file.
+ */
+public class WabConverterTest
+{
+  /**
+   * Test that we can handle a null manifest (in case a jar archive was created without manifest)
+   */
+  @Test
+  public void testNullManifest() throws Exception
+  {
+    WarToWabConverter sut = new WarToWabConverter(makeTestFile(new byte[0]), new Properties());
+    
+    Manifest res = sut.updateManifest(null);
+    Attributes attrs = res.getMainAttributes();
+    
+    assertTrue(attrs.getValue("Import-Package").contains("javax.servlet"));
+  }
+  
+  @Test
+  public void testImportPackageMerge() throws Exception
+  {
+    WarToWabConverter sut = new WarToWabConverter(makeTestFile(new byte[0]), new Properties());
+    
+    Manifest input = new Manifest();
+    input.getMainAttributes().putValue("Import-Package", "com.ibm.test,javax.servlet.http");
+    
+    Manifest res = sut.updateManifest(input);
+    Attributes attrs = res.getMainAttributes();
+    
+    assertEquals(
+        "com.ibm.test,"+
+        "javax.servlet.http,"+
+        "javax.servlet;version=2.5,"+
+        "javax.el;version=2.1,"+
+        "javax.servlet.jsp;version=2.1,"+
+        "javax.servlet.jsp.el;version=2.1,"+
+        "javax.servlet.jsp.tagext;version=2.1",
+        attrs.getValue("Import-Package"));
+  }
+  
+  
+  @Test
+  public void testAcceptNoManifest() throws Exception
+  {
+    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
+    JarOutputStream out = new JarOutputStream(bout);
+    out.putNextEntry(new ZipEntry("random.html"));
+    out.write("hello world".getBytes());
+    out.close();
+    
+    IFile input = makeTestFile(bout.toByteArray());
+    
+    Properties props = new Properties();
+    props.put(Constants.BUNDLE_SYMBOLICNAME, "test.bundle");
+    WarToWabConverter sut = new WarToWabConverter(input, props);
+    
+    Manifest m = new JarInputStream(sut.getWAB()).getManifest();
+    assertEquals("test.bundle", m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME));
+  }
+  
+  private IFile makeTestFile(byte[] content) {
+    return Skeleton.newMock(new IFileProxy(content), IFile.class);
+  }
+  
+  private static class IFileProxy {
+    private byte[] content;
+    
+    public IFileProxy(byte[] content) {
+      this.content = content;
+    }
+    
+    public InputStream open() {
+      return new ByteArrayInputStream(content);
+    }
+    
+    public String getName() { return "test.war"; }
+  }
+  
+}

Added: incubator/aries/trunk/application/application-converters/src/test/resources/JSPs/helloImport.jsp
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-converters/src/test/resources/JSPs/helloImport.jsp?rev=898199&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-converters/src/test/resources/JSPs/helloImport.jsp (added)
+++ incubator/aries/trunk/application/application-converters/src/test/resources/JSPs/helloImport.jsp Tue Jan 12 07:17:28 2010
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<HTML>
+<HEAD>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+	pageEncoding="ISO-8859-1"%>
+<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<META name="GENERATOR" content="IBM Software Development Platform">
+<TITLE>helloWorld.jsp</TITLE>
+</HEAD>
+<BODY>
+<P>
+Hello world - from JSP! With JMS Import!
+xxx <%@ page import="javax.jms.*, javax.mystuff.SomeClass" %> <%@ page import = "javax.transaction.package" %>xxx
+<%@ page import="a.b.AClass" %>
+<%@ page import="a.b.AnotherClassInADotB" %>
+<%@ page import="java.util.List" %>
+
+<BR/><BR/>
+Here is a random number <%= Math.random() %>
+</P>
+
+<% 
+  JMSException jmsx = new JMSException ("reason");
+%>
+Here's an exception: <%= jmsx.toString() %>
+
+</BODY>
+</HTML>

Modified: incubator/aries/trunk/application/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/pom.xml?rev=898199&r1=898198&r2=898199&view=diff
==============================================================================
--- incubator/aries/trunk/application/pom.xml (original)
+++ incubator/aries/trunk/application/pom.xml Tue Jan 12 07:17:28 2010
@@ -1,3 +1,4 @@
+<?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
@@ -15,8 +16,7 @@
  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">
+--><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">
 
     <parent>
         <groupId>org.apache.aries</groupId>
@@ -86,6 +86,7 @@
         <module>application-utils</module>
         <module>application-api</module>
         <module>application-management</module>
-    </modules>
+        <module>application-converters</module>
+  </modules>
 
-</project>
+</project>
\ No newline at end of file



Mime
View raw message