cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r559838 - in /incubator/cxf/trunk: common/common/src/test/java/org/apache/cxf/jaxb/ common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/ common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ distribution/manifest/ tools/wsdlto/databinding/jaxb/s...
Date Thu, 26 Jul 2007 14:49:43 GMT
Author: eglynn
Date: Thu Jul 26 07:49:40 2007
New Revision: 559838

URL: http://svn.apache.org/viewvc?view=rev&rev=559838
Log:
Applying patch for CXF-851 "wsld2java -xjc usage is too minimal, there is no way to know what
plugin options are available" on behalf of Gary Tully.


Added:
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/JAXBToStringBuilderTest.java
  (with props)
Modified:
    incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
    incubator/cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java
    incubator/cxf/trunk/distribution/manifest/pom.xml
    incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
    incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
    incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java

Added: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/JAXBToStringBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/JAXBToStringBuilderTest.java?view=auto&rev=559838
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/JAXBToStringBuilderTest.java
(added)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/JAXBToStringBuilderTest.java
Thu Jul 26 07:49:40 2007
@@ -0,0 +1,67 @@
+/**
+ * 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.cxf.jaxb;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class JAXBToStringBuilderTest {
+
+    final String dataV = "someData";    
+
+    @Test
+    public void testToString() throws Exception {    
+        String res = JAXBToStringBuilder.valueOf(dataV);
+        Assert.assertEquals(res, dataV);
+    }
+
+    @Test
+    public void testToStringArray() throws Exception {  
+        String[] data = new String[]{dataV};
+        String res = JAXBToStringBuilder.valueOf(data);
+        Assert.assertTrue(res.indexOf(dataV) != -1);
+    }
+
+    @Test
+    public void testToStringCollection() throws Exception {  
+        List<String> data = new ArrayList<String>();
+        data.add(dataV);
+        String res = JAXBToStringBuilder.valueOf(data);
+        Assert.assertTrue(res.indexOf(dataV) != -1);
+    }
+
+    
+    @Test
+    public void testToStringMap() throws Exception {  
+        Map<String, String> data = new HashMap<String, String>();
+        data.put(dataV, dataV);
+        
+        // no content as it is not a Collection
+        String res = JAXBToStringBuilder.valueOf(data);
+        Assert.assertTrue(res.indexOf(dataV) == -1);
+    }
+
+}

Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/JAXBToStringBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/JAXBToStringBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java?view=diff&rev=559838&r1=559837&r2=559838
==============================================================================
--- incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
(original)
+++ incubator/cxf/trunk/common/xjc/dv/src/main/java/org/apache/cxf/xjc/dv/DefaultValuePlugin.java
Thu Jul 26 07:49:40 2007
@@ -70,7 +70,7 @@
     }
 
     public String getUsage() {
-        return "-Xdv: Initialize fields mapped from elements with their default values";
+        return "  -Xdv                 : Initialize fields mapped from elements with their
default values";
     }
 
     public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {

Modified: incubator/cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java?view=diff&rev=559838&r1=559837&r2=559838
==============================================================================
--- incubator/cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java
(original)
+++ incubator/cxf/trunk/common/xjc/ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java
Thu Jul 26 07:49:40 2007
@@ -57,9 +57,9 @@
     }
 
     public String getUsage() {
-        return "-Xts                 : Activate plugin to add a toString() method to generated
classes\n"
-            +  "-Xts:style:multiline : Have toString produce multi line output\n"
-            +  "-Xts:style:simple    : Have toString produce single line terse output\n";
+        return "  -Xts                 : Activate plugin to add a toString() method to generated
classes\n"
+            +  "  -Xts:style:multiline : Have toString produce multi line output\n"
+            +  "  -Xts:style:simple    : Have toString produce single line terse output\n";
     }
 
     public int parseArgument(Options opt, String[] args, int index) 

Modified: incubator/cxf/trunk/distribution/manifest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/manifest/pom.xml?view=diff&rev=559838&r1=559837&r2=559838
==============================================================================
--- incubator/cxf/trunk/distribution/manifest/pom.xml (original)
+++ incubator/cxf/trunk/distribution/manifest/pom.xml Thu Jul 26 07:49:40 2007
@@ -89,6 +89,11 @@
             <artifactId>cxf-xjc-dv</artifactId>
             <version>${pom.version}</version>
         </dependency>
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>cxf-xjc-ts</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>${pom.groupId}</groupId>

Modified: incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?view=diff&rev=559838&r1=559837&r2=559838
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Thu Jul 26 07:49:40 2007
@@ -57,6 +57,7 @@
 import com.sun.codemodel.JType;
 import com.sun.tools.xjc.BadCommandLineException;
 import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.Plugin;
 import com.sun.tools.xjc.api.Mapping;
 import com.sun.tools.xjc.api.Property;
 import com.sun.tools.xjc.api.S2JJAXBModel;
@@ -181,14 +182,24 @@
                 args.add(arg);
                 LOG.log(Level.FINE, "xjc arg:" + arg);
             }
+            Options opts = null;
             try {
-                Options opts = getOptions(schemaCompiler);
+                opts = getOptions(schemaCompiler);
                 // keep parseArguments happy, supply dummy required command-line opts
                 opts.addGrammar(new InputSource("null"));
                 opts.parseArguments(args.toArray(new String[]{}));
             } catch (BadCommandLineException e) {
-                String msg = "XJC reported 'BadParameterException' for -xjc argument:" +
xjcArgs;
-                LOG.log(Level.SEVERE, msg, e);
+                String msg = "XJC reported 'BadCommandLineException' for -xjc argument:"
+ xjcArgs;
+                LOG.log(Level.FINE, msg, e);
+                if (opts != null) {
+                    String pluginUsage = getPluginUsageString(opts);
+                    if ("-X".equals(xjcArgs)) {
+                        msg = pluginUsage;
+                    } else {
+                        msg += pluginUsage;
+                    }
+                }
+                
                 throw new ToolException(msg, e);
             }
         }
@@ -213,6 +224,16 @@
                 }
             }
         }
+    }
+
+    private String getPluginUsageString(Options opts) {
+        StringBuffer buf = new StringBuffer();
+        buf.append("\navaliable plugin options:\n");
+        for (Plugin pl : opts.getAllPlugins()) {
+            buf.append(pl.getUsage());
+            buf.append('\n');
+        }
+        return buf.toString();
     }
 
     // TODO  this can be repaced with schemaCompiler.getOptions() once we

Modified: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml?view=diff&rev=559838&r1=559837&r2=559838
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
(original)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
Thu Jul 26 07:49:40 2007
@@ -252,6 +252,12 @@
                     Comma separated arguments that are passed directly to XJC when the
                     default databinding of JAXB is used. Using this option, it is possible
                     to cause XJC to load additional plugins that can augment code generation.
+                    For example to load the toString(ts) plugin that will add a toString()

+                    method to all generated types the following &lt;xjc arguments&gt;
would 
+                    be used:
+                          -xjc-Xts
+                    A list of available XJC plugins can be obtained by pasing -X as the 
+                    &lt;xjc arguments&gt;.                     
                 </annotation>
                 <associatedArgument placement="immediate">
                     <annotation>xjc arguments</annotation>

Modified: incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java?view=diff&rev=559838&r1=559837&r2=559838
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
Thu Jul 26 07:49:40 2007
@@ -40,6 +40,7 @@
 
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.util.AnnotationUtil;
 import org.apache.cxf.tools.wsdlto.core.DataBindingProfile;
 import org.apache.cxf.tools.wsdlto.core.FrontEndProfile;
@@ -495,6 +496,47 @@
         Class<?> clz = classLoader.loadClass("org.apache.hello_world_soap_http.types.SayHi");
         Method method = clz.getMethod("dummy", new Class[] {});
         assertTrue("method declared on SayHi", method.getDeclaringClass().equals(clz));
+    }
+
+    @Test
+    public void testInvalidXjcArgDummyPluginUsage() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
+
+        env.put(ToolConstants.CFG_XJC_ARGS, "-" + DummyXjcPlugin.XDUMMY_XJC_PLUGIN
+                + ",-" + DummyXjcPlugin.XDUMMY_XJC_PLUGIN  + ":some_rubbish_argument");
+        processor.setContext(env);
+        String msg = null;
+        try {
+            processor.execute();
+            fail("Expect a ToolException on invalid xjc argument");
+        } catch (ToolException expected) {
+            msg = expected.getMessage();
+        }
+        assertNotNull(msg);
+        assertTrue(":some_rubbish_argument is present in :" + msg, 
+                   msg.indexOf(":some_rubbish_argument") != -1);
+        assertTrue("Dummy plugin usage string present in :" + msg, 
+                   msg.indexOf(DummyXjcPlugin.DUMMY_ARG) != -1);
+    }
+
+    @Test
+    public void testXjcMinusXArgGivesPluginUsage() throws Exception {
+        env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
+
+        env.put(ToolConstants.CFG_XJC_ARGS, "-X");
+        processor.setContext(env);
+        String msg = null;
+        try {
+            processor.execute();
+            fail("Expect a ToolException on invalid xjc argument");
+        } catch (ToolException expected) {
+            msg = expected.getMessage();
+        }
+        assertNotNull(msg);
+        assertTrue("Dummy plugin usage string present in :" + msg, 
+                   msg.indexOf(DummyXjcPlugin.DUMMY_ARG) != -1);
+        assertTrue("No BadParameter in msg:" + msg,
+                   msg.indexOf("Bad") == -1);
     }
 
     @Test

Modified: incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java?view=diff&rev=559838&r1=559837&r2=559838
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
(original)
+++ incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/DummyXjcPlugin.java
Thu Jul 26 07:49:40 2007
@@ -36,7 +36,8 @@
 
 
     static final String XDUMMY_XJC_PLUGIN = "Xdummy-xjc-plugin";
-
+    static final String DUMMY_ARG = "-" + XDUMMY_XJC_PLUGIN + ":" + "arg";
+    
     @Override
     public String getOptionName() {
         return XDUMMY_XJC_PLUGIN;
@@ -44,7 +45,7 @@
 
     @Override
     public String getUsage() {
-        return null;
+        return DUMMY_ARG;
     }
 
     @Override
@@ -64,7 +65,7 @@
     public int parseArgument(Options opt, String[] args, int i)
         throws BadCommandLineException {
         int ret = 0;
-        if (args[i].equals("-" + XDUMMY_XJC_PLUGIN + ":" + "arg")) {
+        if (args[i].equals(DUMMY_ARG)) {
             ret = 1;
         }
         



Mime
View raw message