cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1038416 - in /cxf/branches/2.3.x-fixes: ./ maven-plugins/java2ws-plugin/pom.xml maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java systests/wsdl_maven/java2ws/pom.xml
Date Wed, 24 Nov 2010 01:13:36 GMT
Author: dkulp
Date: Wed Nov 24 01:13:36 2010
New Revision: 1038416

URL: http://svn.apache.org/viewvc?rev=1038416&view=rev
Log:
Merged revisions 1038386 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1038386 | dkulp | 2010-11-23 18:42:45 -0500 (Tue, 23 Nov 2010) | 2 lines
  
  [CXF-3074] Add fork mode to java2ws plugin
  Patch from Vincent Siveton applied
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/pom.xml
    cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
    cxf/branches/2.3.x-fixes/systests/wsdl_maven/java2ws/pom.xml

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 24 01:13:36 2010
@@ -1 +1 @@
-/cxf/trunk:1038206,1038374
+/cxf/trunk:1038206,1038374,1038386

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/pom.xml?rev=1038416&r1=1038415&r2=1038416&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/pom.xml (original)
+++ cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/pom.xml Wed Nov 24 01:13:36 2010
@@ -50,6 +50,12 @@
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-project</artifactId>
             <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.codehaus.plexus</groupId>
+                    <artifactId>plexus-utils</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
@@ -58,6 +64,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-utils</artifactId>
+            <version>2.0.5</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-tools-common</artifactId>
             <version>${project.version}</version>
@@ -86,7 +98,5 @@
             <artifactId>cxf-tools-java2ws</artifactId>
             <version>${project.version}</version>
         </dependency>
-                     
     </dependencies>
-
 </project>

Modified: cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java?rev=1038416&r1=1038415&r2=1038416&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
(original)
+++ cxf/branches/2.3.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
Wed Nov 24 01:13:36 2010
@@ -20,17 +20,24 @@
 package org.apache.cxf.maven_plugin;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
 
