Author: rsearls
Date: 2015-02-08 15:27:48 -0500 (Sun, 08 Feb 2015)
New Revision: 19436
Added:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/UrlUtils.java
Modified:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractToolsMojo.java
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsConsumeMojo.java
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsProvideMojo.java
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractConsumerParams.java
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractDelegate.java
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractProviderParams.java
Log:
[JBWS-3824] code added to generate manifest-only jar file for both wsprovide and
wsconsume.
Modified:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractToolsMojo.java
===================================================================
---
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractToolsMojo.java 2015-01-29
07:09:24 UTC (rev 19435)
+++
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractToolsMojo.java 2015-02-08
20:27:48 UTC (rev 19436)
@@ -22,11 +22,16 @@
package org.jboss.ws.plugins.tools;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
@@ -72,7 +77,7 @@
* @parameter default-value="false"
*/
protected Boolean fork;
-
+
/**
* Either ${build.outputDirectory} or ${build.testOutputDirectory}.
*/
@@ -164,5 +169,47 @@
{
return fork;
}
-
+
+ /**
+ * Create a jar with just a manifest containing a Main-Class entry and a Class-Path
entry
+ * for all classpath elements.
+ *
+ * @param classPath List<String> of all classpath elements.
+ * @param startClassName The classname to start (main-class)
+ * @return The file pointint to the jar
+ * @throws java.io.IOException When a file operation fails.
+ */
+ public File createJar( List<String> classPath, String startClassName )
+ throws IOException
+ {
+ File tempDirectory = getOutputDirectory();
+ tempDirectory.mkdirs();
+ File file = File.createTempFile( "jbosswsJaxwsTools", ".jar",
tempDirectory );
+
+ FileOutputStream fos = new FileOutputStream( file );
+ JarOutputStream jos = new JarOutputStream( fos );
+ jos.setLevel( JarOutputStream.STORED );
+ JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" );
+ jos.putNextEntry( je );
+
+ Manifest man = new Manifest();
+
+ // we can't use StringUtils.join here since we need to add a '/' to
+ // the end of directory entries - otherwise the jvm will ignore them.
+ String cp = "";
+ for ( String el : classPath )
+ {
+ // NOTE: if File points to a directory, this entry MUST end in '/'.
+ cp += UrlUtils.getURL(new File(el)).toExternalForm() + " ";
+ }
+
+ man.getMainAttributes().putValue( "Manifest-Version", "1.0" );
+ man.getMainAttributes().putValue( "Class-Path", cp.trim() );
+ man.getMainAttributes().putValue( "Main-Class", startClassName );
+
+ man.write( jos );
+ jos.close();
+
+ return file;
+ }
}
Modified:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsConsumeMojo.java
===================================================================
---
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsConsumeMojo.java 2015-01-29
07:09:24 UTC (rev 19435)
+++
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsConsumeMojo.java 2015-02-08
20:27:48 UTC (rev 19436)
@@ -148,6 +148,10 @@
params.setEncoding(encoding);
params.setArgLine(argLine);
params.setFork(fork);
+
+ File manifestOnlyJar = createJar(getClasspathElements(), "");
+ params.setManifestOnlyJar(manifestOnlyJar);
+
WSContractDelegate delegate = new WSContractDelegate(getLog());
for (String wsdl : wsdls)
@@ -167,6 +171,10 @@
}
updateProjectSourceRoots();
}
+ catch (java.io.IOException ioe)
+ {
+ throw new MojoExecutionException("Error while running wsconsume",
ioe);
+ }
finally
{
Thread.currentThread().setContextClassLoader(origLoader);
Modified:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsProvideMojo.java
===================================================================
---
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsProvideMojo.java 2015-01-29
07:09:24 UTC (rev 19435)
+++
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/AbstractWsProvideMojo.java 2015-02-08
20:27:48 UTC (rev 19436)
@@ -92,7 +92,7 @@
log.info(" " + s);
}
}
-
+
ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader loader = getMavenClasspathAwareClassLoader();
Thread.currentThread().setContextClassLoader(loader);
@@ -110,7 +110,10 @@
params.setFork(fork);
params.setArgLine(argLine);
params.setPortSoapAddress(portSoapAddress);
-
+
+ File manifestOnlyJar = createJar(getClasspathElements(), endpointClass);
+ params.setManifestOnlyJar(manifestOnlyJar);
+
WSContractDelegate delegate = new WSContractDelegate(getLog());
delegate.runProvider(params);
Added:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/UrlUtils.java
===================================================================
---
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/UrlUtils.java
(rev 0)
+++
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/UrlUtils.java 2015-02-08
20:27:48 UTC (rev 19436)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.plugins.tools;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.BitSet;
+
+/**
+ * Utility for dealing with URLs in pre-JDK 1.4.
+ *
+ * User: rsearls
+ * Date: 2/6/15
+ */
+public class UrlUtils {
+ private static final BitSet UNRESERVED = new BitSet( Byte.MAX_VALUE - Byte.MIN_VALUE +
1 );
+
+ private static final int RADIX = 16;
+
+ private static final int MASK = 0xf;
+
+ private UrlUtils()
+ {
+ }
+
+ private static final String ENCODING = "UTF-8";
+
+ static
+ {
+ try
+ {
+ byte[] bytes =
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'():/".getBytes(
ENCODING );
+ for ( byte aByte : bytes )
+ {
+ UNRESERVED.set( aByte );
+ }
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ // can't happen as UTF-8 must be present
+ }
+ }
+
+ public static URL getURL( File file )
+ throws MalformedURLException
+ {
+ // with JDK 1.4+, code would be: return new URL( file.toURI().toASCIIString() );
+ //noinspection deprecation
+ URL url = file.toURL();
+ // encode any characters that do not comply with RFC 2396
+ // this is primarily to handle Windows where the user's home directory contains
spaces
+ try
+ {
+ byte[] bytes = url.toString().getBytes( ENCODING );
+ StringBuilder buf = new StringBuilder( bytes.length );
+ for ( byte b : bytes )
+ {
+ if ( b > 0 && UNRESERVED.get( b ) )
+ {
+ buf.append( (char) b );
+ }
+ else
+ {
+ buf.append( '%' );
+ buf.append( Character.forDigit( b >>> 4 & MASK, RADIX ) );
+ buf.append( Character.forDigit( b & MASK, RADIX ) );
+ }
+ }
+ return new URL( buf.toString() );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ // should not happen as UTF-8 must be present
+ throw new RuntimeException( e );
+ }
+ }
+}
Modified:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractConsumerParams.java
===================================================================
---
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractConsumerParams.java 2015-01-29
07:09:24 UTC (rev 19435)
+++
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractConsumerParams.java 2015-02-08
20:27:48 UTC (rev 19436)
@@ -43,7 +43,8 @@
private String wsdlLocation;
private String encoding;
private String argLine;
-
+ private File manifestOnlyJar;
+
public boolean isAdditionalHeaders()
{
return additionalHeaders;
@@ -172,4 +173,14 @@
{
this.sourceDirectory = sourceDirectory;
}
+
+ public File getManifestOnlyJar()
+ {
+ return manifestOnlyJar;
+ }
+
+ public void setManifestOnlyJar(File manifestOnlyJar)
+ {
+ this.manifestOnlyJar = manifestOnlyJar;
+ }
}
Modified:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractDelegate.java
===================================================================
---
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractDelegate.java 2015-01-29
07:09:24 UTC (rev 19435)
+++
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractDelegate.java 2015-02-08
20:27:48 UTC (rev 19436)
@@ -68,13 +68,7 @@
private void runProviderOutOfProcess(WSContractProviderParams params) throws
Exception
{
- List<String> classpath = new LinkedList<String>();
- URL[] urls = params.getLoader().getURLs();
- for (URL url : urls)
- {
- classpath.add(url.getFile());
- }
- List<String> commandList = initCommandList(params.getArgLine(), classpath,
"org.jboss.ws.tools.cmd.WSProvide");
+ List<String> commandList = initCommandList(params.getArgLine(),
params.getManifestOnlyJar(), "org.jboss.ws.tools.cmd.WSProvide");
String commandLine = getProviderCommandLine(commandList, params);
if (log.isDebugEnabled())
@@ -116,13 +110,7 @@
private void runConsumerOutOfProcess(WSContractConsumerParams params, String wsdl)
throws Exception
{
- List<String> classpath = new LinkedList<String>();
- URL[] urls = params.getLoader().getURLs();
- for (URL url : urls)
- {
- classpath.add(url.getFile());
- }
- List<String> commandList = initCommandList(params.getArgLine(), classpath,
"org.jboss.ws.tools.cmd.WSConsume");
+ List<String> commandList = initCommandList(params.getArgLine(),
params.getManifestOnlyJar(), "org.jboss.ws.tools.cmd.WSConsume");
String commandLine = getConsumerCommandLine(commandList, params, wsdl);
if (log.isDebugEnabled())
@@ -140,6 +128,14 @@
}
}
+ /**
+ * Write list of archives on the command-line
+ *
+ * @param argLine
+ * @param classpath
+ * @param toolClass
+ * @return
+ */
private static List<String> initCommandList(String argLine, List<String>
classpath, String toolClass)
{
List<String> commandList = new ArrayList<String>();
@@ -165,6 +161,29 @@
return commandList;
}
+ /**
+ * Write manifest-only jar to the command-line
+ *
+ * @param argLine
+ * @param manifestOnlyJar
+ * @param toolClass
+ * @return
+ * @throws Exception
+ */
+ private static List<String> initCommandList(String argLine, File
manifestOnlyJar, String toolClass) throws Exception
+ {
+ List<String> commandList = new ArrayList<String>();
+ commandList.add("java");
+ if (argLine != null)
+ {
+ commandList.add(argLine);
+ }
+ commandList.add("-classpath ");
+ commandList.add(manifestOnlyJar.getCanonicalPath());
+ commandList.add(toolClass);
+ return commandList;
+ }
+
private static String getConsumerCommandLine(List<String> commandList,
WSContractConsumerParams params, String wsdl)
{
List<String> bindingFiles = params.getBindingFiles();
Modified:
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractProviderParams.java
===================================================================
---
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractProviderParams.java 2015-01-29
07:09:24 UTC (rev 19435)
+++
projects/plugins/maven/jaxws-tools/trunk/src/main/java/org/jboss/ws/plugins/tools/WSContractProviderParams.java 2015-02-08
20:27:48 UTC (rev 19436)
@@ -38,6 +38,7 @@
private File sourceDirectory;
private String argLine;
private String portSoapAddress;
+ private File manifestOnlyJar;
public boolean isFork()
{
@@ -128,4 +129,15 @@
{
this.portSoapAddress = portSoapAddress;
}
+
+ public File getManifestOnlyJar()
+ {
+ return manifestOnlyJar;
+ }
+
+ public void setManifestOnlyJar(File manifestOnlyJar)
+ {
+ this.manifestOnlyJar = manifestOnlyJar;
+ }
}
+