You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jo...@apache.org on 2016/12/16 23:26:20 UTC

[2/6] git commit: [flex-falcon] [refs/heads/develop] - compiler-jx: better error handling in externc, including catching configuration errors (resolves FLEX-35221)

compiler-jx: better error handling in externc, including catching configuration errors (resolves FLEX-35221)


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/1c2570a3
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/1c2570a3
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/1c2570a3

Branch: refs/heads/develop
Commit: 1c2570a382f85b037b3fa73c422182cf9c238c71
Parents: 8714ab1
Author: Josh Tynjala <jo...@gmail.com>
Authored: Fri Dec 16 11:28:00 2016 -0800
Committer: Josh Tynjala <jo...@gmail.com>
Committed: Fri Dec 16 15:25:39 2016 -0800

----------------------------------------------------------------------
 .../apache/flex/compiler/clients/EXTERNC.java   | 96 ++++++++++++++------
 .../compiler/config/ExterncConfigurator.java    | 52 +++++++++++
 .../externals/reference/ReferenceModel.java     |  3 +-
 3 files changed, 123 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1c2570a3/compiler-jx/src/main/java/org/apache/flex/compiler/clients/EXTERNC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/EXTERNC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/EXTERNC.java
index 547bae4..3ef8703 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/EXTERNC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/EXTERNC.java
@@ -20,20 +20,26 @@
 package org.apache.flex.compiler.clients;
 
 import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
 import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.flex.compiler.clients.problems.ProblemFormatter;
+import org.apache.flex.compiler.clients.problems.ProblemPrinter;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
 import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.config.ExterncConfigurator;
 import org.apache.flex.compiler.internal.codegen.externals.emit.ReferenceEmitter;
 import org.apache.flex.compiler.internal.codegen.externals.pass.ReferenceCompiler;
 import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
-import org.apache.flex.compiler.internal.codegen.js.JSSharedData;
 import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.UnexpectedExceptionProblem;
 import org.apache.flex.compiler.targets.ITarget.TargetType;
+import org.apache.flex.tools.FlexTool;
 
 import com.google.javascript.jscomp.Result;
