reta commented on code in PR #303:
URL: https://github.com/apache/cxf-xjc-utils/pull/303#discussion_r2918067847


##########
cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java:
##########
@@ -547,13 +547,40 @@ private int runForked(XsdOption option, String outputDir) 
throws Exception {
         }
         cmd.addArguments(args);
 
-        StreamConsumer out = new StreamConsumer() {
+        StreamConsumer out = createStreamConsumer();
+        StreamConsumer err = createStreamConsumer();
+        int exitCode;
+        try {
+            exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
+        } catch (CommandLineException e) {
+            getLog().debug(e);
+            throw new MojoExecutionException(e.getMessage(), e);
+        }
+        
+
+        String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
+
+        if (exitCode != 0) {
+            StringBuffer msg = new StringBuffer("\nExit code: ");
+            msg.append(exitCode);
+            msg.append('\n');
+            msg.append("Command line was: 
").append(cmdLine).append('\n').append('\n');
+
+            throw new MojoExecutionException(msg.toString());
+        }
+
+        file.delete();
+        return 0;
+    }
+
+    private StreamConsumer createStreamConsumer() {
+        return new StreamConsumer() {
             File file;
             int severity;
             int linenum;
             int column;
             StringBuilder message = new StringBuilder();
-            
+
             public void consumeLine(String line) {

Review Comment:
   Thanks @gnodet , would `synchronized` solve the issue? The concern I have 
with 2 consumer is that they still could attempt to write to the same file, 
concurrently, since it is being extracted from the log line
   
   ```suggestion
               public synchronized void consumeLine(String line) {
   ```



##########
cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java:
##########
@@ -547,13 +547,40 @@ private int runForked(XsdOption option, String outputDir) 
throws Exception {
         }
         cmd.addArguments(args);
 
-        StreamConsumer out = new StreamConsumer() {
+        StreamConsumer out = createStreamConsumer();
+        StreamConsumer err = createStreamConsumer();
+        int exitCode;
+        try {
+            exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
+        } catch (CommandLineException e) {
+            getLog().debug(e);
+            throw new MojoExecutionException(e.getMessage(), e);
+        }
+        
+
+        String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
+
+        if (exitCode != 0) {
+            StringBuffer msg = new StringBuffer("\nExit code: ");
+            msg.append(exitCode);
+            msg.append('\n');
+            msg.append("Command line was: 
").append(cmdLine).append('\n').append('\n');
+
+            throw new MojoExecutionException(msg.toString());
+        }
+
+        file.delete();
+        return 0;
+    }
+
+    private StreamConsumer createStreamConsumer() {
+        return new StreamConsumer() {
             File file;
             int severity;
             int linenum;
             int column;
             StringBuilder message = new StringBuilder();
-            
+
             public void consumeLine(String line) {

Review Comment:
   Thanks @gnodet , wouldn't `synchronized` solve the issue? The concern I have 
with 2 consumer is that they still could attempt to write to the same file, 
concurrently, since it is being extracted from the log line
   
   ```suggestion
               public synchronized void consumeLine(String line) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to