You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2017/01/31 17:08:38 UTC

[1/8] git commit: [flex-falcon] [refs/heads/dual] - saw it compile for SWF and FlexJS. Needs MXMLFlexJSPublisher fix from develop branch

Repository: flex-falcon
Updated Branches:
  refs/heads/dual [created] 4d0e513db


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCFlex.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCFlex.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCFlex.java
new file mode 100644
index 0000000..ec4b173
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCFlex.java
@@ -0,0 +1,742 @@
+/*
+ *
+ *  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.clients;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.flex.compiler.clients.problems.ProblemPrinter;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
+import org.apache.flex.compiler.clients.problems.ProblemQueryProvider;
+import org.apache.flex.compiler.clients.problems.WorkspaceProblemFormatter;
+import org.apache.flex.compiler.codegen.js.IJSPublisher;
+import org.apache.flex.compiler.codegen.js.IJSWriter;
+import org.apache.flex.compiler.config.Configuration;
+import org.apache.flex.compiler.config.ConfigurationBuffer;
+import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.config.ICompilerSettingsConstants;
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.driver.js.IJSApplication;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
+import org.apache.flex.compiler.exceptions.ConfigurationException.IOError;
+import org.apache.flex.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
+import org.apache.flex.compiler.exceptions.ConfigurationException.OnlyOneSource;
+import org.apache.flex.compiler.internal.config.FlashBuilderConfigurator;
+import org.apache.flex.compiler.internal.driver.as.ASBackend;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
+import org.apache.flex.compiler.internal.driver.js.jsc.JSCBackend;
+import org.apache.flex.compiler.internal.driver.js.node.NodeBackend;
+import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSBackend;
+import org.apache.flex.compiler.internal.parsing.as.FlexJSASDocDelegate;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
+import org.apache.flex.compiler.internal.targets.FlexJSTarget;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.units.ResourceModuleCompilationUnit;
+import org.apache.flex.compiler.internal.units.SourceCompilationUnitFactory;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.ConfigurationProblem;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.InternalCompilerProblem;
+import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
+import org.apache.flex.compiler.problems.UnexpectedExceptionProblem;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.targets.ITarget;
+import org.apache.flex.compiler.targets.ITarget.TargetType;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.tools.FlexTool;
+import org.apache.flex.utils.ArgumentUtil;
+import org.apache.flex.utils.FilenameNormalization;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+
+/**
+ * @author Erik de Bruin
+ * @author Michael Schmalle
+ */
+public class MXMLJSCFlex implements JSCompilerEntryPoint, ProblemQueryProvider,
+        FlexTool
+{
+    @Override
+    public ProblemQuery getProblemQuery()
+    {
+        return problems;
+    }
+
+
+    /*
+     * Exit code enumerations.
+     */
+    static enum ExitCode
+    {
+        SUCCESS(0),
+        PRINT_HELP(1),
+        FAILED_WITH_PROBLEMS(2),
+        FAILED_WITH_ERRORS(3),
+        FAILED_WITH_EXCEPTIONS(4),
+        FAILED_WITH_CONFIG_PROBLEMS(5);
+
+        ExitCode(int code)
+        {
+            this.code = code;
+        }
+
+        final int code;
+    }
+
+    public static MXMLJSC.JSOutputType jsOutputType;
+
+    @Override
+    public String getName()
+    {
+        return FLEX_TOOL_MXMLC;
+    }
+
+    @Override
+    public int execute(String[] args)
+    {
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        return mainNoExit(args, problems, true);
+    }
+
+    /**
+     * Java program entry point.
+     * 
+     * @param args command line arguments
+     */
+    public static void main(final String[] args)
+    {
+        int exitCode = staticMainNoExit(args);
+        System.exit(exitCode);
+    }
+
+    /**
+     * Entry point for the {@code <compc>} Ant task.
+     *
+     * @param args Command line arguments.
+     * @return An exit code.
+     */
+    public static int staticMainNoExit(final String[] args)
+    {
+        long startTime = System.nanoTime();
+
+        final MXMLJSCFlex mxmlc = new MXMLJSCFlex();
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        final int exitCode = mxmlc.mainNoExit(args, problems, true);
+
+        long endTime = System.nanoTime();
+        System.out.println((endTime - startTime) / 1e9 + " seconds");
+
+        return exitCode;
+    }
+
+    protected Workspace workspace;
+    protected FlexJSProject project;
+
+    protected ProblemQuery problems;
+    protected ISourceFileHandler asFileHandler;
+    protected Configuration config;
+    protected Configurator projectConfigurator;
+    private ConfigurationBuffer configBuffer;
+    private ICompilationUnit mainCU;
+    protected ITarget target;
+    protected ITargetSettings targetSettings;
+    protected IJSApplication jsTarget;
+    private IJSPublisher jsPublisher;
+    
+    public MXMLJSCFlex()
+    {
+        IBackend backend = new MXMLFlexJSBackend();
+        workspace = new Workspace();
+        workspace.setASDocDelegate(new FlexJSASDocDelegate());
+        project = new FlexJSProject(workspace, backend);
+        problems = new ProblemQuery(); // this gets replaced in configure().  Do we need it here?
+        asFileHandler = backend.getSourceFileHandlerInstance();
+    }
+
+    @Override
+    public int mainNoExit(final String[] args, List<ICompilerProblem> problems,
+            Boolean printProblems)
+    {
+        int exitCode = -1;
+        try
+        {
+            exitCode = _mainNoExit(ArgumentUtil.fixArgs(args), problems);
+        }
+        catch (Exception e)
+        {
+            System.err.println(e.toString());
+        }
+        finally
+        {
+            if (problems != null && !problems.isEmpty())
+            {
+                if (printProblems)
+                {
+                    final WorkspaceProblemFormatter formatter = new WorkspaceProblemFormatter(
+                            workspace);
+                    final ProblemPrinter printer = new ProblemPrinter(formatter);
+                    printer.printProblems(problems);
+                }
+            }
+        }
+        return exitCode;
+    }
+
+    /**
+     * Entry point that doesn't call <code>System.exit()</code>. This is for
+     * unit testing.
+     * 
+     * @param args command line arguments
+     * @return exit code
+     */
+    private int _mainNoExit(final String[] args,
+            List<ICompilerProblem> outProblems)
+    {
+        ExitCode exitCode = ExitCode.SUCCESS;
+        try
+        {
+            final boolean continueCompilation = configure(args);
+
+/*            if (outProblems != null && !config.isVerbose())
+                JSSharedData.STDOUT = JSSharedData.STDERR = null;*/
+
+            if (continueCompilation)
+            {
+                project.setProblems(problems.getProblems());
+               	compile();
+                if (problems.hasFilteredProblems())
+                {
+                    if (problems.hasErrors())
+                        exitCode = ExitCode.FAILED_WITH_ERRORS;
+                    else
+                        exitCode = ExitCode.FAILED_WITH_PROBLEMS;
+                }
+            }
+            else if (problems.hasFilteredProblems())
+            {
+                exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+            }
+            else
+            {
+                exitCode = ExitCode.PRINT_HELP;
+            }
+        }
+        catch (Exception e)
+        {
+            if (outProblems == null) {
+                System.err.println(e.getMessage());
+            } else
+            {
+                final ICompilerProblem unexpectedExceptionProblem = new UnexpectedExceptionProblem(
+                        e);
+                problems.add(unexpectedExceptionProblem);
+            }
+            exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+        }
+        finally
+        {
+            waitAndClose();
+
+            if (outProblems != null && problems.hasFilteredProblems())
+            {
+                for (ICompilerProblem problem : problems.getFilteredProblems())
+                {
+                    outProblems.add(problem);
+                }
+            }
+        }
+        return exitCode.code;
+    }
+
+    /**
+     * Main body of this program. This method is called from the public static
+     * method's for this program.
+     * 
+     * @return true if compiler succeeds
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    protected boolean compile()
+    {
+        JSGoogConfiguration googConfiguration = (JSGoogConfiguration) config;
+        boolean compilationSuccess = false;
+
+        try
+        {
+            project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+
+            if (!googConfiguration.getSkipTranspile())
+            {
+	            if (!setupTargetFile()) {
+                    return false;
+                }
+
+	            buildArtifact();
+            }
+            if (jsTarget != null || googConfiguration.getSkipTranspile())
+            {
+                List<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
+                List<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>();
+
+                if (!config.getCreateTargetWithErrors())
+                {
+                    problems.getErrorsAndWarnings(errors, warnings);
+                    if (errors.size() > 0)
+                        return false;
+                }
+
+                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                        project, errors, config);
+
+                File outputFolder = jsPublisher.getOutputFolder();
+
+                if (!googConfiguration.getSkipTranspile())
+                {
+	                ArrayList<ICompilationUnit> roots = new ArrayList<ICompilationUnit>();
+	                roots.add(mainCU);
+	                Set<ICompilationUnit> incs = target.getIncludesCompilationUnits();
+	                roots.addAll(incs);
+	                project.mixinClassNames = new TreeSet<String>();
+	                List<ICompilationUnit> reachableCompilationUnits = project.getReachableCompilationUnitsInSWFOrder(roots);
+	                ((FlexJSTarget)target).collectMixinMetaData(project.mixinClassNames, reachableCompilationUnits);
+	                for (final ICompilationUnit cu : reachableCompilationUnits)
+	                {
+	                    ICompilationUnit.UnitType cuType = cu.getCompilationUnitType();
+	
+	                    if (cuType == ICompilationUnit.UnitType.AS_UNIT
+	                            || cuType == ICompilationUnit.UnitType.MXML_UNIT)
+	                    {
+	                        final File outputClassFile = getOutputClassFile(
+	                                cu.getQualifiedNames().get(0), outputFolder);
+	
+	                        System.out.println("Compiling file: " + outputClassFile);
+	
+	                        ICompilationUnit unit = cu;
+	
+	                        IJSWriter writer;
+	                        if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+	                        {
+	                            writer = (IJSWriter) project.getBackend().createWriter(project,
+	                                    errors, unit, false);
+	                        }
+	                        else
+	                        {
+	                            writer = (IJSWriter) project.getBackend().createMXMLWriter(
+	                                    project, errors, unit, false);
+	                        }
+	
+	                        BufferedOutputStream out = new BufferedOutputStream(
+	                                new FileOutputStream(outputClassFile));
+	
+	                        File outputSourceMapFile = null;
+	                        if (project.config.getSourceMap())
+	                        {
+	                            outputSourceMapFile = getOutputSourceMapFile(
+	                                    cu.getQualifiedNames().get(0), outputFolder);
+	                        }
+	                        
+	                        writer.writeTo(out, outputSourceMapFile);
+	                        out.flush();
+	                        out.close();
+	                        writer.close();
+	                    }
+	                }
+                }
+                
+                if (jsPublisher != null)
+                {
+                    compilationSuccess = jsPublisher.publish(problems);
+                }
+                else
+                {
+                    compilationSuccess = true;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new InternalCompilerProblem(e);
+            problems.add(problem);
+        }
+
+        return compilationSuccess;
+    }
+
+    /**
+     * Build target artifact.
+     * 
+     * @throws InterruptedException threading error
+     * @throws IOException IO error
+     * @throws ConfigurationException
+     */
+    protected void buildArtifact() throws InterruptedException, IOException,
+            ConfigurationException
+    {
+        jsTarget = buildJSTarget();
+    }
+
+    private IJSApplication buildJSTarget() throws InterruptedException,
+            FileNotFoundException, ConfigurationException
+    {
+        final List<ICompilerProblem> problemsBuildingSWF = new ArrayList<ICompilerProblem>();
+
+        project.mainCU = mainCU;
+        final IJSApplication app = buildApplication(project,
+                config.getMainDefinition(), mainCU, problemsBuildingSWF);
+        problems.addAll(problemsBuildingSWF);
+        if (app == null)
+        {
+            ICompilerProblem problem = new UnableToBuildSWFProblem(
+                    getOutputFilePath());
+            problems.add(problem);
+        }
+
+        return app;
+    }
+
+    /**
+     * Replaces FlexApplicationProject::buildSWF()
+     * 
+     * @param applicationProject
+     * @param rootClassName
+     * @param problems
+     * @return
+     * @throws InterruptedException
+     */
+
+    private IJSApplication buildApplication(CompilerProject applicationProject,
+            String rootClassName, ICompilationUnit mainCU,
+            Collection<ICompilerProblem> problems) throws InterruptedException,
+            ConfigurationException, FileNotFoundException
+    {
+        Collection<ICompilerProblem> fatalProblems = applicationProject.getFatalProblems();
+        if (!fatalProblems.isEmpty())
+        {
+            problems.addAll(fatalProblems);
+            return null;
+        }
+
+        return ((JSTarget) target).build(mainCU, problems);
+    }
+
+    /**
+     * Get the output file path. If {@code -output} is specified, use its value;
+     * otherwise, use the same base name as the target file.
+     * 
+     * @return output file path
+     */
+    private String getOutputFilePath()
+    {
+        if (config.getOutput() == null)
+        {
+            final String extension = "." + project.getBackend().getOutputExtension();
+            return FilenameUtils.removeExtension(config.getTargetFile()).concat(
+                    extension);
+        }
+        else
+            return config.getOutput();
+    }
+
+    /**
+     * @author Erik de Bruin
+     * 
+     *         Get the output class file. This includes the (sub)directory in
+     *         which the original class file lives. If the directory structure
+     *         doesn't exist, it is created.
+     * 
+     * @param qname
+     * @param outputFolder
+     * @return output class file path
+     */
+    private File getOutputClassFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension());
+    }
+
+    /**
+     * @param qname
+     * @param outputFolder
+     * @return output source map file path
+     */
+    private File getOutputSourceMapFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension() + ".map");
+    }
+
+    /**
+     * Mxmlc uses target file as the main compilation unit and derive the output
+     * SWF file name from this file.
+     * 
+     * @return true if successful, false otherwise.
+     * @throws OnlyOneSource
+     * @throws InterruptedException
+     */
+    protected boolean setupTargetFile() throws InterruptedException
+    {
+        final String mainFileName = config.getTargetFile();
+
+        final String normalizedMainFileName = FilenameNormalization.normalize(mainFileName);
+
+        final SourceCompilationUnitFactory compilationUnitFactory = project.getSourceCompilationUnitFactory();
+
+        File normalizedMainFile = new File(normalizedMainFileName);
+        if (compilationUnitFactory.canCreateCompilationUnit(normalizedMainFile))
+        {
+            project.addIncludeSourceFile(normalizedMainFile);
+
+            final List<String> sourcePath = config.getCompilerSourcePath();
+            String mainQName = null;
+            if (sourcePath != null && !sourcePath.isEmpty())
+            {
+                for (String path : sourcePath)
+                {
+                    final String otherPath = new File(path).getAbsolutePath();
+                    if (mainFileName.startsWith(otherPath))
+                    {
+                        mainQName = mainFileName.substring(otherPath.length() + 1);
+                        mainQName = mainQName.replaceAll("\\\\", "/");
+                        mainQName = mainQName.replaceAll("\\/", ".");
+                        if (mainQName.endsWith(".as"))
+                            mainQName = mainQName.substring(0,
+                                    mainQName.length() - 3);
+                        break;
+                    }
+                }
+            }
+
+            if (mainQName == null)
+                mainQName = FilenameUtils.getBaseName(mainFileName);
+
+            Collection<ICompilationUnit> mainFileCompilationUnits = workspace.getCompilationUnits(
+                    normalizedMainFileName, project);
+
+            mainCU = Iterables.getOnlyElement(mainFileCompilationUnits);
+
+            config.setMainDefinition(mainQName);
+        }
+
+        Preconditions.checkNotNull(mainCU,
+                "Main compilation unit can't be null");
+
+        ITargetSettings settings = getTargetSettings();
+        if (settings != null)
+            project.setTargetSettings(settings);
+
+        target = project.getBackend().createTarget(project,
+                getTargetSettings(), null);
+
+        return true;
+    }
+
+    private ITargetSettings getTargetSettings()
+    {
+        if (targetSettings == null)
+            targetSettings = projectConfigurator.getTargetSettings(null);
+
+        return targetSettings;
+    }
+
+    /**
+     * Create a new Configurator. This method may be overridden to allow
+     * Configurator subclasses to be created that have custom configurations.
+     * 
+     * @return a new instance or subclass of {@link Configurator}.
+     */
+    protected Configurator createConfigurator()
+    {
+        return project.getBackend().createConfigurator();
+    }
+
+    /**
+     * Load configurations from all the sources.
+     * 
+     * @param args command line arguments
+     * @return True if mxmlc should continue with compilation.
+     */
+    protected boolean configure(final String[] args)
+    {
+        project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+        project.configurator = projectConfigurator = createConfigurator();
+
+        try
+        {
+            if (useFlashBuilderProjectFiles(args))
+            {
+                projectConfigurator.setConfiguration(
+                        FlashBuilderConfigurator.computeFlashBuilderArgs(args,
+                                getTargetType().getExtension()),
+                        ICompilerSettingsConstants.FILE_SPECS_VAR);
+            }
+            else
+            {
+                projectConfigurator.setConfiguration(args,
+                        ICompilerSettingsConstants.FILE_SPECS_VAR);
+            }
+
+            projectConfigurator.applyToProject(project);
+            project.config = (JSGoogConfiguration) projectConfigurator.getConfiguration();
+
+            config = projectConfigurator.getConfiguration();
+            configBuffer = projectConfigurator.getConfigurationBuffer();
+
+            problems = new ProblemQuery(projectConfigurator.getCompilerProblemSettings());
+            problems.addAll(projectConfigurator.getConfigurationProblems());
+
+            if (configBuffer.getVar("version") != null) //$NON-NLS-1$
+                return false;
+
+            if (problems.hasErrors())
+                return false;
+
+            validateTargetFile();
+            return true;
+        }
+        catch (ConfigurationException e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(e);
+            problems.add(problem);
+            return false;
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(null, -1,
+                    -1, -1, -1, e.getMessage());
+            problems.add(problem);
+            return false;
+        }
+        finally
+        {
+            if (config == null)
+            {
+                config = new Configuration();
+                configBuffer = new ConfigurationBuffer(Configuration.class,
+                        Configuration.getAliases());
+            }
+        }
+    }
+
+    private boolean useFlashBuilderProjectFiles(String[] args)
+    {
+        for (String arg : args)
+        {
+            if (arg.equals("-fb")
+                    || arg.equals("-use-flashbuilder-project-files"))
+                return true;
+        }
+        return false;
+    }
+
+    protected TargetType getTargetType()
+    {
+        return TargetType.SWF;
+    }
+
+    /**
+     * Validate target file.
+     * 
+     * @throws MustSpecifyTarget
+     * @throws IOError
+     */
+    protected void validateTargetFile() throws ConfigurationException
+    {
+        if (mainCU instanceof ResourceModuleCompilationUnit)
+            return; //when compiling a Resource Module, no target file is defined.
+
+        final String targetFile = config.getTargetFile();
+        if (targetFile == null)
+            throw new ConfigurationException.MustSpecifyTarget(null, null, -1);
+
+        final File file = new File(targetFile);
+        if (!file.exists())
+            throw new ConfigurationException.IOError(targetFile);
+    }
+
+    /**
+     * Wait till the workspace to finish compilation and close.
+     */
+    protected void waitAndClose()
+    {
+        workspace.startIdleState();
+        try
+        {
+            workspace.close();
+        }
+        finally
+        {
+            workspace.endIdleState(Collections.<ICompilerProject, Set<ICompilationUnit>> emptyMap());
+        }
+    }
+
+    /**
+     * Force terminate the compilation process.
+     */
+    protected void close()
+    {
+        workspace.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNative.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNative.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNative.java
new file mode 100644
index 0000000..5ae898d
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNative.java
@@ -0,0 +1,741 @@
+/*
+ *
+ *  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.clients;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.flex.compiler.clients.problems.ProblemPrinter;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
+import org.apache.flex.compiler.clients.problems.ProblemQueryProvider;
+import org.apache.flex.compiler.clients.problems.WorkspaceProblemFormatter;
+import org.apache.flex.compiler.codegen.js.IJSPublisher;
+import org.apache.flex.compiler.codegen.js.IJSWriter;
+import org.apache.flex.compiler.config.Configuration;
+import org.apache.flex.compiler.config.ConfigurationBuffer;
+import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.config.ICompilerSettingsConstants;
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.driver.js.IJSApplication;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
+import org.apache.flex.compiler.exceptions.ConfigurationException.IOError;
+import org.apache.flex.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
+import org.apache.flex.compiler.exceptions.ConfigurationException.OnlyOneSource;
+import org.apache.flex.compiler.internal.config.FlashBuilderConfigurator;
+import org.apache.flex.compiler.internal.driver.as.ASBackend;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
+import org.apache.flex.compiler.internal.driver.js.jsc.JSCBackend;
+import org.apache.flex.compiler.internal.driver.js.node.NodeBackend;
+import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSBackend;
+import org.apache.flex.compiler.internal.parsing.as.FlexJSASDocDelegate;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
+import org.apache.flex.compiler.internal.targets.FlexJSTarget;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.units.ResourceModuleCompilationUnit;
+import org.apache.flex.compiler.internal.units.SourceCompilationUnitFactory;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.ConfigurationProblem;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.InternalCompilerProblem;
+import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
+import org.apache.flex.compiler.problems.UnexpectedExceptionProblem;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.targets.ITarget;
+import org.apache.flex.compiler.targets.ITarget.TargetType;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.tools.FlexTool;
+import org.apache.flex.utils.ArgumentUtil;
+import org.apache.flex.utils.FilenameNormalization;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+
+/**
+ * @author Erik de Bruin
+ * @author Michael Schmalle
+ */
+public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider,
+        FlexTool
+{
+    @Override
+    public ProblemQuery getProblemQuery()
+    {
+        return problems;
+    }
+
+
+    /*
+     * Exit code enumerations.
+     */
+    static enum ExitCode
+    {
+        SUCCESS(0),
+        PRINT_HELP(1),
+        FAILED_WITH_PROBLEMS(2),
+        FAILED_WITH_ERRORS(3),
+        FAILED_WITH_EXCEPTIONS(4),
+        FAILED_WITH_CONFIG_PROBLEMS(5);
+
+        ExitCode(int code)
+        {
+            this.code = code;
+        }
+
+        final int code;
+    }
+
+    @Override
+    public String getName()
+    {
+        return FLEX_TOOL_MXMLC;
+    }
+
+    @Override
+    public int execute(String[] args)
+    {
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        return mainNoExit(args, problems, true);
+    }
+
+    /**
+     * Java program entry point.
+     * 
+     * @param args command line arguments
+     */
+    public static void main(final String[] args)
+    {
+        int exitCode = staticMainNoExit(args);
+        System.exit(exitCode);
+    }
+
+    /**
+     * Entry point for the {@code <compc>} Ant task.
+     *
+     * @param args Command line arguments.
+     * @return An exit code.
+     */
+    public static int staticMainNoExit(final String[] args)
+    {
+        long startTime = System.nanoTime();
+
+        final MXMLJSCNative mxmlc = new MXMLJSCNative();
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        final int exitCode = mxmlc.mainNoExit(args, problems, true);
+
+        long endTime = System.nanoTime();
+        System.out.println((endTime - startTime) / 1e9 + " seconds");
+
+        return exitCode;
+    }
+
+    protected Workspace workspace;
+    protected FlexJSProject project;
+
+    protected ProblemQuery problems;
+    protected ISourceFileHandler asFileHandler;
+    protected Configuration config;
+    protected Configurator projectConfigurator;
+    private ConfigurationBuffer configBuffer;
+    private ICompilationUnit mainCU;
+    protected ITarget target;
+    protected ITargetSettings targetSettings;
+    protected IJSApplication jsTarget;
+    private IJSPublisher jsPublisher;
+    
+    public MXMLJSCNative()
+    {
+        IBackend backend = new JSCBackend();
+
+        workspace = new Workspace();
+        workspace.setASDocDelegate(new FlexJSASDocDelegate());
+        project = new FlexJSProject(workspace, backend);
+        problems = new ProblemQuery(); // this gets replaced in configure().  Do we need it here?
+        asFileHandler = backend.getSourceFileHandlerInstance();
+    }
+
+    @Override
+    public int mainNoExit(final String[] args, List<ICompilerProblem> problems,
+            Boolean printProblems)
+    {
+        int exitCode = -1;
+        try
+        {
+            exitCode = _mainNoExit(ArgumentUtil.fixArgs(args), problems);
+        }
+        catch (Exception e)
+        {
+            System.err.println(e.toString());
+        }
+        finally
+        {
+            if (problems != null && !problems.isEmpty())
+            {
+                if (printProblems)
+                {
+                    final WorkspaceProblemFormatter formatter = new WorkspaceProblemFormatter(
+                            workspace);
+                    final ProblemPrinter printer = new ProblemPrinter(formatter);
+                    printer.printProblems(problems);
+                }
+            }
+        }
+        return exitCode;
+    }
+
+    /**
+     * Entry point that doesn't call <code>System.exit()</code>. This is for
+     * unit testing.
+     * 
+     * @param args command line arguments
+     * @return exit code
+     */
+    private int _mainNoExit(final String[] args,
+            List<ICompilerProblem> outProblems)
+    {
+        ExitCode exitCode = ExitCode.SUCCESS;
+        try
+        {
+            final boolean continueCompilation = configure(args);
+
+/*            if (outProblems != null && !config.isVerbose())
+                JSSharedData.STDOUT = JSSharedData.STDERR = null;*/
+
+            if (continueCompilation)
+            {
+                project.setProblems(problems.getProblems());
+               	compile();
+                if (problems.hasFilteredProblems())
+                {
+                    if (problems.hasErrors())
+                        exitCode = ExitCode.FAILED_WITH_ERRORS;
+                    else
+                        exitCode = ExitCode.FAILED_WITH_PROBLEMS;
+                }
+            }
+            else if (problems.hasFilteredProblems())
+            {
+                exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+            }
+            else
+            {
+                exitCode = ExitCode.PRINT_HELP;
+            }
+        }
+        catch (Exception e)
+        {
+            if (outProblems == null) {
+                System.err.println(e.getMessage());
+            } else
+            {
+                final ICompilerProblem unexpectedExceptionProblem = new UnexpectedExceptionProblem(
+                        e);
+                problems.add(unexpectedExceptionProblem);
+            }
+            exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+        }
+        finally
+        {
+            waitAndClose();
+
+            if (outProblems != null && problems.hasFilteredProblems())
+            {
+                for (ICompilerProblem problem : problems.getFilteredProblems())
+                {
+                    outProblems.add(problem);
+                }
+            }
+        }
+        return exitCode.code;
+    }
+
+    /**
+     * Main body of this program. This method is called from the public static
+     * method's for this program.
+     * 
+     * @return true if compiler succeeds
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    protected boolean compile()
+    {
+        JSGoogConfiguration googConfiguration = (JSGoogConfiguration) config;
+        boolean compilationSuccess = false;
+
+        try
+        {
+            project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+
+            if (!googConfiguration.getSkipTranspile())
+            {
+	            if (!setupTargetFile()) {
+                    return false;
+                }
+
+	            buildArtifact();
+            }
+            if (jsTarget != null || googConfiguration.getSkipTranspile())
+            {
+                List<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
+                List<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>();
+
+                if (!config.getCreateTargetWithErrors())
+                {
+                    problems.getErrorsAndWarnings(errors, warnings);
+                    if (errors.size() > 0)
+                        return false;
+                }
+
+                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                        project, errors, config);
+
+                File outputFolder = jsPublisher.getOutputFolder();
+
+                if (!googConfiguration.getSkipTranspile())
+                {
+	                ArrayList<ICompilationUnit> roots = new ArrayList<ICompilationUnit>();
+	                roots.add(mainCU);
+	                Set<ICompilationUnit> incs = target.getIncludesCompilationUnits();
+	                roots.addAll(incs);
+	                project.mixinClassNames = new TreeSet<String>();
+	                List<ICompilationUnit> reachableCompilationUnits = project.getReachableCompilationUnitsInSWFOrder(roots);
+	                ((FlexJSTarget)target).collectMixinMetaData(project.mixinClassNames, reachableCompilationUnits);
+	                for (final ICompilationUnit cu : reachableCompilationUnits)
+	                {
+	                    ICompilationUnit.UnitType cuType = cu.getCompilationUnitType();
+	
+	                    if (cuType == ICompilationUnit.UnitType.AS_UNIT
+	                            || cuType == ICompilationUnit.UnitType.MXML_UNIT)
+	                    {
+	                        final File outputClassFile = getOutputClassFile(
+	                                cu.getQualifiedNames().get(0), outputFolder);
+	
+	                        System.out.println("Compiling file: " + outputClassFile);
+	
+	                        ICompilationUnit unit = cu;
+	
+	                        IJSWriter writer;
+	                        if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+	                        {
+	                            writer = (IJSWriter) project.getBackend().createWriter(project,
+	                                    errors, unit, false);
+	                        }
+	                        else
+	                        {
+	                            writer = (IJSWriter) project.getBackend().createMXMLWriter(
+	                                    project, errors, unit, false);
+	                        }
+	
+	                        BufferedOutputStream out = new BufferedOutputStream(
+	                                new FileOutputStream(outputClassFile));
+	
+	                        File outputSourceMapFile = null;
+	                        if (project.config.getSourceMap())
+	                        {
+	                            outputSourceMapFile = getOutputSourceMapFile(
+	                                    cu.getQualifiedNames().get(0), outputFolder);
+	                        }
+	                        
+	                        writer.writeTo(out, outputSourceMapFile);
+	                        out.flush();
+	                        out.close();
+	                        writer.close();
+	                    }
+	                }
+                }
+                
+                if (jsPublisher != null)
+                {
+                    compilationSuccess = jsPublisher.publish(problems);
+                }
+                else
+                {
+                    compilationSuccess = true;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new InternalCompilerProblem(e);
+            problems.add(problem);
+        }
+
+        return compilationSuccess;
+    }
+
+    /**
+     * Build target artifact.
+     * 
+     * @throws InterruptedException threading error
+     * @throws IOException IO error
+     * @throws ConfigurationException
+     */
+    protected void buildArtifact() throws InterruptedException, IOException,
+            ConfigurationException
+    {
+        jsTarget = buildJSTarget();
+    }
+
+    private IJSApplication buildJSTarget() throws InterruptedException,
+            FileNotFoundException, ConfigurationException
+    {
+        final List<ICompilerProblem> problemsBuildingSWF = new ArrayList<ICompilerProblem>();
+
+        project.mainCU = mainCU;
+        final IJSApplication app = buildApplication(project,
+                config.getMainDefinition(), mainCU, problemsBuildingSWF);
+        problems.addAll(problemsBuildingSWF);
+        if (app == null)
+        {
+            ICompilerProblem problem = new UnableToBuildSWFProblem(
+                    getOutputFilePath());
+            problems.add(problem);
+        }
+
+        return app;
+    }
+
+    /**
+     * Replaces FlexApplicationProject::buildSWF()
+     * 
+     * @param applicationProject
+     * @param rootClassName
+     * @param problems
+     * @return
+     * @throws InterruptedException
+     */
+
+    private IJSApplication buildApplication(CompilerProject applicationProject,
+            String rootClassName, ICompilationUnit mainCU,
+            Collection<ICompilerProblem> problems) throws InterruptedException,
+            ConfigurationException, FileNotFoundException
+    {
+        Collection<ICompilerProblem> fatalProblems = applicationProject.getFatalProblems();
+        if (!fatalProblems.isEmpty())
+        {
+            problems.addAll(fatalProblems);
+            return null;
+        }
+
+        return ((JSTarget) target).build(mainCU, problems);
+    }
+
+    /**
+     * Get the output file path. If {@code -output} is specified, use its value;
+     * otherwise, use the same base name as the target file.
+     * 
+     * @return output file path
+     */
+    private String getOutputFilePath()
+    {
+        if (config.getOutput() == null)
+        {
+            final String extension = "." + project.getBackend().getOutputExtension();
+            return FilenameUtils.removeExtension(config.getTargetFile()).concat(
+                    extension);
+        }
+        else
+            return config.getOutput();
+    }
+
+    /**
+     * @author Erik de Bruin
+     * 
+     *         Get the output class file. This includes the (sub)directory in
+     *         which the original class file lives. If the directory structure
+     *         doesn't exist, it is created.
+     * 
+     * @param qname
+     * @param outputFolder
+     * @return output class file path
+     */
+    private File getOutputClassFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension());
+    }
+
+    /**
+     * @param qname
+     * @param outputFolder
+     * @return output source map file path
+     */
+    private File getOutputSourceMapFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension() + ".map");
+    }
+
+    /**
+     * Mxmlc uses target file as the main compilation unit and derive the output
+     * SWF file name from this file.
+     * 
+     * @return true if successful, false otherwise.
+     * @throws OnlyOneSource
+     * @throws InterruptedException
+     */
+    protected boolean setupTargetFile() throws InterruptedException
+    {
+        final String mainFileName = config.getTargetFile();
+
+        final String normalizedMainFileName = FilenameNormalization.normalize(mainFileName);
+
+        final SourceCompilationUnitFactory compilationUnitFactory = project.getSourceCompilationUnitFactory();
+
+        File normalizedMainFile = new File(normalizedMainFileName);
+        if (compilationUnitFactory.canCreateCompilationUnit(normalizedMainFile))
+        {
+            project.addIncludeSourceFile(normalizedMainFile);
+
+            final List<String> sourcePath = config.getCompilerSourcePath();
+            String mainQName = null;
+            if (sourcePath != null && !sourcePath.isEmpty())
+            {
+                for (String path : sourcePath)
+                {
+                    final String otherPath = new File(path).getAbsolutePath();
+                    if (mainFileName.startsWith(otherPath))
+                    {
+                        mainQName = mainFileName.substring(otherPath.length() + 1);
+                        mainQName = mainQName.replaceAll("\\\\", "/");
+                        mainQName = mainQName.replaceAll("\\/", ".");
+                        if (mainQName.endsWith(".as"))
+                            mainQName = mainQName.substring(0,
+                                    mainQName.length() - 3);
+                        break;
+                    }
+                }
+            }
+
+            if (mainQName == null)
+                mainQName = FilenameUtils.getBaseName(mainFileName);
+
+            Collection<ICompilationUnit> mainFileCompilationUnits = workspace.getCompilationUnits(
+                    normalizedMainFileName, project);
+
+            mainCU = Iterables.getOnlyElement(mainFileCompilationUnits);
+
+            config.setMainDefinition(mainQName);
+        }
+
+        Preconditions.checkNotNull(mainCU,
+                "Main compilation unit can't be null");
+
+        ITargetSettings settings = getTargetSettings();
+        if (settings != null)
+            project.setTargetSettings(settings);
+
+        target = project.getBackend().createTarget(project,
+                getTargetSettings(), null);
+
+        return true;
+    }
+
+    private ITargetSettings getTargetSettings()
+    {
+        if (targetSettings == null)
+            targetSettings = projectConfigurator.getTargetSettings(null);
+
+        return targetSettings;
+    }
+
+    /**
+     * Create a new Configurator. This method may be overridden to allow
+     * Configurator subclasses to be created that have custom configurations.
+     * 
+     * @return a new instance or subclass of {@link Configurator}.
+     */
+    protected Configurator createConfigurator()
+    {
+        return project.getBackend().createConfigurator();
+    }
+
+    /**
+     * Load configurations from all the sources.
+     * 
+     * @param args command line arguments
+     * @return True if mxmlc should continue with compilation.
+     */
+    protected boolean configure(final String[] args)
+    {
+        project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+        project.configurator = projectConfigurator = createConfigurator();
+
+        try
+        {
+            if (useFlashBuilderProjectFiles(args))
+            {
+                projectConfigurator.setConfiguration(
+                        FlashBuilderConfigurator.computeFlashBuilderArgs(args,
+                                getTargetType().getExtension()),
+                        ICompilerSettingsConstants.FILE_SPECS_VAR);
+            }
+            else
+            {
+                projectConfigurator.setConfiguration(args,
+                        ICompilerSettingsConstants.FILE_SPECS_VAR);
+            }
+
+            projectConfigurator.applyToProject(project);
+            project.config = (JSGoogConfiguration) projectConfigurator.getConfiguration();
+
+            config = projectConfigurator.getConfiguration();
+            configBuffer = projectConfigurator.getConfigurationBuffer();
+
+            problems = new ProblemQuery(projectConfigurator.getCompilerProblemSettings());
+            problems.addAll(projectConfigurator.getConfigurationProblems());
+
+            if (configBuffer.getVar("version") != null) //$NON-NLS-1$
+                return false;
+
+            if (problems.hasErrors())
+                return false;
+
+            validateTargetFile();
+            return true;
+        }
+        catch (ConfigurationException e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(e);
+            problems.add(problem);
+            return false;
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(null, -1,
+                    -1, -1, -1, e.getMessage());
+            problems.add(problem);
+            return false;
+        }
+        finally
+        {
+            if (config == null)
+            {
+                config = new Configuration();
+                configBuffer = new ConfigurationBuffer(Configuration.class,
+                        Configuration.getAliases());
+            }
+        }
+    }
+
+    private boolean useFlashBuilderProjectFiles(String[] args)
+    {
+        for (String arg : args)
+        {
+            if (arg.equals("-fb")
+                    || arg.equals("-use-flashbuilder-project-files"))
+                return true;
+        }
+        return false;
+    }
+
+    protected TargetType getTargetType()
+    {
+        return TargetType.SWF;
+    }
+
+    /**
+     * Validate target file.
+     * 
+     * @throws MustSpecifyTarget
+     * @throws IOError
+     */
+    protected void validateTargetFile() throws ConfigurationException
+    {
+        if (mainCU instanceof ResourceModuleCompilationUnit)
+            return; //when compiling a Resource Module, no target file is defined.
+
+        final String targetFile = config.getTargetFile();
+        if (targetFile == null)
+            throw new ConfigurationException.MustSpecifyTarget(null, null, -1);
+
+        final File file = new File(targetFile);
+        if (!file.exists())
+            throw new ConfigurationException.IOError(targetFile);
+    }
+
+    /**
+     * Wait till the workspace to finish compilation and close.
+     */
+    protected void waitAndClose()
+    {
+        workspace.startIdleState();
+        try
+        {
+            workspace.close();
+        }
+        finally
+        {
+            workspace.endIdleState(Collections.<ICompilerProject, Set<ICompilationUnit>> emptyMap());
+        }
+    }
+
+    /**
+     * Force terminate the compilation process.
+     */
+    protected void close()
+    {
+        workspace.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java
new file mode 100644
index 0000000..94b0842
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSCNode.java
@@ -0,0 +1,739 @@
+/*
+ *
+ *  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.clients;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.flex.compiler.clients.problems.ProblemPrinter;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
+import org.apache.flex.compiler.clients.problems.ProblemQueryProvider;
+import org.apache.flex.compiler.clients.problems.WorkspaceProblemFormatter;
+import org.apache.flex.compiler.codegen.js.IJSPublisher;
+import org.apache.flex.compiler.codegen.js.IJSWriter;
+import org.apache.flex.compiler.config.Configuration;
+import org.apache.flex.compiler.config.ConfigurationBuffer;
+import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.config.ICompilerSettingsConstants;
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.driver.js.IJSApplication;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
+import org.apache.flex.compiler.exceptions.ConfigurationException.IOError;
+import org.apache.flex.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
+import org.apache.flex.compiler.exceptions.ConfigurationException.OnlyOneSource;
+import org.apache.flex.compiler.internal.config.FlashBuilderConfigurator;
+import org.apache.flex.compiler.internal.driver.as.ASBackend;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
+import org.apache.flex.compiler.internal.driver.js.jsc.JSCBackend;
+import org.apache.flex.compiler.internal.driver.js.node.NodeBackend;
+import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSBackend;
+import org.apache.flex.compiler.internal.parsing.as.FlexJSASDocDelegate;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
+import org.apache.flex.compiler.internal.targets.FlexJSTarget;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.units.ResourceModuleCompilationUnit;
+import org.apache.flex.compiler.internal.units.SourceCompilationUnitFactory;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.ConfigurationProblem;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.InternalCompilerProblem;
+import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
+import org.apache.flex.compiler.problems.UnexpectedExceptionProblem;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.targets.ITarget;
+import org.apache.flex.compiler.targets.ITarget.TargetType;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.tools.FlexTool;
+import org.apache.flex.utils.ArgumentUtil;
+import org.apache.flex.utils.FilenameNormalization;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+
+/**
+ * @author Erik de Bruin
+ * @author Michael Schmalle
+ */
+public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider,
+        FlexTool
+{
+    @Override
+    public ProblemQuery getProblemQuery()
+    {
+        return problems;
+    }
+
+    /*
+     * Exit code enumerations.
+     */
+    static enum ExitCode
+    {
+        SUCCESS(0),
+        PRINT_HELP(1),
+        FAILED_WITH_PROBLEMS(2),
+        FAILED_WITH_ERRORS(3),
+        FAILED_WITH_EXCEPTIONS(4),
+        FAILED_WITH_CONFIG_PROBLEMS(5);
+
+        ExitCode(int code)
+        {
+            this.code = code;
+        }
+
+        final int code;
+    }
+
+    @Override
+    public String getName()
+    {
+        return FLEX_TOOL_MXMLC;
+    }
+
+    @Override
+    public int execute(String[] args)
+    {
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        return mainNoExit(args, problems, true);
+    }
+
+    /**
+     * Java program entry point.
+     * 
+     * @param args command line arguments
+     */
+    public static void main(final String[] args)
+    {
+        int exitCode = staticMainNoExit(args);
+        System.exit(exitCode);
+    }
+
+    /**
+     * Entry point for the {@code <compc>} Ant task.
+     *
+     * @param args Command line arguments.
+     * @return An exit code.
+     */
+    public static int staticMainNoExit(final String[] args)
+    {
+        long startTime = System.nanoTime();
+
+        final MXMLJSCNode mxmlc = new MXMLJSCNode();
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        final int exitCode = mxmlc.mainNoExit(args, problems, true);
+
+        long endTime = System.nanoTime();
+        System.out.println((endTime - startTime) / 1e9 + " seconds");
+
+        return exitCode;
+    }
+
+    protected Workspace workspace;
+    protected FlexJSProject project;
+
+    protected ProblemQuery problems;
+    protected ISourceFileHandler asFileHandler;
+    protected Configuration config;
+    protected Configurator projectConfigurator;
+    private ConfigurationBuffer configBuffer;
+    private ICompilationUnit mainCU;
+    protected ITarget target;
+    protected ITargetSettings targetSettings;
+    protected IJSApplication jsTarget;
+    private IJSPublisher jsPublisher;
+    
+    public MXMLJSCNode()
+    {
+        IBackend backend = new NodeBackend();
+        workspace = new Workspace();
+        workspace.setASDocDelegate(new FlexJSASDocDelegate());
+        project = new FlexJSProject(workspace, backend);
+        problems = new ProblemQuery(); // this gets replaced in configure().  Do we need it here?
+        asFileHandler = backend.getSourceFileHandlerInstance();
+    }
+
+    @Override
+    public int mainNoExit(final String[] args, List<ICompilerProblem> problems,
+            Boolean printProblems)
+    {
+        int exitCode = -1;
+        try
+        {
+            exitCode = _mainNoExit(ArgumentUtil.fixArgs(args), problems);
+        }
+        catch (Exception e)
+        {
+            System.err.println(e.toString());
+        }
+        finally
+        {
+            if (problems != null && !problems.isEmpty())
+            {
+                if (printProblems)
+                {
+                    final WorkspaceProblemFormatter formatter = new WorkspaceProblemFormatter(
+                            workspace);
+                    final ProblemPrinter printer = new ProblemPrinter(formatter);
+                    printer.printProblems(problems);
+                }
+            }
+        }
+        return exitCode;
+    }
+
+    /**
+     * Entry point that doesn't call <code>System.exit()</code>. This is for
+     * unit testing.
+     * 
+     * @param args command line arguments
+     * @return exit code
+     */
+    private int _mainNoExit(final String[] args,
+            List<ICompilerProblem> outProblems)
+    {
+        ExitCode exitCode = ExitCode.SUCCESS;
+        try
+        {
+            final boolean continueCompilation = configure(args);
+
+/*            if (outProblems != null && !config.isVerbose())
+                JSSharedData.STDOUT = JSSharedData.STDERR = null;*/
+
+            if (continueCompilation)
+            {
+                project.setProblems(problems.getProblems());
+               	compile();
+                if (problems.hasFilteredProblems())
+                {
+                    if (problems.hasErrors())
+                        exitCode = ExitCode.FAILED_WITH_ERRORS;
+                    else
+                        exitCode = ExitCode.FAILED_WITH_PROBLEMS;
+                }
+            }
+            else if (problems.hasFilteredProblems())
+            {
+                exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+            }
+            else
+            {
+                exitCode = ExitCode.PRINT_HELP;
+            }
+        }
+        catch (Exception e)
+        {
+            if (outProblems == null) {
+                System.err.println(e.getMessage());
+            } else
+            {
+                final ICompilerProblem unexpectedExceptionProblem = new UnexpectedExceptionProblem(
+                        e);
+                problems.add(unexpectedExceptionProblem);
+            }
+            exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+        }
+        finally
+        {
+            waitAndClose();
+
+            if (outProblems != null && problems.hasFilteredProblems())
+            {
+                for (ICompilerProblem problem : problems.getFilteredProblems())
+                {
+                    outProblems.add(problem);
+                }
+            }
+        }
+        return exitCode.code;
+    }
+
+    /**
+     * Main body of this program. This method is called from the public static
+     * method's for this program.
+     * 
+     * @return true if compiler succeeds
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    protected boolean compile()
+    {
+        JSGoogConfiguration googConfiguration = (JSGoogConfiguration) config;
+        boolean compilationSuccess = false;
+
+        try
+        {
+            project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+
+            if (!googConfiguration.getSkipTranspile())
+            {
+	            if (!setupTargetFile()) {
+                    return false;
+                }
+
+	            buildArtifact();
+            }
+            if (jsTarget != null || googConfiguration.getSkipTranspile())
+            {
+                List<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
+                List<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>();
+
+                if (!config.getCreateTargetWithErrors())
+                {
+                    problems.getErrorsAndWarnings(errors, warnings);
+                    if (errors.size() > 0)
+                        return false;
+                }
+
+                jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+                        project, errors, config);
+
+                File outputFolder = jsPublisher.getOutputFolder();
+
+                if (!googConfiguration.getSkipTranspile())
+                {
+	                ArrayList<ICompilationUnit> roots = new ArrayList<ICompilationUnit>();
+	                roots.add(mainCU);
+	                Set<ICompilationUnit> incs = target.getIncludesCompilationUnits();
+	                roots.addAll(incs);
+	                project.mixinClassNames = new TreeSet<String>();
+	                List<ICompilationUnit> reachableCompilationUnits = project.getReachableCompilationUnitsInSWFOrder(roots);
+	                ((FlexJSTarget)target).collectMixinMetaData(project.mixinClassNames, reachableCompilationUnits);
+	                for (final ICompilationUnit cu : reachableCompilationUnits)
+	                {
+	                    ICompilationUnit.UnitType cuType = cu.getCompilationUnitType();
+	
+	                    if (cuType == ICompilationUnit.UnitType.AS_UNIT
+	                            || cuType == ICompilationUnit.UnitType.MXML_UNIT)
+	                    {
+	                        final File outputClassFile = getOutputClassFile(
+	                                cu.getQualifiedNames().get(0), outputFolder);
+	
+	                        System.out.println("Compiling file: " + outputClassFile);
+	
+	                        ICompilationUnit unit = cu;
+	
+	                        IJSWriter writer;
+	                        if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+	                        {
+	                            writer = (IJSWriter) project.getBackend().createWriter(project,
+	                                    errors, unit, false);
+	                        }
+	                        else
+	                        {
+	                            writer = (IJSWriter) project.getBackend().createMXMLWriter(
+	                                    project, errors, unit, false);
+	                        }
+	
+	                        BufferedOutputStream out = new BufferedOutputStream(
+	                                new FileOutputStream(outputClassFile));
+	
+	                        File outputSourceMapFile = null;
+	                        if (project.config.getSourceMap())
+	                        {
+	                            outputSourceMapFile = getOutputSourceMapFile(
+	                                    cu.getQualifiedNames().get(0), outputFolder);
+	                        }
+	                        
+	                        writer.writeTo(out, outputSourceMapFile);
+	                        out.flush();
+	                        out.close();
+	                        writer.close();
+	                    }
+	                }
+                }
+                
+                if (jsPublisher != null)
+                {
+                    compilationSuccess = jsPublisher.publish(problems);
+                }
+                else
+                {
+                    compilationSuccess = true;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new InternalCompilerProblem(e);
+            problems.add(problem);
+        }
+
+        return compilationSuccess;
+    }
+
+    /**
+     * Build target artifact.
+     * 
+     * @throws InterruptedException threading error
+     * @throws IOException IO error
+     * @throws ConfigurationException
+     */
+    protected void buildArtifact() throws InterruptedException, IOException,
+            ConfigurationException
+    {
+        jsTarget = buildJSTarget();
+    }
+
+    private IJSApplication buildJSTarget() throws InterruptedException,
+            FileNotFoundException, ConfigurationException
+    {
+        final List<ICompilerProblem> problemsBuildingSWF = new ArrayList<ICompilerProblem>();
+
+        project.mainCU = mainCU;
+        final IJSApplication app = buildApplication(project,
+                config.getMainDefinition(), mainCU, problemsBuildingSWF);
+        problems.addAll(problemsBuildingSWF);
+        if (app == null)
+        {
+            ICompilerProblem problem = new UnableToBuildSWFProblem(
+                    getOutputFilePath());
+            problems.add(problem);
+        }
+
+        return app;
+    }
+
+    /**
+     * Replaces FlexApplicationProject::buildSWF()
+     * 
+     * @param applicationProject
+     * @param rootClassName
+     * @param problems
+     * @return
+     * @throws InterruptedException
+     */
+
+    private IJSApplication buildApplication(CompilerProject applicationProject,
+            String rootClassName, ICompilationUnit mainCU,
+            Collection<ICompilerProblem> problems) throws InterruptedException,
+            ConfigurationException, FileNotFoundException
+    {
+        Collection<ICompilerProblem> fatalProblems = applicationProject.getFatalProblems();
+        if (!fatalProblems.isEmpty())
+        {
+            problems.addAll(fatalProblems);
+            return null;
+        }
+
+        return ((JSTarget) target).build(mainCU, problems);
+    }
+
+    /**
+     * Get the output file path. If {@code -output} is specified, use its value;
+     * otherwise, use the same base name as the target file.
+     * 
+     * @return output file path
+     */
+    private String getOutputFilePath()
+    {
+        if (config.getOutput() == null)
+        {
+            final String extension = "." + project.getBackend().getOutputExtension();
+            return FilenameUtils.removeExtension(config.getTargetFile()).concat(
+                    extension);
+        }
+        else
+            return config.getOutput();
+    }
+
+    /**
+     * @author Erik de Bruin
+     * 
+     *         Get the output class file. This includes the (sub)directory in
+     *         which the original class file lives. If the directory structure
+     *         doesn't exist, it is created.
+     * 
+     * @param qname
+     * @param outputFolder
+     * @return output class file path
+     */
+    private File getOutputClassFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension());
+    }
+
+    /**
+     * @param qname
+     * @param outputFolder
+     * @return output source map file path
+     */
+    private File getOutputSourceMapFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension() + ".map");
+    }
+
+    /**
+     * Mxmlc uses target file as the main compilation unit and derive the output
+     * SWF file name from this file.
+     * 
+     * @return true if successful, false otherwise.
+     * @throws OnlyOneSource
+     * @throws InterruptedException
+     */
+    protected boolean setupTargetFile() throws InterruptedException
+    {
+        final String mainFileName = config.getTargetFile();
+
+        final String normalizedMainFileName = FilenameNormalization.normalize(mainFileName);
+
+        final SourceCompilationUnitFactory compilationUnitFactory = project.getSourceCompilationUnitFactory();
+
+        File normalizedMainFile = new File(normalizedMainFileName);
+        if (compilationUnitFactory.canCreateCompilationUnit(normalizedMainFile))
+        {
+            project.addIncludeSourceFile(normalizedMainFile);
+
+            final List<String> sourcePath = config.getCompilerSourcePath();
+            String mainQName = null;
+            if (sourcePath != null && !sourcePath.isEmpty())
+            {
+                for (String path : sourcePath)
+                {
+                    final String otherPath = new File(path).getAbsolutePath();
+                    if (mainFileName.startsWith(otherPath))
+                    {
+                        mainQName = mainFileName.substring(otherPath.length() + 1);
+                        mainQName = mainQName.replaceAll("\\\\", "/");
+                        mainQName = mainQName.replaceAll("\\/", ".");
+                        if (mainQName.endsWith(".as"))
+                            mainQName = mainQName.substring(0,
+                                    mainQName.length() - 3);
+                        break;
+                    }
+                }
+            }
+
+            if (mainQName == null)
+                mainQName = FilenameUtils.getBaseName(mainFileName);
+
+            Collection<ICompilationUnit> mainFileCompilationUnits = workspace.getCompilationUnits(
+                    normalizedMainFileName, project);
+
+            mainCU = Iterables.getOnlyElement(mainFileCompilationUnits);
+
+            config.setMainDefinition(mainQName);
+        }
+
+        Preconditions.checkNotNull(mainCU,
+                "Main compilation unit can't be null");
+
+        ITargetSettings settings = getTargetSettings();
+        if (settings != null)
+            project.setTargetSettings(settings);
+
+        target = project.getBackend().createTarget(project,
+                getTargetSettings(), null);
+
+        return true;
+    }
+
+    private ITargetSettings getTargetSettings()
+    {
+        if (targetSettings == null)
+            targetSettings = projectConfigurator.getTargetSettings(null);
+
+        return targetSettings;
+    }
+
+    /**
+     * Create a new Configurator. This method may be overridden to allow
+     * Configurator subclasses to be created that have custom configurations.
+     * 
+     * @return a new instance or subclass of {@link Configurator}.
+     */
+    protected Configurator createConfigurator()
+    {
+        return project.getBackend().createConfigurator();
+    }
+
+    /**
+     * Load configurations from all the sources.
+     * 
+     * @param args command line arguments
+     * @return True if mxmlc should continue with compilation.
+     */
+    protected boolean configure(final String[] args)
+    {
+        project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+        project.configurator = projectConfigurator = createConfigurator();
+
+        try
+        {
+            if (useFlashBuilderProjectFiles(args))
+            {
+                projectConfigurator.setConfiguration(
+                        FlashBuilderConfigurator.computeFlashBuilderArgs(args,
+                                getTargetType().getExtension()),
+                        ICompilerSettingsConstants.FILE_SPECS_VAR);
+            }
+            else
+            {
+                projectConfigurator.setConfiguration(args,
+                        ICompilerSettingsConstants.FILE_SPECS_VAR);
+            }
+
+            projectConfigurator.applyToProject(project);
+            project.config = (JSGoogConfiguration) projectConfigurator.getConfiguration();
+
+            config = projectConfigurator.getConfiguration();
+            configBuffer = projectConfigurator.getConfigurationBuffer();
+
+            problems = new ProblemQuery(projectConfigurator.getCompilerProblemSettings());
+            problems.addAll(projectConfigurator.getConfigurationProblems());
+
+            if (configBuffer.getVar("version") != null) //$NON-NLS-1$
+                return false;
+
+            if (problems.hasErrors())
+                return false;
+
+            validateTargetFile();
+            return true;
+        }
+        catch (ConfigurationException e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(e);
+            problems.add(problem);
+            return false;
+        }
+        catch (Exception e)
+        {
+            final ICompilerProblem problem = new ConfigurationProblem(null, -1,
+                    -1, -1, -1, e.getMessage());
+            problems.add(problem);
+            return false;
+        }
+        finally
+        {
+            if (config == null)
+            {
+                config = new Configuration();
+                configBuffer = new ConfigurationBuffer(Configuration.class,
+                        Configuration.getAliases());
+            }
+        }
+    }
+
+    private boolean useFlashBuilderProjectFiles(String[] args)
+    {
+        for (String arg : args)
+        {
+            if (arg.equals("-fb")
+                    || arg.equals("-use-flashbuilder-project-files"))
+                return true;
+        }
+        return false;
+    }
+
+    protected TargetType getTargetType()
+    {
+        return TargetType.SWF;
+    }
+
+    /**
+     * Validate target file.
+     * 
+     * @throws MustSpecifyTarget
+     * @throws IOError
+     */
+    protected void validateTargetFile() throws ConfigurationException
+    {
+        if (mainCU instanceof ResourceModuleCompilationUnit)
+            return; //when compiling a Resource Module, no target file is defined.
+
+        final String targetFile = config.getTargetFile();
+        if (targetFile == null)
+            throw new ConfigurationException.MustSpecifyTarget(null, null, -1);
+
+        final File file = new File(targetFile);
+        if (!file.exists())
+            throw new ConfigurationException.IOError(targetFile);
+    }
+
+    /**
+     * Wait till the workspace to finish compilation and close.
+     */
+    protected void waitAndClose()
+    {
+        workspace.startIdleState();
+        try
+        {
+            workspace.close();
+        }
+        finally
+        {
+            workspace.endIdleState(Collections.<ICompilerProject, Set<ICompilationUnit>> emptyMap());
+        }
+    }
+
+    /**
+     * Force terminate the compilation process.
+     */
+    protected void close()
+    {
+        workspace.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java
index 23c5fa1..1afe68f 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogPublisher.java
@@ -132,12 +132,12 @@ public class JSGoogPublisher extends JSPublisher implements IJSPublisher
 
         // XXX (mschmalle) until we figure out what is going on with this configuration, just skip
         // HTML generation for JSC output type
-        String outputType = googConfiguration.getJSOutputType();
-        if (!outputType.equals(JSOutputType.JSC.getText()))
-        {
+        //String outputType = googConfiguration.getJSOutputType();
+        //if (!outputType.equals(JSOutputType.JSC.getText()))
+        //{
             writeHTML("intermediate", projectName, intermediateDirPath);
             writeHTML("release", projectName, releaseDirPath);
-        }
+        //}
 
         ArrayList<String> optionList = new ArrayList<String>();
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
index 8cb54be..70dec15 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
@@ -21,13 +21,16 @@ package org.apache.flex.compiler.internal.codegen.mxml.flexjs;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
+import org.apache.flex.compiler.clients.MXMLJSC;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.driver.js.flexjs.JSCSSCompilationSession;
 import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.test.FlexJSTestBase;
+import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.utils.FilenameNormalization;
 import org.apache.flex.utils.ITestAdapter;
 import org.apache.flex.utils.TestAdapterFactory;
 import org.junit.Test;
@@ -787,6 +790,27 @@ public class TestFlexJSMXMLApplication extends FlexJSTestBase
         assertOutMXMLPostProcess(outTemplate.replaceAll("AppName", appName), true);
     }
 