-import org.apache.flex.tools.FlexTool;
 
 /**
  * @author Michael Schmalle
@@ -56,7 +62,7 @@ public class EXTERNC implements FlexTool
         final int code;
     }
 
-    public Set<ICompilerProblem> problems;
+    public ProblemQuery problems;
     protected Configurator projectConfigurator;
     private ExternCConfiguration configuration;
     private ReferenceModel model;
@@ -87,12 +93,20 @@ public class EXTERNC implements FlexTool
         configure(configuration);
     }
 
-    public void configure(String[] args)
+    public boolean configure(String[] args)
     {
         projectConfigurator = createConfigurator();
         projectConfigurator.setConfiguration(args, "external", false);
         projectConfigurator.getTargetSettings(TargetType.SWC);
         configure((ExternCConfiguration) projectConfigurator.getConfiguration());
+        problems = new ProblemQuery(
+                projectConfigurator.getCompilerProblemSettings());
+        problems.addAll(projectConfigurator.getConfigurationProblems());
+        if (problems.hasErrors())
+        {
+            return false;
+        }
+        return true;
     }
 
     public void configure(ExternCConfiguration configuration)
@@ -112,7 +126,7 @@ public class EXTERNC implements FlexTool
      */
     protected Configurator createConfigurator()
     {
-        return new Configurator(ExternCConfiguration.class);
+        return new ExterncConfigurator(ExternCConfiguration.class);
     }
 
     /**
@@ -137,46 +151,74 @@ public class EXTERNC implements FlexTool
         long startTime = System.nanoTime();
 
         final EXTERNC compiler = new EXTERNC();
-        compiler.configure(args);
-        Set<ICompilerProblem> problems = new HashSet<ICompilerProblem>();
-        final int exitCode = compiler.mainNoExit(args, problems, true);
+        final int exitCode = compiler.mainNoExit(args, System.err);
 
         long endTime = System.nanoTime();
-        JSSharedData.instance.stdout((endTime - startTime) / 1e9 + " seconds");
+        System.out.println((endTime - startTime) / 1e9 + " seconds");
 
         return exitCode;
     }
 
-    public int mainNoExit(final String[] args, Set<ICompilerProblem> problems,
-            Boolean printProblems)
+    public int mainNoExit(final String[] args, OutputStream stderr)
     {
-        int exitCode = 0;
-
+        int exitCode = -1;
         try
         {
-        	model.problems = problems;
-            cleanOutput();
-            compile();
-            emit();
+            exitCode = _mainNoExit(args);
         }
-        catch (IOException e)
+        catch (Exception e)
         {
-            JSSharedData.instance.stderr(e.toString());
+            PrintWriter writer = new PrintWriter(stderr);
+            writer.println(e.toString());
         }
         finally
         {
-            if (problems != null && !problems.isEmpty())
+            final ProblemFormatter formatter = new ProblemFormatter();
+            final ProblemPrinter printer = new ProblemPrinter(formatter, stderr);
+            printer.printProblems(problems.getFilteredProblems());
+        }
+        return exitCode;
+    }
+
+    public int _mainNoExit(final String[] args)
+    {
+        ExitCode exitCode = ExitCode.SUCCESS;
+
+        try
+        {
+            final boolean continueCompilation = configure(args);
+            if (continueCompilation)
+            {
+                model.problems = problems;
+                cleanOutput();
+                compile();
+                emit();
+            }
+            else if (problems.hasFilteredProblems())
+            {
+                exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+            }
+            else
+            {
+                exitCode = ExitCode.PRINT_HELP;
+            }
+        }
+        catch (Exception e)
+        {
+            if (problems == null)
             {
-                if (printProblems)
-                {
-                	for (ICompilerProblem problem : problems)
-                		System.out.println(problem.toString() + " " + problem.getSourcePath() + " line:" + problem.getLine());
-                	exitCode = ExitCode.FAILED_WITH_PROBLEMS.code;
-                }
+                System.err.println(e.getMessage());
             }
+            else
+            {
+                final ICompilerProblem unexpectedExceptionProblem = new UnexpectedExceptionProblem(
+                        e);
+                problems.add(unexpectedExceptionProblem);
+            }
+            exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
         }
 
-        return exitCode;
+        return exitCode.code;
     }
 
     public void cleanOutput() throws IOException

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1c2570a3/compiler-jx/src/main/java/org/apache/flex/compiler/config/ExterncConfigurator.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/config/ExterncConfigurator.java b/compiler-jx/src/main/java/org/apache/flex/compiler/config/ExterncConfigurator.java
new file mode 100644
index 0000000..1e741ef
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/config/ExterncConfigurator.java
@@ -0,0 +1,52 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.config;
+
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
+
+public class ExterncConfigurator extends Configurator
+{
+    /**
+     * Constructor
+     */
+    public ExterncConfigurator()
+    {
+        this(ExternCConfiguration.class);
+    }
+
+    /**
+     * Constructor
+     */
+    public ExterncConfigurator(Class<? extends ExternCConfiguration> configurationClass)
+    {
+        super(configurationClass);
+    }
+    
+    @Override
+    protected void validateSWCInputs() throws ConfigurationException
+    {
+        ExternCConfiguration configuration = (ExternCConfiguration) getConfiguration();
+        if (configuration.getExternals().isEmpty())
+        {
+            throw new ConfigurationException.NoSwcInputs( null, null, -1 );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1c2570a3/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
index 5049189..9a4a784 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
@@ -27,6 +27,7 @@ import java.util.Set;
 
 import org.apache.flex.compiler.clients.ExternCConfiguration;
 import org.apache.flex.compiler.clients.ExternCConfiguration.ExcludedMember;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
 import org.apache.flex.compiler.internal.codegen.externals.utils.DebugLogUtils;
 import org.apache.flex.compiler.problems.ICompilerProblem;
 
@@ -39,7 +40,7 @@ import com.google.javascript.rhino.jstype.JSType;
 
 public class ReferenceModel
 {
-    public Set<ICompilerProblem> problems;
+    public ProblemQuery problems;
     private ExternCConfiguration configuration;
     private Compiler jscompiler;