cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1102003 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/jaxb/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ tools/common/src/main/java/org/apache/cxf/tools/common/ tools/wadlto/jaxrs/src/main/java/org/apache...
Date Wed, 11 May 2011 18:04:55 GMT
Author: sergeyb
Date: Wed May 11 18:04:54 2011
New Revision: 1102003

URL: http://svn.apache.org/viewvc?rev=1102003&view=rev
Log:
[CXF-3498] Support for optional compilation

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=1102003&r1=1102002&r2=1102003&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java Wed May 11 18:04:54
2011
@@ -719,6 +719,18 @@ public final class JAXBUtils {
         logger.log(Level.INFO, "Created classes: " + sb.toString());
     }
     
+    public static List<String> getGeneratedClassNames(JCodeModel codeModel) {
+        List<String> classes = new ArrayList<String>();
+        for (Iterator<JPackage> itr = codeModel.packages(); itr.hasNext();) {
+            JPackage package1 = itr.next();
+            
+            for (Iterator<JDefinedClass> citr = package1.classes(); citr.hasNext();)
{
+                classes.add(citr.next().fullName());
+            }
+        }
+        return classes;
+    }
+    
     public static Object createFileCodeWriter(File f) throws JAXBException {
         try {
             Class<?> cls;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1102003&r1=1102002&r2=1102003&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Wed May 11 18:04:54 2011
@@ -24,6 +24,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringReader;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -75,6 +76,9 @@ import org.apache.cxf.jaxrs.model.wadl.W
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 
+/**
+ * TODO: This will need to be moved into a separate module
+ */
 public class SourceGenerator {
     public static final String CODE_TYPE_GRAMMAR = "grammar";
     public static final String CODE_TYPE_PROXY = "proxy";
@@ -115,6 +119,9 @@ public class SourceGenerator {
     
     private Map<String, String> properties; 
     
+    private List<String> generatedServiceClasses = new ArrayList<String>(); 
+    private List<String> generatedTypeClasses = new ArrayList<String>();
+    
     public SourceGenerator() {
         this(Collections.<String, String>emptyMap());
     }
@@ -234,8 +241,13 @@ public class SourceGenerator {
         if (resourceId.length() == 0) {
             resourceId = DEFAULT_RESOURCE_NAME;
         }
+        //TODO: if it's expanded QName then use PackageUtils.getPackageNameByNameSpaceURI
+        // otherwise assume the last segment after the last dot is the name of the class
+        // and the package name is before the last dot
         QName qname = JAXRSUtils.convertStringToQName(resourceId);
-        if (getSchemaClassName(PackageUtils.getPackageNameByNameSpaceURI(qname.getNamespaceURI()),

+        String namespaceURI = qname.getNamespaceURI();
+        
+        if (getSchemaClassName(PackageUtils.getPackageNameByNameSpaceURI(namespaceURI), 
                                gInfo, qname.getLocalPart(), typeClassNames) != null) {
             return; 
         }
@@ -244,7 +256,7 @@ public class SourceGenerator {
         StringBuilder sbCode = new StringBuilder();
         Set<String> imports = createImports();
         
-        final String classPackage = getClassPackageName(qname.getNamespaceURI());
+        final String classPackage = getClassPackageName(namespaceURI);
         final String className = getClassName(qname.getLocalPart(), interfaceIsGenerated);
         
         sbImports.append(getClassComment()).append(getLineSep());
@@ -667,6 +679,8 @@ public class SourceGenerator {
         String content = sbImports.toString() + getLineSep() + sbCode.toString();
         
         String namespace = qname.getNamespaceURI();
+        generatedServiceClasses.add(namespace + "." + qname.getLocalPart());
+        
         namespace = namespace.replace(".", getFileSep());
         
         File currentDir = new File(src.getAbsolutePath(), namespace);
@@ -697,6 +711,7 @@ public class SourceGenerator {
         try {
             Object writer = JAXBUtils.createFileCodeWriter(src);
             codeModel.build(writer);
+            generatedTypeClasses = JAXBUtils.getGeneratedClassNames(codeModel);
         } catch (Exception e) {
             throw new IllegalStateException("Unable to write generated Java files for schemas:
"
                                             + e.getMessage(), e);
@@ -777,6 +792,14 @@ public class SourceGenerator {
         this.resourceName = name;
     }
     
+    public List<String> getGeneratedServiceClasses() {
+        return generatedServiceClasses;    
+    }
+    
+    public List<String> getGeneratedTypeClasses() {
+        return generatedTypeClasses;    
+    }
+    
     private static class GrammarInfo {
         private Map<String, String> nsMap;
         private Map<String, String> elementTypeMap;

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java?rev=1102003&r1=1102002&r2=1102003&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
(original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
Wed May 11 18:04:54 2011
@@ -37,6 +37,7 @@ import org.apache.cxf.tools.common.tools
 import org.apache.cxf.tools.common.toolspec.parser.CommandDocument;
 import org.apache.cxf.tools.common.toolspec.parser.CommandLineParser;
 import org.apache.cxf.tools.common.toolspec.parser.ErrorVisitor;
+import org.apache.cxf.tools.util.ClassCollector;
 import org.apache.cxf.version.Version;
 
 /**
@@ -282,4 +283,14 @@ public abstract class AbstractCXFToolCon
         return map;
     }
 
+    protected ClassCollector createClassCollector() {
+        ClassCollector collector = new ClassCollector();
+        String reserved[] = (String[])context.get(ToolConstants.CFG_RESERVE_NAME);
+        if (reserved != null) {
+            for (String r : reserved) {
+                collector.reserveClass(r);
+            }
+        }
+        return collector;
+    }
 }

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=1102003&r1=1102002&r2=1102003&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 May 11 18:04:54 2011
@@ -22,6 +22,7 @@ package org.apache.cxf.tools.wadlto.jaxr
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.util.List;
 
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.ext.codegen.SourceGenerator;
@@ -30,6 +31,7 @@ import org.apache.cxf.tools.common.Class
 import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.common.toolspec.ToolSpec;
 import org.apache.cxf.tools.common.toolspec.parser.BadUsageException;
+import org.apache.cxf.tools.util.ClassCollector;
 import org.apache.cxf.tools.util.URIParserUtil;
 import org.apache.cxf.tools.wadlto.WadlToolConstants;
 
@@ -99,6 +101,24 @@ public class JAXRSContainer extends Abst
         
         // compile 
         if (context.optionSet(WadlToolConstants.CFG_COMPILE)) {
+            ClassCollector collector = createClassCollector();
+            List<String> generatedServiceClasses = sg.getGeneratedServiceClasses();
+            for (String className : generatedServiceClasses) {
+                int index = className.lastIndexOf(".");
+                collector.addServiceClassName(className.substring(0, index), 
+                                              className.substring(index + 1), 
+                                              className);
+            }
+            
+            List<String> generatedTypeClasses = sg.getGeneratedTypeClasses();
+            for (String className : generatedTypeClasses) {
+                int index = className.lastIndexOf(".");
+                collector.addTypesClassName(className.substring(0, index), 
+                                              className.substring(index + 1), 
+                                              className);
+            }
+            
+            context.put(ClassCollector.class, collector);
             new ClassUtils().compile(context);
         }
 

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1102003&r1=1102002&r2=1102003&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Wed May 11 18:04:54 2011
@@ -40,7 +40,7 @@ public class JAXRSContainerTest extends 
             ToolContext context = new ToolContext();
             context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
             context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstore.xml"));
-            //context.put(WadlToolConstants.CFG_COMPILE, "true");
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
 
             container.setContext(context);
             container.execute();
@@ -48,7 +48,7 @@ public class JAXRSContainerTest extends 
             assertNotNull(output.list());
             
             verifyFiles("java", false, "org.apache.cxf.jaxrs.model.wadl");
-            //verifyFiles("class");
+            verifyFiles("class", false, "org.apache.cxf.jaxrs.model.wadl");
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -90,7 +90,7 @@ public class JAXRSContainerTest extends 
             context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
             context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstore.xml"));
             context.put(WadlToolConstants.CFG_PACKAGENAME, "custom.books");
-            //context.put(WadlToolConstants.CFG_COMPILE, "true");
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
 
             container.setContext(context);
             container.execute();
@@ -98,7 +98,7 @@ public class JAXRSContainerTest extends 
             assertNotNull(output.list());
             
             verifyFiles("java", false, "custom.books");
-            //verifyFiles("class");
+            verifyFiles("class", false, "custom.books");
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -115,7 +115,7 @@ public class JAXRSContainerTest extends 
             context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
             context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstore.xml"));
             context.put(WadlToolConstants.CFG_SERVER, "true");
-            //context.put(WadlToolConstants.CFG_COMPILE, "true");
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
             
             container.setContext(context);
             container.execute();
@@ -123,7 +123,7 @@ public class JAXRSContainerTest extends 
             assertNotNull(output.list());
             
             verifyFiles("java", false, "org.apache.cxf.jaxrs.model.wadl");
-            //verifyFiles("classes");
+            verifyFiles("class", false, "org.apache.cxf.jaxrs.model.wadl");
         } catch (Exception e) {
             fail();
             e.printStackTrace();
@@ -140,7 +140,7 @@ public class JAXRSContainerTest extends 
             context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstore.xml"));
             context.put(WadlToolConstants.CFG_INTERFACE, "true");
             context.put(WadlToolConstants.CFG_SERVER, "true");
-            //context.put(WadlToolConstants.CFG_COMPILE, "true");
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
             
             container.setContext(context);
             container.execute();
@@ -148,7 +148,7 @@ public class JAXRSContainerTest extends 
             assertNotNull(output.list());
             
             verifyFiles("java", true, "org.apache.cxf.jaxrs.model.wadl");
-            //verifyFiles("classes");
+            verifyFiles("class", true, "org.apache.cxf.jaxrs.model.wadl");
         } catch (Exception e) {
             fail();
             e.printStackTrace();

Modified: cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java?rev=1102003&r1=1102002&r2=1102003&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
(original)
+++ cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
Wed May 11 18:04:54 2011
@@ -217,14 +217,7 @@ public class WSDLToJavaContainer extends
         
         context.put(ToolConstants.PORTTYPE_MAP, interfaces);
         
-        ClassCollector collector = new ClassCollector();
-        String reserved[] = (String[])context.get(ToolConstants.CFG_RESERVE_NAME);
-        if (reserved != null) {
-            for (String r : reserved) {
-                collector.reserveClass(r);
-            }
-        }
-        context.put(ClassCollector.class, collector);
+        context.put(ClassCollector.class, createClassCollector());
         Processor processor = frontend.getProcessor();
         if (processor instanceof ClassNameProcessor) {
             processor.setEnvironment(context);



Mime
View raw message