+    @Test
+    public void testFlexJSMainFileDual()
+    {
+        MXMLJSC mxmlc = new MXMLJSC();
+        String[] args = new String[7];
+        args[0] = "-compiler.targets=SWF,JSFlex";
+        args[1] = "-remove-circulars";
+        args[2] = "-library-path=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/libs")).getPath();
+        args[3] = "-external-library-path+=" + testAdapter.getPlayerglobal().getPath();
+        args[4] = "-output=" + new File(testAdapter.getTempDir(), "bin-debug/FlexJSTest_again.swf").getPath();
+        if (env.GOOG != null)
+        	args[5] = "-closure-lib=" + new File(FilenameNormalization.normalize(env.GOOG)).getPath();
+        else
+        	args[5] = "-define=COMPILE::temp,false";
+        args[6] = new File(testAdapter.getUnitTestBaseDir(), "flexjs/files/FlexJSTest_again.mxml").getPath();
+
+        ArrayList<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        int result = mxmlc.mainNoExit(args, problems, true);
+        assertThat(result, is(0));
+    }
+
     @Override
     protected void addSourcePaths(List<File> sourcePaths)
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/test/java/org/apache/flex/utils/EnvProperties.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/utils/EnvProperties.java b/compiler-jx/src/test/java/org/apache/flex/utils/EnvProperties.java
index ea75057..1b526b8 100644
--- a/compiler-jx/src/test/java/org/apache/flex/utils/EnvProperties.java
+++ b/compiler-jx/src/test/java/org/apache/flex/utils/EnvProperties.java
@@ -66,6 +66,11 @@ public class EnvProperties {
     public String ASJS;
 
     /**
+     * GOOG_HOME
+     */
+    public String GOOG;
+
+    /**
      * PLAYERGLOBAL_VERSION
      */
     public String FPVER;
@@ -144,6 +149,9 @@ public class EnvProperties {
         if (ASJS == null)
             ASJS = FilenameNormalization.normalize("../../../../flex-asjs");
         System.out.println("environment property - ASJS_HOME = " + ASJS);
+        
+        GOOG = p.getProperty(prefix + "GOOG_HOME", System.getenv("GOOG_HOME"));
+        System.out.println("environment property - GOOG_HOME = " + GOOG);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css b/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css
index f18dc6f..8b48967 100755
--- a/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css
+++ b/compiler-jx/src/test/resources/flexjs/files/CSSTestSource.css
@@ -22,6 +22,12 @@
 @namespace basic "library://ns.apache.org/flexjs/basic";
 @namespace "http://www.w3.org/1999/xhtml";
 
+table.tableSection tr>td:last-child
+{ /* removing fraction of width i.e 2% to align the tbody columns with thead columns. */ /* It is must as we need to consider the tbody scroll width too */ /* if the width is in pixels, then (width - 18px) would be enough */ width: 31%; }
+/** for older browsers (IE8), if you know number of columns in your table **/
+table.tableSection tr>td:first-child + td + td
+{ width : 31%; }
+
 /*
 //----------------------------
 // Named styles

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/test/resources/flexjs/files/CSSTestSource_result.css
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/resources/flexjs/files/CSSTestSource_result.css b/compiler-jx/src/test/resources/flexjs/files/CSSTestSource_result.css
index 6a17c84..8cedccd 100755
--- a/compiler-jx/src/test/resources/flexjs/files/CSSTestSource_result.css
+++ b/compiler-jx/src/test/resources/flexjs/files/CSSTestSource_result.css
@@ -19,6 +19,16 @@
 ////////////////////////////////////////////////////////////////////////////////
 */
 /* Generated by Apache Flex Cross-Compiler */
+table.tableSection tr>td:last-child {
+        width: 31%;
+}
+
+
+table.tableSection tr>td:first-child + td + td {
+        width : 31%;
+}
+
+
 .glass {
         border-color: #767473;
         highlight-alphas: .07 .45;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/test/resources/flexjs/files/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/resources/flexjs/files/MyInitialView.mxml b/compiler-jx/src/test/resources/flexjs/files/MyInitialView.mxml
index 1fe77f9..c083269 100644
--- a/compiler-jx/src/test/resources/flexjs/files/MyInitialView.mxml
+++ b/compiler-jx/src/test/resources/flexjs/files/MyInitialView.mxml
@@ -48,7 +48,7 @@ limitations under the License.
 				return String(comboBox.selectedItem);
 			}
 			
-			public function startTimer(event:org.apache.flex.events.Event):void
+			public function startTimer():void
 			{
 				timer = new org.apache.flex.utils.Timer(1000);
 				timer.addEventListener('timer', timerHandler);
@@ -69,7 +69,7 @@ limitations under the License.
 								 destinationPropertyName="text" />
 		</basic:beads>
 	</basic:Label>
-	<basic:TextButton text="Let's Start Timer" x="100" y="75" click="startTimer(event)" />
+	<basic:TextButton text="Let's Start Timer" x="100" y="75" click="startTimer()" />
 	<basic:TextButton text="Stop Timer" x="100" y="100" click="timer.removeEventListener('timer', timerHandler);timer.stop()" />
 	<basic:Label id="timerLabel" x="100" y="125" />
 	


[4/8] git commit: [flex-falcon] [refs/heads/dual] - handle other scopes in ambiguous definitions

Posted by ah...@apache.org.
handle other scopes in ambiguous definitions


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

Branch: refs/heads/dual
Commit: 55ee96879f92c27598ef74a6a329d7af8bddbd75
Parents: dd69be2
Author: Alex Harui <ah...@apache.org>
Authored: Sat Jan 28 22:28:54 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Sat Jan 28 22:28:54 2017 -0800

----------------------------------------------------------------------
 .../apache/flex/compiler/internal/projects/FlexProject.java | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/55ee9687/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
index 602de21..9721d2a 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/projects/FlexProject.java
@@ -2129,12 +2129,13 @@ public class FlexProject extends ASProject implements IFlexProject
             thisPackage = scopeDef.getPackageName();
         else
         {
-            if (scope instanceof PackageScope)
-                thisPackage = ((PackageScope)scope).getDefinition().getBaseName();
-            else
+            while (!(scope instanceof PackageScope))
             {
-                return null;
+            	scope = scope.getContainingScope();
             }
+            if (!(scope instanceof PackageScope))
+            	return null;
+            thisPackage = ((PackageScope)scope).getDefinition().getBaseName();
         }
         String package1 = def1.getPackageName();
         String package2 = def2.getPackageName();


[5/8] git commit: [flex-falcon] [refs/heads/dual] - multiple target compiling

Posted by ah...@apache.org.
multiple target compiling


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

Branch: refs/heads/dual
Commit: 283e87ec2c0b4a3724ae0578c3a327436b08b221
Parents: 55ee968
Author: Alex Harui <ah...@apache.org>
Authored: Sat Jan 28 22:29:47 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Sat Jan 28 22:29:47 2017 -0800

----------------------------------------------------------------------
 .../flex/compiler/clients/JSConfiguration.java  | 57 ++++++++++++++++++++
 .../apache/flex/compiler/clients/MXMLJSC.java   |  2 +
 .../mxml/flexjs/TestFlexJSMXMLApplication.java  | 33 ++++++++++++
 .../flexjs/files/FlexJSTest_again_Flash.mxml    | 51 ++++++++++++++++++
 .../flex/compiler/config/Configuration.java     |  4 +-
 5 files changed, 145 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/283e87ec/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
index a06698d..35d3a4b 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
@@ -33,6 +33,7 @@ import org.apache.flex.compiler.internal.config.annotations.Arguments;
 import org.apache.flex.compiler.internal.config.annotations.Config;
 import org.apache.flex.compiler.internal.config.annotations.InfiniteArguments;
 import org.apache.flex.compiler.internal.config.annotations.Mapping;
+import org.apache.flex.compiler.internal.config.annotations.SoftPrerequisites;
 
 import com.google.common.collect.ImmutableList;
 
@@ -111,4 +112,60 @@ public class JSConfiguration extends Configuration
         sourceMap = value;
     }
 
+    //
+    // 'compiler.js-external-library-path' option
+    //
+
+    private final List<String> jsexternalLibraryPath = new ArrayList<String>();
+
+    @Override
+    public List<String> getCompilerExternalLibraryPath()
+    {
+    	if (jsexternalLibraryPath.size() > 0)
+    		return jsexternalLibraryPath;
+    	return super.getCompilerExternalLibraryPath();
+    }
+
+    @Config(allowMultiple = true, isPath = true)
+    @Mapping({ "compiler", "js-external-library-path" })
+    @Arguments(Arguments.PATH_ELEMENT)
+    @InfiniteArguments
+    public void setCompilerJsExternalLibraryPath(ConfigurationValue cv, String[] pathlist) throws ConfigurationException
+    {
+        final ImmutableList<String> pathElements = ImmutableList.copyOf(pathlist);
+        final ImmutableList<String> resolvedPaths = expandTokens(pathElements, locales, cv,
+                !reportMissingCompilerLibraries);
+        jsexternalLibraryPath.addAll(resolvedPaths);
+    }
+
+    //
+    // 'compiler.js-library-path' option
+    //
+
+    private final List<String> jslibraryPath = new ArrayList<String>();
+
+    @Override
+    public List<String> getCompilerLibraryPath()
+    {
+    	if (jslibraryPath.size() > 0)
+    		return jslibraryPath;
+    	return super.getCompilerLibraryPath();
+    }
+
+    /**
+     * Links SWC files to the resulting application SWF file. The compiler only links in those classes for the SWC file
+     * that are required. You can specify a directory or individual SWC files.
+     */
+    @Config(allowMultiple = true, isPath = true)
+    @Mapping({ "compiler", "js-library-path" })
+    @Arguments(Arguments.PATH_ELEMENT)
+    @InfiniteArguments
+    public void setCompilerJsLibraryPath(ConfigurationValue cv, String[] pathlist) throws CannotOpen
+    {
+        final ImmutableList<String> resolvedPaths = expandTokens(Arrays.asList(pathlist), locales, cv,
+                !reportMissingCompilerLibraries);
+        jslibraryPath.addAll(resolvedPaths);
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/283e87ec/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
index 8a96d6d..12ac04f 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -395,6 +395,8 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     		if (!(arg.startsWith("-compiler.targets") ||
     			  arg.startsWith("-closure-lib") ||
     			  arg.startsWith("-remove-circulars") ||
+    			  arg.startsWith("-compiler.js-external-library-path") ||
+    			  arg.startsWith("-compiler.js-library-path") ||
     			  arg.startsWith("-source-map")))
     			list.add(arg);						
     	}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/283e87ec/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
index 70dec15..0f4e0de 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
@@ -811,6 +811,39 @@ public class TestFlexJSMXMLApplication extends FlexJSTestBase
         assertThat(result, is(0));
     }
 
+    @Test
+    public void testFlexJSMainFileDualFlash()
+    {
+    	/* this should error because a Flash APi is used */
+        MXMLJSC mxmlc = new MXMLJSC();
+        String[] args = new String[18];
+        args[0] = "-compiler.targets=SWF,JSFlex";
+        args[1] = "-remove-circulars";
+        args[2] = "-library-path=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/libs/Core.swc")).getPath();
+        args[3] = "-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/libs/Binding.swc")).getPath();
+        args[4] = "-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/libs/Network.swc")).getPath();
+        args[5] = "-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/libs/Collections.swc")).getPath();
+        args[6] = "-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/projects/Basic/target/Basic.swc")).getPath();
+        args[7] = "-external-library-path+=" + testAdapter.getPlayerglobal().getPath();
+        args[8] = "-output=" + new File(testAdapter.getTempDir(), "bin-debug/FlexJSTest_again_Flash.swf").getPath();
+        if (env.GOOG != null)
+        	args[9] = "-closure-lib=" + new File(FilenameNormalization.normalize(env.GOOG)).getPath();
+        else
+        	args[9] = "-define=COMPILE::temp,false";
+        args[10] = "-compiler.allow-subclass-overrides";
+        args[11] = "-compiler.js-library-path=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/js/FlexJS/libs/CoreJS.swc")).getPath();
+        args[12] = "-compiler.js-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/js/FlexJS/libs/BindingJS.swc")).getPath();
+        args[13] = "-compiler.js-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/js/FlexJS/libs/NetworkJS.swc")).getPath();
+        args[14] = "-compiler.js-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/js/FlexJS/libs/CollectionsJS.swc")).getPath();
+        args[15] = "-compiler.js-library-path+=" + new File(FilenameNormalization.normalize(env.ASJS + "/frameworks/js/FlexJS/libs/BasicJS.swc")).getPath();
+        args[16] = "-compiler.js-external-library-path=" + new File(FilenameNormalization.normalize(env.ASJS + "/js/libs/js.swc")).getPath();
+        args[17] = new File(testAdapter.getUnitTestBaseDir(), "flexjs/files/FlexJSTest_again_Flash.mxml").getPath();
+
+        int result = mxmlc.mainNoExit(args, errors, true);
+        assertThat(result, is(3));
+        assertErrors("Access of possibly undefined property scrollRect.");
+    }
+
     @Override
     protected void addSourcePaths(List<File> sourcePaths)
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/283e87ec/compiler-jx/src/test/resources/flexjs/files/FlexJSTest_again_Flash.mxml
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/resources/flexjs/files/FlexJSTest_again_Flash.mxml b/compiler-jx/src/test/resources/flexjs/files/FlexJSTest_again_Flash.mxml
new file mode 100644
index 0000000..286664d
--- /dev/null
+++ b/compiler-jx/src/test/resources/flexjs/files/FlexJSTest_again_Flash.mxml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+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.
+
+-->
+<basic:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+				   xmlns:local="*"
+				   xmlns:basic="library://ns.apache.org/flexjs/basic" 
+				   xmlns:models="models.*" 
+				   xmlns:controllers="controllers.*"
+				   initialize="MyModel(model).labelText='Hello World'; scrollRect = null"
+				   >
+	<basic:valuesImpl>
+		<basic:SimpleCSSValuesImpl />
+	</basic:valuesImpl>
+	<basic:initialView>
+		<local:MyInitialView />
+	</basic:initialView>
+	<basic:model>
+		<models:MyModel />
+	</basic:model>
+	<basic:controller>
+		<controllers:MyController />
+	</basic:controller>
+    <basic:beads>
+        <basic:HTTPService id="service">
+            <basic:LazyCollection id="collection">
+                <basic:inputParser>
+                    <basic:JSONInputParser />
+                </basic:inputParser>
+                <basic:itemConverter>
+                    <local:StockDataJSONItemConverter />
+                </basic:itemConverter> 
+            </basic:LazyCollection>
+        </basic:HTTPService>
+    </basic:beads>
+</basic:Application>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/283e87ec/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
index 3fbf713..7d9f3d7 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
@@ -2224,7 +2224,7 @@ public class Configuration
     //
 
     private final List<String> libraryPath = new ArrayList<String>();
