cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1375635 - in /cxf/trunk: maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/ tools/common/src/main/java/org/apache/cxf/tools/common/ tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/data...
Date Tue, 21 Aug 2012 16:05:14 GMT
Author: dkulp
Date: Tue Aug 21 16:05:13 2012
New Revision: 1375635

URL: http://svn.apache.org/viewvc?rev=1375635&view=rev
Log:
Update to keep the "file" where the error occured as a String for as long as possible to avoid
NPE and allow the file to be a real url like an HTTP url

Modified:
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolErrorListener.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolException.java
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java?rev=1375635&r1=1375634&r2=1375635&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
Tue Aug 21 16:05:13 2012
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashSet;
@@ -51,6 +52,69 @@ import org.sonatype.plexus.build.increme
  */
 public class WSDL2JavaMojo extends AbstractCodegenMoho {
 
+    final class MavenToolErrorListener extends ToolErrorListener {
+        private final List<File> errorfiles;
+
+        MavenToolErrorListener(List<File> errorfiles) {
+            this.errorfiles = errorfiles;
+        }
+
+        public void addError(final String file, int line, int column, String message, Throwable
t) {
+            super.addError(file, line, column, message, t);
+            
+            File f = mapFile(file);
+            
+            if (f != null && !errorfiles.contains(f)) {
+                buildContext.removeMessages(f);
+                errorfiles.add(f);
+            }
+            if (f == null) {
+                f = new File(file) {
+                    private static final long serialVersionUID = 1L;
+                    public String getAbsolutePath() {
+                        return file;
+                    }
+                };
+            }
+            buildContext.addMessage(f, line, column, message, BuildContext.SEVERITY_ERROR,
t);
+        }
+
+        public void addWarning(final String file, int line, int column, String message, Throwable
t) {
+            File f = mapFile(file);
+            if (f != null && !errorfiles.contains(f)) {
+                buildContext.removeMessages(f);
+                errorfiles.add(f);
+            }
+            if (f == null) {
+                f = new File(file) {
+                    private static final long serialVersionUID = 1L;
+                    public String getAbsolutePath() {
+                        return file;
+                    }
+                };
+            }
+            //don't send to super which just LOG.warns.   We'll let Maven do that to
+            //not duplicate the error message.
+            buildContext.addMessage(f, line, column, message, BuildContext.SEVERITY_WARNING,
t);
+        }
+
+        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;
+        }
+    }
+
     /**
      * @parameter expression="${cxf.testSourceRoot}"
      */
@@ -257,26 +321,7 @@ public class WSDL2JavaMojo extends Abstr
                         return buildContext.newFileOutputStream(file);
                     }
                 });
