You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/05/22 21:20:33 UTC

[royale-compiler] 02/02: get help working in mxmljsc

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit ddf2f922e447824f8a036deab8a0ac04aa4b1ec9
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue May 22 14:20:22 2018 -0700

    get help working in mxmljsc
---
 .../apache/royale/compiler/clients/MXMLJSC.java    | 93 ++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
index c2f38e2..bdf77ed 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -42,8 +43,10 @@ import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
 import org.apache.royale.compiler.codegen.js.IJSPublisher;
 import org.apache.royale.compiler.codegen.js.IJSWriter;
 import org.apache.royale.compiler.common.VersionInfo;
+import org.apache.royale.compiler.config.CommandLineConfigurator;
 import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.config.ConfigurationBuffer;
+import org.apache.royale.compiler.config.ConfigurationValue;
 import org.apache.royale.compiler.config.Configurator;
 import org.apache.royale.compiler.config.ICompilerProblemSettings;
 import org.apache.royale.compiler.config.ICompilerSettingsConstants;
@@ -53,6 +56,7 @@ import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
 import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
 import org.apache.royale.compiler.exceptions.ConfigurationException.OnlyOneSource;
 import org.apache.royale.compiler.internal.config.FlashBuilderConfigurator;
+import org.apache.royale.compiler.internal.config.localization.LocalizationManager;
 import org.apache.royale.compiler.internal.driver.js.goog.JSGoogConfiguration;
 import org.apache.royale.compiler.internal.parsing.as.RoyaleASDocDelegate;
 import org.apache.royale.compiler.internal.projects.CompilerProject;
@@ -97,6 +101,10 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     {
         return problems;
     }
+    
+    static final String NEWLINE = System.getProperty("line.separator");
+    private static final String DEFAULT_VAR = "file-specs";
+    private static final String L10N_CONFIG_PREFIX = "org.apache.royale.compiler.internal.config.configuration";
 
     /*
      * JS output type enumerations.
@@ -205,6 +213,16 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
         return FLEX_TOOL_MXMLC;
     }
 
+    /**
+     * Get my program name.
+     * 
+     * @return always "mxmlc".
+     */
+    protected String getProgramName()
+    {
+        return "mxmljsc";
+    }
+
     @Override
     public int execute(String[] args)
     {
@@ -820,6 +838,18 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     	
         try
         {
+            if (args.length == 0)
+            {
+                final String usage = CommandLineConfigurator.brief(
+                        getProgramName(),
+                        DEFAULT_VAR,
+                        LocalizationManager.get(),
+                        L10N_CONFIG_PREFIX);
+                println(getStartMessage());
+                if (usage != null)
+                    println(usage);
+            }
+            
             if (useFlashBuilderProjectFiles(args))
             {
                 projectConfigurator.setConfiguration(
@@ -845,6 +875,14 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
                 System.out.println(VersionInfo.buildMessage());
                 return false;
             }
+            
+            // Print help if "-help" is present.
+            final List<ConfigurationValue> helpVar = configBuffer.getVar("help");
+            if (helpVar != null)
+            {
+                processHelp(helpVar);
+                return false;
+            }
 
             if (problems.hasErrors())
                 return false;
@@ -880,6 +918,61 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
         return false;
     }
 
+    /**
+     * Print a message.
+     * 
+     * @param msg Message text.
+     */
+    public void println(final String msg)
+    {
+        System.out.println(msg);
+    }
+    
+    /**
+     * Get the start up message that contains the program name 
+     * with the copyright notice.
+     * 
+     * @return The startup message.
+     */
+    protected String getStartMessage()
+    {
+        // This message should not be localized.
+        String message = "Apache Royale MXML and ActionScript Compiler (mxmlc)" + NEWLINE +
+            VersionInfo.buildMessage() + NEWLINE;
+        return message;
+    }
+
+    /**
+     * Print detailed help information if -help is provided.
+     */
+    private void processHelp(final List<ConfigurationValue> helpVar)
+    {
+        final Set<String> keywords = new LinkedHashSet<String>();
+        for (final ConfigurationValue val : helpVar)
+        {
+            for (final Object element : val.getArgs())
+            {
+                String keyword = (String)element;
+                while (keyword.startsWith("-"))
+                    keyword = keyword.substring(1);
+                keywords.add(keyword);
+            }
+        }
+
+        if (keywords.size() == 0)
+            keywords.add("help");
+
+        final String usages = CommandLineConfigurator.usage(
+                    getProgramName(),
+                    DEFAULT_VAR,
+                    configBuffer,
+                    keywords,
+                    LocalizationManager.get(),
+                    L10N_CONFIG_PREFIX);
+        println(getStartMessage());
+        println(usages);
+    }
+    
     protected TargetType getTargetType()
     {
         return TargetType.SWF;

-- 
To stop receiving notification emails like this one, please contact
aharui@apache.org.