-    private boolean reportMissingCompilerLibraries = true;
+    protected boolean reportMissingCompilerLibraries = true;
 
     /**
      * Sets whether to report missing libraries in the configuration. If this is false any missing libraries will not be
@@ -2264,7 +2264,7 @@ public class Configuration
     // 'compiler.locale' option
     //
 
-    private final List<String> locales = new ArrayList<String>();
+    protected final List<String> locales = new ArrayList<String>();
 
     public List<String> getCompilerLocales()
     {


[7/8] git commit: [flex-falcon] [refs/heads/dual] - more attempts to use compiler.target. Still not working

Posted by ah...@apache.org.
more attempts to use compiler.target.  Still not working


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

Branch: refs/heads/dual
Commit: 0dd88355a458732bf6e40c839b77afd4b5684f97
Parents: f094bae
Author: Alex Harui <ah...@apache.org>
Authored: Mon Jan 30 10:16:10 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Mon Jan 30 10:16:10 2017 -0800

----------------------------------------------------------------------
 .../flex/compiler/clients/JSConfiguration.java  |   2 +-
 .../apache/flex/compiler/clients/MXMLJSC.java   |   4 +-
 .../compiler/common/CompilerConfiguration.java  | 281 +++++++++++++++++++
 .../flex2/tools/CommandLineConfiguration.java   |  20 ++
 .../java/flex2/tools/oem/internal/OEMUtil.java  |  10 +-
 5 files changed, 309 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0dd88355/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
index b6b2906..53a2f54 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
@@ -250,7 +250,7 @@ public class JSConfiguration extends Configuration
     @Override
     public Map<String, String> getCompilerDefine()
     {
-    	if (jsconfigVars.size() > 0)
+    	if (jsconfigVars != null)
     		return jsconfigVars;
     	return super.getCompilerDefine();
     }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0dd88355/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
index 7eb863e..4d4410e 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -235,7 +235,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
 
     protected ProblemQuery problems;
     protected ISourceFileHandler asFileHandler;
-    protected JSConfiguration config;
+    public JSConfiguration config;
     protected Configurator projectConfigurator;
     private ConfigurationBuffer configBuffer;
     private ICompilationUnit mainCU;
@@ -742,7 +742,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
      * @param args command line arguments
      * @return True if mxmlc should continue with compilation.
      */
