cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1411783 - in /cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin: AbstractXSDToJavaMojo.java TestXSDToJavaMojo.java XSDToJavaMojo.java
Date Tue, 20 Nov 2012 18:39:00 GMT
Author: dkulp
Date: Tue Nov 20 18:38:59 2012
New Revision: 1411783

URL: http://svn.apache.org/viewvc?rev=1411783&view=rev
Log:
Wire cxf-xjc-plugin into m2e better
Also detect changes to binding files to trigger rebuilds

Modified:
    cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java
    cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/TestXSDToJavaMojo.java
    cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XSDToJavaMojo.java

Modified: cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java?rev=1411783&r1=1411782&r2=1411783&view=diff
==============================================================================
--- cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java
(original)
+++ cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java
Tue Nov 20 18:38:59 2012
@@ -30,6 +30,10 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import org.xml.sax.SAXParseException;
+
+import com.sun.tools.xjc.XJCListener;
+
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -128,6 +132,65 @@ public abstract class AbstractXSDToJavaM
     abstract String getOutputDir();
     
     
+    
+    class Listener extends XJCListener {
+        private final List<File> errorfiles;
+
+        Listener(List<File> errorfiles) {
+            this.errorfiles = errorfiles;
+        }
+
+        public void error(SAXParseException exception) {
+            File file = mapFile(exception.getSystemId());
+            if (file != null && !errorfiles.contains(file)) {
+                buildContext.removeMessages(file);
+                errorfiles.add(file);
+            }
+            buildContext.addMessage(file, exception.getLineNumber(), exception.getColumnNumber(),
+                                    mapMessage(exception.getLocalizedMessage()),
+                                    BuildContext.SEVERITY_ERROR, exception);
+
+        }
+
+        private String mapMessage(String localizedMessage) {
+            return localizedMessage;
+        }
+
+        private File mapFile(String s) {
+            File file = null;
+            if (s != null && s.startsWith("file:")) {
+                if (s.contains("#")) {
+                    s = s.substring(0, s.indexOf('#'));
+                }
+                try {
+                    URI uri = new URI(s);
+                    file = new File(uri);
+                } catch (URISyntaxException e) {
+                    //ignore
+                }
+            }
+            return file;
+        }
+
+        public void fatalError(SAXParseException exception) {
+            error(exception);
+        }
+
+        public void warning(SAXParseException exception) {
+            File file = mapFile(exception.getSystemId());
+            if (file != null && !errorfiles.contains(file)) {
+                buildContext.removeMessages(file);
+                errorfiles.add(file);
+            }
+            buildContext.addMessage(file, exception.getLineNumber(), exception.getColumnNumber(),
+                                    mapMessage(exception.getLocalizedMessage()),
+                                    BuildContext.SEVERITY_WARNING, exception);
+        }
+
+        public void info(SAXParseException exception) {
+        }
+    }
+    
     private URI mapLocation(String s) throws MojoExecutionException {
         try {
             File file = new File(s);
@@ -170,6 +233,7 @@ public abstract class AbstractXSDToJavaM
         if (xsdOptions == null) {
             throw new MojoExecutionException("Must specify xsdOptions");           
         }
+        List<File> errorFiles = new ArrayList<File>();
     
         for (int x = 0; x < xsdOptions.length; x++) {
             ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
@@ -201,7 +265,16 @@ public abstract class AbstractXSDToJavaM
                         //ignore
                     }
                 }
-                
+                if (xsdOptions[x].getBindingFile() != null) { 
+                    URI bindingURI = mapLocation(xsdOptions[x].getBindingFile());
+                    if ("file".equals(bindingURI.getScheme())) {
+                        long bts = new File(bindingURI).lastModified();
+                        if (bts > srctimestamp) {
+                            srctimestamp = bts;
+                        }
+                    }
+                }
+
                 boolean doWork = false;
                 if (!doneFile.exists()) {
                     doWork = true;
@@ -220,7 +293,18 @@ public abstract class AbstractXSDToJavaM
                 
                 if (doWork) {
                     try {
-                        int i = com.sun.tools.xjc.Driver.run(args, System.out, System.err);
+                        File files[] = xsdOptions[x].getDependencies();
+                        if (files != null) {
+                            for (int z = 0; z < files.length; ++z) {
+                                if (files[z].lastModified() > doneFile.lastModified())
{
+                                    buildContext.removeMessages(files[z]);
+                                }
+                            }
+                        }
+                        removeMessages(xsdOptions[x].getXsd());
+                        removeMessages(xsdOptions[x].getBindingFile());
+                        
+                        int i = com.sun.tools.xjc.Driver.run(args, new Listener(errorFiles));
                         if (i == 0) {
                             doneFile.delete();
                             doneFile.createNewFile();
@@ -246,6 +330,18 @@ public abstract class AbstractXSDToJavaM
         }
     }
     
+    private void removeMessages(String file) throws MojoExecutionException {
+        if (file == null) {
+            return;
+        }
+        URI location = mapLocation(file);
+        if ("file".equals(location.getScheme())) {
+            File f = new File(location);
+            if (f.exists()) {
+                buildContext.removeMessages(f);
+            }
+        }        
+    }
     private String[] getArguments(XsdOption option, String outputDir) throws MojoExecutionException
{
         List<URL> newCp = new ArrayList<URL>();
         List<String> list = new ArrayList<String>();

Modified: cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/TestXSDToJavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/TestXSDToJavaMojo.java?rev=1411783&r1=1411782&r2=1411783&view=diff
==============================================================================
--- cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/TestXSDToJavaMojo.java
(original)
+++ cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/TestXSDToJavaMojo.java
Tue Nov 20 18:38:59 2012
@@ -36,11 +36,10 @@ public class TestXSDToJavaMojo extends A
     
 
     public void execute() throws MojoExecutionException {
-        super.execute();
-        
         if (project != null && testSourceRoot != null) {
             project.addTestCompileSourceRoot(testSourceRoot);
         }
+        super.execute();
     }
 
 

Modified: cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XSDToJavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XSDToJavaMojo.java?rev=1411783&r1=1411782&r2=1411783&view=diff
==============================================================================
--- cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XSDToJavaMojo.java
(original)
+++ cxf/xjc-utils/trunk/cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XSDToJavaMojo.java
Tue Nov 20 18:38:59 2012
@@ -36,10 +36,10 @@ public class XSDToJavaMojo extends Abstr
     
 
     public void execute() throws MojoExecutionException {
-        super.execute();
         if (project != null && sourceRoot != null) {
             project.addCompileSourceRoot(sourceRoot);
         }
+        super.execute();
     }
 
 



Mime
View raw message