geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r565600 - /geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
Date Tue, 14 Aug 2007 01:22:29 GMT
Author: gawor
Date: Mon Aug 13 18:22:28 2007
New Revision: 565600

URL: http://svn.apache.org/viewvc?view=rev&rev=565600
Log:
fork wsgen process on windows (GERONIMO-3405)

Modified:
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java

Modified: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java?view=diff&rev=565600&r1=565599&r2=565600
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsdlGenerator.java
Mon Aug 13 18:22:28 2007
@@ -27,6 +27,7 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Random;
@@ -39,7 +40,6 @@
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.DeploymentConfigurationManager;
 import org.apache.geronimo.deployment.DeploymentContext;
-import org.apache.geronimo.j2ee.deployment.EARContext;
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.jaxws.PortInfo;
 import org.apache.geronimo.kernel.repository.Artifact;
@@ -50,6 +50,8 @@
 
     private static final Log LOG = LogFactory.getLog(WsdlGenerator.class);
     
+    private final static String FORK_WSGEN_PROPERTY = "org.apache.geronimo.jaxws.wsgen.fork";
+    
     private final static Artifact AXIS2_JAXWS_API_ARTIFACT = new Artifact("org.apache.axis2","axis2-jaxws-api",
(Version)null, "jar");
     private final static Artifact AXIS2_SAAJ_API_ARTIFACT = new Artifact("org.apache.axis2","axis2-saaj-api",
(Version)null, "jar");
     private final static Artifact AXIS2_SAAJ_IMPL_ARTIFACT = new Artifact("org.apache.axis2","axis2-saaj",
(Version)null, "jar");
@@ -68,7 +70,23 @@
     private Artifact saajImpl;
     private QName wsdlService;
     private QName wsdlPort;
+    private boolean forkWsgen = getForkWsgen();
         
+    private static boolean getForkWsgen() {
+        String value = System.getProperty(FORK_WSGEN_PROPERTY);
+        if (value != null) {
+            return Boolean.valueOf(value).booleanValue();
+        } else {
+            String osName = System.getProperty("os.name");
+            if (osName == null) {
+                return false;
+            }
+            osName = osName.toLowerCase();
+            // Fork on Windows only
+            return (osName.indexOf("windows") != -1);            
+        }
+    }
+    
     public WsdlGenerator() {
     }
     
@@ -329,20 +347,12 @@
         String[] arguments = buildArguments(serviceClass, classPath.toString(), baseDir,
portInfo);
         
         try {
-            URLClassLoader loader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
-            Class clazz = loader.loadClass("com.sun.tools.ws.spi.WSToolsObjectFactory");
-            Method method = clazz.getMethod("newInstance");
-            Object factory = method.invoke(null);
-            Method method2 = clazz.getMethod("wsgen", OutputStream.class, String[].class);
-            ByteArrayOutputStream os = new ByteArrayOutputStream();
-            Boolean result = (Boolean) method2.invoke(factory, os, arguments);
-            os.close();
-            
-            byte [] arr = os.toByteArray();
-            String wsgenOutput = new String(arr, 0, arr.length);
+            boolean result = false;
             
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("wsgen output: " + wsgenOutput);
+            if (this.forkWsgen) {
+                result = forkWsgen(classPath, arguments);
+            } else {
+                result = invokeWsgen(urls, arguments);
             }
             
             if (result) {
@@ -353,12 +363,65 @@
                 }
                 return getRelativeNameOrURL(moduleBase, wsdlFile);
             } else {
-                throw new DeploymentException("wsgen failed: " + wsgenOutput);
-            }
+                throw new DeploymentException("wsgen failed");
+            }            
+                                 
         } catch (DeploymentException e) {
             throw e;
         } catch (Exception e) {
             throw new DeploymentException("Unable to generate the wsdl file using wsgen.",
e);
+        }
+    }
+
+    private boolean invokeWsgen(URL[] urls, String[] arguments) throws Exception {
+        URLClassLoader loader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
+        Class clazz = loader.loadClass("com.sun.tools.ws.spi.WSToolsObjectFactory");
+        Method method = clazz.getMethod("newInstance");
+        Object factory = method.invoke(null);
+        Method method2 = clazz.getMethod("wsgen", OutputStream.class, String[].class);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        LOG.debug("Invoking wsgen");
+        
+        Boolean result = (Boolean) method2.invoke(factory, os, arguments);
+        os.close();
+        
+        byte [] arr = os.toByteArray();
+        String wsgenOutput = new String(arr, 0, arr.length);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("wsgen output: " + wsgenOutput);
+        }
+        
+        return result;
+    }
+    
+    private boolean forkWsgen(StringBuilder classPath, String[] arguments) throws Exception
{           
+        List<String> cmd = new ArrayList<String>();
+        String javaHome = System.getProperty("java.home");                       
+        String java = javaHome + File.separator + "bin" + File.separator + "java";
+        cmd.add(java);
+        cmd.add("-classpath");
+        cmd.add(classPath.toString());
+        cmd.add("com.sun.tools.ws.WsGen");
+        cmd.addAll(Arrays.asList(arguments));
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Executing wsgen: " + cmd);
+        }
+                
+        String [] cmdArray = (String[]) cmd.toArray(new String[] {});
+        
+        Process process = Runtime.getRuntime().exec(cmdArray);
+        int errorCode = process.waitFor();
+        
+        if (errorCode == 0) {
+            return true;
+        } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("wsgen error code: " + errorCode);
+            }
+            return false;
         }
     }
 }



Mime
View raw message