You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2024/12/01 19:41:29 UTC
(maven) 02/03: Remove usages of Properties
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 175e219a561ddc57c32249585f079d11dc0412e4
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Nov 29 14:31:58 2024 +0100
Remove usages of Properties
---
.../internal/impl/model/DefaultModelBuilder.java | 5 ++-
.../model/DefaultProfileActivationContext.java | 37 ----------------------
.../profile/AbstractProfileActivatorTest.java | 13 +++++---
.../impl/model/profile/ConditionParserTest.java | 12 +++----
.../profile/ConditionProfileActivatorTest.java | 26 ++++++---------
.../profile/JdkVersionProfileActivatorTest.java | 8 ++---
.../OperatingSystemProfileActivatorTest.java | 10 ++----
.../profile/PropertyProfileActivatorTest.java | 12 +++----
8 files changed, 36 insertions(+), 87 deletions(-)
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
index 6da040a297..908f2e0e1e 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
@@ -34,7 +34,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -1116,7 +1115,7 @@ public class DefaultModelBuilder implements ModelBuilder {
result.setActiveExternalProfiles(activeExternalProfiles);
if (!activeExternalProfiles.isEmpty()) {
- Properties profileProps = new Properties();
+ Map<String, String> profileProps = new HashMap<>();
for (Profile profile : activeExternalProfiles) {
profileProps.putAll(profile.getProperties());
}
@@ -1160,7 +1159,7 @@ public class DefaultModelBuilder implements ModelBuilder {
List<Profile> activeExternalProfiles = result.getActiveExternalProfiles();
if (!activeExternalProfiles.isEmpty()) {
- Properties profileProps = new Properties();
+ Map<String, String> profileProps = new HashMap<>();
for (Profile profile : activeExternalProfiles) {
profileProps.putAll(profile.getProperties());
}
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultProfileActivationContext.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultProfileActivationContext.java
index b6c350c1d8..ef04023b21 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultProfileActivationContext.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultProfileActivationContext.java
@@ -21,8 +21,6 @@ package org.apache.maven.internal.impl.model;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
-import java.util.stream.Collectors;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.services.model.ProfileActivationContext;
@@ -80,18 +78,6 @@ public class DefaultProfileActivationContext implements ProfileActivationContext
return systemProperties;
}
- /**
- * Sets the system properties to use for interpolation and profile activation. The system properties are collected
- * from the runtime environment like {@link System#getProperties()} and environment variables.
- *
- * @param systemProperties The system properties, may be {@code null}.
- * @return This context, never {@code null}.
- */
- @SuppressWarnings("unchecked")
- public DefaultProfileActivationContext setSystemProperties(Properties systemProperties) {
- return setSystemProperties(toMap(systemProperties));
- }
-
/**
* Sets the system properties to use for interpolation and profile activation. The system properties are collected
* from the runtime environment like {@link System#getProperties()} and environment variables.
@@ -109,19 +95,6 @@ public class DefaultProfileActivationContext implements ProfileActivationContext
return userProperties;
}
- /**
- * Sets the user properties to use for interpolation and profile activation. The user properties have been
- * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
- * line.
- *
- * @param userProperties The user properties, may be {@code null}.
- * @return This context, never {@code null}.
- */
- @SuppressWarnings("unchecked")
- public DefaultProfileActivationContext setUserProperties(Properties userProperties) {
- return setUserProperties(toMap(userProperties));
- }
-
/**
* Sets the user properties to use for interpolation and profile activation. The user properties have been
* configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
@@ -153,14 +126,4 @@ public class DefaultProfileActivationContext implements ProfileActivationContext
private static Map<String, String> unmodifiable(Map<String, String> map) {
return map != null ? Collections.unmodifiableMap(map) : Collections.emptyMap();
}
-
- private static Map<String, String> toMap(Properties properties) {
- if (properties != null && !properties.isEmpty()) {
- return properties.entrySet().stream()
- .collect(Collectors.toMap(e -> String.valueOf(e.getKey()), e -> String.valueOf(e.getValue())));
-
- } else {
- return null;
- }
- }
}
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/AbstractProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/AbstractProfileActivatorTest.java
index ea68bb8e05..6e40ef8f10 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/AbstractProfileActivatorTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/AbstractProfileActivatorTest.java
@@ -19,7 +19,7 @@
package org.apache.maven.internal.impl.model.profile;
import java.nio.file.Path;
-import java.util.Properties;
+import java.util.Map;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Profile;
@@ -54,9 +54,14 @@ public abstract class AbstractProfileActivatorTest<T extends ProfileActivator> {
activator = null;
}
- protected ProfileActivationContext newContext(final Properties userProperties, final Properties systemProperties) {
- DefaultProfileActivationContext context = new DefaultProfileActivationContext();
- return context.setUserProperties(userProperties)
+ protected DefaultProfileActivationContext newContext() {
+ return new DefaultProfileActivationContext();
+ }
+
+ protected ProfileActivationContext newContext(
+ Map<String, String> userProperties, Map<String, String> systemProperties) {
+ return newContext()
+ .setUserProperties(userProperties)
.setSystemProperties(systemProperties)
.setModel(Model.newInstance());
}
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionParserTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionParserTest.java
index b665c11485..fe6081d28a 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionParserTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionParserTest.java
@@ -19,7 +19,6 @@
package org.apache.maven.internal.impl.model.profile;
import java.util.Map;
-import java.util.Properties;
import java.util.function.Function;
import org.apache.maven.api.model.Model;
@@ -65,12 +64,11 @@ class ConditionParserTest {
private ProfileActivationContext createMockContext() {
DefaultProfileActivationContext context = new DefaultProfileActivationContext();
- Properties systemProperties = new Properties();
- systemProperties.setProperty("os.name", "windows");
- systemProperties.setProperty("os.arch", "amd64");
- systemProperties.setProperty("os.version", "10.0");
- systemProperties.setProperty("java.version", "1.8.0_292");
- context.setSystemProperties(systemProperties);
+ context.setSystemProperties(Map.of(
+ "os.name", "windows",
+ "os.arch", "amd64",
+ "os.version", "10.0",
+ "java.version", "1.8.0_292"));
context.setModel(Model.newInstance());
return context;
}
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionProfileActivatorTest.java
index 7b1c48abed..71cd0228de 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionProfileActivatorTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/ConditionProfileActivatorTest.java
@@ -20,7 +20,7 @@ package org.apache.maven.internal.impl.model.profile;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Properties;
+import java.util.Map;
import org.apache.maven.api.model.Activation;
import org.apache.maven.api.model.ActivationFile;
@@ -74,10 +74,8 @@ public class ConditionProfileActivatorTest extends AbstractProfileActivatorTest<
return p;
}
- private Properties newJdkProperties(String javaVersion) {
- Properties props = new Properties();
- props.setProperty("java.version", javaVersion);
- return props;
+ private Map<String, String> newJdkProperties(String javaVersion) {
+ return Map.of("java.version", javaVersion);
}
@Test
@@ -223,12 +221,8 @@ public class ConditionProfileActivatorTest extends AbstractProfileActivatorTest<
problems.getWarnings().toString());
}
- private Properties newOsProperties(String osName, String osVersion, String osArch) {
- Properties props = new Properties();
- props.setProperty("os.name", osName);
- props.setProperty("os.version", osVersion);
- props.setProperty("os.arch", osArch);
- return props;
+ private Map<String, String> newOsProperties(String osName, String osVersion, String osArch) {
+ return Map.of("os.name", osName, "os.version", osVersion, "os.arch", osArch);
}
@Test
@@ -323,10 +317,8 @@ public class ConditionProfileActivatorTest extends AbstractProfileActivatorTest<
assertActivation(true, profile, newContext(null, newOsProperties("Mac OS X", "14.5", "aarch64")));
}
- private Properties newPropProperties(String key, String value) {
- Properties props = new Properties();
- props.setProperty(key, value);
- return props;
+ private Map<String, String> newPropProperties(String key, String value) {
+ return Map.of(key, value);
}
@Test
@@ -405,8 +397,8 @@ public class ConditionProfileActivatorTest extends AbstractProfileActivatorTest<
void testPropWithValue_UserPropertyDominantOverSystemProperty() throws Exception {
Profile profile = newProfile("${prop} == 'value'");
- Properties props1 = newPropProperties("prop", "value");
- Properties props2 = newPropProperties("prop", "other");
+ Map<String, String> props1 = newPropProperties("prop", "value");
+ Map<String, String> props2 = newPropProperties("prop", "other");
assertActivation(true, profile, newContext(props1, props2));
assertActivation(false, profile, newContext(props2, props1));
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/JdkVersionProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/JdkVersionProfileActivatorTest.java
index 1bee37f5e6..46e6f0db21 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/JdkVersionProfileActivatorTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/JdkVersionProfileActivatorTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.maven.internal.impl.model.profile;
-import java.util.Properties;
+import java.util.Map;
import org.apache.maven.api.model.Activation;
import org.apache.maven.api.model.Profile;
@@ -50,10 +50,8 @@ class JdkVersionProfileActivatorTest extends AbstractProfileActivatorTest<JdkVer
return p;
}
- private Properties newProperties(String javaVersion) {
- Properties props = new Properties();
- props.setProperty("java.version", javaVersion);
- return props;
+ private Map<String, String> newProperties(String javaVersion) {
+ return Map.of("java.version", javaVersion);
}
@Test
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/OperatingSystemProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/OperatingSystemProfileActivatorTest.java
index 486a947270..cb717489b1 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/OperatingSystemProfileActivatorTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/OperatingSystemProfileActivatorTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.maven.internal.impl.model.profile;
-import java.util.Properties;
+import java.util.Map;
import org.apache.maven.api.model.Activation;
import org.apache.maven.api.model.ActivationOS;
@@ -46,12 +46,8 @@ class OperatingSystemProfileActivatorTest extends AbstractProfileActivatorTest<O
return p;
}
- private Properties newProperties(String osName, String osVersion, String osArch) {
- Properties props = new Properties();
- props.setProperty("os.name", osName);
- props.setProperty("os.version", osVersion);
- props.setProperty("os.arch", osArch);
- return props;
+ private Map<String, String> newProperties(String osName, String osVersion, String osArch) {
+ return Map.of("os.name", osName, "os.version", osVersion, "os.arch", osArch);
}
@Test
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/PropertyProfileActivatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/PropertyProfileActivatorTest.java
index bdeffff13d..6b044a82b7 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/PropertyProfileActivatorTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/profile/PropertyProfileActivatorTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.maven.internal.impl.model.profile;
-import java.util.Properties;
+import java.util.Map;
import org.apache.maven.api.model.Activation;
import org.apache.maven.api.model.ActivationProperty;
@@ -49,10 +49,8 @@ class PropertyProfileActivatorTest extends AbstractProfileActivatorTest<Property
return p;
}
- private Properties newProperties(String key, String value) {
- Properties props = new Properties();
- props.setProperty(key, value);
- return props;
+ private Map<String, String> newProperties(String key, String value) {
+ return Map.of(key, value);
}
@Test
@@ -158,8 +156,8 @@ class PropertyProfileActivatorTest extends AbstractProfileActivatorTest<Property
void testWithValue_UserPropertyDominantOverSystemProperty() throws Exception {
Profile profile = newProfile("prop", "value");
- Properties props1 = newProperties("prop", "value");
- Properties props2 = newProperties("prop", "other");
+ Map<String, String> props1 = newProperties("prop", "value");
+ Map<String, String> props2 = newProperties("prop", "other");
assertActivation(true, profile, newContext(props1, props2));