Skip to content

Commit

Permalink
Revert "Revert "Unset config properties: System.getProperty should …
Browse files Browse the repository at this point in the history
…return d…"

This reverts commit a0cd441.
  • Loading branch information
zbynek authored Feb 19, 2025
1 parent 32a0771 commit a1d2edd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
11 changes: 11 additions & 0 deletions dev/core/src/com/google/gwt/dev/cfg/ConfigurationProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ public List<String> getStrings(String key) {
return properties.get(key);
}

/**
* Returns all the values of a multi-valued configuration property, or null
* if not found.
*
* <p>A single-valued and unset configuration property will be returned as a list
* containing one null.
*/
public List<String> getStringsOrNull(String key) {
return properties.get(key);
}

/**
* Reads a configuration property as a comma-separated list of strings.
* It may be a single-valued or multi-valued property. If multi-valued,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -74,21 +75,28 @@ public void endVisit(JPermutationDependentValue x, Context ctx) {
}

private JExpression propertyValueExpression(JPermutationDependentValue x) {
List<String> propertyValues = props.getConfigurationProperties().getStrings(x.getRequestedValue());

String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").join(propertyValues);

if (propertyValue != null) {
List<String> propertyValues = props.getConfigurationProperties()
.getStringsOrNull(x.getRequestedValue());
if (propertyValues != null) {
// It is a configuration property.
return program.getLiteral(x.getSourceInfo(), propertyValue);
// If no values are set, propertyValues is either empty (multivalued properties)
// or contains a single null (other properties).
if (propertyValues.stream().anyMatch(Objects::nonNull)) {
return program.getLiteral(x.getSourceInfo(),
Joiner.on(",").skipNulls().join(propertyValues));
}
if (x.getDefaultValueExpression() != null) {
return x.getDefaultValueExpression();
}
return program.getLiteralNull();
}

if (isSoftPermutationProperty(x.getRequestedValue())) {
JMethod method = getOrCreateSoftPropertyMethod(x.getSourceInfo(), x.getRequestedValue());
return new JMethodCall(x.getSourceInfo(), null, method);
}

propertyValue = commonPropertyAndBindingInfo.getPropertyValue(x.getRequestedValue());
String propertyValue = commonPropertyAndBindingInfo.getPropertyValue(x.getRequestedValue());

if (propertyValue != null) {
return program.getLiteral(x.getSourceInfo(), propertyValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
<set-property name="someOtherDynamicProperty" value="blue">
<when-property-is name="collapsedProperty" value="two"/>
</set-property>
<define-configuration-property name="configPropertyUnset" is-multi-valued="false"/>
<define-configuration-property name="multivaluedConfigPropertyUnset" is-multi-valued="true"/>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ public void testBindingProperties() {
String expectedResult = "safari".equals(System.getProperty("user.agent")) ?
"InSafari" : "NotInSafari";
assertEquals(expectedResult, System.getProperty("someDynamicProperty"));
assertEquals("foo", System.getProperty("configPropertyUnset", "foo"));
assertNull(System.getProperty("configPropertyUnset"));
assertEquals("foo", System.getProperty("multivaluedConfigPropertyUnset", "foo"));
assertNull(System.getProperty("multivaluedConfigPropertyUnset"));
}
}

0 comments on commit a1d2edd

Please sign in to comment.