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/01/18 16:26:10 UTC
svn commit: r613186 - in /servicemix/smx4/features/trunk: ./ assembly/
assembly/src/main/descriptors/ assembly/src/main/filtered-resources/etc/
war/deployer/
war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/
Author: gnodet
Date: Fri Jan 18 07:26:05 2008
New Revision: 613186
URL: http://svn.apache.org/viewvc?rev=613186&view=rev
Log:
Update Features with the kernel modules
Added:
servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/BndUtils.java
Modified:
servicemix/smx4/features/trunk/assembly/pom.xml
servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml
servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml
servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties
servicemix/smx4/features/trunk/pom.xml
servicemix/smx4/features/trunk/war/deployer/pom.xml
servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/Activator.java
servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/WarDeploymentListener.java
Modified: servicemix/smx4/features/trunk/assembly/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/pom.xml?rev=613186&r1=613185&r2=613186&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/pom.xml (original)
+++ servicemix/smx4/features/trunk/assembly/pom.xml Fri Jan 18 07:26:05 2008
@@ -35,15 +35,15 @@
<dependencies>
<dependency>
- <groupId>org.apache.servicemix.runtime</groupId>
- <artifactId>apache-servicemix-runtime</artifactId>
- <version>${servicemix.runtime.version}</version>
+ <groupId>org.apache.servicemix.kernel</groupId>
+ <artifactId>apache-servicemix-kernel</artifactId>
+ <version>${servicemix.kernel.version}</version>
<type>zip</type>
</dependency>
<dependency>
- <groupId>org.apache.servicemix.runtime</groupId>
- <artifactId>apache-servicemix-runtime</artifactId>
- <version>${servicemix.runtime.version}</version>
+ <groupId>org.apache.servicemix.kernel</groupId>
+ <artifactId>apache-servicemix-kernel</artifactId>
+ <version>${servicemix.kernel.version}</version>
<type>tar.gz</type>
</dependency>
@@ -153,9 +153,9 @@
<configuration>
<artifactItems>
<artifactItem>
- <groupId>org.apache.servicemix.runtime</groupId>
- <artifactId>apache-servicemix-runtime</artifactId>
- <version>${servicemix.runtime.version}</version>
+ <groupId>org.apache.servicemix.kernel</groupId>
+ <artifactId>apache-servicemix-kernel</artifactId>
+ <version>${servicemix.kernel.version}</version>
<type>tar.gz</type>
<outputDirectory>target/dependencies/unix</outputDirectory>
</artifactItem>
@@ -171,9 +171,9 @@
<configuration>
<artifactItems>
<artifactItem>
- <groupId>org.apache.servicemix.runtime</groupId>
- <artifactId>apache-servicemix-runtime</artifactId>
- <version>${servicemix.runtime.version}</version>
+ <groupId>org.apache.servicemix.kernel</groupId>
+ <artifactId>apache-servicemix-kernel</artifactId>
+ <version>${servicemix.kernel.version}</version>
<type>zip</type>
<outputDirectory>target/dependencies/win</outputDirectory>
</artifactItem>
Modified: servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml?rev=613186&r1=613185&r2=613186&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml (original)
+++ servicemix/smx4/features/trunk/assembly/src/main/descriptors/unix-bin.xml Fri Jan 18 07:26:05 2008
@@ -24,7 +24,7 @@
<!-- Expanded ServiceMix Runtime -->
<fileSet>
- <directory>target/dependencies/unix/apache-servicemix-runtime-${servicemix.runtime.version}</directory>
+ <directory>target/dependencies/unix/apache-servicemix-kernel-${servicemix.kernel.version}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
Modified: servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml?rev=613186&r1=613185&r2=613186&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml (original)
+++ servicemix/smx4/features/trunk/assembly/src/main/descriptors/windows-bin.xml Fri Jan 18 07:26:05 2008
@@ -24,7 +24,7 @@
<!-- Expanded ServiceMix Runtime -->
<fileSet>
- <directory>target/dependencies/win/apache-servicemix-runtime-${servicemix.runtime.version}</directory>
+ <directory>target/dependencies/win/apache-servicemix-kernel-${servicemix.kernel.version}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
Modified: servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties?rev=613186&r1=613185&r2=613186&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties (original)
+++ servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/etc/startup.properties Fri Jan 18 07:26:05 2008
@@ -26,18 +26,18 @@
geronimo-servlet_2.5_spec-${geronimo.servlet.version}.jar=10
org.osgi.compendium-${felix.compendium.version}.jar=10
org.apache.felix.configadmin-${felix.configadmin.version}.jar=10
-org.apache.servicemix.runtime.filemonitor-${servicemix.runtime.version}.jar=15
+org.apache.servicemix.kernel.filemonitor-${servicemix.kernel.version}.jar=15
pax-logging-api-${pax.logging.version}.jar=20
pax-logging-service-${pax.logging.version}.jar=20
#
# The rest of the services..
#
-org.apache.servicemix.bundles.ant-${ant.version}-${servicemix.runtime.version}.jar=50
-org.apache.servicemix.bundles.aopalliance-${aopalliance.version}-${servicemix.runtime.version}.jar=50
-org.apache.servicemix.bundles.cglib-${cglib.version}-${servicemix.runtime.version}.jar=50
-org.apache.servicemix.bundles.mina-${mina.version}-${servicemix.runtime.version}.jar=50
-org.apache.servicemix.bundles.xstream-${xstream.version}-${servicemix.runtime.version}.jar=50
+org.apache.servicemix.bundles.ant-${ant.version}-${servicemix.kernel.version}.jar=50
+org.apache.servicemix.bundles.aopalliance-${aopalliance.version}-${servicemix.kernel.version}.jar=50
+org.apache.servicemix.bundles.cglib-${cglib.version}-${servicemix.kernel.version}.jar=50
+org.apache.servicemix.bundles.mina-${mina.version}-${servicemix.kernel.version}.jar=50
+org.apache.servicemix.bundles.xstream-${xstream.version}-${servicemix.kernel.version}.jar=50
geronimo-stax-api_1.0_spec-${geronimo.stax.version}.jar=50
geronimo-activation_1.1_spec-${geronimo.activation.version}.jar=50
spring-aop-${spring.version}.jar=50
@@ -49,9 +49,9 @@
spring-osgi-io-${spring.osgi.version}.jar=50
org.apache.felix.bundlerepository-${felix.bundlerepository.version}.jar=50
pax-runner-handler-mvn-${pax.runner.version}.jar=50
-org.apache.servicemix.runtime.gshell.obr-${servicemix.runtime.version}.jar=50
-org.apache.servicemix.runtime.gshell.osgi-${servicemix.runtime.version}.jar=50
-org.apache.servicemix.runtime.gshell.features-${servicemix.runtime.version}.jar=50
+org.apache.servicemix.kernel.gshell.obr-${servicemix.kernel.version}.jar=50
+org.apache.servicemix.kernel.gshell.osgi-${servicemix.kernel.version}.jar=50
+org.apache.servicemix.kernel.gshell.features-${servicemix.kernel.version}.jar=50
org.apache.servicemix.preferences-${servicemix.nmr.version}.jar=50
org.apache.servicemix.nmr.api-${servicemix.nmr.version}.jar=50
@@ -68,5 +68,5 @@
#
# Start console last
#
-org.apache.servicemix.runtime.gshell.core-${servicemix.runtime.version}.jar=100
+org.apache.servicemix.kernel.gshell.core-${servicemix.kernel.version}.jar=100
Modified: servicemix/smx4/features/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/pom.xml?rev=613186&r1=613185&r2=613186&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/pom.xml (original)
+++ servicemix/smx4/features/trunk/pom.xml Fri Jan 18 07:26:05 2008
@@ -60,6 +60,7 @@
<ant.version>1.7.0</ant.version>
<aopalliance.version>1.0</aopalliance.version>
<asm.version>2.2.3</asm.version>
+ <bnd.version>0.0.227</bnd.version>
<cglib.version>2.1_3</cglib.version>
<camel.version>1.3-SNAPSHOT</camel.version>
<commons.io.version>1.3.1</commons.io.version>
@@ -89,7 +90,7 @@
<mina.version>1.1.6-r602102</mina.version>
<pax.logging.version>1.0-RC2</pax.logging.version>
<pax.runner.version>0.5.5</pax.runner.version>
- <servicemix.runtime.version>1.0-m2-SNAPSHOT</servicemix.runtime.version>
+ <servicemix.kernel.version>1.0-m1-SNAPSHOT</servicemix.kernel.version>
<servicemix.nmr.version>1.0-SNAPSHOT</servicemix.nmr.version>
<spring.version>2.5</spring.version>
<spring.osgi.version>1.0-rc1</spring.osgi.version>
Modified: servicemix/smx4/features/trunk/war/deployer/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/war/deployer/pom.xml?rev=613186&r1=613185&r2=613186&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/war/deployer/pom.xml (original)
+++ servicemix/smx4/features/trunk/war/deployer/pom.xml Fri Jan 18 07:26:05 2008
@@ -36,9 +36,9 @@
<dependencies>
<dependency>
- <groupId>org.apache.servicemix.runtime</groupId>
- <artifactId>org.apache.servicemix.runtime.filemonitor</artifactId>
- <version>${servicemix.runtime.version}</version>
+ <groupId>org.apache.servicemix.kernel</groupId>
+ <artifactId>org.apache.servicemix.kernel.filemonitor</artifactId>
+ <version>${servicemix.kernel.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
@@ -58,6 +58,11 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>biz.aQute</groupId>
+ <artifactId>bndlib</artifactId>
+ <version>${bnd.version}</version>
+ </dependency>
</dependencies>
<build>
@@ -71,6 +76,7 @@
<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>
Modified: servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/Activator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/Activator.java?rev=613186&r1=613185&r2=613186&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/Activator.java (original)
+++ servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/Activator.java Fri Jan 18 07:26:05 2008
@@ -17,7 +17,7 @@
package org.apache.servicemix.war.deployer.impl;
import org.osgi.framework.*;
-import org.apache.servicemix.runtime.filemonitor.DeploymentListener;
+import org.apache.servicemix.kernel.filemonitor.DeploymentListener;
public class Activator implements BundleActivator {
Added: servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/BndUtils.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/BndUtils.java?rev=613186&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/BndUtils.java (added)
+++ servicemix/smx4/features/trunk/war/deployer/src/main/java/org/apache/servicemix/war/deployer/impl/BndUtils.java Fri Jan 18 07:26:05 2008
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2008 Alin Dreghiciu.
+ * Copyright 2008 Peter Kriens.
+ *
+ * Licensed 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.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Properties;
+import java.util.jar.Manifest;
+
+import aQute.lib.osgi.Analyzer;
+import aQute.lib.osgi.Jar;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Wrapper over PeterK's bnd lib.
+ *
+ * @author Alin Dreghiciu
+ * @since 0.1.0, January 14, 2008
+ */
+public class BndUtils
+{
+
+ /**
+ * Logger.
+ */
+ private static final Log LOG = LogFactory.getLog( BndUtils.class );
+
+ /**
+ * Utility class. Ment to be used using static methods
+ */
+ private BndUtils()
+ {
+ // utility class
+ }
+
+ /**
+ * Precesses the input jar and generates the necessary OSGi headers using specified instructions.
+ *
+ * @param input input file for the jar to be processed. Cannot be null.
+ * @param output output file for the new jar. Cannot be null.
+ * @param instructions bnd specific processing instructions. Cannot be null.
+ * @param jarInfo information about the jar to be processed. Usually the jar url. Cannot be null or empty.
+ *
+ * @return an input strim for the generated bundle
+ *
+ * @throws IOException re-thron during jar processing
+ */
+ public static void createBundle( final File input,
+ final File output,
+ final Properties instructions,
+ final String jarInfo )
+ throws IOException
+ {
+ LOG.debug( "Creating bundle for [" + jarInfo + "]" );
+ LOG.trace( "Using instructions " + instructions );
+
+ final Jar jar = new Jar( "dot", input );
+ final Manifest manifest = jar.getManifest();
+ final OutputStream outputStream = new FileOutputStream(output);
+
+ // Make the jar a bundle if it is not already a bundle
+ if( manifest == null
+ || ( manifest.getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE ) == null
+ && manifest.getMainAttributes().getValue( Analyzer.IMPORT_PACKAGE ) == null )
+ )
+ {
+ final Properties properties = new Properties( instructions );
+ properties.put( "Generated-By-Ops4j-Pax-From", jarInfo );
+ final Analyzer analyzer = new Analyzer();
+ analyzer.setJar( jar );
+ analyzer.setProperties( properties );
+ checkMandatoryProperties( analyzer, jar, jarInfo );
+ analyzer.mergeManifest( manifest );
+ analyzer.calcManifest();
+ }
+
+ try {
+ jar.write( outputStream );
+ }
+ catch( IOException e ) {
+ throw new RuntimeException( "Bundle cannot be generated, e" );
+ }
+ finally {
+ try {
+ jar.close();
+ outputStream.close();
+ }
+ catch( IOException ignore ) {
+ // if we get here something is very wrong
+ LOG.error( "Bundle cannot be generated, e" );
+ }
+ }
+ }
+
+ /**
+ * Check if manadatory properties are present, otherwise generate default.
+ *
+ * @param analyzer bnd analyzer
+ * @param jar bnd jar
+ * @param symbolicName bundle symbolic name
+ */
+ private static void checkMandatoryProperties( final Analyzer analyzer,
+ final Jar jar,
+ final String symbolicName )
+ {
+ final String importPackage = analyzer.getProperty( Analyzer.IMPORT_PACKAGE );
+ if( importPackage == null || importPackage.trim().length() == 0 )
+ {
+ analyzer.setProperty( Analyzer.IMPORT_PACKAGE, "*;resolution:=optional" );
+ }
+ final String exportPackage = analyzer.getProperty( Analyzer.EXPORT_PACKAGE );
+ if( exportPackage == null || exportPackage.trim().length() == 0 )
+ {
+ analyzer.setProperty( Analyzer.EXPORT_PACKAGE, analyzer.calculateExportsFromContents( jar ) );
+ }
+ final String localSymbolicName = analyzer.getProperty( Analyzer.BUNDLE_SYMBOLICNAME, symbolicName );
+ analyzer.setProperty( Analyzer.BUNDLE_SYMBOLICNAME, generateSymbolicName( localSymbolicName ) );
+ }
+
+ /**
+ * Processes symbolic name and replaces osgi spec invalid characters with "_".
+ *
+ * @param symbolicName bundle symbolic name
+ *
+ * @return a valid symbolic name
+ */
+ private static String generateSymbolicName( final String symbolicName )
+ {
+ return symbolicName.replaceAll( "[^a-zA-Z_0-9.-]", "_" );
+ }
+
+}
Modified: 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/impl/WarDeploymentListener.java?rev=613186&r1=613185&r2=613186&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/impl/WarDeploymentListener.java Fri Jan 18 07:26:05 2008
@@ -17,22 +17,22 @@
package org.apache.servicemix.war.deployer.impl;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+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.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.runtime.filemonitor.DeploymentListener;
+import org.apache.servicemix.kernel.filemonitor.DeploymentListener;
public class WarDeploymentListener implements DeploymentListener {
@@ -41,10 +41,6 @@
public boolean canHandle(File artifact) {
try {
- // Accept wars
- if (!artifact.getName().endsWith(".war")) {
- return false;
- }
JarFile jar = new JarFile(artifact);
JarEntry entry = jar.getJarEntry("WEB-INF/web.xml");
// Only handle WAR artifacts
@@ -65,79 +61,144 @@
public File handle(File artifact, File tmpDir) {
try {
- JarFile jar = new JarFile(artifact);
- Manifest m = jar.getManifest();
+ final Properties instructions = getInstructions();
+ generateClassPathInstruction(instructions, artifact);
- String version = m.getMainAttributes().getValue("Implementation-Version");
- String name = m.getMainAttributes().getValue("Implementation-Title");
- if (name == null) {
- name = artifact.getName();
- int idx = name.lastIndexOf('/');
- if (idx > 0) {
- name = name.substring(idx + 1);
- }
- idx = name.lastIndexOf('.');
- if (idx > 0) {
- name = name.substring(0, idx - 1);
- }
- }
- m.getMainAttributes().put(new Attributes.Name("Bundle-SymbolicName"), name);
- m.getMainAttributes().put(new Attributes.Name("Bundle-Version"), version);
- m.getMainAttributes().put(new Attributes.Name("Bundle-ClassPath"), getClassPath(jar));
- m.getMainAttributes().put(new Attributes.Name("Import-Package"), "javax.servlet,javax.servlet.http");
- m.getMainAttributes().put(new Attributes.Name("DynamicImport-Package"), "javax.*,org.xml.*,org.w3c.*");
+ File outFile = new File(tmpDir, artifact.getName());
- return generateWARArtifactBundle(artifact, tmpDir, m);
- } catch (Exception e) {
- LOGGER.error("Failed in transforming the WAR artifact to be OSGified");
+ BndUtils.createBundle(
+ artifact,
+ outFile,
+ instructions,
+ tmpDir.toURI().toString()
+ );
+
+ return outFile;
+
+ } catch (Exception e) {
+ LOGGER.error("Failed to transform the WAR artifact into an OSGi bundle");
return null;
}
}
- private String getClassPath(JarFile jar) {
- StringBuilder sb = new StringBuilder();
- sb.append(".,WEB-INF/classes");
- for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
- JarEntry j = e.nextElement();
- if (j.getName().startsWith("WEB-INF/lib/")) {
- sb.append(",");
- sb.append(j.getName());
+ 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
+ }
}
}
- return sb.toString();
}
- private File generateWARArtifactBundle(File artifact, File tmpDir, Manifest m) throws Exception {
- String bundleName = artifact.getName().substring(0, artifact.getName().length() -4 ) + ".jar";
- File destFile = new File(tmpDir, bundleName);
- if (destFile.exists()) {
- destFile.delete();
- }
-
- JarInputStream jis = new JarInputStream(new FileInputStream(artifact));
- JarOutputStream jos = new JarOutputStream(new FileOutputStream(destFile), m);
-
- JarEntry entry = jis.getNextJarEntry();
- while (entry != null) {
- jos.putNextEntry(entry);
- copyInputStream(jis, jos);
- jos.closeEntry();
- entry = jis.getNextJarEntry();
- }
-
- jos.close();
- jis.close();
-
- LOGGER.debug("Converted the WAR artifact to OSGified bundle [" + destFile.getAbsolutePath() + "]");
- return destFile;
- }
+ /**
+ * 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;
+ }
- protected void copyInputStream(InputStream in, OutputStream out) throws IOException {
- byte[] buffer = new byte[4096];
- int len;
- while ((len = in.read(buffer)) >= 0) {
- out.write(buffer, 0, len);
+ /**
+ * 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();
}
}