Fixes complex property restriction in SDM. Previously there was a bug in the restricting/releasing process of temporarily modifying binding properties in SDM as it triggered compiles customized for individual requesting browsers. When releasing a restriction on a complex property that contained some conditionals it would wipe out those conditionals with a single "all" condition. Change-Id: Ib593475fe62c1f860d141a275cbce2e8ceb46fde
diff --git a/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java b/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java index 0e86063..ca42e9d 100644 --- a/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java +++ b/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java
@@ -425,8 +425,7 @@ // Undo all permutation restriction customizations from previous compiles. for (BindingProperty bindingProperty : moduleDef.getProperties().getBindingProperties()) { - String[] allowedValues = bindingProperty.getAllowedValues(bindingProperty.getRootCondition()); - bindingProperty.setRootGeneratedValues(allowedValues); + bindingProperty.resetGeneratedValues(); } // A snapshot of the module's configuration before we modified it.
diff --git a/dev/core/src/com/google/gwt/dev/cfg/BindingProperty.java b/dev/core/src/com/google/gwt/dev/cfg/BindingProperty.java index a796c4c..9990506 100644 --- a/dev/core/src/com/google/gwt/dev/cfg/BindingProperty.java +++ b/dev/core/src/com/google/gwt/dev/cfg/BindingProperty.java
@@ -325,6 +325,15 @@ return generatedValues.allConditionsHaveOneValue(); } + /** + * Undo any value restrictions that have been put in place specifically on the set of values used + * for code generation as opposed to being present in the actual module definition. + */ + public void resetGeneratedValues() { + generatedValues.valueMap.clear(); + generatedValues.valueMap.putAll(allowedValues.valueMap); + } + public void setFallback(String token) { fallback = token; }
diff --git a/user/test/com/google/gwt/dev/cfg/PropertyTest.java b/user/test/com/google/gwt/dev/cfg/PropertyTest.java index 74cfce8..f7da7f2 100644 --- a/user/test/com/google/gwt/dev/cfg/PropertyTest.java +++ b/user/test/com/google/gwt/dev/cfg/PropertyTest.java
@@ -25,6 +25,7 @@ import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.Set; /** @@ -32,6 +33,14 @@ */ public class PropertyTest extends TestCase { + private static int computePermutationCount(ModuleDef moduleDef) { + PropertyPermutations propertyPermutations = + new PropertyPermutations(moduleDef.getProperties(), moduleDef.getActiveLinkerNames()); + List<PropertyPermutations> collapsePropertySets = propertyPermutations.collapseProperties(); + int numPermutations = collapsePropertySets.size(); + return numPermutations; + } + private static TreeLogger getRootLogger() { PrintWriterTreeLogger logger = new PrintWriterTreeLogger(new PrintWriter( System.err, true)); @@ -167,4 +176,26 @@ // OK } } + + public void testRestrictAndReleaseProperty() throws UnableToCompleteException { + ModuleDef moduleDef = ModuleDefLoader.loadFromClassPath(getRootLogger(), new CompilerContext(), + getClass().getCanonicalName() + "2"); + Properties properties = moduleDef.getProperties(); + + // Show that there are initially 7 combinations of form and ratio. + assertEquals(7, computePermutationCount(moduleDef)); + + // Restrict a simple property that contains no conditions. + properties.findBindingProp("form").setRootGeneratedValues("desktop"); + assertEquals(3, computePermutationCount(moduleDef)); + + // Restrict a *complex* property that contains some conditions. + properties.findBindingProp("ratio").setRootGeneratedValues("widescreen"); + assertEquals(1, computePermutationCount(moduleDef)); + + // Unrestrict both properties and show that the original permutation count is restored. + properties.findBindingProp("form").resetGeneratedValues(); + properties.findBindingProp("ratio").resetGeneratedValues(); + assertEquals(7, computePermutationCount(moduleDef)); + } }
diff --git a/user/test/com/google/gwt/dev/cfg/PropertyTest2.gwt.xml b/user/test/com/google/gwt/dev/cfg/PropertyTest2.gwt.xml new file mode 100644 index 0000000..871facd --- /dev/null +++ b/user/test/com/google/gwt/dev/cfg/PropertyTest2.gwt.xml
@@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- --> +<!-- Copyright 2015 Google Inc. --> +<!-- Licensed under the Apache License, Version 2.0 (the "License"); you --> +<!-- may not use this file except in compliance with the License. You may --> +<!-- 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. License for the specific language governing permissions and --> +<!-- limitations under the License. --> +<module> + <define-property name="form" values="desktop,tablet,phone" /> + + <define-property name="ratio" values="normal,widescreen,theatre" /> + <set-property name="ratio" value="normal,widescreen,theatre" /> + <set-property name="ratio" value="theatre" > + <when-property-is name="form" value="phone" /> + </set-property> +</module>