-    protected boolean configure(final String[] args)
+    public boolean configure(final String[] args)
     {
     	projectConfigurator = new Configurator(JSGoogConfiguration.class);
     	

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0dd88355/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java b/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
index 4da4828..627d178 100644
--- a/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
+++ b/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
@@ -617,6 +617,146 @@ public class CompilerConfiguration implements As3Configuration,
         };
     }
 
+    //
+    // 'compiler.js-define' option
+    //
+
+    /**
+     * Syntax:<br/>
+     * <code>-define=&lt;name&gt;,&lt;value&gt;</code>
+     * where name is <code>NAMESPACE::name</code> and value is a legal definition value
+     * (e.g. <code>true</code> or <code>1</code> or <code>!CONFIG::debugging</code>)
+     *
+     * Example: <code>-define=CONFIG::debugging,true</code>
+     *
+     * In <code>flex-config.xml</code>:<br/>
+     * <pre>
+     * <flex-config>
+     *    <compiler>
+     *       <define>
+     *          <name>CONFIG::debugging</name>
+     *          <value>true</value>
+     *       </define>
+     *       ...
+     *    </compile>
+     * </flex-config>
+     * </pre>
+     *
+     * Values:<br/>
+     * Values are ActionScript expressions that must coerce and evaluate to constants at compile-time.
+     * Effectively, they are replaced in AS code, verbatim, so <code>-define=TEST::oneGreaterTwo,"1>2"</code>
+     * will get coerced and evaluated, at compile-time, to <code>false</code>.
+     *
+     * It is good practice to wrap values with double-quotes,
+     * so that MXMLC correctly parses them as a single argument:<br/>
+     * <code>-define=TEST::oneShiftRightTwo,"1 >> 2"</code>
+     *
+     * Values may contain compile-time constants and other configuration values:<br/>
+     * <code>-define=CONFIG::bool2,false -define=CONFIG::and1,"CONFIG::bool2 && false" TestApp.mxml</code>
+     *
+     * String values on the command-line <i>must</i> be surrounded by double-quotes, and either
+     * escape-quoted (<code>"\"foo\""</code> or <code>"\'foo\'"</code>) or single-quoted
+     * (<code>"'foo'"</code>).
+     *
+     * String values in configuration files need only be single- or double- quoted:<br/>
+     * <pre>
+     * <flex-config>
+     *    <compiler>
+     *       <define>
+     *          <name>NAMES::Company</name>
+     *          <value>'Apache Software Foundation'</value>
+     *       </define>
+     *       <define>
+     *          <name>NAMES::Application</name>
+     *          <value>"Flex 4.7"</value>
+     *       </define>
+     *       ...
+     *    </compile>
+     * </flex-config>
+     * </pre>
+     *
+     * Empty strings <i>must</i> be passed as <code>"''"</code> on the command-line, and
+     * <code>''</code> or <code>""</code> in configuration files.
+     * 
+     * Finally, if you have existing definitions in a configuration file, and you would
+     * like to add to them with the command-line (let's say most of your build settings
+     * are in the configuration, and that you are adding one temporarily using the
+     * command-line), you use the following syntax:
+     * <code>-define+=TEST::temporary,false</code> (noting the plus sign)
+     * 
+     * Note that definitions can be overridden/redefined if you use the append ("+=") syntax
+     * (on the commandline or in a user config file, for instance) with the same namespace
+     * and name, and a new value.
+     * 
+     * Definitions cannot be removed/undefined. You can undefine ALL existing definitions
+     * from (e.g. from flex-config.xml) if you do not use append syntax ("=" or append="false").
+     * 
+     * IMPORTANT FOR FLEXBUILDER
+     * If you are using "Additional commandline arguments" to "-define", don't use the following
+     * syntax though I suggest it above:
+     *     -define+=CONFIG::foo,"'value'"
+     * The trouble is that FB parses the double quotes incorrectly as <"'value'> -- the trailing
+     * double-quote is dropped. The solution is to avoid inner double-quotes and put them around the whole expression:
+     *    -define+="CONFIG::foo,'value'"
+     */
+	private ObjectList<ConfigVar> jsconfigVars = new ObjectList<ConfigVar>();
+    
+    /**
+     * @return A list of ConfigVars
+     */
+    public ObjectList<ConfigVar> jsgetDefine()
+    {
+        return configVars;
+    }
+
+    public void cfgJsDefine( ConfigurationValue _cv, final String _name, String _value )
+        throws ConfigurationException
+    {
+        assert _name  != null;
+        assert _value != null;
+        assert _cv    != null;
+
+        // macromedia.asc.embedding.Main.parseConfigVar(_name + "=" + _value)
+        final int ns_end = _name.indexOf("::");
+        if( (ns_end == -1) || (ns_end == 0) || (ns_end == _name.length()-2) )
+        {
+            throw new ConfigurationException.BadDefinition(_name + " " + _value,
+                                                           _cv.getVar(),
+                                                           _cv.getSource(),
+                                                           _cv.getLine());
+        }
+        
+        final String ns = _name.substring(0, ns_end);
+        final String name = _name.substring(ns_end + 2);
+        
+        if (configVars == null)
+        {
+            configVars = new ObjectList<ConfigVar>();
+        }
+
+        // try removing any existing definition
+        for (final Iterator<ConfigVar> iter = configVars.iterator(); iter.hasNext();)
+        {
+            final ConfigVar other = iter.next();
+            if (ns.equals(other.ns) && name.equals(other.name))
+            {
+                iter.remove();
+                break;
+            }
+        }
+        
+        configVars.add(new ConfigVar(ns, name, _value));
+    }
+    
+    public static ConfigurationInfo getJsDefineInfo()
+    {
+        return new ConfigurationInfo(new String[] {"name", "value"})
+        {
+            public boolean allowMultiple() { return true; }
+            public boolean isAdvanced()    { return true; }
+        };
+    }
+
 	//
     // 'compiler.conservative' option (hidden)
     //
@@ -851,6 +991,50 @@ public class CompilerConfiguration implements As3Configuration,
     }
 
     //
+    // 'compiler.js-external-library-path' option
+    //
+
+    private VirtualFile[] jsexternalLibraryPath;
+
+    public VirtualFile[] getJsExternalLibraryPath()
+    {
+        return jsexternalLibraryPath;
+    }
+
+    public void cfgJsExternalLibraryPath( ConfigurationValue cv, String[] pathlist ) throws ConfigurationException
+    {
+    	String[] locales = getLocales();
+    	VirtualFile[] newPathElements = expandTokens(pathlist, locales, cv);
+    	jsexternalLibraryPath = (VirtualFile[])merge(jsexternalLibraryPath, newPathElements, VirtualFile.class);
+	}
+
+    public static ConfigurationInfo getJsExternalLibraryPathInfo()
+    {
+        return new ConfigurationInfo( -1, new String[] { "path-element" } )
+        {
+            public boolean allowMultiple()
+            {
+                return true;
+            }
+
+	        public String[] getSoftPrerequisites()
+	        {
+		        return PATH_TOKENS;
+	        }
+
+            public boolean isPath()
+            {
+                return true;
+            }
+
+            public boolean doChecksum()
+            {
+            	return false;
+            }
+        };
+    }
+
+    //
     // 'compiler.fonts.*' options
     //
 
@@ -1232,6 +1416,103 @@ public class CompilerConfiguration implements As3Configuration,
     }
 
     //