-                ctx.setErrorListener(new ToolErrorListener() {
-                    public void addError(File file, int line, int column, String message,
Throwable t) {
-                        super.addError(file, line, column, message, t);
-                        if (!errorfiles.contains(file)) {
-                            buildContext.removeMessages(file);
-                            errorfiles.add(file);
-                        }
-                        buildContext.addMessage(file, line, column, message, BuildContext.SEVERITY_ERROR,
t);
-                    }
-
-                    public void addWarning(File file, int line, int column, String message,
Throwable t) {
-                        if (!errorfiles.contains(file)) {
-                            buildContext.removeMessages(file);
-                            errorfiles.add(file);
-                        }
-                        //don't send to super which just LOG.warns.   We'll let Maven do
that to
-                        //not duplicate the error message.
-                        buildContext.addMessage(file, line, column, message, BuildContext.SEVERITY_WARNING,
t);
-                    }
-                });
+                ctx.setErrorListener(new MavenToolErrorListener(errorfiles));
                 new WSDLToJava(args).run(ctx);
                 
                 List<File> oldFiles = CastUtils.cast((List<?>)buildContext

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolErrorListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolErrorListener.java?rev=1375635&r1=1375634&r2=1375635&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolErrorListener.java
(original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolErrorListener.java
Tue Aug 21 16:05:13 2012
@@ -19,7 +19,6 @@
 
 package org.apache.cxf.tools.common;
 
-import java.io.File;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.logging.Logger;
@@ -33,13 +32,13 @@ public class ToolErrorListener {
     private static final Logger LOG = LogUtils.getL7dLogger(ToolErrorListener.class);
     
     class ErrorInfo {
-        File file;
+        String file;
         int line;
         int col;
         Throwable cause;
         String message;
         
-        ErrorInfo(File f, int l, int c, String m, Throwable t) {
+        ErrorInfo(String f, int l, int c, String m, Throwable t) {
             file = f;
             line = l;
             col = c;
@@ -49,19 +48,19 @@ public class ToolErrorListener {
     }
     List<ErrorInfo> errors = new LinkedList<ErrorInfo>();
     
-    public void addError(File file, int line, int column, String message) {
+    public void addError(String file, int line, int column, String message) {
         addError(file, line, column, null);
     }
-    public void addError(File file, int line, int column, String message, Throwable t) {
+    public void addError(String file, int line, int column, String message, Throwable t)
{
         errors.add(new ErrorInfo(file, line, column, message, t));
     }
 
-    public void addWarning(File file, int line, int column, String message) {
+    public void addWarning(String file, int line, int column, String message) {
         addWarning(file, line, column, null);
     }
-    public void addWarning(File file, int line, int column, String message, Throwable t)
{
+    public void addWarning(String file, int line, int column, String message, Throwable t)
{
         if (file != null) {
-            message = file.getAbsolutePath() + " [" + line + "," + column + "]: " + message;

+            message = file + " [" + line + "," + column + "]: " + message; 
         }
         LOG.warning(message);
     }
@@ -71,7 +70,7 @@ public class ToolErrorListener {
     }
     private StringBuilder createMessage(StringBuilder b, ToolErrorListener.ErrorInfo e) {
         if (e.file != null) {
-            b.append(e.file.getAbsolutePath())
+            b.append(e.file)
                 .append(" [").append(e.line).append(',').append(e.col).append("]: ").append(e.message);
         } else if (e.message == null && e.cause != null) {
             b.append(e.cause.getLocalizedMessage());

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolException.java?rev=1375635&r1=1375634&r2=1375635&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolException.java (original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolException.java Tue
Aug 21 16:05:13 2012
@@ -89,7 +89,7 @@ public class ToolException extends Runti
     }
     private String createMessage(ToolErrorListener.ErrorInfo e) {
         if (e.file != null) {
-            return e.file.getAbsolutePath() + " [" + e.line + "," + e.col + "]: " + e.message;

+            return e.file + " [" + e.line + "," + e.col + "]: " + e.message; 
         }
         if (e.message == null && e.cause != null) {
             return e.cause.getLocalizedMessage();

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java?rev=1375635&r1=1375634&r2=1375635&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBBindErrorListener.java
Tue Aug 21 16:05:13 2012
@@ -19,10 +19,6 @@
 
 package org.apache.cxf.tools.wsdlto.databinding.jaxb;
 
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-
 import com.sun.tools.xjc.api.ErrorListener;
 
 import org.apache.cxf.tools.common.ToolErrorListener;
@@ -41,20 +37,7 @@ public class JAXBBindErrorListener imple
     }
 
     public void error(org.xml.sax.SAXParseException exception) {
-        String s = exception.getSystemId();
-        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
-            }
-        }
-        listener.addError(file,
+        listener.addError(exception.getSystemId(),
                           exception.getLineNumber(),
                           exception.getColumnNumber(),
                           mapMessage(exception.getLocalizedMessage()),
@@ -77,20 +60,7 @@ public class JAXBBindErrorListener imple
             System.out.println("JAXB parsing schema warning " + exception.toString()
                                + " in schema " + exception.getSystemId());
         }
-        String s = exception.getSystemId();
-        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
-            }
-        }
-        listener.addWarning(file,
+        listener.addWarning(exception.getSystemId(),
                           exception.getLineNumber(),
                           exception.getColumnNumber(),
                           mapMessage(exception.getLocalizedMessage()),



Mime
View raw message