+import org.apache.commons.lang.SystemUtils;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.tools.common.CommandInterfaceUtils;
 import org.apache.cxf.tools.java2ws.JavaToWS;
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
 
 /**
  * @goal java2ws
@@ -39,7 +46,7 @@ import org.apache.maven.project.MavenPro
 */
 public class Java2WSMojo extends AbstractMojo {
     /**
-     * @parameter 
+     * @parameter
      * @required
      */
     private String className;
@@ -54,7 +61,7 @@ public class Java2WSMojo extends Abstrac
      * @parameter
      */
     private String outputFile;
-    
+
     /**
      * @parameter
      */
@@ -94,22 +101,22 @@ public class Java2WSMojo extends Abstrac
 
     /**
      * Maven ProjectHelper.
-     * 
+     *
      * @component
      * @readonly
      */
-    private MavenProjectHelper projectHelper;    
+    private MavenProjectHelper projectHelper;
 
     /**
      * @parameter
      */
     private String argline;
-    
+
     /**
      * @parameter
      */
     private String frontend;
-    
+
     /**
      * @parameter
      */
@@ -130,26 +137,86 @@ public class Java2WSMojo extends Abstrac
      * @parameter default-value="false"
      */
     private Boolean genWrapperbean;
-    
+
     /**
      * Attach the generated wsdl file to the list of files to be deployed
      * on install. This means the wsdl file will be copied to the repository
      * with groupId, artifactId and version of the project and type "wsdl".
-     * 
+     *
      * With this option you can use the maven repository as a Service Repository.
-     * 
+     *
      * @parameter default-value="true"
      */
     private Boolean attachWsdl;
-    
+
+    /**
+     * The plugin dependencies, needed for the fork mode.
+     *
+     * @parameter expression="${plugin.artifacts}"
+     * @required
+     * @readonly
+     */
+    private List<Artifact> pluginArtifacts;
+
+    /**
+     * Specifies whether the JavaToWs execution should be skipped.
+     *
+     * @parameter default-value="false"
+     * @since 2.4
+     */
+    private Boolean skip;
+
+    /**
+     * Allows running the JavaToWs in a separate process.
+     *
+     * @parameter default-value="false"
+     * @since 2.4
+     */
+    private Boolean fork;
+
+    /**
+     * Sets the Java executable to use when fork parameter is <code>true</code>.
+     *
+     * @parameter default-value="${java.home}/bin/java"
+     * @since 2.4
+     */
+    private String javaExecutable;
+
+    /**
+     * Sets the JVM arguments (i.e. <code>-Xms128m -Xmx128m</code>) if fork is
set to <code>true</code>.
+     *
+     * @parameter
+     * @since 2.4
+     */
+    private String additionalJvmArgs;
+
     public void execute() throws MojoExecutionException {
+        if (skip) {
+            getLog().info("Skipping Java2WS execution");
+            return;
+        }
+
         ClassLoaderSwitcher classLoaderSwitcher = new ClassLoaderSwitcher(getLog());
-        
 
         try {
-            String cp = classLoaderSwitcher.switchClassLoader(project, false, 
+            String cp = classLoaderSwitcher.switchClassLoader(project, false,
                                                               classpath, classpathElements);
-            processJavaClass(cp);
+            if (fork) {
+                List<String> artifactsPath = new ArrayList<String>(pluginArtifacts.size());
+                for (Artifact a : pluginArtifacts) {
+                    File file = a.getFile();
+                    if (file == null) {
+                        throw new MojoExecutionException("Unable to find " + file + " for
artifact "
+                                                         + a.getGroupId() + ":" + a.getArtifactId()
+                                                         + ":" + a.getVersion());
+                    }
+                    artifactsPath.add(file.getPath());
+                }
+                cp = StringUtils.join(artifactsPath.iterator(), File.pathSeparator) + File.pathSeparator
+ cp;
+            }
+
+            List<String> args = initArgs(cp);
+            processJavaClass(args);
         } finally {
             classLoaderSwitcher.restoreClassLoader();
         }
@@ -157,15 +224,29 @@ public class Java2WSMojo extends Abstrac
         System.gc();
     }
 
-    private void processJavaClass(String cp) throws MojoExecutionException {
+    private List<String> initArgs(String cp) {
         List<String> args = new ArrayList<String>();
 
+        if (fork) {
+            args.add(additionalJvmArgs);
+            // @see JavaToWS#isExitOnFinish()
+            args.add("-DexitOnFinish=true");
+        }
+
+        // classpath arg
+        args.add("-cp");
+        args.add(cp);
+
+        if (fork) {
+            args.add(JavaToWS.class.getCanonicalName());
+        }
+
         // outputfile arg
         if (outputFile == null && project != null) {
             // Put the wsdl in target/generated/wsdl
             int i = className.lastIndexOf('.');
             // Prone to OoBE, but then it's wrong anyway
-            String name = className.substring(i + 1); 
+            String name = className.substring(i + 1);
             outputFile = (project.getBuild().getDirectory() + "/generated/wsdl/" + name +
".wsdl")
                 .replace("/", File.separator);
         }
@@ -181,7 +262,7 @@ public class Java2WSMojo extends Abstrac
               Sometimes JavaToWSDL creates Java code for the wrappers.  I don't *think* this
is
               needed by the end user.
             */
-            
+
             // Commiter's comment:
             // Yes, it's required, it's defined in the JAXWS spec.
 
@@ -189,36 +270,32 @@ public class Java2WSMojo extends Abstrac
                 project.addCompileSourceRoot(new File(outputFile).getParentFile().getAbsolutePath());
             }
         }
-        
+
         if (frontend != null) {
             args.add("-frontend");
             args.add(frontend);
         }
-        
+
         if (databinding != null) {
             args.add("-databinding");
             args.add(databinding);
         }
-        
+
         if (genWrapperbean) {
             args.add("-wrapperbean");
         }
-        
+
         if (genWsdl) {
             args.add("-wsdl");
         }
-        
+
         if (genServer) {
             args.add("-server");
         }
-        
+
         if (genClient) {
             args.add("-client");
         }
-        
-        // classpath arg
-        args.add("-cp");
-        args.add(cp);
 
         // soap12 arg
         if (soap12 != null && soap12.booleanValue()) {
@@ -257,21 +334,101 @@ public class Java2WSMojo extends Abstrac
         // classname arg
         args.add(className);
 
-        try {
-            CommandInterfaceUtils.commandCommonMain();
-            JavaToWS j2w = new JavaToWS(args.toArray(new String[args.size()]));
-            j2w.run();
-        } catch (Throwable e) {
-            getLog().debug(e);
-            throw new MojoExecutionException(e.getMessage(), e);
+        return args;
+    }
+
+    private void processJavaClass(List<String> args) throws MojoExecutionException
{
+        if (!fork) {
+            try {
+                CommandInterfaceUtils.commandCommonMain();
+                JavaToWS j2w = new JavaToWS(args.toArray(new String[args.size()]));
+                j2w.run();
+            } catch (OutOfMemoryError e) {
+                getLog().debug(e);
+
+                StringBuffer msg = new StringBuffer();
+                msg.append(e.getMessage()).append('\n');
+                msg.append("Try to run this goal using the <fork>true</fork>
and "
+                        + "<additionalJvmArgs>-Xms128m -Xmx128m</additionalJvmArgs>
parameters.");
+                throw new MojoExecutionException(msg.toString(), e);
+            } catch (Throwable e) {
+                getLog().debug(e);
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+        } else {
+            getLog().info("Running java2ws in fork mode...");
+
+            Commandline cmd = new Commandline();
+            cmd.getShell().setQuotedArgumentsEnabled(false); // for JVM args
+            cmd.setWorkingDirectory(project.getBuild().getDirectory());
+            try {
+                cmd.setExecutable(getJavaExecutable().getAbsolutePath());
+            } catch (IOException e) {
+                getLog().debug(e);
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+
+            cmd.addArguments(args.toArray(new String[args.size()]));
+
+            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
+            CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
+
+            int exitCode;
+            try {
+                exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
+            } catch (CommandLineException e) {
+                getLog().debug(e);
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+
+            String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim();
+
+            String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
+
+            if (exitCode != 0) {
+                if (StringUtils.isNotEmpty(output)) {
+                    getLog().info(output);
+                }
+
+                StringBuffer msg = new StringBuffer("\nExit code: ");
+                msg.append(exitCode);
+                if (StringUtils.isNotEmpty(err.getOutput())) {
+                    msg.append(" - ").append(err.getOutput());
+                }
+                msg.append('\n');
+                msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
+
+                throw new MojoExecutionException(msg.toString());
+            }
+
+            if (StringUtils.isNotEmpty(err.getOutput()) && err.getOutput().contains("JavaToWS
Error")) {
+                StringBuffer msg = new StringBuffer();
+                msg.append(err.getOutput());
+                msg.append('\n');
+                msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
+                throw new MojoExecutionException(msg.toString());
+            }
         }
 
         // Attach the generated wsdl file to the artifacts that get deployed
         // with the enclosing project
         if (attachWsdl && outputFile != null) {
             File wsdlFile = new File(outputFile);
-            projectHelper.attachArtifact(project, "wsdl", wsdlFile);
+            if (wsdlFile.exists()) {
+                projectHelper.attachArtifact(project, "wsdl", wsdlFile);
+            }
+        }
+    }
+
+    private File getJavaExecutable() throws IOException {
+        String exe = (SystemUtils.IS_OS_WINDOWS && !javaExecutable.endsWith(".exe"))
? ".exe" : "";
+        File javaExe = new File(javaExecutable + exe);
+
+        if (!javaExe.isFile()) {
+            throw new IOException("The java executable '" + javaExe
+                + "' doesn't exist or is not a file. Verify the <javaExecutable/> parameter.");
         }
+
+        return javaExe;
     }
-       
 }
\ No newline at end of file

Modified: cxf/branches/2.3.x-fixes/systests/wsdl_maven/java2ws/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/wsdl_maven/java2ws/pom.xml?rev=1038416&r1=1038415&r2=1038416&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/wsdl_maven/java2ws/pom.xml (original)
+++ cxf/branches/2.3.x-fixes/systests/wsdl_maven/java2ws/pom.xml Wed Nov 24 01:13:36 2010
@@ -56,6 +56,7 @@
 							<genWsdl>true</genWsdl>
 							<verbose>true</verbose>
 							<attachWsdl>true</attachWsdl>
+                            <fork>true</fork>
 						</configuration>
 						<goals>
 							<goal>java2ws</goal>



Mime
View raw message