+    // 'compiler.js-library-path' option
+    //
+
+    /**
+     * A list of SWC component libraries or directories containing SWCs.
+     * All SWCs found in the library-path are merged together
+     * and resolved via priority and version.
+     * The order in the library-path is ignored.
+     *
+     * The specified compiler.library-path can have path elements
+     * which contain a special {locale} token.
+     * If you compile for a single locale,
+     * this token is replaced by the specified locale.
+     * If you compile for multiple locales,
+     * any path element with the {locale} token
+	 * is expanded into multiple path elements,
+	 * one for each locale.
+     * If you compile for no locale,
+     * any path element with {locale} is ignored.
+     */
+    private VirtualFile[] jslibraryPath;
+
+    public VirtualFile[] getJsLibraryPath()
+    {
+        return jslibraryPath;
+    }
+
+    public void cfgJsLibraryPath( ConfigurationValue cv, String[] pathlist ) throws ConfigurationException
+    {
+    	String[] locales = getLocales();
+    	VirtualFile[] newPathElements = expandTokens(pathlist, locales, cv);
+    	libraryPath = (VirtualFile[])merge(libraryPath, newPathElements, VirtualFile.class);
+    }
+
+    public static ConfigurationInfo getJsLibraryPathInfo()
+    {
+        return new ConfigurationInfo( -1, new String[] { "path-element" } )
+        {
+            public boolean allowMultiple()
+            {
+                return true;
+            }
+
+	        public String[] getSoftPrerequisites()
+	        {
+		        return PATH_TOKENS;
+	        }
+
+            public boolean isPath()
+            {
+                return true;
+            }
+
+            public boolean doChecksum()
+            {
+            	return false;
+            }
+        };
+    }
+
+    //
+    // 'compiler.targets' option
+    //
+
+    /*
+     * This is never null. If you specify "no targets"
+     * it will compile to JS.
+     */
+    private String[] targets = new String[] {};
+
+    public String[] getTargets()
+    {
+        return targets;
+    }
+
+	public String targets()
+	{
+		return targets.length > 0 ? locales[0] : null;
+	}
+
+    public void cfgTarget( ConfigurationValue cv, String[] newTargets )
+    {
+        locales = (String[])merge(newTargets, targets, String.class);
+    }
+
+    public static ConfigurationInfo getTargetInfo()
+    {
+        return new ConfigurationInfo( -1, new String[] { "target-element" } )
+        {
+            public boolean allowMultiple()
+            {
+                return true;
+            }
+        };
+    }
+
+    //
     // 'compiler.locale' option
     //
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0dd88355/flex-compiler-oem/src/main/java/flex2/tools/CommandLineConfiguration.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/CommandLineConfiguration.java b/flex-compiler-oem/src/main/java/flex2/tools/CommandLineConfiguration.java
index b0a4f12..a158543 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/CommandLineConfiguration.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/CommandLineConfiguration.java
@@ -257,6 +257,26 @@ public class CommandLineConfiguration extends ToolsConfiguration
 	}
 
 	//
+	// 'js-output' option
+	//
+	
+	public void cfgJsOutput(ConfigurationValue val, String output) throws ConfigurationException
+	{
+        this.output = Configuration.getOutputPath(val, output);
+	}
+
+	public static ConfigurationInfo getJsOutputInfo()
+	{
+	    return new ConfigurationInfo(1, "filename")
+	    {
+	        public boolean isRequired()
+	        {
+	            return false;
+	        }
+	    };
+	}
+
+	//
 	// 'projector' option (hidden)
 	//
 	

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0dd88355/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMUtil.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMUtil.java b/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMUtil.java
index e530ce3..ae805f1 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMUtil.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMUtil.java
@@ -40,8 +40,8 @@ import flex2.tools.CompcConfiguration;
 import flex2.tools.ToolsConfiguration;
 import flex2.tools.oem.*;
 
-import org.apache.flex.compiler.clients.COMPC;
-import org.apache.flex.compiler.clients.MXMLC;
+import org.apache.flex.compiler.clients.COMPJSC;
+import org.apache.flex.compiler.clients.MXMLJSC;
 
 /**
  * A collection of utility methods used by classes in flex2.tools.oem.
@@ -145,7 +145,7 @@ public class OEMUtil
             													 ApplicationCompilerConfiguration.getAliases());
             cfgbuf.setDefaultVar("--file-specs" /*Mxmlc.FILE_SPECS*/);            
             DefaultsConfigurator.loadDefaults(cfgbuf);
-            MXMLC mxmlc = new MXMLC();
+            MXMLJSC mxmlc = new MXMLJSC();
             mxmlc.configure(args);
             ApplicationCompilerConfiguration configuration = processMXMLCConfiguration(mxmlc.config);
             
@@ -271,7 +271,7 @@ public class OEMUtil
             ConfigurationBuffer cfgbuf = new ConfigurationBuffer(LibraryCompilerConfiguration.class,
             													 LibraryCompilerConfiguration.getAliases());
 	        DefaultsConfigurator.loadOEMCompcDefaults( cfgbuf );
-            COMPC compc = new COMPC();
+            COMPJSC compc = new COMPJSC();
             compc.configure(args);
             LibraryCompilerConfiguration configuration = processCOMPCCConfiguration(compc.config);
             configuration.keepLinkReport(keepLinkReport);
@@ -331,7 +331,7 @@ public class OEMUtil
                     ApplicationCompilerConfiguration.getAliases());
             cfgbuf.setDefaultVar("--file-specs" /*Mxmlc.FILE_SPECS*/);            
             DefaultsConfigurator.loadDefaults(cfgbuf);
-            MXMLC mxmlc = new MXMLC();
+            MXMLJSC mxmlc = new MXMLJSC();
             mxmlc.configure(args);
             ApplicationCompilerConfiguration configuration = processMXMLCConfiguration(mxmlc.config);
             


[6/8] git commit: [flex-falcon] [refs/heads/dual] - clean compile of oem. May not run

Posted by ah...@apache.org.
clean compile of oem.  May not run


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

Branch: refs/heads/dual
Commit: f094bae3c0f08849aa8f6a3ea2b08a6e4907511c
Parents: 283e87e
Author: Alex Harui <ah...@apache.org>
Authored: Sun Jan 29 10:02:10 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Sun Jan 29 10:02:10 2017 -0800

----------------------------------------------------------------------
 .../flex/compiler/clients/JSConfiguration.java  | 128 ++++++++++
 .../apache/flex/compiler/clients/MXMLJSC.java   |   2 +
 .../flex/compiler/config/Configuration.java     |  11 +-
 .../src/main/java/flex2/tools/Compc.java        |   2 -
 .../src/main/java/flex2/tools/Mxmlc.java        |   2 -
 .../src/main/java/flex2/tools/Tool.java         | 248 +------------------
 6 files changed, 144 insertions(+), 249 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
index 35d3a4b..b6b2906 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
@@ -21,7 +21,9 @@ package org.apache.flex.compiler.clients;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.flex.compiler.clients.MXMLJSC.JSOutputType;
 import org.apache.flex.compiler.clients.MXMLJSC.JSTargetType;
@@ -167,5 +169,131 @@ public class JSConfiguration extends Configuration
         jslibraryPath.addAll(resolvedPaths);
     }
 
+    /**
+     * Syntax:<br/>
+     * <code>-define=&lt;name&gt;,&lt;value&gt;</code> where name is <code>NAMESPACE::name</code> and value is a legal
+     * definition value (e.g. <code>true</code> or <code>1</code> or <code>!CONFIG::debugging</code>)
+     *
+     * Example: <code>-define=CONFIG::debugging,true</code>
+     *
+     * In <code>flex-config.xml</code>:<br/>
+     * 
+     * <pre>
+     * <flex-config>
+     *    <compiler>
+     *       <define>
+     *          <name>CONFIG::debugging</name>
+     *          <value>true</value>
+     *       </define>
+     *       ...
+     *    </compile>
+     * </flex-config>
+     * </pre>
+     *
+     * Values:<br/>
+     * Values are ActionScript expressions that must coerce and evaluate to constants at compile-time. Effectively, they
+     * are replaced in AS code, verbatim, so <code>-define=TEST::oneGreaterTwo,"1>2"</code> will getCompiler coerced and
+     * evaluated, at compile-time, to <code>false</code>.
+     *
+     * It is good practice to wrap values with double-quotes, so that MXMLC correctly parses them as a single argument:
+     * <br/>
+     * <code>-define=TEST::oneShiftRightTwo,"1 >> 2"</code>
+     *
+     * Values may contain compile-time constants and other configuration values:<br/>
+     * <code>-define=CONFIG::bool2,false -define=CONFIG::and1,"CONFIG::bool2 && false" TestApp.mxml</code>
+     *
+     * String values on the command-line <i>must</i> be surrounded by double-quotes, and either escape-quoted (
+     * <code>"\"foo\""</code> or <code>"\'foo\'"</code>) or single-quoted (<code>"'foo'"</code>).
+     *
+     * String values in configuration files need only be single- or double- quoted:<br/>
+     * 
+     * <pre>
+     * <flex-config>
+     *    <compiler>
+     *       <define>
+     *          <name>NAMES::Organization</name>
+     *          <value>'Apache Software Foundation'</value>
+     *       </define>
+     *       <define>
+     *          <name>NAMES::Application</name>
+     *          <value>"Flex 4.8.0"</value>
+     *       </define>
+     *       ...
+     *    </compile>
+     * </flex-config>
+     * </pre>
+     *
+     * Empty strings <i>must</i> be passed as <code>"''"</code> on the command-line, and <code>''</code> or
+     * <code>""</code> in configuration files.
+     * 
+     * Finally, if you have existing definitions in a configuration file, and you would like to add to them with the
+     * command-line (let's say most of your build setCompilertings are in the configuration, and that you are adding one
+     * temporarily using the command-line), you use the following syntax: <code>-define+=TEST::temporary,false</code>
+     * (noting the plus sign)
+     * 
+     * Note that definitions can be overridden/redefined if you use the append ("+=") syntax (on the commandline or in a
+     * user config file, for instance) with the same namespace and name, and a new value.
+     * 
+     * Definitions cannot be removed/undefined. You can undefine ALL existing definitions from (e.g. from
+     * flex-config.xml) if you do not use append syntax ("=" or append="false").
+     * 
+     * IMPORTANT FOR FLEXBUILDER If you are using "Additional commandline arguments" to "-define", don't use the
+     * following syntax though I suggest it above: -define+=CONFIG::foo,"'value'" The trouble is that FB parses the
+     * double quotes incorrectly as <"'value'> -- the trailing double-quote is dropped. The solution is to avoid inner
+     * double-quotes and put them around the whole expression: -define+="CONFIG::foo,'value'"
+     */
+    private Map<String, String> jsconfigVars;
+
+    /**
+     * @return A list of ConfigVars
+     */
+    @Override
+    public Map<String, String> getCompilerDefine()
+    {
+    	if (jsconfigVars.size() > 0)
+    		return jsconfigVars;
+    	return super.getCompilerDefine();
+    }
+
+    @Config(advanced = true, allowMultiple = true)
+    @Arguments({ "name", "value" })
+    public void setJsCompilerDefine(ConfigurationValue cv, String name, String value) throws ConfigurationException
+    {
+        if (jsconfigVars == null)
+        	jsconfigVars = new LinkedHashMap<String, String>();
+
+        jsconfigVars.put(name, value);
+    }
+
+    //
+    // 'output' option
+    //
+
+    private String jsoutput;
+
+    @Override
+    public String getOutput()
+    {
+    	if (jsoutput != null)
+    		return jsoutput;
+    	return super.getOutput();
+    }
+
+    @Config
+    @Arguments("filename")
+    public void setJsOutput(ConfigurationValue val, String output) throws ConfigurationException
+    {
+        this.jsoutput = getOutputPath(val, output);
+    }
+
+    @Override
+    protected String overrideDefinedValue(String name, String value)
+    {
+    	if (name.equals("COMPILE::SWF") && value.equals("AUTO"))
+    		return "false";
+    	if (name.equals("COMPILE::JS") && value.equals("AUTO"))
+    		return "true";
+    	return value;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
index 12ac04f..7eb863e 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -397,6 +397,8 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     			  arg.startsWith("-remove-circulars") ||
     			  arg.startsWith("-compiler.js-external-library-path") ||
     			  arg.startsWith("-compiler.js-library-path") ||
+    			  arg.startsWith("-compiler.js-define") ||
+    			  arg.startsWith("-js-output") ||
     			  arg.startsWith("-source-map")))
     			list.add(arg);						
     	}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
index 7d9f3d7..f206e47 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java
@@ -1870,9 +1870,18 @@ public class Configuration
         if (configVars == null)
             configVars = new LinkedHashMap<String, String>();
 
-        configVars.put(name, value);
+        configVars.put(name, overrideDefinedValue(name, value));
     }
 
