You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/02/23 19:22:18 UTC
[royale-compiler] branch develop updated: playerglobalc: make
command line arguments work like other compiler tools
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new ebebc68 playerglobalc: make command line arguments work like other compiler tools
ebebc68 is described below
commit ebebc68263ada6d2b92a90831790ea21226ce748
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Feb 23 11:21:44 2021 -0800
playerglobalc: make command line arguments work like other compiler tools
---
.../royale/compiler/clients/PLAYERGLOBALC.java | 90 ++++++++++++++++++----
.../clients/PlayerglobalcConfiguration.java | 71 +++++++++++++++++
.../compiler/config/PlayerglobalcConfigurator.java | 55 +++++++++++++
3 files changed, 203 insertions(+), 13 deletions(-)
diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index d1e8de4..6a0d931 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -33,6 +33,12 @@ import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.flex.tools.FlexTool;
+import org.apache.royale.compiler.clients.problems.ProblemFormatter;
+import org.apache.royale.compiler.clients.problems.ProblemPrinter;
+import org.apache.royale.compiler.clients.problems.ProblemQuery;
+import org.apache.royale.compiler.config.Configurator;
+import org.apache.royale.compiler.config.PlayerglobalcConfigurator;
+import org.apache.royale.compiler.targets.ITarget.TargetType;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
@@ -44,7 +50,22 @@ import org.dom4j.io.SAXReader;
*/
class PLAYERGLOBALC implements FlexTool {
- private static final String OUTPUT_FOLDER_NAME = "playerglobal";
+ 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;
+ }
+
private static final List<String> VECTOR_SUFFIXES = Arrays.asList("$double", "$int", "$uint", "$object");
//From the docs: Methods of the Object class are dynamically created on Object's prototype.
private static final List<String> OBJECT_PROTOTYPE_METHODS = Arrays.asList("hasOwnProperty", "isPrototypeOf",
@@ -70,6 +91,9 @@ class PLAYERGLOBALC implements FlexTool {
"setNamespace"));
}
+ protected ProblemQuery problems;
+ protected Configurator projectConfigurator;
+ protected PlayerglobalcConfiguration configuration;
private File sourceFolder;
private File targetFolder;
private File currentFile;
@@ -96,21 +120,63 @@ class PLAYERGLOBALC implements FlexTool {
return "PLAYERGLOBALC";
}
+ /**
+ * 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 new PlayerglobalcConfigurator(PlayerglobalcConfiguration.class);
+ }
+
+ protected boolean configure(String[] args)
+ {
+ projectConfigurator = createConfigurator();
+ projectConfigurator.setConfiguration(args, "asdoc-root", false);
+ projectConfigurator.getTargetSettings(TargetType.SWC);
+ configuration = ((PlayerglobalcConfiguration) projectConfigurator.getConfiguration());
+ problems = new ProblemQuery(
+ projectConfigurator.getCompilerProblemSettings());
+ problems.addAll(projectConfigurator.getConfigurationProblems());
+ if (problems.hasErrors() || configuration == null)
+ {
+ return false;
+ }
+ return true;
+ }
+
@Override
public int execute(String[] args) {
- if(sourceFolder == null) {
- sourceFolder = new File(System.getProperty("user.dir"), "src/main/docs/");
- }
- if(targetFolder == null) {
- targetFolder = new File(System.getProperty("user.dir"), "target/generated-sources/");
- }
+ ExitCode exitCode = ExitCode.SUCCESS;
try {
- generateSources();
+ boolean continueGeneration = configure(args);
+ if (continueGeneration) {
+ sourceFolder = configuration.getASDocRoot();
+ targetFolder = configuration.getAsRoot();
+ generateSources();
+ }
+ else if (problems.hasFilteredProblems())
+ {
+ exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+ }
+ else
+ {
+ exitCode = ExitCode.PRINT_HELP;
+ }
} catch (Exception e) {
System.err.println(e.getMessage());
- return 1;
+ exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
}
- return 0;
+ finally
+ {
+ final ProblemFormatter formatter = new ProblemFormatter();
+ final ProblemPrinter printer = new ProblemPrinter(formatter, System.err);
+ printer.printProblems(problems.getFilteredProblems());
+ }
+
+ return exitCode.code;
}
public void generateSources() throws Exception {
@@ -132,14 +198,12 @@ class PLAYERGLOBALC implements FlexTool {
}
private void preclean() throws Exception {
- File playerglobalFolder = new File(targetFolder, OUTPUT_FOLDER_NAME);
- FileUtils.deleteDirectory(playerglobalFolder);
+ FileUtils.deleteDirectory(targetFolder);
}
private void writeFileForDefinition(String fullyQualifiedName, boolean airOnly, String contents)
throws IOException {
StringBuilder fileNameBuilder = new StringBuilder();
- fileNameBuilder.append(OUTPUT_FOLDER_NAME);
String[] parts = fullyQualifiedName.split("\\.");
for (String part : parts) {
fileNameBuilder.append("/");
diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PlayerglobalcConfiguration.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PlayerglobalcConfiguration.java
new file mode 100644
index 0000000..b08ea19
--- /dev/null
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PlayerglobalcConfiguration.java
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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.royale.compiler.clients;
+
+import java.io.File;
+import java.util.Arrays;
+
+import org.apache.royale.compiler.config.Configuration;
+import org.apache.royale.compiler.config.ConfigurationValue;
+import org.apache.royale.compiler.exceptions.ConfigurationException;
+import org.apache.royale.compiler.exceptions.ConfigurationException.CannotOpen;
+import org.apache.royale.compiler.internal.config.annotations.Config;
+import org.apache.royale.compiler.internal.config.annotations.Mapping;
+import org.apache.royale.utils.FilenameNormalization;
+
+public class PlayerglobalcConfiguration extends Configuration
+{
+ private File asdocRoot;
+ private File asRoot;
+
+ public PlayerglobalcConfiguration()
+ {
+ }
+
+ public File getAsRoot()
+ {
+ return asRoot;
+ }
+
+ @Config
+ @Mapping("as-root")
+ public void setASRoot(ConfigurationValue cfgval, String filename) throws CannotOpen
+ {
+ setASRoot(new File(FilenameNormalization.normalize(getOutputPath(cfgval, filename))));
+ }
+
+ public void setASRoot(File file)
+ {
+ this.asRoot = file;
+ }
+
+ public File getASDocRoot()
+ {
+ return asdocRoot;
+ }
+
+ @Config
+ @Mapping("asdoc-root")
+ public void setASDocRoot(ConfigurationValue cfgval, String filename) throws ConfigurationException
+ {
+ assertThatAllPathsAreDirectories(Arrays.asList(filename), cfgval);
+ this.asdocRoot = new File(FilenameNormalization.normalize(filename));
+ }
+}
diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/config/PlayerglobalcConfigurator.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/config/PlayerglobalcConfigurator.java
new file mode 100644
index 0000000..6115228
--- /dev/null
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/config/PlayerglobalcConfigurator.java
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.royale.compiler.config;
+
+import java.io.File;
+
+import org.apache.royale.compiler.clients.PlayerglobalcConfiguration;
+import org.apache.royale.compiler.exceptions.ConfigurationException;
+
+public class PlayerglobalcConfigurator extends Configurator
+{
+ /**
+ * Constructor
+ */
+ public PlayerglobalcConfigurator()
+ {
+ this(PlayerglobalcConfiguration.class);
+ }
+
+ /**
+ * Constructor
+ */
+ public PlayerglobalcConfigurator(Class<? extends PlayerglobalcConfiguration> configurationClass)
+ {
+ super(configurationClass);
+ }
+
+ @Override
+ protected void validateSWCInputs() throws ConfigurationException
+ {
+ PlayerglobalcConfiguration configuration = (PlayerglobalcConfiguration) getConfiguration();
+ File asdocRoot = configuration.getASDocRoot();
+ if (asdocRoot == null || !asdocRoot.exists())
+ {
+ throw new ConfigurationException.NoSwcInputs( null, null, -1 );
+ }
+ }
+}