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
commit 52a8c279180ce9c57741e57c14c72a91a8915d62 Author: Josh Tynjala <[email protected]> AuthorDate: Thu Feb 6 09:50:42 2020 -0800 New compiler options: -rename-public-symbols and -rename-protected-symbols --- .../apache/royale/compiler/clients/MXMLJSC.java | 11 ++- .../royale/compiler/clients/MXMLJSCNative.java | 11 ++- .../royale/compiler/clients/MXMLJSCNode.java | 11 ++- .../royale/compiler/clients/MXMLJSCRoyale.java | 13 ++-- .../compiler/clients/MXMLJSCRoyaleCordova.java | 11 ++- .../compiler/codegen/js/goog/IJSGoogPublisher.java | 33 +++++++++ .../codegen/js/royale/JSRoyaleDocEmitter.java | 2 +- .../codegen/mxml/royale/MXMLRoyaleEmitter.java | 2 +- .../codegen/mxml/royale/MXMLRoyalePublisher.java | 12 +++- .../driver/js/goog/JSGoogConfiguration.java | 41 ++++++++++- .../apache/royale/compiler/utils/ClosureUtils.java | 81 ++++++++++++++++++++++ .../compiler/utils/JSClosureCompilerWrapper.java | 34 ++++++++- 12 files changed, 238 insertions(+), 24 deletions(-) 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 b8cb3fb..f58dc4d 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 @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -42,8 +43,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter; import org.apache.royale.compiler.clients.problems.ProblemQuery; import org.apache.royale.compiler.clients.problems.ProblemQueryProvider; 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.codegen.js.goog.IJSGoogPublisher; import org.apache.royale.compiler.common.VersionInfo; import org.apache.royale.compiler.config.CommandLineConfigurator; import org.apache.royale.compiler.config.CompilerDiagnosticsConstants; @@ -82,6 +83,7 @@ import org.apache.royale.compiler.targets.ITarget; import org.apache.royale.compiler.targets.ITarget.TargetType; import org.apache.royale.compiler.targets.ITargetSettings; import org.apache.royale.compiler.units.ICompilationUnit; +import org.apache.royale.compiler.utils.ClosureUtils; import org.apache.royale.swf.ISWF; import org.apache.royale.swf.SWF; import org.apache.royale.swf.types.RGB; @@ -279,7 +281,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, protected ITarget target; protected ITargetSettings targetSettings; protected IJSApplication jsTarget; - private IJSPublisher jsPublisher; + private IJSGoogPublisher jsPublisher; protected MXMLC mxmlc; protected JSCompilerEntryPoint lastCompiler; public boolean noLink; @@ -539,7 +541,8 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, return false; } - jsPublisher = (IJSPublisher) project.getBackend().createPublisher( + Set<String> closurePropNamesToKeep = new HashSet<String>(); + jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher( project, errors, config); File outputFolder = jsPublisher.getOutputFolder(); @@ -623,11 +626,13 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider, outputClassFile.setLastModified(fileDate); } } + ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep); } } if (jsPublisher != null) { + jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep); compilationSuccess = jsPublisher.publish(problems); } else diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java index 1c4474f..9b54b1e 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -36,8 +37,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter; import org.apache.royale.compiler.clients.problems.ProblemQuery; import org.apache.royale.compiler.clients.problems.ProblemQueryProvider; 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.codegen.js.goog.IJSGoogPublisher; import org.apache.royale.compiler.config.Configuration; import org.apache.royale.compiler.config.ConfigurationBuffer; import org.apache.royale.compiler.config.Configurator; @@ -72,6 +73,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType; import org.apache.royale.compiler.targets.ITargetSettings; import org.apache.royale.compiler.units.ICompilationUnit; import org.apache.royale.compiler.units.ICompilationUnit.UnitType; +import org.apache.royale.compiler.utils.ClosureUtils; import org.apache.flex.tools.FlexTool; import org.apache.royale.utils.ArgumentUtil; import org.apache.royale.utils.FilenameNormalization; @@ -169,7 +171,7 @@ public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider protected ITarget target; protected ITargetSettings targetSettings; protected IJSApplication jsTarget; - private IJSPublisher jsPublisher; + private IJSGoogPublisher jsPublisher; public MXMLJSCNative() { @@ -315,7 +317,8 @@ public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider return false; } - jsPublisher = (IJSPublisher) project.getBackend().createPublisher( + Set<String> closurePropNamesToKeep = new HashSet<String>(); + jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher( project, errors, config); File outputFolder = jsPublisher.getOutputFolder(); @@ -381,11 +384,13 @@ public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider } writer.close(); } + ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep); } } if (jsPublisher != null) { + jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep); compilationSuccess = jsPublisher.publish(problems); } else diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java index bb83228..a1111b0 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -36,8 +37,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter; import org.apache.royale.compiler.clients.problems.ProblemQuery; import org.apache.royale.compiler.clients.problems.ProblemQueryProvider; 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.codegen.js.goog.IJSGoogPublisher; import org.apache.royale.compiler.config.Configuration; import org.apache.royale.compiler.config.ConfigurationBuffer; import org.apache.royale.compiler.config.Configurator; @@ -72,6 +73,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType; import org.apache.royale.compiler.targets.ITargetSettings; import org.apache.royale.compiler.units.ICompilationUnit; import org.apache.royale.compiler.units.ICompilationUnit.UnitType; +import org.apache.royale.compiler.utils.ClosureUtils; import org.apache.flex.tools.FlexTool; import org.apache.royale.utils.ArgumentUtil; import org.apache.royale.utils.FilenameNormalization; @@ -168,7 +170,7 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider, protected ITarget target; protected ITargetSettings targetSettings; protected IJSApplication jsTarget; - private IJSPublisher jsPublisher; + private IJSGoogPublisher jsPublisher; public MXMLJSCNode() { @@ -317,7 +319,8 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider, return false; } - jsPublisher = (IJSPublisher) project.getBackend().createPublisher( + Set<String> closurePropNamesToKeep = new HashSet<String>(); + jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher( project, errors, config); File outputFolder = jsPublisher.getOutputFolder(); @@ -383,11 +386,13 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider, } writer.close(); } + ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep); } } if (jsPublisher != null) { + jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep); compilationSuccess = jsPublisher.publish(problems); } else diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java index fe7c209..817b7c4 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -45,8 +46,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter; import org.apache.royale.compiler.clients.problems.ProblemQuery; import org.apache.royale.compiler.clients.problems.ProblemQueryProvider; 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.codegen.js.goog.IJSGoogPublisher; import org.apache.royale.compiler.config.Configuration; import org.apache.royale.compiler.config.ConfigurationBuffer; import org.apache.royale.compiler.config.Configurator; @@ -93,6 +94,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType; import org.apache.royale.compiler.targets.ITargetSettings; import org.apache.royale.compiler.units.ICompilationUnit; import org.apache.royale.compiler.units.ICompilationUnit.UnitType; +import org.apache.royale.compiler.utils.ClosureUtils; import org.apache.flex.tools.FlexTool; import org.apache.royale.swc.ISWC; import org.apache.royale.swc.ISWCFileEntry; @@ -195,7 +197,7 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider protected ITarget target; protected ITargetSettings targetSettings; protected IJSApplication jsTarget; - private IJSPublisher jsPublisher; + private IJSGoogPublisher jsPublisher; public MXMLJSCRoyale() { @@ -344,7 +346,8 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider return false; } - jsPublisher = (IJSPublisher) project.getBackend().createPublisher( + Set<String> closurePropNamesToKeep = new HashSet<String>(); + jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher( project, errors, config); File outputFolder = jsPublisher.getOutputFolder(); @@ -419,8 +422,9 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider sourceMapOut.flush(); sourceMapOut.close(); } - writer.close(); + writer.close(); } + ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep); } File externsReportFile = googConfiguration.getExternsReport(); if (externsReportFile != null) @@ -438,6 +442,7 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider if (jsPublisher != null) { + jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep); compilationSuccess = jsPublisher.publish(problems); } else diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java index 378339c..80bca1a 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -36,8 +37,8 @@ import org.apache.royale.compiler.clients.problems.ProblemPrinter; import org.apache.royale.compiler.clients.problems.ProblemQuery; import org.apache.royale.compiler.clients.problems.ProblemQueryProvider; 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.codegen.js.goog.IJSGoogPublisher; import org.apache.royale.compiler.config.Configuration; import org.apache.royale.compiler.config.ConfigurationBuffer; import org.apache.royale.compiler.config.Configurator; @@ -72,6 +73,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType; import org.apache.royale.compiler.targets.ITargetSettings; import org.apache.royale.compiler.units.ICompilationUnit; import org.apache.royale.compiler.units.ICompilationUnit.UnitType; +import org.apache.royale.compiler.utils.ClosureUtils; import org.apache.flex.tools.FlexTool; import org.apache.royale.utils.ArgumentUtil; import org.apache.royale.utils.FilenameNormalization; @@ -171,7 +173,7 @@ public class MXMLJSCRoyaleCordova implements JSCompilerEntryPoint, ProblemQueryP protected ITarget target; protected ITargetSettings targetSettings; protected IJSApplication jsTarget; - private IJSPublisher jsPublisher; + private IJSGoogPublisher jsPublisher; public MXMLJSCRoyaleCordova() { @@ -320,7 +322,8 @@ public class MXMLJSCRoyaleCordova implements JSCompilerEntryPoint, ProblemQueryP return false; } - jsPublisher = (IJSPublisher) project.getBackend().createPublisher( + Set<String> closurePropNamesToKeep = new HashSet<String>(); + jsPublisher = (IJSGoogPublisher) project.getBackend().createPublisher( project, errors, config); File outputFolder = jsPublisher.getOutputFolder(); @@ -386,11 +389,13 @@ public class MXMLJSCRoyaleCordova implements JSCompilerEntryPoint, ProblemQueryP } writer.close(); } + ClosureUtils.collectPropertyNamesToKeep(cu, project, closurePropNamesToKeep); } } if (jsPublisher != null) { + jsPublisher.setClosurePropertyNamesToKeep(closurePropNamesToKeep); compilationSuccess = jsPublisher.publish(problems); } else diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/goog/IJSGoogPublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/goog/IJSGoogPublisher.java new file mode 100644 index 0000000..eaa3bad --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/goog/IJSGoogPublisher.java @@ -0,0 +1,33 @@ +/* + * + * 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.codegen.js.goog; + +import java.util.Set; + +import org.apache.royale.compiler.codegen.js.IJSPublisher; + +/** + * The {@link IJSGoogPublisher} interface allows the abstraction of project output + * generation. + */ +public interface IJSGoogPublisher extends IJSPublisher +{ + void setClosurePropertyNamesToKeep(Set<String> propertyNames); +} \ No newline at end of file diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java index d9b4c0a..7af2c0e 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleDocEmitter.java @@ -557,7 +557,7 @@ public class JSRoyaleDocEmitter extends JSGoogDocEmitter else { RoyaleJSProject fjp = (RoyaleJSProject)project; - boolean warnPublicVars = fjp.config != null && fjp.config.getWarnPublicVars(); + boolean warnPublicVars = fjp.config != null && fjp.config.getRenamePublicSymbols() && fjp.config.getWarnPublicVars(); IMetaTagsNode meta = node.getMetaTags(); boolean bindable = false; if (meta != null) diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java index ffbd25b..db550fc 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java @@ -2854,7 +2854,7 @@ public class MXMLRoyaleEmitter extends MXMLEmitter implements MXMLDescriptorSpecifier currentPropertySpecifier = new MXMLDescriptorSpecifier(); currentPropertySpecifier.isProperty = true; - currentPropertySpecifier.useGoogReflectObjectProperty = project.config.getMxmlReflectObjectProperty(); + currentPropertySpecifier.useGoogReflectObjectProperty = project.config.getRenamePublicSymbols() && project.config.getMxmlReflectObjectProperty(); currentPropertySpecifier.name = cdef != null ? cdef.getQualifiedName() : node.getName(); currentPropertySpecifier.parent = currentInstance; diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java index 77abfad..d823a33 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java @@ -28,7 +28,7 @@ import org.apache.commons.io.filefilter.FileFileFilter; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.io.filefilter.IOFileFilter; import org.apache.royale.compiler.clients.problems.ProblemQuery; -import org.apache.royale.compiler.codegen.js.IJSPublisher; +import org.apache.royale.compiler.codegen.js.goog.IJSGoogPublisher; import org.apache.royale.compiler.config.Configuration; import org.apache.royale.compiler.css.ICSSPropertyValue; import org.apache.royale.compiler.definitions.IClassDefinition; @@ -40,7 +40,6 @@ import org.apache.royale.compiler.internal.codegen.js.goog.JarSourceFile; import org.apache.royale.compiler.internal.css.CSSArrayPropertyValue; import org.apache.royale.compiler.internal.css.CSSFontFace; import org.apache.royale.compiler.internal.css.CSSFunctionCallPropertyValue; -import org.apache.royale.compiler.internal.definitions.ClassDefinition; import org.apache.royale.compiler.internal.driver.js.royale.JSCSSCompilationSession; import org.apache.royale.compiler.internal.driver.js.goog.JSGoogConfiguration; import org.apache.royale.compiler.internal.graph.GoogDepsWriter; @@ -58,7 +57,7 @@ import java.net.URLDecoder; import java.nio.charset.Charset; import java.util.*; -public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher +public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSGoogPublisher { public static final String ROYALE_OUTPUT_DIR_NAME = "bin"; @@ -103,6 +102,7 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher private String moduleOutput; private boolean useStrictPublishing; private List<String> additionalHTML = new ArrayList<String>(); + private Set<String> closurePropertyNamesToKeep; private GoogDepsWriter getGoogDepsWriter(File intermediateDir, String mainClassQName, @@ -183,6 +183,11 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher return outputFolder; } + public void setClosurePropertyNamesToKeep(Set<String> propertyNames) + { + closurePropertyNamesToKeep = propertyNames; + } + @Override public boolean publish(ProblemQuery problems) throws IOException { @@ -381,6 +386,7 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher if (configuration.release()) { compilerWrapper = new JSClosureCompilerWrapper(googConfiguration.getJSCompilerOptions()); + compilerWrapper.setPropertyNamesToKeep(closurePropertyNamesToKeep); } if (compilerWrapper != null) diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java index d06475c..3c941d0 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java @@ -447,6 +447,45 @@ public class JSGoogConfiguration extends JSConfiguration } // + // 'rename-public-symbols' + // + + private boolean renamePublicSymbols = false; + + public boolean getRenamePublicSymbols() + { + return renamePublicSymbols; + } + + @Config + @Mapping("rename-public-symbols") + public void setRenamePublicSymbols(ConfigurationValue cv, boolean value) + throws ConfigurationException + { + renamePublicSymbols = value; + } + + + // + // 'rename-protected-symbols' + // + + private boolean renameProtectedSymbols = false; + + public boolean getRenameProtectedSymbols() + { + return renameProtectedSymbols; + } + + @Config + @Mapping("rename-protected-symbols") + public void setRenameProtectedSymbols(ConfigurationValue cv, boolean value) + throws ConfigurationException + { + renameProtectedSymbols = value; + } + + // // 'mxml-reflect-object-property' // @@ -470,7 +509,7 @@ public class JSGoogConfiguration extends JSConfiguration // 'warn-public-vars' // - private boolean warnPublicVars = false; + private boolean warnPublicVars = true; public boolean getWarnPublicVars() { diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ClosureUtils.java b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ClosureUtils.java new file mode 100644 index 0000000..fa5df55 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/ClosureUtils.java @@ -0,0 +1,81 @@ +/* + * + * 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.utils; + +import java.util.Set; + +import org.apache.royale.compiler.definitions.IDefinition; +import org.apache.royale.compiler.definitions.ITypeDefinition; +import org.apache.royale.compiler.definitions.IVariableDefinition; +import org.apache.royale.compiler.internal.projects.RoyaleJSProject; +import org.apache.royale.compiler.internal.scopes.ASProjectScope.DefinitionPromise; +import org.apache.royale.compiler.units.ICompilationUnit; + +public class ClosureUtils +{ + public static void collectPropertyNamesToKeep(ICompilationUnit cu, RoyaleJSProject project, Set<String> result) + { + if (project.isExternalLinkage(cu)) + { + return; + } + for (IDefinition def : cu.getDefinitionPromises()) + { + if(def instanceof DefinitionPromise) + { + def = ((DefinitionPromise) def).getActualDefinition(); + } + if (def instanceof ITypeDefinition) + { + if (def.isImplicit() || def.isNative()) + { + continue; + } + boolean renamePublic = project.config.getRenamePublicSymbols(); + boolean renameProtected = project.config.getRenameProtectedSymbols(); + ITypeDefinition typeDef = (ITypeDefinition) def; + for (IDefinition localDef : typeDef.getContainedScope().getAllLocalDefinitions()) + { + if (localDef.isImplicit()) + { + continue; + } + if (!localDef.isPublic() && !localDef.isProtected()) + { + continue; + } + if (localDef.isProtected() && renameProtected) + { + continue; + } + if (localDef.isPublic() && renamePublic) + { + continue; + } + if (!(localDef instanceof IVariableDefinition)) + { + continue; + } + result.add(localDef.getBaseName()); + } + } + } + } +} \ No newline at end of file diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java index ae3d614..382f78b 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java @@ -25,7 +25,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.logging.Level; import com.google.javascript.jscomp.CheckLevel; @@ -88,6 +91,7 @@ public class JSClosureCompilerWrapper private String propertyMapOutputPath; private String variableMapInputPath; private String propertyMapInputPath; + private Set<String> propertyNamesToKeep; private boolean skipTypeInference; private boolean sourceMap = false; private boolean verbose = false; @@ -123,6 +127,11 @@ public class JSClosureCompilerWrapper { verbose = enabled; } + + public void setPropertyNamesToKeep(Set<String> propertyNames) + { + propertyNamesToKeep = propertyNames; + } public boolean compile() { @@ -146,17 +155,38 @@ public class JSClosureCompilerWrapper } } + Map<String, String> propertyMap = null; + if (propertyNamesToKeep != null) + { + if (propertyMap == null) + { + propertyMap = new HashMap<String, String>(); + } + for (String name : propertyNamesToKeep) + { + propertyMap.put(name, name); + } + } if (propertyMapInputPath != null) { + if (propertyMap == null) + { + propertyMap = new HashMap<String, String>(); + } File inputFile = new File(outputFolder, propertyMapInputPath); try { - VariableMap map = VariableMap.load(inputFile.getAbsolutePath()); - CompilerMapFetcher.setPropertyMap(options_, map); + VariableMap inputMap = VariableMap.load(inputFile.getAbsolutePath()); + propertyMap.putAll(inputMap.getOriginalNameToNewNameMap()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } + if (propertyMap != null) + { + VariableMap map = VariableMap.fromMap(propertyMap); + CompilerMapFetcher.setPropertyMap(options_, map); + } compiler_.setPassConfig(new RoyaleClosurePassConfig(options_, jsSourceFiles_.get(jsSourceFiles_.size() - 1).getName(),