+    protected String overrideDefinedValue(String name, String value)
+    {
+    	if (name.equals("COMPILE::SWF") && value.equals("AUTO"))
+    		return "true";
+    	if (name.equals("COMPILE::JS") && value.equals("AUTO"))
+    		return "false";
+    	return value;
+    }
+    
     //
     // 'compiler.conservative' option (hidden)
     //

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/Compc.java b/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
index 9186cbc..db8c1c2 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/Compc.java
@@ -42,7 +42,6 @@ public class Compc extends Tool {
 
     public static int compcNoExit(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
 
-        COMPILER = COMPC.class;
         JS_COMPILER = CompJSC.class;
 
         return compile(args);
@@ -50,7 +49,6 @@ public class Compc extends Tool {
 
     public static void compc(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
 
-        COMPILER = COMPC.class;
         JS_COMPILER = CompJSC.class;
 
         compile(args);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java b/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
index 93ed8e2..c78f90b 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/Mxmlc.java
@@ -61,7 +61,6 @@ public final class Mxmlc extends Tool {
 
     public static int mxmlcNoExit(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
 
-        COMPILER = MXMLC.class;
         JS_COMPILER = MxmlJSC.class;
 
         return compile(args);
@@ -69,7 +68,6 @@ public final class Mxmlc extends Tool {
 
     public static void mxmlc(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
 
-        COMPILER = MXMLC.class;
         JS_COMPILER = MxmlJSC.class;
 
         compile(args);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f094bae3/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/Tool.java b/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
index 7d1f138..dc59a00 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/Tool.java
@@ -57,7 +57,6 @@ import flex2.tools.oem.Message;
  */
 public class Tool
 {
-    protected static Class<? extends MXMLC> COMPILER;
     protected static Class<? extends MxmlJSC> JS_COMPILER;
 
     protected static int compile(String[] args)
@@ -65,223 +64,14 @@ public class Tool
     {
         int exitCode;
 
-        final String value = ArgumentUtil.getValue(args, "-js-output-type");
-        JSOutputType jsOutputType = null;
+        MxmlJSC mxmlJSC = JS_COMPILER.newInstance();
+        exitCode = mxmlJSC.execute(args);
 
-        if (value != null)
+        if (mxmlJSC.getProblemQuery().hasErrors())
         {
-            jsOutputType = JSOutputType.fromString(value);
+            processProblemReport(mxmlJSC);
         }
 
-        if (jsOutputType != null)
-        {
-            ArgumentBag bag = prepareJs(new ArgumentBag(args));
-
-            MxmlJSC mxmlJSC = JS_COMPILER.newInstance();
-            exitCode = mxmlJSC.execute(bag.args);
-
-            if (!mxmlJSC.getProblemQuery().hasErrors())
-            {
-                if (jsOutputType.equals(FLEXJS_DUAL))
-                {
-                    prepareAs3(bag);
-                    exitCode = flexCompile(bag.args);
-                }
-            }
-            else
-            {
-                processProblemReport(mxmlJSC);
-            }
-        }
-        else
-        {
-            exitCode = flexCompile(args);
-        }
-
-        return exitCode;
-    }
-
-    protected static ArgumentBag prepareJs(ArgumentBag bag)
-    {
-        SwitchDefineToCompileJs(bag);
-        prepareJsOutput(bag);
-
-        return bag;
-    }
-
-    protected static ArgumentBag prepareAs3(ArgumentBag bag)
-    {
-        SwitchDefineToCompileAs3(bag);
-        prepareAs3Output(bag);
-        removeNativeJSLibraries(bag);
-
-        return bag;
-    }
-
-    private static void removeNativeJSLibraries(ArgumentBag bag)
-    {
-        final List<String> argList = new ArrayList<String>(Arrays.asList(bag.args));
-        argList.add("--exclude-native-js-libraries=true");
-        bag.args = argList.toArray(new String[argList.size()]);
-    }
-
-    private static void prepareJsOutput(ArgumentBag bag)
-    {
-        bag.isCommandLineOutput = true;
-        bag.oldOutputPath = ArgumentUtil.getValue(bag.args, "-output");
-
-        if (bag.oldOutputPath == null)
-        {
-            bag.oldOutputPath = ArgumentUtil.getValue(bag.args, "-o");
-            if (bag.oldOutputPath != null)
-            {
-                bag.outputAlias = "-o";
-            }
-        }
-        else
-        {
-            bag.outputAlias = "-output";
-        }
-
-        if (bag.oldOutputPath == null)
-        {
-            bag.isCommandLineOutput = false;
-            List<ConfigurationBuffer> flexConfigs = null;
-
-            try
-            {
-                flexConfigs = loadConfig(bag.args);
-
-                for (ConfigurationBuffer flexConfig : flexConfigs)
-                {
-                    if (bag.oldOutputPath == null) {
-                        final List<ConfigurationValue> output = flexConfig != null ? flexConfig.getVar("output") : null;
-                        final ConfigurationValue configurationValue = output != null ? output.get(0) : null;
-                        bag.oldOutputPath = configurationValue != null ? configurationValue.getArgs().get(0)
-                                : bag.oldOutputPath;
-                    }
-                }
-            }
-            catch (org.apache.flex.compiler.exceptions.ConfigurationException ignored)
-            {
-            }
-        }
-
-        if (bag.oldOutputPath != null)
-        {
-            final int lastIndexOf = Math.max(bag.oldOutputPath.lastIndexOf("/"), bag.oldOutputPath.lastIndexOf("\\"));
-
-            if (lastIndexOf > -1)
-            {
-                bag.newOutputPath = bag.oldOutputPath.substring(0, lastIndexOf) + File.separator + "js" + File.separator
-                        + "out";
-
-                if (bag.isCommandLineOutput)
-                {
-                    ArgumentUtil.setValue(bag.args, bag.outputAlias, bag.newOutputPath);
-                }
-                else
-                {
-                    bag.args = ArgumentUtil.addValue(bag.args, "-output", bag.newOutputPath);
-                }
-            }
-        }
-    }
-
-    private static void SwitchDefineToCompileJs(ArgumentBag bag)
-    {
-        final Collection<String> defines = ArgumentUtil.getValues(bag.args, "-define");
-        if (defines.contains("COMPILE::AS3,AUTO") && defines.contains("COMPILE::JS,AUTO"))
-        {
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, "-define", "COMPILE::JS,AUTO");
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, "-define", "COMPILE::AS3,AUTO");
-
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", "COMPILE::JS,true", true);
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", "COMPILE::AS3,false", true);
-
-            bag.args = ArgumentUtil.addValue(bag.args, "-keep-asdoc", null);
-        }
-    }
-
-    private static void prepareAs3Output(ArgumentBag bag)
-    {
-        if (bag.oldOutputPath != null)
-        {
-            if (bag.isCommandLineOutput)
-            {
-                ArgumentUtil.setValue(bag.args, bag.outputAlias, bag.oldOutputPath);
-            }
-            else
-            {
-                bag.args = ArgumentUtil.removeElement(bag.args, "-output");
-            }
-        }
-
-        if (COMPILER.getName().equals(COMPC.class.getName()))
-        {
-            bag.args = ArgumentUtil.addValue(bag.args, "-include-file",
-                    "js" + File.separator + "out" + File.separator + "*," + bag.newOutputPath);
-        }
-    }
-
-    private static void SwitchDefineToCompileAs3(ArgumentBag bag)
-    {
-        final Collection<String> defines = ArgumentUtil.getValues(bag.args, "-define");
-        if (defines.contains("COMPILE::AS3,false") && defines.contains("COMPILE::JS,true"))
-        {
-            bag.args = ArgumentUtil.removeElement(bag.args, "-keep-asdoc");
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, "-define", "COMPILE::AS3,false");
-            bag.args = ArgumentUtil.removeElementWithValue(bag.args, "-define", "COMPILE::JS,true");
-
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", "COMPILE::JS,false", true);
-            bag.args = ArgumentUtil.addValue(bag.args, "-define", "COMPILE::AS3,true", true);
-        }
-
-        bag.args = ArgumentUtil.removeElement(bag.args, "-js-output-type");
-    }
-
-    private static List<ConfigurationBuffer> loadConfig(String[] args)
-            throws org.apache.flex.compiler.exceptions.ConfigurationException
-    {
-        List<ConfigurationBuffer> configurationBuffers = null;
-
-        final Collection<String> configFilePaths = ArgumentUtil.getValues(args, "-load-config");
-        if (configFilePaths != null)
-        {
-            for (String configFilePath : configFilePaths)
-            {
-                final File configFile = new File(configFilePath);
-                final FileSpecification fileSpecification = new FileSpecification(configFile.getAbsolutePath());
-                final ConfigurationBuffer cfgbuf = createConfigurationBuffer(Configuration.class);
-
-                FileConfigurator.load(cfgbuf, fileSpecification, new File(configFile.getPath()).getParent(),
-                        "flex-config", false);
-
-                if (configurationBuffers == null)
-                {
-                    configurationBuffers = new ArrayList<ConfigurationBuffer>(0);
-                }
-                configurationBuffers.add(cfgbuf);
-            }
-        }
-
-        return configurationBuffers;
-    }
-
-    private static ConfigurationBuffer createConfigurationBuffer(Class<? extends Configuration> configurationClass)
-    {
-        return new ConfigurationBuffer(configurationClass, Configuration.getAliases());
-    }
-
-    protected static int flexCompile(String[] args)
-            throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
-    {
-        int exitCode;
-
-        MXMLC mxmlc = COMPILER.newInstance();
-        exitCode = mxmlc.execute(args);
-        processProblemReport(new CompilerRequestableProblems(mxmlc));
-
         return exitCode;
     }
 
@@ -444,34 +234,4 @@ public class Tool
         }
     }
 
-    static class CompilerRequestableProblems implements ProblemQueryProvider
-    {
-        private MXMLC mxmlc;
-
-        public CompilerRequestableProblems(MXMLC mxmlc)
-        {
-            this.mxmlc = mxmlc;
-        }
-
-        @Override
-        public ProblemQuery getProblemQuery()
-        {
-            return mxmlc.getProblems();
-        }
-    }
-
-    protected static class ArgumentBag
-    {
-        public String[] args;
-
-        public String outputAlias;
-        public String oldOutputPath;
-        public String newOutputPath;
-        public boolean isCommandLineOutput;
-
-        public ArgumentBag(String[] args)
-        {
-            this.args = args;
-        }
-    }
 }


[8/8] git commit: [flex-falcon] [refs/heads/dual] - got it working for DataBindingExample

Posted by ah...@apache.org.
got it working for DataBindingExample


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

Branch: refs/heads/dual
Commit: 4d0e513db057c7a7a62ad1638fe04232a28254fe
Parents: 0dd8835
Author: Alex Harui <ah...@apache.org>
Authored: Tue Jan 31 09:07:19 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Jan 31 09:07:19 2017 -0800

----------------------------------------------------------------------
 .../apache/flex/compiler/clients/MXMLJSC.java   | 38 ++++++++++++++++++--
 .../compiler/common/CompilerConfiguration.java  |  6 ++--
 .../main/java/flex2/tools/oem/Application.java  | 19 +++++-----
 .../oem/internal/ConfigurationConstants.java    |  6 ++++
 .../tools/oem/internal/OEMConfiguration.java    |  5 +++
 5 files changed, 60 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4d0e513d/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
index 4d4410e..8ce5f4c 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -24,6 +24,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -75,6 +76,10 @@ import org.apache.flex.compiler.targets.ITarget;
 import org.apache.flex.compiler.targets.ITarget.TargetType;
 import org.apache.flex.compiler.targets.ITargetSettings;
 import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.swf.ISWF;
+import org.apache.flex.swf.SWF;
+import org.apache.flex.swf.types.RGB;
+import org.apache.flex.swf.types.Rect;
 import org.apache.flex.tools.FlexTool;
 import org.apache.flex.utils.ArgumentUtil;
 import org.apache.flex.utils.FilenameNormalization;
@@ -243,6 +248,9 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     protected ITargetSettings targetSettings;
     protected IJSApplication jsTarget;
     private IJSPublisher jsPublisher;
+    private MXMLC mxmlc;
+    public boolean noLink;
+    public OutputStream err;
     
     public MXMLJSC()
     {
@@ -307,8 +315,11 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
             		switch (JSTargetType.fromString(target))
 	                {
 	                case SWF:
-	                    MXMLC mxmlc = new MXMLC();
-	                    result = mxmlc.mainNoExit(removeJSArgs(args));
+	                    mxmlc = new MXMLC();
+	                    if (noLink)
+	                    	result = mxmlc.mainCompileOnly(removeJSArgs(args), err);
+	                    else
+	                    	result = mxmlc.mainNoExit(removeJSArgs(args));
 	                    if (result != 0)
 	                    {
 	                    	problems.addAll(mxmlc.problems.getProblems());
@@ -852,4 +863,27 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     {
         workspace.close();
     }
+    
+    /**
+     * return a data structure for FB integration
+     * @return
+     */
+    public ISWF getSWFTarget()
+    {
+    	SWF swf = new SWF();
+    	Rect rect = new Rect(getTargetSettings().getDefaultWidth(),
+    						getTargetSettings().getDefaultHeight());
+    	swf.setFrameSize(rect);
+    	// we might need to report actual color some day
+    	swf.setBackgroundColor(new RGB(255, 255, 255));
+    	swf.setTopLevelClass(config.getTargetFile());
+    	return swf;
+    }
+    
+    public long writeSWF(OutputStream output)
+    {
+    	if (mxmlc != null)
+    		return mxmlc.writeSWF(output);
+    	return 0;
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4d0e513d/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java b/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
index 627d178..cce9fb6 100644
--- a/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
+++ b/flex-compiler-oem/src/main/java/flex2/compiler/common/CompilerConfiguration.java
@@ -1496,12 +1496,12 @@ public class CompilerConfiguration implements As3Configuration,
 		return targets.length > 0 ? locales[0] : null;
 	}
 
-    public void cfgTarget( ConfigurationValue cv, String[] newTargets )
+    public void cfgTargets( ConfigurationValue cv, String[] newTargets )
     {
-        locales = (String[])merge(newTargets, targets, String.class);
+        targets = (String[])merge(newTargets, targets, String.class);
     }
 
-    public static ConfigurationInfo getTargetInfo()
+    public static ConfigurationInfo getTargetsInfo()
     {
         return new ConfigurationInfo( -1, new String[] { "target-element" } )
         {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4d0e513d/flex-compiler-oem/src/main/java/flex2/tools/oem/Application.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/oem/Application.java b/flex-compiler-oem/src/main/java/flex2/tools/oem/Application.java
index 5c5cfe5..626962a 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/oem/Application.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/oem/Application.java
@@ -33,7 +33,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import org.apache.flex.compiler.clients.MXMLC;
+import org.apache.flex.compiler.clients.MXMLJSC;
 import org.apache.flex.compiler.clients.problems.ProblemFormatter;
 import org.apache.flex.compiler.clients.problems.ProblemQuery;
 import org.apache.flex.compiler.problems.CompilerProblemSeverity;
@@ -622,15 +622,16 @@ public class Application implements Builder
     
             //Map licenseMap = OEMUtil.getLicenseMap(tempOEMConfiguration.configuration);
     
-            mxmlc = new MXMLC();
+            mxmljsc = new MXMLJSC();
+            mxmljsc.noLink = true;
             //int returnValue = mxmlc.mainCompileOnly(constructCommandLine2(tempOEMConfiguration.configuration), null);
-            int returnValue = mxmlc.mainCompileOnly(constructCommandLine(oemConfiguration), null);
+            int returnValue = mxmljsc.mainNoExit(constructCommandLine(oemConfiguration), null, true);
             if (returnValue == 0)
                 returnValue = OK;
             else
                 returnValue = FAIL;
             
-            processMXMLCReport(mxmlc, tempOEMConfiguration);
+            processMXMLCReport(mxmljsc, tempOEMConfiguration);
             
             clean(returnValue == FAIL /* cleanData */,
                   false /* cleanCache */,
@@ -650,15 +651,15 @@ public class Application implements Builder
 
     public long link(OutputStream output)
     {
-        return mxmlc.writeSWF(output);
+        return mxmljsc.writeSWF(output);
     }
     
-    private MXMLC mxmlc = new MXMLC();
+    private MXMLJSC mxmljsc = new MXMLJSC();
     private List<Source> sources;
     private SimpleMovie movie;
     private SourceList sourceList;
     
-    void processMXMLCReport(MXMLC mxmlc, OEMConfiguration config)
+    void processMXMLCReport(MXMLJSC mxmljsc, OEMConfiguration config)
     {
         /* not sure we need this
         ApplicationCompilerConfiguration acc = ((ApplicationCompilerConfiguration)config.configuration);
@@ -685,7 +686,7 @@ public class Application implements Builder
             }
         }
         */
-        ProblemQuery pq = mxmlc.getProblems();
+        ProblemQuery pq = mxmljsc.getProblemQuery();
         List<ICompilerProblem> probs = pq.getProblems();
         for (ICompilerProblem prob : probs)
         {
@@ -774,7 +775,7 @@ public class Application implements Builder
             }
             
         }
-        ISWF swf = mxmlc.getSWFTarget();
+        ISWF swf = mxmljsc.getSWFTarget();
         movie = new SimpleMovie(null);
         org.apache.flex.swf.types.Rect r = swf.getFrameSize();
         flash.swf.types.Rect fr = new flash.swf.types.Rect();

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4d0e513d/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/ConfigurationConstants.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/ConfigurationConstants.java b/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/ConfigurationConstants.java
index 1d59834..8f4a64d 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/ConfigurationConstants.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/ConfigurationConstants.java
@@ -28,6 +28,7 @@ package flex2.tools.oem.internal;
 interface ConfigurationConstants
 {
     String USE_NETWORK                                          = "--use-network";
+    String REMOVE_CIRCULARS                                     = "--remove-circulars";
     String RUNTIME_SHARED_LIBRARIES                             = "--runtime-shared-libraries";
     String RAW_METADATA                                         = "--raw-metadata";
     String PROJECTOR                                            = "--projector";
@@ -38,6 +39,7 @@ interface ConfigurationConstants
     String METADATA_DATE                                        = "--metadata.date";
     String METADATA_CREATOR                                     = "--metadata.creator";
     String METADATA_CONTRIBUTOR                                 = "--metadata.contributor";
+    String JS_OUTPUT                                            = "--js-output";
     String LINK_REPORT                                          = "--link-report";
     String SIZE_REPORT                                          = "--size-report";
     String LICENSES_LICENSE                                     = "--licenses.license";
@@ -104,7 +106,9 @@ interface ConfigurationConstants
     String COMPILER_NAMESPACES_NAMESPACE                        = "--compiler.namespaces.namespace";
     String COMPILER_MOBILE                                      = "--compiler.mobile";
     String COMPILER_LOCALE                                      = "--compiler.locale";
+    String COMPILER_TARGETS                                     = "--compiler.targets";
     String COMPILER_LIBRARY_PATH                                = "--compiler.library-path";
+    String COMPILER_JS_LIBRARY_PATH                             = "--compiler.js-library-path";
     String COMPILER_INCLUDE_LIBRARIES                           = "--compiler.include-libraries";
     String COMPILER_KEEP_GENERATED_ACTIONSCRIPT                 = "--compiler.keep-generated-actionscript";
     String COMPILER_KEEP_AS3_METADATA                           = "--compiler.keep-as3-metadata";
@@ -119,6 +123,7 @@ interface ConfigurationConstants
     String COMPILER_FONTS_FLASH_TYPE                            = "--compiler.fonts.flash-type";
     String COMPILER_FONTS_ADVANCED_ANTI_ALIASING                = "--compiler.fonts.advanced-anti-aliasing";
     String COMPILER_EXTERNAL_LIBRARY_PATH                       = "--compiler.external-library-path";
+    String COMPILER_JS_EXTERNAL_LIBRARY_PATH                    = "--compiler.js-external-library-path";
     String COMPILER_ES                                          = "--compiler.es";
     String COMPILER_DEFAULTS_CSS_URL                            = "--compiler.defaults-css-url";
     String COMPILER_DEBUG                                       = "--compiler.debug";
@@ -133,6 +138,7 @@ interface ConfigurationConstants
     String VERIFY_DIGESTS                                       = "--verify-digests";
     String COMPILER_COMPUTE_DIGEST                              = "--compute-digest";
     String COMPILER_DEFINE                                      = "--compiler.define";
+    String COMPILER_JS_DEFINE                                   = "--compiler.js-define";
     String COMPILER_MXML_COMPATIBILITY							= "--compiler.mxml.compatibility-version";
     String COMPILER_EXTENSIONS                                  = "--compiler.extensions.extension";
     String REMOVE_UNUSED_RSLS                                   = "--remove-unused-rsls";

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4d0e513d/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMConfiguration.java
----------------------------------------------------------------------
diff --git a/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMConfiguration.java b/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMConfiguration.java
index f8f3ff1..f141fd8 100644
--- a/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMConfiguration.java
+++ b/flex-compiler-oem/src/main/java/flex2/tools/oem/internal/OEMConfiguration.java
@@ -978,6 +978,11 @@ public class OEMConfiguration implements Configuration, ConfigurationConstants,
 		addFiles(COMPILER_LIBRARY_PATH, paths);
 	}
 	
+	public void setTargets(String[] targets)
+	{
+		args.put(COMPILER_TARGETS, targets);
+	}
+	
 	/**
 	 * Sets the locales that the compiler would use to replace <code>{locale}</code> tokens that appear in some configuration values.
 	 * This is equivalent to using <code>mxmlc/compc --compiler.locale</code>.


[2/8] git commit: [flex-falcon] [refs/heads/dual] - saw it compile for SWF and FlexJS. Needs MXMLFlexJSPublisher fix from develop branch

Posted by ah...@apache.org.
saw it compile for SWF and FlexJS.  Needs MXMLFlexJSPublisher fix from develop branch


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

Branch: refs/heads/dual
Commit: 6fced513f6268dde43b4a7d1789e7cc45bf59137
Parents: a89c2d7
Author: Alex Harui <ah...@apache.org>
Authored: Fri Jan 27 08:48:25 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Fri Jan 27 08:48:25 2017 -0800

----------------------------------------------------------------------
 .../apache/flex/compiler/clients/ASDOCJSC.java  |   1 -
 .../apache/flex/compiler/clients/COMPJSC.java   | 165 ++++-
 .../flex/compiler/clients/COMPJSCFlex.java      | 528 +++++++++++++
 .../flex/compiler/clients/COMPJSCNative.java    | 529 +++++++++++++
 .../flex/compiler/clients/FlexJSToolGroup.java  |   4 +-
 .../flex/compiler/clients/JSConfiguration.java  |  41 +-
 .../apache/flex/compiler/clients/MXMLJSC.java   | 173 +++--
 .../flex/compiler/clients/MXMLJSCFlex.java      | 742 +++++++++++++++++++
 .../flex/compiler/clients/MXMLJSCNative.java    | 741 ++++++++++++++++++
 .../flex/compiler/clients/MXMLJSCNode.java      | 739 ++++++++++++++++++
 .../codegen/js/goog/JSGoogPublisher.java        |   8 +-
 .../mxml/flexjs/TestFlexJSMXMLApplication.java  |  24 +
 .../org/apache/flex/utils/EnvProperties.java    |   8 +
 .../resources/flexjs/files/CSSTestSource.css    |   6 +
 .../flexjs/files/CSSTestSource_result.css       |  10 +
 .../resources/flexjs/files/MyInitialView.mxml   |   4 +-
 16 files changed, 3609 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java
index a74c7d8..2c8660f 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/ASDOCJSC.java
@@ -160,7 +160,6 @@ public class ASDOCJSC extends MXMLJSC
 
     public ASDOCJSC(IBackend backend)
     {
-        super(backend);
         project = new FlexJSASDocProject(workspace, backend);
     }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
index b208351..0eba441 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
@@ -38,6 +38,10 @@ import java.util.zip.ZipOutputStream;
 
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.flex.compiler.clients.MXMLJSC.ExitCode;
+import org.apache.flex.compiler.clients.MXMLJSC.JSTargetType;
+import org.apache.flex.compiler.clients.problems.ProblemPrinter;
+import org.apache.flex.compiler.clients.problems.WorkspaceProblemFormatter;
 import org.apache.flex.compiler.codegen.as.IASWriter;
 import org.apache.flex.compiler.driver.IBackend;
 import org.apache.flex.compiler.driver.js.IJSApplication;
@@ -57,10 +61,12 @@ import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.problems.InternalCompilerProblem;
 import org.apache.flex.compiler.problems.LibraryNotFoundProblem;
 import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
+import org.apache.flex.compiler.problems.UnexpectedExceptionProblem;
 import org.apache.flex.compiler.targets.ITarget.TargetType;
 import org.apache.flex.compiler.targets.ITargetSettings;
 import org.apache.flex.compiler.units.ICompilationUnit;
 import org.apache.flex.swc.io.SWCReader;
+import org.apache.flex.utils.ArgumentUtil;
 
 /**
  * @author Erik de Bruin
@@ -120,51 +126,148 @@ public class COMPJSC extends MXMLJSC
     {
         long startTime = System.nanoTime();
 
-        IBackend backend = new ASBackend();
-        for (String s : args)
+        final COMPJSC mxmlc = new COMPJSC();
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        final int exitCode = mxmlc.mainNoExit(args, problems, true);
+
+        long endTime = System.nanoTime();
+        System.out.println((endTime - startTime) / 1e9 + " seconds");
+
+        return exitCode;
+    }
+
+    @Override
+    public int mainNoExit(final String[] args, List<ICompilerProblem> problems,
+            Boolean printProblems)
+    {
+        int exitCode = -1;
+        try
         {
-            if (s.contains("-js-output-type"))
+            exitCode = _mainNoExit(ArgumentUtil.fixArgs(args), problems);
+        }
+        catch (Exception e)
+        {
+            System.err.println(e.toString());
+        }
+        finally
+        {
+            if (problems != null && !problems.isEmpty())
             {
-                jsOutputType = JSOutputType.fromString(s.split("=")[1]);
-
-                switch (jsOutputType)
+                if (printProblems)
                 {
-                case AMD:
-                    backend = new AMDBackend();
-                    break;
+                    final WorkspaceProblemFormatter formatter = new WorkspaceProblemFormatter(
+                            workspace);
+                    final ProblemPrinter printer = new ProblemPrinter(formatter);
+                    printer.printProblems(problems);
+                }
+            }
+        }
+        return exitCode;
+    }
 
-                case JSC:
-                    backend = new MXMLJSCJSSWCBackend();
-                    break;
+    /**
+     * Entry point that doesn't call <code>System.exit()</code>. This is for
+     * unit testing.
+     * 
+     * @param args command line arguments
+     * @return exit code
+     */
+    private int _mainNoExit(final String[] args,
+            List<ICompilerProblem> outProblems)
+    {
+        ExitCode exitCode = ExitCode.SUCCESS;
+        try
+        {
+            final boolean continueCompilation = configure(args);
 
-                case FLEXJS:
-                case FLEXJS_DUAL:
-                    backend = new MXMLFlexJSSWCBackend();
-                    break;
+/*            if (outProblems != null && !config.isVerbose())
+                JSSharedData.STDOUT = JSSharedData.STDERR = null;*/
 
-                case GOOG:
-                    backend = new GoogBackend();
-                    break;
+            if (continueCompilation)
+            {
 
-                default:
-                    throw new UnsupportedOperationException();
+            	targetloop:
+            	for (String target : config.getCompilerTargets())
+            	{
+            		int result = 0;
+            		switch (JSTargetType.fromString(target))
+	                {
+	                case SWF:
+	                    COMPC compc = new COMPC();
+	                    result = compc.mainNoExit(args);
+	                    if (result != 0)
+	                    {
+	                    	problems.addAll(compc.problems.getProblems());
+	                    	break targetloop;
+	                    }
+	                    break;
+	                case JS_FLEX:
+	                	COMPJSCFlex flex = new COMPJSCFlex();
+	                    result = flex.mainNoExit(args, problems.getProblems(), false);
+	                    if (result != 0)
+	                    {
+	                    	break targetloop;
+	                    }
+	                    break;
+	                case JS_NATIVE:
+	                	COMPJSCNative jsc = new COMPJSCNative();
+	                    result = jsc.mainNoExit(args, problems.getProblems(), false);
+	                    if (result != 0)
+	                    {
+	                    	break targetloop;
+	                    }
+	                    break;
+	                // if you add a new js-output-type here, don't forget to also add it
+	                // to flex2.tools.MxmlJSC in flex-compiler-oem for IDE support
+	                }
+            	}
+                if (problems.hasFilteredProblems())
+                {
+                    if (problems.hasErrors())
+                        exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+                    else
+                        exitCode = ExitCode.FAILED_WITH_PROBLEMS;
                 }
             }
+            else if (problems.hasFilteredProblems())
+            {
+                exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+            }
+            else
+            {
+                exitCode = ExitCode.PRINT_HELP;
+            }
         }
+        catch (Exception e)
+        {
+            if (outProblems == null) {
+                System.err.println(e.getMessage());
+            } else
+            {
+                final ICompilerProblem unexpectedExceptionProblem = new UnexpectedExceptionProblem(
+                        e);
+                problems.add(unexpectedExceptionProblem);
+            }
+            exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+        }
+        finally
+        {
+            waitAndClose();
 
-        final COMPJSC mxmlc = new COMPJSC(backend);
-        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
-        final int exitCode = mxmlc.mainNoExit(args, problems, true);
-
-        long endTime = System.nanoTime();
-        System.out.println((endTime - startTime) / 1e9 + " seconds");
-
-        return exitCode;
+            if (outProblems != null && problems.hasFilteredProblems())
+            {
+                for (ICompilerProblem problem : problems.getFilteredProblems())
+                {
+                    outProblems.add(problem);
+                }
+            }
+        }
+        return exitCode.code;
     }
 
-    public COMPJSC(IBackend backend)
+    public COMPJSC()
     {
-        super(backend);
+        super();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCFlex.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCFlex.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCFlex.java
new file mode 100644
index 0000000..dead1c3
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCFlex.java
@@ -0,0 +1,528 @@
+/*
+ *
+ *  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.clients;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Set;
+import java.util.zip.Deflater;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
+import org.apache.flex.compiler.codegen.as.IASWriter;
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.driver.js.IJSApplication;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
+import org.apache.flex.compiler.exceptions.ConfigurationException.IOError;
+import org.apache.flex.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
+import org.apache.flex.compiler.internal.codegen.js.JSWriter;
+import org.apache.flex.compiler.internal.driver.as.ASBackend;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSSWCBackend;
+import org.apache.flex.compiler.internal.driver.mxml.jsc.MXMLJSCJSSWCBackend;
+import org.apache.flex.compiler.internal.parsing.as.FlexJSASDocDelegate;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.targets.FlexJSSWCTarget;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.InternalCompilerProblem;
+import org.apache.flex.compiler.problems.LibraryNotFoundProblem;
+import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
+import org.apache.flex.compiler.targets.ITarget.TargetType;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.swc.io.SWCReader;
+
+/**
+ * @author Erik de Bruin
+ * @author Michael Schmalle
+ */
+public class COMPJSCFlex extends MXMLJSC
+{
+    /*
+     * Exit code enumerations.
+     */
+    static enum ExitCode
+    {
+        SUCCESS(0),
+        PRINT_HELP(1),
+        FAILED_WITH_PROBLEMS(2),
+        FAILED_WITH_EXCEPTIONS(3),
+        FAILED_WITH_CONFIG_PROBLEMS(4);
+
+        ExitCode(int code)
+        {
+            this.code = code;
+        }
+
+        final int code;
+    }
+
+    @Override
+    public String getName()
+    {
+        return FLEX_TOOL_COMPC;
+    }
+
+    @Override
+    public int execute(String[] args)
+    {
+        return staticMainNoExit(args);
+    }
+
+    /**
+     * Java program entry point.
+     * 
+     * @param args command line arguments
+     */
+    public static void main(final String[] args)
+    {
+        int exitCode = staticMainNoExit(args);
+        System.exit(exitCode);
+    }
+
+    /**
+     * Entry point for the {@code <compc>} Ant task.
+     *
+     * @param args Command line arguments.
+     * @return An exit code.
+     */
+    public static int staticMainNoExit(final String[] args)
+    {
+        long startTime = System.nanoTime();
+
+        final COMPJSCFlex mxmlc = new COMPJSCFlex();
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        final int exitCode = mxmlc.mainNoExit(args, problems, true);
+
+        long endTime = System.nanoTime();
+        System.out.println((endTime - startTime) / 1e9 + " seconds");
+
+        return exitCode;
+    }
+
+    public COMPJSCFlex()
+    {
+        IBackend backend = new MXMLFlexJSSWCBackend();
+
+        workspace = new Workspace();
+        workspace.setASDocDelegate(new FlexJSASDocDelegate());
+        project = new FlexJSProject(workspace, backend);
+        problems = new ProblemQuery(); // this gets replaced in configure().  Do we need it here?
+        asFileHandler = backend.getSourceFileHandlerInstance();
+    }
+
+    /**
+     * Main body of this program. This method is called from the public static
+     * method's for this program.
+     * 
+     * @return true if compiler succeeds
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    @Override
+    protected boolean compile()
+    {
+        boolean compilationSuccess = false;
+
+        try
+        {
+            project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+
+            if (setupTargetFile())
+                buildArtifact();
+
+            if (jsTarget != null)
+            {
+                Collection<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
+                Collection<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>();
+
+                if (!config.getCreateTargetWithErrors())
+                {
+                    problems.getErrorsAndWarnings(errors, warnings);
+                    if (errors.size() > 0)
+                        return false;
+                }
+
+                boolean packingSWC = false;
+                String outputFolderName = getOutputFilePath();
+            	File swcFile = new File(outputFolderName);
+            	File jsOut = new File("js/out");
+            	File externsOut = new File("externs");
+                ZipFile zipFile = null;
+            	ZipOutputStream zipOutputStream = null;
+            	String catalog = null;
+            	StringBuilder fileList = new StringBuilder();
+                if (outputFolderName.endsWith(".swc"))
+                {
+                	packingSWC = true;
+                	if (!swcFile.exists())
+                	{
+                		problems.add(new LibraryNotFoundProblem(outputFolderName));
+                		return false;
+                	}
+                    zipFile = new ZipFile(swcFile, ZipFile.OPEN_READ);
+                    final InputStream catalogInputStream = SWCReader.getInputStream(zipFile, SWCReader.CATALOG_XML);
+                    
+                    catalog = IOUtils.toString(catalogInputStream);
+                    catalogInputStream.close();
+                    zipOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFolderName + ".new")));
+                    zipOutputStream.setLevel(Deflater.NO_COMPRESSION);
+                    for (final Enumeration<? extends ZipEntry> entryEnum = zipFile.entries(); entryEnum.hasMoreElements();)
+                    {
+                        final ZipEntry entry = entryEnum.nextElement();
+                        if (!entry.getName().contains("js/out") &&
+                        	!entry.getName().contains(SWCReader.CATALOG_XML))
+                        {
+                            System.out.println("Copy " + entry.getName());
+                        	InputStream input = zipFile.getInputStream(entry);
+                        	zipOutputStream.putNextEntry(new ZipEntry(entry.getName()));
+                        	IOUtils.copy(input, zipOutputStream);
+                            zipOutputStream.flush();
+                        	zipOutputStream.closeEntry();
+                        }
+                    }
+                    int filesIndex = catalog.indexOf("<files>");
+                    if (filesIndex != -1)
+                    {
+                    	int filesIndex2 = catalog.indexOf("</files>");
+                    	String files = catalog.substring(filesIndex, filesIndex2);
+                    	int fileIndex = files.indexOf("<file", 6);
+                    	int pathIndex = files.indexOf("path=");
+                    	while (pathIndex != -1)
+                    	{
+                    		int pathIndex2 = files.indexOf("\"", pathIndex + 6);
+                    		int fileIndex2 = files.indexOf("/>", fileIndex);
+                    		String path = files.substring(pathIndex + 6, pathIndex2);
+                    		if (!path.startsWith("js/out"))
+                    		{
+                    			fileList.append(files.substring(fileIndex - 8, fileIndex2 + 3));
+                    		}
+                    		pathIndex = files.indexOf("path=", pathIndex2);
+                    		fileIndex = files.indexOf("<file", fileIndex2);
+                    	}
+                        catalog = catalog.substring(0, filesIndex) + catalog.substring(filesIndex2 + 8);
+                    }
+                }
+
+                File outputFolder = null;
+                if (!packingSWC) 
+                	outputFolder = new File(outputFolderName);
+
+                Set<String> externs = config.getExterns();
+                Collection<ICompilationUnit> roots = ((FlexJSSWCTarget)target).getReachableCompilationUnits(errors);
+                Collection<ICompilationUnit> reachableCompilationUnits = project.getReachableCompilationUnitsInSWFOrder(roots);
+                for (final ICompilationUnit cu : reachableCompilationUnits)
+                {
+                    ICompilationUnit.UnitType cuType = cu.getCompilationUnitType();
+
+                    if (cuType == ICompilationUnit.UnitType.AS_UNIT
+                            || cuType == ICompilationUnit.UnitType.MXML_UNIT)
+                    {
+                    	String symbol = cu.getQualifiedNames().get(0);
+                    	if (externs.contains(symbol)) continue;
+                    	
+                    	if (project.isExternalLinkage(cu)) continue;
+                    	
+                    	if (!packingSWC)
+                    	{
+	                        final File outputClassFile = getOutputClassFile(
+	                                cu.getQualifiedNames().get(0), outputFolder);
+	
+	                        System.out.println("Compiling file: " + outputClassFile);
+	
+	                        ICompilationUnit unit = cu;
+	
+	                        IASWriter writer;
+	                        if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+	                        {
+	                            writer = project.getBackend().createWriter(project,
+	                                    (List<ICompilerProblem>) errors, unit,
+	                                    false);
+	                        }
+	                        else
+	                        {
+	                            writer = project.getBackend().createMXMLWriter(
+	                                    project, (List<ICompilerProblem>) errors,
+	                                    unit, false);
+	                        }
+	                        problems.addAll(errors);
+	                        BufferedOutputStream out = new BufferedOutputStream(
+	                                new FileOutputStream(outputClassFile));
+	                        writer.writeTo(out);
+	                        out.flush();
+	                        out.close();
+	                        writer.close();
+                    	}
+                    	else
+                    	{
+	                        System.out.println("Compiling file: " + cu.getQualifiedNames().get(0));
+	                    	
+	                        ICompilationUnit unit = cu;
+	
+	                        IASWriter writer;
+	                        if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+	                        {
+	                            writer = project.getBackend().createWriter(project,
+	                                    (List<ICompilerProblem>) errors, unit,
+	                                    false);
+	                        }
+	                        else
+	                        {
+	                            writer = project.getBackend().createMXMLWriter(
+	                                    project, (List<ICompilerProblem>) errors,
+	                                    unit, false);
+	                        }
+	                        problems.addAll(errors);
+	                        ByteArrayOutputStream temp = new ByteArrayOutputStream();
+	                        writer.writeTo(temp);
+	                        boolean isExterns = false;
+	                        if (writer instanceof JSWriter)
+	                        	isExterns = ((JSWriter)writer).isExterns();
+                    		String outputClassFile = getOutputClassFile(
+	                                cu.getQualifiedNames().get(0), isExterns ? externsOut : jsOut).getPath();
+	                        System.out.println("Writing file: " + outputClassFile);     	
+	                        zipOutputStream.putNextEntry(new ZipEntry(outputClassFile));
+	                        temp.writeTo(zipOutputStream);
+                            zipOutputStream.flush();
+	                        zipOutputStream.closeEntry();
+	                        writer.close();
+	                        fileList.append("        <file path=\"" + outputClassFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
+                    	}
+                    }
+                }
+                if (packingSWC)
+                {
+                	zipFile.close();
+                	int libraryIndex = catalog.indexOf("</libraries>");
+                	catalog = catalog.substring(0, libraryIndex + 13) +
+                		"    <files>\n" + fileList.toString() + "    </files>" + 
+                		catalog.substring(libraryIndex + 13);
+                    zipOutputStream.putNextEntry(new ZipEntry(SWCReader.CATALOG_XML));
+                	zipOutputStream.write(catalog.getBytes());
+                    zipOutputStream.flush();
+                    zipOutputStream.closeEntry();
+                    zipOutputStream.flush();
+                	zipOutputStream.close();
+                	swcFile.delete();
+                	File newSWCFile = new File(outputFolderName + ".new");
+                	newSWCFile.renameTo(swcFile);
+                }
+                compilationSuccess = true;
+            }
+        }
+        catch (Exception e)
+        {
+            System.out.println(e);
+            final ICompilerProblem problem = new InternalCompilerProblem(e);
+            problems.add(problem);
+        }
+
+        return compilationSuccess;
+    }
+
+    /**
+     * Build target artifact.
+     * 
+     * @throws InterruptedException threading error
+     * @throws IOException IO error
+     * @throws ConfigurationException
+     */
+    @Override
+    protected void buildArtifact() throws InterruptedException, IOException,
+            ConfigurationException
+    {
+        jsTarget = buildJSTarget();
+    }
+
+    private IJSApplication buildJSTarget() throws InterruptedException,
+            FileNotFoundException, ConfigurationException
+    {
+        final List<ICompilerProblem> problemsBuildingSWF = new ArrayList<ICompilerProblem>();
+
+        final IJSApplication app = buildApplication(project,
+                config.getMainDefinition(), null, problemsBuildingSWF);
+        problems.addAll(problemsBuildingSWF);
+        if (app == null)
+        {
+            ICompilerProblem problem = new UnableToBuildSWFProblem(
+                    getOutputFilePath());
+            problems.add(problem);
+        }
+
+        return app;
+    }
+
+    /**
+     * Replaces FlexApplicationProject::buildSWF()
+     * 
+     * @param applicationProject
+     * @param rootClassName
+     * @param problems
+     * @return
+     * @throws InterruptedException
+     */
+
+    private IJSApplication buildApplication(CompilerProject applicationProject,
+            String rootClassName, ICompilationUnit mainCU,
+            Collection<ICompilerProblem> problems) throws InterruptedException,
+            ConfigurationException, FileNotFoundException
+    {
+        Collection<ICompilerProblem> fatalProblems = applicationProject.getFatalProblems();
+        if (!fatalProblems.isEmpty())
+        {
+            problems.addAll(fatalProblems);
+            return null;
+        }
+
+        return ((JSTarget) target).build(mainCU, problems);
+    }
+
+    /**
+     * Get the output file path. If {@code -output} is specified, use its value;
+     * otherwise, use the same base name as the target file.
+     * 
+     * @return output file path
+     */
+    private String getOutputFilePath()
+    {
+        if (config.getOutput() == null)
+        {
+            final String extension = "." + project.getBackend().getOutputExtension();
+            return FilenameUtils.removeExtension(config.getTargetFile()).concat(
+                    extension);
+        }
+        else
+        {
+            String outputFolderName = config.getOutput();
+            return outputFolderName;
+        }
+    }
+
+    /**
+     * Get the output class file. This includes the (sub)directory in which the
+     * original class file lives. If the directory structure doesn't exist, it
+     * is created.
+     * 
+     * @author Erik de Bruin
+     * @param qname
+     * @param outputFolder
+     * @return output class file path
+     */
+    private File getOutputClassFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension());
+    }
+
+    /**
+     * Mxmlc uses target file as the main compilation unit and derive the output
+     * SWF file name from this file.
+     * 
+     * @return true if successful, false otherwise.
+     * @throws InterruptedException
+     */
+    @Override
+    protected boolean setupTargetFile() throws InterruptedException
+    {
+        config.getTargetFile();
+
+        ITargetSettings settings = getTargetSettings();
+        if (settings != null)
+            project.setTargetSettings(settings);
+        else
+            return false;
+
+        target = project.getBackend().createTarget(project,
+                getTargetSettings(), null);
+
+        return true;
+    }
+
+    private ITargetSettings getTargetSettings()
+    {
+        if (targetSettings == null)
+            targetSettings = projectConfigurator.getTargetSettings(getTargetType());
+
+        if (targetSettings == null)
+            problems.addAll(projectConfigurator.getConfigurationProblems());
+
+        return targetSettings;
+    }
+
+    /**
+     * Validate target file.
+     * 
+     * @throws MustSpecifyTarget
+     * @throws IOError
+     */
+    @Override
+    protected void validateTargetFile() throws ConfigurationException
+    {
+
+    }
+
+    protected String getProgramName()
+    {
+        return "compc";
+    }
+
+    protected boolean isCompc()
+    {
+        return true;
+    }
+
+    @Override
+    protected TargetType getTargetType()
+    {
+        return TargetType.SWC;
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCNative.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCNative.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCNative.java
new file mode 100644
index 0000000..7517a63
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSCNative.java
@@ -0,0 +1,529 @@
+/*
+ *
+ *  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.clients;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Set;
+import java.util.zip.Deflater;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.flex.compiler.clients.problems.ProblemQuery;
+import org.apache.flex.compiler.codegen.as.IASWriter;
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.driver.js.IJSApplication;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
+import org.apache.flex.compiler.exceptions.ConfigurationException.IOError;
+import org.apache.flex.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
+import org.apache.flex.compiler.internal.codegen.js.JSWriter;
+import org.apache.flex.compiler.internal.driver.as.ASBackend;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.driver.js.jsc.JSCBackend;
+import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSSWCBackend;
+import org.apache.flex.compiler.internal.driver.mxml.jsc.MXMLJSCJSSWCBackend;
+import org.apache.flex.compiler.internal.parsing.as.FlexJSASDocDelegate;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.targets.FlexJSSWCTarget;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.InternalCompilerProblem;
+import org.apache.flex.compiler.problems.LibraryNotFoundProblem;
+import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
+import org.apache.flex.compiler.targets.ITarget.TargetType;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.swc.io.SWCReader;
+
+/**
+ * @author Erik de Bruin
+ * @author Michael Schmalle
+ */
+public class COMPJSCNative extends MXMLJSC
+{
+    /*
+     * Exit code enumerations.
+     */
+    static enum ExitCode
+    {
+        SUCCESS(0),
+        PRINT_HELP(1),
+        FAILED_WITH_PROBLEMS(2),
+        FAILED_WITH_EXCEPTIONS(3),
+        FAILED_WITH_CONFIG_PROBLEMS(4);
+
+        ExitCode(int code)
+        {
+            this.code = code;
+        }
+
+        final int code;
+    }
+
+    @Override
+    public String getName()
+    {
+        return FLEX_TOOL_COMPC;
+    }
+
+    @Override
+    public int execute(String[] args)
+    {
+        return staticMainNoExit(args);
+    }
+
+    /**
+     * Java program entry point.
+     * 
+     * @param args command line arguments
+     */
+    public static void main(final String[] args)
+    {
+        int exitCode = staticMainNoExit(args);
+        System.exit(exitCode);
+    }
+
+    /**
+     * Entry point for the {@code <compc>} Ant task.
+     *
+     * @param args Command line arguments.
+     * @return An exit code.
+     */
+    public static int staticMainNoExit(final String[] args)
+    {
+        long startTime = System.nanoTime();
+
+        final COMPJSCNative mxmlc = new COMPJSCNative();
+        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+        final int exitCode = mxmlc.mainNoExit(args, problems, true);
+
+        long endTime = System.nanoTime();
+        System.out.println((endTime - startTime) / 1e9 + " seconds");
+
+        return exitCode;
+    }
+
+    public COMPJSCNative()
+    {
+        IBackend backend = new MXMLJSCJSSWCBackend();
+
+        workspace = new Workspace();
+        workspace.setASDocDelegate(new FlexJSASDocDelegate());
+        project = new FlexJSProject(workspace, backend);
+        problems = new ProblemQuery(); // this gets replaced in configure().  Do we need it here?
+        asFileHandler = backend.getSourceFileHandlerInstance();
+    }
+
+    /**
+     * Main body of this program. This method is called from the public static
+     * method's for this program.
+     * 
+     * @return true if compiler succeeds
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    @Override
+    protected boolean compile()
+    {
+        boolean compilationSuccess = false;
+
+        try
+        {
+            project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
+
+            if (setupTargetFile())
+                buildArtifact();
+
+            if (jsTarget != null)
+            {
+                Collection<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
+                Collection<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>();
+
+                if (!config.getCreateTargetWithErrors())
+                {
+                    problems.getErrorsAndWarnings(errors, warnings);
+                    if (errors.size() > 0)
+                        return false;
+                }
+
+                boolean packingSWC = false;
+                String outputFolderName = getOutputFilePath();
+            	File swcFile = new File(outputFolderName);
+            	File jsOut = new File("js/out");
+            	File externsOut = new File("externs");
+                ZipFile zipFile = null;
+            	ZipOutputStream zipOutputStream = null;
+            	String catalog = null;
+            	StringBuilder fileList = new StringBuilder();
+                if (outputFolderName.endsWith(".swc"))
+                {
+                	packingSWC = true;
+                	if (!swcFile.exists())
+                	{
+                		problems.add(new LibraryNotFoundProblem(outputFolderName));
+                		return false;
+                	}
+                    zipFile = new ZipFile(swcFile, ZipFile.OPEN_READ);
+                    final InputStream catalogInputStream = SWCReader.getInputStream(zipFile, SWCReader.CATALOG_XML);
+                    
+                    catalog = IOUtils.toString(catalogInputStream);
+                    catalogInputStream.close();
+                    zipOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFolderName + ".new")));
+                    zipOutputStream.setLevel(Deflater.NO_COMPRESSION);
+                    for (final Enumeration<? extends ZipEntry> entryEnum = zipFile.entries(); entryEnum.hasMoreElements();)
+                    {
+                        final ZipEntry entry = entryEnum.nextElement();
+                        if (!entry.getName().contains("js/out") &&
+                        	!entry.getName().contains(SWCReader.CATALOG_XML))
+                        {
+                            System.out.println("Copy " + entry.getName());
+                        	InputStream input = zipFile.getInputStream(entry);
+                        	zipOutputStream.putNextEntry(new ZipEntry(entry.getName()));
+                        	IOUtils.copy(input, zipOutputStream);
+                            zipOutputStream.flush();
+                        	zipOutputStream.closeEntry();
+                        }
+                    }
+                    int filesIndex = catalog.indexOf("<files>");
+                    if (filesIndex != -1)
+                    {
+                    	int filesIndex2 = catalog.indexOf("</files>");
+                    	String files = catalog.substring(filesIndex, filesIndex2);
+                    	int fileIndex = files.indexOf("<file", 6);
+                    	int pathIndex = files.indexOf("path=");
+                    	while (pathIndex != -1)
+                    	{
+                    		int pathIndex2 = files.indexOf("\"", pathIndex + 6);
+                    		int fileIndex2 = files.indexOf("/>", fileIndex);
+                    		String path = files.substring(pathIndex + 6, pathIndex2);
+                    		if (!path.startsWith("js/out"))
+                    		{
+                    			fileList.append(files.substring(fileIndex - 8, fileIndex2 + 3));
+                    		}
+                    		pathIndex = files.indexOf("path=", pathIndex2);
+                    		fileIndex = files.indexOf("<file", fileIndex2);
+                    	}
+                        catalog = catalog.substring(0, filesIndex) + catalog.substring(filesIndex2 + 8);
+                    }
+                }
+
+                File outputFolder = null;
+                if (!packingSWC) 
+                	outputFolder = new File(outputFolderName);
+
+                Set<String> externs = config.getExterns();
+                Collection<ICompilationUnit> roots = ((FlexJSSWCTarget)target).getReachableCompilationUnits(errors);
+                Collection<ICompilationUnit> reachableCompilationUnits = project.getReachableCompilationUnitsInSWFOrder(roots);
+                for (final ICompilationUnit cu : reachableCompilationUnits)
+                {
+                    ICompilationUnit.UnitType cuType = cu.getCompilationUnitType();
+
+                    if (cuType == ICompilationUnit.UnitType.AS_UNIT
+                            || cuType == ICompilationUnit.UnitType.MXML_UNIT)
+                    {
+                    	String symbol = cu.getQualifiedNames().get(0);
+                    	if (externs.contains(symbol)) continue;
+                    	
+                    	if (project.isExternalLinkage(cu)) continue;
+                    	
+                    	if (!packingSWC)
+                    	{
+	                        final File outputClassFile = getOutputClassFile(
+	                                cu.getQualifiedNames().get(0), outputFolder);
+	
+	                        System.out.println("Compiling file: " + outputClassFile);
+	
+	                        ICompilationUnit unit = cu;
+	
+	                        IASWriter writer;
+	                        if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+	                        {
+	                            writer = project.getBackend().createWriter(project,
+	                                    (List<ICompilerProblem>) errors, unit,
+	                                    false);
+	                        }
+	                        else
+	                        {
+	                            writer = project.getBackend().createMXMLWriter(
+	                                    project, (List<ICompilerProblem>) errors,
+	                                    unit, false);
+	                        }
+	                        problems.addAll(errors);
+	                        BufferedOutputStream out = new BufferedOutputStream(
+	                                new FileOutputStream(outputClassFile));
+	                        writer.writeTo(out);
+	                        out.flush();
+	                        out.close();
+	                        writer.close();
+                    	}
+                    	else
+                    	{
+	                        System.out.println("Compiling file: " + cu.getQualifiedNames().get(0));
+	                    	
+	                        ICompilationUnit unit = cu;
+	
+	                        IASWriter writer;
+	                        if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+	                        {
+	                            writer = project.getBackend().createWriter(project,
+	                                    (List<ICompilerProblem>) errors, unit,
+	                                    false);
+	                        }
+	                        else
+	                        {
+	                            writer = project.getBackend().createMXMLWriter(
+	                                    project, (List<ICompilerProblem>) errors,
+	                                    unit, false);
+	                        }
+	                        problems.addAll(errors);
+	                        ByteArrayOutputStream temp = new ByteArrayOutputStream();
+	                        writer.writeTo(temp);
+	                        boolean isExterns = false;
+	                        if (writer instanceof JSWriter)
+	                        	isExterns = ((JSWriter)writer).isExterns();
+                    		String outputClassFile = getOutputClassFile(
+	                                cu.getQualifiedNames().get(0), isExterns ? externsOut : jsOut).getPath();
+	                        System.out.println("Writing file: " + outputClassFile);     	
+	                        zipOutputStream.putNextEntry(new ZipEntry(outputClassFile));
+	                        temp.writeTo(zipOutputStream);
+                            zipOutputStream.flush();
+	                        zipOutputStream.closeEntry();
+	                        writer.close();
+	                        fileList.append("        <file path=\"" + outputClassFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
+                    	}
+                    }
+                }
+                if (packingSWC)
+                {
+                	zipFile.close();
+                	int libraryIndex = catalog.indexOf("</libraries>");
+                	catalog = catalog.substring(0, libraryIndex + 13) +
+                		"    <files>\n" + fileList.toString() + "    </files>" + 
+                		catalog.substring(libraryIndex + 13);
+                    zipOutputStream.putNextEntry(new ZipEntry(SWCReader.CATALOG_XML));
+                	zipOutputStream.write(catalog.getBytes());
+                    zipOutputStream.flush();
+                    zipOutputStream.closeEntry();
+                    zipOutputStream.flush();
+                	zipOutputStream.close();
+                	swcFile.delete();
+                	File newSWCFile = new File(outputFolderName + ".new");
+                	newSWCFile.renameTo(swcFile);
+                }
+                compilationSuccess = true;
+            }
+        }
+        catch (Exception e)
+        {
+            System.out.println(e);
+            final ICompilerProblem problem = new InternalCompilerProblem(e);
+            problems.add(problem);
+        }
+
+        return compilationSuccess;
+    }
+
+    /**
+     * Build target artifact.
+     * 
+     * @throws InterruptedException threading error
+     * @throws IOException IO error
+     * @throws ConfigurationException
+     */
+    @Override
+    protected void buildArtifact() throws InterruptedException, IOException,
+            ConfigurationException
+    {
+        jsTarget = buildJSTarget();
+    }
+
+    private IJSApplication buildJSTarget() throws InterruptedException,
+            FileNotFoundException, ConfigurationException
+    {
+        final List<ICompilerProblem> problemsBuildingSWF = new ArrayList<ICompilerProblem>();
+
+        final IJSApplication app = buildApplication(project,
+                config.getMainDefinition(), null, problemsBuildingSWF);
+        problems.addAll(problemsBuildingSWF);
+        if (app == null)
+        {
+            ICompilerProblem problem = new UnableToBuildSWFProblem(
+                    getOutputFilePath());
+            problems.add(problem);
+        }
+
+        return app;
+    }
+
+    /**
+     * Replaces FlexApplicationProject::buildSWF()
+     * 
+     * @param applicationProject
+     * @param rootClassName
+     * @param problems
+     * @return
+     * @throws InterruptedException
+     */
+
+    private IJSApplication buildApplication(CompilerProject applicationProject,
+            String rootClassName, ICompilationUnit mainCU,
+            Collection<ICompilerProblem> problems) throws InterruptedException,
+            ConfigurationException, FileNotFoundException
+    {
+        Collection<ICompilerProblem> fatalProblems = applicationProject.getFatalProblems();
+        if (!fatalProblems.isEmpty())
+        {
+            problems.addAll(fatalProblems);
+            return null;
+        }
+
+        return ((JSTarget) target).build(mainCU, problems);
+    }
+
+    /**
+     * Get the output file path. If {@code -output} is specified, use its value;
+     * otherwise, use the same base name as the target file.
+     * 
+     * @return output file path
+     */
+    private String getOutputFilePath()
+    {
+        if (config.getOutput() == null)
+        {
+            final String extension = "." + project.getBackend().getOutputExtension();
+            return FilenameUtils.removeExtension(config.getTargetFile()).concat(
+                    extension);
+        }
+        else
+        {
+            String outputFolderName = config.getOutput();
+            return outputFolderName;
+        }
+    }
+
+    /**
+     * Get the output class file. This includes the (sub)directory in which the
+     * original class file lives. If the directory structure doesn't exist, it
+     * is created.
+     * 
+     * @author Erik de Bruin
+     * @param qname
+     * @param outputFolder
+     * @return output class file path
+     */
+    private File getOutputClassFile(String qname, File outputFolder)
+    {
+        String[] cname = qname.split("\\.");
+        String sdirPath = outputFolder + File.separator;
+        if (cname.length > 0)
+        {
+            for (int i = 0, n = cname.length - 1; i < n; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            File sdir = new File(sdirPath);
+            if (!sdir.exists())
+                sdir.mkdirs();
+
+            qname = cname[cname.length - 1];
+        }
+
+        return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension());
+    }
+
+    /**
+     * Mxmlc uses target file as the main compilation unit and derive the output
+     * SWF file name from this file.
+     * 
+     * @return true if successful, false otherwise.
+     * @throws InterruptedException
+     */
+    @Override
+    protected boolean setupTargetFile() throws InterruptedException
+    {
+        config.getTargetFile();
+
+        ITargetSettings settings = getTargetSettings();
+        if (settings != null)
+            project.setTargetSettings(settings);
+        else
+            return false;
+
+        target = project.getBackend().createTarget(project,
+                getTargetSettings(), null);
+
+        return true;
+    }
+
+    private ITargetSettings getTargetSettings()
+    {
+        if (targetSettings == null)
+            targetSettings = projectConfigurator.getTargetSettings(getTargetType());
+
+        if (targetSettings == null)
+            problems.addAll(projectConfigurator.getConfigurationProblems());
+
+        return targetSettings;
+    }
+
+    /**
+     * Validate target file.
+     * 
+     * @throws MustSpecifyTarget
+     * @throws IOError
+     */
+    @Override
+    protected void validateTargetFile() throws ConfigurationException
+    {
+
+    }
+
+    protected String getProgramName()
+    {
+        return "compc";
+    }
+
+    protected boolean isCompc()
+    {
+        return true;
+    }
+
+    @Override
+    protected TargetType getTargetType()
+    {
+        return TargetType.SWC;
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/FlexJSToolGroup.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/FlexJSToolGroup.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/FlexJSToolGroup.java
index dd9bc14..63f1c35 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/FlexJSToolGroup.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/FlexJSToolGroup.java
@@ -31,8 +31,8 @@ public class FlexJSToolGroup extends AbstractFlexToolGroup {
 
     public FlexJSToolGroup() {
         super("FlexJS");
-        addFlexTool(new COMPJSC(new MXMLFlexJSSWCBackend()));
-        addFlexTool(new MXMLJSC(new MXMLFlexJSBackend()));
+        addFlexTool(new COMPJSC());
+        addFlexTool(new MXMLJSC());
         addFlexTool(new ASDOCJSC(new MXMLFlexJSASDocDITABackend()));
         addFlexTool(new EXTERNC());
     }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
index 3ce8665..a06698d 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/JSConfiguration.java
@@ -19,12 +19,23 @@
 
 package org.apache.flex.compiler.clients;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.flex.compiler.clients.MXMLJSC.JSOutputType;
+import org.apache.flex.compiler.clients.MXMLJSC.JSTargetType;
 import org.apache.flex.compiler.config.Configuration;
 import org.apache.flex.compiler.config.ConfigurationValue;
 import org.apache.flex.compiler.exceptions.ConfigurationException;
+import org.apache.flex.compiler.exceptions.ConfigurationException.CannotOpen;
+import org.apache.flex.compiler.internal.config.annotations.Arguments;
 import org.apache.flex.compiler.internal.config.annotations.Config;
+import org.apache.flex.compiler.internal.config.annotations.InfiniteArguments;
 import org.apache.flex.compiler.internal.config.annotations.Mapping;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * The {@link JSConfiguration} class holds all compiler arguments needed for
  * compiling ActionScript to JavaScript.
@@ -43,22 +54,42 @@ public class JSConfiguration extends Configuration
     }
 
     //
-    // 'js-output-type'
+    // 'compiler.targets' option
     //
 
-    private String jsOutputType = MXMLJSC.JSOutputType.FLEXJS.getText();
+    protected final List<String> targets = new ArrayList<String>();
+
+    public List<String> getCompilerTargets()
+    {
+    	if (targets.size() == 0)
+    		targets.add(JSTargetType.JS_FLEX.getText());
+        return targets;
+    }
 
-    public String getJSOutputType()
+    /**
+     * The list of compiler outputs to generate
+     */
+    @Config(allowMultiple = true, isPath = false)
+    @Mapping({ "compiler", "targets" })
+    @Arguments("type")
+    @InfiniteArguments
+    public void setCompilerTargets(ConfigurationValue cv, String[] targetlist)
     {
-        return jsOutputType;
+    	for (String target : targetlist)
+    		targets.add(target);
     }
 
+    //
+    // 'js-output-type'
+    //
+
     @Config
     @Mapping("js-output-type")
     public void setJSOutputType(ConfigurationValue cv, String value)
             throws ConfigurationException
     {
-        jsOutputType = value;
+         targets.clear();
+         targets.add(value);
     }
 
     //

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6fced513/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
index bb10a06..8a96d6d 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -96,8 +96,8 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     }
 
     /*
-    	 * JS output type enumerations.
-    	 */
+     * JS output type enumerations.
+     */
     public enum JSOutputType
     {
         AMD("amd"),
@@ -132,6 +132,40 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     }
 
     /*
+     * JS output type enumerations.
+     */
+    public enum JSTargetType
+    {
+        SWF("SWF"),
+        JS_FLEX("JSFlex"),
+        JS_FLEX_CORDOVA("JSFlexCordova"),
+        JS_NATIVE("JS"),
+        JS_NODE("JSNode");
+
+        private String text;
+
+        JSTargetType(String text)
+        {
+            this.text = text;
+        }
+
+        public String getText()
+        {
+            return this.text;
+        }
+
+        public static JSTargetType fromString(String text)
+        {
+            for (JSTargetType jsTargetType : JSTargetType.values())
+            {
+                if (text.equalsIgnoreCase(jsTargetType.text))
+                    return jsTargetType;
+            }
+            return JS_FLEX;
+        }
+    }
+
+    /*
      * Exit code enumerations.
      */
     static enum ExitCode
@@ -186,48 +220,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     public static int staticMainNoExit(final String[] args)
     {
         long startTime = System.nanoTime();
-
-        IBackend backend = new ASBackend();
-        String jsOutputTypeString = "";
-        for (String s : args)
-        {
-            String[] kvp = s.split("=");
-
-            if (s.contains("-js-output-type"))
-            {
-                jsOutputTypeString = kvp[1];
-            }
-        }
-
-        if (jsOutputTypeString.equals(""))
-        {
-            jsOutputTypeString = JSOutputType.FLEXJS.getText();
-        }
-
-        jsOutputType = JSOutputType.fromString(jsOutputTypeString);
-        switch (jsOutputType)
-        {
-        case AMD:
-            backend = new AMDBackend();
-            break;
-        case JSC:
-            backend = new JSCBackend();
-            break;
-        case NODE:
-            backend = new NodeBackend();
-            break;
-        case FLEXJS:
-        case FLEXJS_DUAL:
-            backend = new MXMLFlexJSBackend();
-            break;
-        case GOOG:
-            backend = new GoogBackend();
-            break;
-        // if you add a new js-output-type here, don't forget to also add it
-        // to flex2.tools.MxmlJSC in flex-compiler-oem for IDE support
-        }
-
-        final MXMLJSC mxmlc = new MXMLJSC(backend);
+        final MXMLJSC mxmlc = new MXMLJSC();
         final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
         final int exitCode = mxmlc.mainNoExit(args, problems, true);
 
@@ -242,7 +235,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
 
     protected ProblemQuery problems;
     protected ISourceFileHandler asFileHandler;
-    protected Configuration config;
+    protected JSConfiguration config;
     protected Configurator projectConfigurator;
     private ConfigurationBuffer configBuffer;
     private ICompilationUnit mainCU;
@@ -251,13 +244,10 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     protected IJSApplication jsTarget;
     private IJSPublisher jsPublisher;
     
-    public MXMLJSC(IBackend backend)
+    public MXMLJSC()
     {
         workspace = new Workspace();
         workspace.setASDocDelegate(new FlexJSASDocDelegate());
-        project = new FlexJSProject(workspace, backend);
-        problems = new ProblemQuery(); // this gets replaced in configure().  Do we need it here?
-        asFileHandler = backend.getSourceFileHandlerInstance();
     }
 
     @Override
@@ -309,8 +299,50 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
 
             if (continueCompilation)
             {
-                project.setProblems(problems.getProblems());
-               	compile();
+
+            	targetloop:
+            	for (String target : config.getCompilerTargets())
+            	{
+            		int result = 0;
+            		switch (JSTargetType.fromString(target))
+	                {
+	                case SWF:
+	                    MXMLC mxmlc = new MXMLC();
+	                    result = mxmlc.mainNoExit(removeJSArgs(args));
+	                    if (result != 0)
+	                    {
+	                    	problems.addAll(mxmlc.problems.getProblems());
+	                    	break targetloop;
+	                    }
+	                    break;
+	                case JS_FLEX:
+	                	MXMLJSCFlex flex = new MXMLJSCFlex();
+	                    result = flex.mainNoExit(args, problems.getProblems(), false);
+	                    if (result != 0)
+	                    {
+	                    	break targetloop;
+	                    }
+	                    break;
+	                case JS_NODE:
+	                	MXMLJSCNode node = new MXMLJSCNode();
+	                    result = node.mainNoExit(args, problems.getProblems(), false);
+	                    if (result != 0)
+	                    {
+	                    	break targetloop;
+	                    }
+	                    break;
+	                case JS_NATIVE:
+	                	MXMLJSCNative jsc = new MXMLJSCNative();
+	                    result = jsc.mainNoExit(args, problems.getProblems(), false);
+	                    if (result != 0)
+	                    {
+	                    	break targetloop;
+	                    }
+	                    break;
+	                // if you add a new js-output-type here, don't forget to also add it
+	                // to flex2.tools.MxmlJSC in flex-compiler-oem for IDE support
+	                }
+            	}
                 if (problems.hasFilteredProblems())
                 {
                     if (problems.hasErrors())
@@ -354,6 +386,20 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
         }
         return exitCode.code;
     }
+    
+    private String[] removeJSArgs(String[] args)
+    {
+    	ArrayList<String> list = new ArrayList<String>();
+    	for (String arg : args)
+    	{
+    		if (!(arg.startsWith("-compiler.targets") ||
+    			  arg.startsWith("-closure-lib") ||
+    			  arg.startsWith("-remove-circulars") ||
+    			  arg.startsWith("-source-map")))
+    			list.add(arg);						
+    	}
+    	return list.toArray(new String[0]);
+    }
 
     /**
      * Main body of this program. This method is called from the public static
@@ -694,9 +740,8 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
      */
     protected boolean configure(final String[] args)
     {
-        project.getSourceCompilationUnitFactory().addHandler(asFileHandler);
-        project.configurator = projectConfigurator = createConfigurator();
-
+    	projectConfigurator = new Configurator(JSGoogConfiguration.class);
+    	
         try
         {
             if (useFlashBuilderProjectFiles(args))
@@ -712,30 +757,20 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
                         ICompilerSettingsConstants.FILE_SPECS_VAR);
             }
 
-            projectConfigurator.applyToProject(project);
-            project.config = (JSGoogConfiguration) projectConfigurator.getConfiguration();
-
-            config = projectConfigurator.getConfiguration();
-            configBuffer = projectConfigurator.getConfigurationBuffer();
-
+            // getCompilerProblemSettings initializes the configuration
             problems = new ProblemQuery(projectConfigurator.getCompilerProblemSettings());
             problems.addAll(projectConfigurator.getConfigurationProblems());
+            config = (JSConfiguration) projectConfigurator.getConfiguration();
+            configBuffer = projectConfigurator.getConfigurationBuffer();
 
             if (configBuffer.getVar("version") != null) //$NON-NLS-1$
                 return false;
 
             if (problems.hasErrors())
                 return false;
-
-            validateTargetFile();
+            
             return true;
         }
-        catch (ConfigurationException e)
-        {
-            final ICompilerProblem problem = new ConfigurationProblem(e);
-            problems.add(problem);
-            return false;
-        }
         catch (Exception e)
         {
             final ICompilerProblem problem = new ConfigurationProblem(null, -1,
@@ -747,7 +782,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
         {
             if (config == null)
             {
-                config = new Configuration();
+                config = new JSConfiguration();
                 configBuffer = new ConfigurationBuffer(Configuration.class,
                         Configuration.getAliases());
             }


[3/8] git commit: [flex-falcon] [refs/heads/dual] - Merge branch 'develop' into dual

Posted by ah...@apache.org.
Merge branch 'develop' into dual


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

Branch: refs/heads/dual
Commit: dd69be27a720c267471582fb4685a9dbc58daa86
Parents: 6fced51 2e888a9
Author: Alex Harui <ah...@apache.org>
Authored: Fri Jan 27 18:21:34 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Fri Jan 27 18:21:34 2017 -0800

----------------------------------------------------------------------
 .../compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------