cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1440386 - in /cxf/trunk/tools/wadlto/jaxrs: ./ src/main/java/org/apache/cxf/tools/wadlto/ src/main/java/org/apache/cxf/tools/wadlto/jaxb/ src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ src/test/java/org/apache/cxf/tools/wadlto/jaxrs/
Date Wed, 30 Jan 2013 13:09:53 GMT
Author: sergeyb
Date: Wed Jan 30 13:09:53 2013
New Revision: 1440386

URL: http://svn.apache.org/viewvc?rev=1440386&view=rev
Log:
[CXF-4791] Get WADL to Java generator to support JAXB compiler arguments, patch from Artur
Chy┼╝y applied

Modified:
    cxf/trunk/tools/wadlto/jaxrs/pom.xml
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
    cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java

Modified: cxf/trunk/tools/wadlto/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/pom.xml?rev=1440386&r1=1440385&r2=1440386&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/pom.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/pom.xml Wed Jan 30 13:09:53 2013
@@ -68,6 +68,12 @@
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.jvnet.jaxb2_commons</groupId>
+            <artifactId>jaxb2-basics</artifactId>
+            <version>0.6.4</version>
+            <scope>test</scope>
+        </dependency>
 
         
     </dependencies>

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1440386&r1=1440385&r2=1440386&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
Wed Jan 30 13:09:53 2013
@@ -26,6 +26,7 @@ public final class WadlToolConstants {
     public static final String CFG_OUTPUTDIR = ToolConstants.CFG_OUTPUTDIR;
     public static final String CFG_COMPILE = ToolConstants.CFG_COMPILE;
     public static final String CFG_CLASSDIR = ToolConstants.CFG_CLASSDIR;
+    public static final String CFG_XJC_ARGS = ToolConstants.CFG_XJC_ARGS;
     
     /**
      * Default

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java?rev=1440386&r1=1440385&r2=1440386&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
Wed Jan 30 13:09:53 2013
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.logging.Logger;
 
@@ -87,6 +88,14 @@ public final class CustomizationParser {
             InputSource ins = new InputSource(bindingFileUrl.toString());
             jaxbBindings.add(ins);
         }
+
+        //pass additional JAXB compiler arguments
+        Object jaxbCompilerArgs = env.get(WadlToolConstants.CFG_XJC_ARGS);
+        if (jaxbCompilerArgs != null) {
+            String[] jaxbArgs = jaxbCompilerArgs instanceof String
+                    ? new String[]{(String)jaxbCompilerArgs} : (String[])jaxbCompilerArgs;
+            compilerArgs.addAll(Arrays.asList(jaxbArgs));
+        }
         
         // Schema Namespace to Package customizations
         for (String ns : env.getNamespacePackageMap().keySet()) {

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1440386&r1=1440385&r2=1440386&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
Wed Jan 30 13:09:53 2013
@@ -104,6 +104,7 @@ public class JAXRSContainer extends Abst
         set.add(WadlToolConstants.CFG_SCHEMA_PACKAGENAME);
         set.add(WadlToolConstants.CFG_SCHEMA_TYPE_MAP);
         set.add(WadlToolConstants.CFG_MEDIA_TYPE_MAP);
+        set.add(WadlToolConstants.CFG_XJC_ARGS);
         return set;
     }
     

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml?rev=1440386&r1=1440385&r2=1440386&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
Wed Jan 30 13:09:53 2013
@@ -313,23 +313,23 @@ TODO: consider implementing most of the 
                 </annotation>
                 <switch>keep</switch>
             </option>
-            
+-->
             <option id="xjc" maxOccurs="unbounded">
                 <annotation>
                     Specifies a comma separated list of arguments that are passed directly
to XJC when the
-                    JAXB data binding  is used. This option causes XJC to load additional
plugins that 
-                    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 
+                    JAXB data binding  is used. This option causes XJC to load additional
plugins that
+                    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 using -xjc-X.    
                
+                    A list of available XJC plugins can be obtained by using -xjc-X.
                 </annotation>
                 <associatedArgument placement="immediate">
                     <annotation>xjc-arguments</annotation>
                 </associatedArgument>
                 <switch>xjc</switch>
             </option>
--->
+
         </optionGroup>
         <optionGroup id="common_options">
             <option id="help" maxOccurs="1">

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java?rev=1440386&r1=1440385&r2=1440386&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
Wed Jan 30 13:09:53 2013
@@ -21,6 +21,9 @@ package org.apache.cxf.tools.wadlto.jaxr
 
 import java.io.File;
 import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.cxf.helpers.FileUtils;
@@ -56,6 +59,91 @@ public class WADLToJavaTest extends Proc
             fail();
         }
     }
+
+    @Test
+    public void testGenerateJAXBToString() throws Exception {
+
+        try {
+            String[] args = new String[] {
+                "-d",
+                output.getCanonicalPath(),
+                "-p",
+                "custom.service",
+                "-async getName,delete",
+                "-compile",
+                "-xjc-XtoString",
+                getLocation("/wadl/bookstore.xml"),
+            };
+
+            WADLToJava tool = new WADLToJava(args);
+            tool.run(new ToolContext());
+            assertNotNull(output.list());
+
+            verifyFiles("java", true, false, "superbooks", "custom.service");
+            verifyFiles("class", true, false, "superbooks", "custom.service");
+
+            List<Class<?>> schemaClassFiles = getSchemaClassFiles();
+            assertEquals(4, schemaClassFiles.size());
+            for (Class<?> c : schemaClassFiles) {
+                c.getMethod("toString");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    
+    private List<Class<?>> getSchemaClassFiles() throws Exception {
+        ClassLoader cl = new URLClassLoader(new URL[] {output.toURI().toURL()},
+                                            Thread.currentThread().getContextClassLoader());
+           
+        List<Class<?>> files = new ArrayList<Class<?>>(4);
+        files.add(cl.loadClass("superbooks.EnumType"));
+        files.add(cl.loadClass("superbooks.Book"));
+        files.add(cl.loadClass("superbooks.TheBook2"));
+        files.add(cl.loadClass("superbooks.Chapter"));
+        return files;
+    }
+
+    @Test
+    public void testGenerateJAXBToStringAndEqualsAndHashCode() throws Exception {
+
+        try {
+            String[] args = new String[] {
+                "-d",
+                output.getCanonicalPath(),
+                "-p",
+                "custom.service",
+                "-async getName,delete",
+                "-compile",
+                "-xjc-XtoString",
+                "-xjc-Xequals",
+                "-xjc-XhashCode",
+                getLocation("/wadl/bookstore.xml"),
+            };
+
+            WADLToJava tool = new WADLToJava(args);
+            tool.run(new ToolContext());
+            assertNotNull(output.list());
+
+            verifyFiles("java", true, false, "superbooks", "custom.service");
+            verifyFiles("class", true, false, "superbooks", "custom.service");
+
+            List<Class<?>> schemaClassFiles = getSchemaClassFiles();
+            assertEquals(4, schemaClassFiles.size());
+            for (Class<?> c : schemaClassFiles) {
+                c.getMethod("toString");
+                c.getMethod("hashCode");
+                c.getMethod("equals", Object.class);
+            }
+            
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+
+
     
     private void verifyFiles(String ext, boolean subresourceExpected, boolean interfacesAndImpl,

                              String schemaPackage, String resourcePackage) {    
@@ -89,13 +177,17 @@ public class WADLToJavaTest extends Proc
     
     private boolean checkContains(List<File> clsFiles, String name) {
         for (File f : clsFiles) {
-            if (f.getAbsolutePath().replace(File.separatorChar, '.').endsWith(name)) {
+            if (checkFileContains(f, name)) {
                 return true;
             }
         }
         return false;
     }
     
+    private boolean checkFileContains(File f, String name) {
+        return f.getAbsolutePath().replace(File.separatorChar, '.').endsWith(name);
+    }
+    
     protected String getLocation(String wsdlFile) throws URISyntaxException {
         return getClass().getResource(wsdlFile).toString();
     }



Mime
View raw message