Author: gawor Date: Mon Dec 3 10:58:02 2007 New Revision: 600633 URL: http://svn.apache.org/viewvc?rev=600633&view=rev Log: add basic GShell commands for wsgen and wsimport tools (they are not hooked up yet) (GERONIMO-3665) Added: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsgenCommand.java (with props) geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsimportCommand.java (with props) Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/pom.xml geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/pom.xml?rev=600633&r1=600632&r2=600633&view=diff ============================================================================== --- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/pom.xml (original) +++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/pom.xml Mon Dec 3 10:58:02 2007 @@ -46,6 +46,36 @@ ${version} + + org.apache.geronimo.gshell + gshell-command-api + + + + + + + org.apache.geronimo.gshell + gshell-maven-plugin + 1.0-alpha-1-SNAPSHOT + + + + + + + org.apache.geronimo.gshell + gshell-maven-plugin + + + + descriptor + + + + + + Modified: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java?rev=600633&r1=600632&r2=600633&view=diff ============================================================================== --- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java (original) +++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSToolsCLI.java Mon Dec 3 10:58:02 2007 @@ -18,6 +18,7 @@ package org.apache.geronimo.jaxws.builder; import java.io.File; +import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; import java.net.JarURLConnection; import java.net.URI; @@ -29,6 +30,8 @@ public class JAXWSToolsCLI { + enum Command { WSGEN, WSIMPORT }; + private static final String USAGE_MSG = "Usage: jaxws-tools \n\n" + "where is:\n" + @@ -40,10 +43,28 @@ System.err.println(USAGE_MSG); System.exit(1); } + + Command cmd = null; + if (args[0].equalsIgnoreCase("wsgen")) { + cmd = Command.WSGEN; + } else if (args[0].equalsIgnoreCase("wsimport")) { + cmd = Command.WSIMPORT; + } else { + System.err.println("Error: Unsupported toolName [" + args[0] + "]."); + System.err.println(); + System.err.println(USAGE_MSG); + System.exit(1); + } String geroninoHome = getGeronimoHome(); + String[] arguments = getCmdArguments(args); + boolean rs = run(cmd, geroninoHome, arguments, System.out); + System.exit( (rs) ? 0 : 1 ); + } + + static boolean run(Command cmd, String geronimoHome, String[] args, OutputStream out) throws Exception { String repository = System.getProperty("Xorg.apache.geronimo.repository.boot.path", "repository"); - Maven2Repository mavenRepository = new Maven2Repository((new File(geroninoHome, repository)).getCanonicalFile()); + Maven2Repository mavenRepository = new Maven2Repository((new File(geronimoHome, repository)).getCanonicalFile()); ArrayList repositories = new ArrayList(1); repositories.add(mavenRepository); @@ -51,30 +72,30 @@ tools.setUseSunSAAJ(); tools.setOverrideContextClassLoader(true); - File [] jars = tools.getClasspath(repositories); - - System.setProperty("java.class.path", JAXWSTools.toString(jars)); - + File [] jars = tools.getClasspath(repositories); URL[] jarUrls = JAXWSTools.toURL(jars); - - boolean rs = false; + + String javaClassPath = System.getProperty("java.class.path"); + System.setProperty("java.class.path", JAXWSTools.toString(jars)); try { - if (args[0].equalsIgnoreCase("wsgen")) { - rs = tools.invokeWsgen(jarUrls, System.out, getCmdArguments(args)); - } else if (args[0].equalsIgnoreCase("wsimport")) { - rs = tools.invokeWsimport(jarUrls, System.out, getCmdArguments(args)); + if (cmd.equals(Command.WSGEN)) { + return tools.invokeWsgen(jarUrls, out, args); + } else if (cmd.equals(Command.WSIMPORT)) { + return tools.invokeWsimport(jarUrls, out, args); } else { - System.err.println("Error: Unsupported toolName [" + args[0] + "]."); - System.err.println(); - System.err.println(USAGE_MSG); - System.exit(1); + throw new IllegalArgumentException("Invalid command: " + cmd); } } catch (InvocationTargetException e) { - throw e.getTargetException(); + Throwable exception = e.getTargetException(); + if (exception instanceof Exception) { + throw (Exception)exception; + } else { + throw e; + } + } finally { + System.setProperty("java.class.path", javaClassPath); } - - System.exit( (rs) ? 0 : 1 ); } private static String[] getCmdArguments(String[] args) { Added: geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsgenCommand.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsgenCommand.java?rev=600633&view=auto ============================================================================== --- geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsgenCommand.java (added) +++ geronimo/server/trunk/plugins/jaxws/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WsgenCommand.java Mon Dec 3 10:58:02 2007 @@ -0,0 +1,63 @@ +/* + * 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. + */ + +package org.apache.geronimo.jaxws.builder; + +import org.apache.geronimo.gshell.command.CommandContext; +import org.apache.geronimo.gshell.command.CommandSupport; +import org.apache.geronimo.gshell.command.annotation.CommandComponent; +import org.apache.geronimo.gshell.command.annotation.Requirement; +import org.apache.geronimo.gshell.shell.ShellInfo; + +/** + * GShell command for wsgen tool. + * + * @version $Rev: 595889 $ $Date: 2007-11-16 20:13:06 -0500 (Fri, 16 Nov 2007) $ + */ +@CommandComponent(id="geronimo-jaxws-builder:wsgen", description="Generate JAX-WS artifacts from class") +public class WsgenCommand extends CommandSupport { + + @Requirement + ShellInfo shellInfo; + + @Override + public Object execute(final CommandContext context, final Object... args) throws Exception { + init(context); + + String[] arguments = toString(args); + return JAXWSToolsCLI.run(JAXWSToolsCLI.Command.WSGEN, + shellInfo.getHomeDir().getAbsolutePath(), + arguments, + System.out); // should use io.out instead of System.out? + } + + @Override + protected Object doExecute() throws Exception { + return null; + } + + private static String[] toString(Object [] args) { + String [] a = new String[args.length]; + for (int i=0; i