All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.royale.compiler.clients.JSConfiguration Maven / Gradle / Ivy

/*
 *
 *  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.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.royale.compiler.clients.MXMLJSC.JSTargetType;
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.Arguments;
import org.apache.royale.compiler.internal.config.annotations.Config;
import org.apache.royale.compiler.internal.config.annotations.RoyaleOnly;
import org.apache.royale.compiler.internal.config.annotations.InfiniteArguments;
import org.apache.royale.compiler.internal.config.annotations.Mapping;
import org.apache.royale.compiler.internal.mxml.MXMLNamespaceMapping;

import com.google.common.collect.ImmutableList;

/**
 * The {@link JSConfiguration} class holds all compiler arguments needed for
 * compiling ActionScript to JavaScript.
 * 

* Specific flags are implemented here for the configuration to be loaded by the * configure() method of {@link MXMLJSC}. *

* This class inherits all compiler arguments from the MXMLC compiler. * * @author Michael Schmalle */ public class JSConfiguration extends Configuration { public JSConfiguration() { } // // 'compiler.targets' option // protected final List targets = new ArrayList(); public List getCompilerTargets() { if (targets.size() == 0) targets.add(JSTargetType.JS_ROYALE.getText()); return targets; } /** * The list of compiler outputs to generate */ @Config(allowMultiple = true, isPath = false) @Mapping({ "compiler", "targets" }) @Arguments("target") @InfiniteArguments public void setCompilerTargets(ConfigurationValue cv, String[] targetlist) { targets.clear(); for (String target : targetlist) targets.add(target); } // // 'js-output-type' // @Config @Mapping("js-output-type") public void setJSOutputType(ConfigurationValue cv, String value) throws ConfigurationException { // ignore if set via compiler.targets if (targets.size() > 0) return; targets.clear(); targets.add(value); } // // 'source-map' // private boolean sourceMap = false; public boolean getSourceMap() { return sourceMap; } @Config @Mapping("source-map") public void setSourceMap(ConfigurationValue cv, boolean value) throws ConfigurationException { sourceMap = value; } // // 'js-default-initializers' // private boolean jsDefaultInitializers = false; public boolean getJsDefaultInitializers() { return jsDefaultInitializers; } @Config @Mapping("js-default-initializers") public void setJsDefaultInitializers(ConfigurationValue cv, boolean value) throws ConfigurationException { jsDefaultInitializers = value; } // // 'compiler.js-external-library-path' option // private final List jsexternalLibraryPath = new ArrayList(); public List getCompilerJsExternalLibraryPath() { return jsexternalLibraryPath; } @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 pathElements = ImmutableList.copyOf(pathlist); final ImmutableList resolvedPaths = expandTokens(pathElements, locales, cv, !reportMissingCompilerLibraries); jsexternalLibraryPath.addAll(resolvedPaths); } // // 'compiler.js-library-path' option // private final List jslibraryPath = new ArrayList(); public List getCompilerJsLibraryPath() { return jslibraryPath; } /** * 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 resolvedPaths = expandTokens(Arrays.asList(pathlist), locales, cv, !reportMissingCompilerLibraries); jslibraryPath.addAll(resolvedPaths); } /** * Syntax:
* -define=<name>,<value> where name is NAMESPACE::name and value is a legal * definition value (e.g. true or 1 or !CONFIG::debugging) * * Example: -define=CONFIG::debugging,true * * In royale-config.xml:
* *

     * 
     *    
     *       
     *          CONFIG::debugging
     *          true
     *       
     *       ...
     *    
     * 
     * 
* * Values:
* Values are ActionScript expressions that must coerce and evaluate to constants at compile-time. Effectively, they * are replaced in AS code, verbatim, so -define=TEST::oneGreaterTwo,"1>2" will getCompiler coerced and * evaluated, at compile-time, to false. * * It is good practice to wrap values with double-quotes, so that MXMLC correctly parses them as a single argument: *
* -define=TEST::oneShiftRightTwo,"1 >> 2" * * Values may contain compile-time constants and other configuration values:
* -define=CONFIG::bool2,false -define=CONFIG::and1,"CONFIG::bool2 && false" TestApp.mxml * * String values on the command-line must be surrounded by double-quotes, and either escape-quoted ( * "\"foo\"" or "\'foo\'") or single-quoted ("'foo'"). * * String values in configuration files need only be single- or double- quoted:
* *
     * 
     *    
     *       
     *          NAMES::Organization
     *          'Apache Software Foundation'
     *       
     *       
     *          NAMES::Application
     *          "Royale 4.8.0"
     *       
     *       ...
     *    
     * 
     * 
* * Empty strings must be passed as "''" on the command-line, and '' or * "" 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: -define+=TEST::temporary,false * (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 * royale-config.xml) if you do not use append syntax ("=" or append="false"). * * IMPORTANT FOR FLASH BUILDER 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 jsconfigVars; /** * @return A list of ConfigVars */ public Map getJsCompilerDefine() { if (jsconfigVars != null) 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(); 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); } /** * @return JS equivalent of -load-config */ public String getJsLoadConfig() { return null; } /** * Placeholder. MXMLJSC picks off these values and changes them to load-config for the JS compilers */ @Config(allowMultiple = true) @Arguments("filename") public void setJsLoadConfig(ConfigurationValue cv, String filename) throws ConfigurationException { } ////////////////////////////////////////////////////////////////////////// // compiler.js-namespaces ////////////////////////////////////////////////////////////////////////// private List jsmanifestMappings; public List getCompilerJsNamespacesManifestMappings() { return jsmanifestMappings; } /** * Configures a list of many manifests mapped to a single namespace URI. * library:adobe/flex/something something-manifest.xml * something-else-manifest.xml ... * * @param cfgval The configuration value context. * @param args A List of values for the namespace element, with the first item expected to be the uri and the * remaining are manifest paths. */ @Config(allowMultiple = true) @Mapping({ "compiler", "js-namespaces", "namespace" }) @Arguments({ "uri", "manifest" }) @InfiniteArguments @RoyaleOnly public void setCompilerJsNamespacesNamespace(ConfigurationValue cfgval, List args) throws ConfigurationException { if (args == null) throw new ConfigurationException.CannotOpen(null, cfgval.getVar(), cfgval.getSource(), cfgval.getLine()); // allow -compiler.namespaces.namespace= which means don't add // anything, which matches the behavior of things like -compiler.library-path // which don't throw an error in this case either. if (args.isEmpty()) return; if (args.size() < 2) throw new ConfigurationException.NamespaceMissingManifest("namespace", cfgval.getSource(), cfgval.getLine()); if (args.size() % 2 != 0) throw new ConfigurationException.IncorrectArgumentCount(args.size() + 1, args.size(), cfgval.getVar(), cfgval.getSource(), cfgval.getLine()); if (jsmanifestMappings == null) jsmanifestMappings = new ArrayList(); for (int i = 0; i < args.size() - 1; i += 2) { final String uri = args.get(i); final String manifestFile = args.get(i + 1); final String path = resolvePathStrict(manifestFile, cfgval); jsmanifestMappings.add(new MXMLNamespaceMapping(uri, path)); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy