This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch MNG-7276 in repository https://gitbox.apache.org/repos/asf/maven.git
commit cdf5971a984ffff9bd381cb850e7054eb7d4a7ce Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Sun Oct 3 21:42:24 2021 +0200 Continued. --- .../main/java/org/apache/maven/ReactorReader.java | 8 +++++-- .../apache/maven/execution/ProfileActivation.java | 2 +- .../maven/extension/internal/CoreExports.java | 14 +++++------ .../lifecycle/mapping/DefaultLifecycleMapping.java | 3 ++- .../profile/DefaultProfileActivationContext.java | 27 +++++++--------------- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/maven-core/src/main/java/org/apache/maven/ReactorReader.java index 07f61e0..1521b1b 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -51,6 +51,10 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Named; +import static java.util.function.Function.identity; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.toMap; + /** * An implementation of a workspace reader that knows how to search the Maven reactor for artifacts, either as packaged * jar if it has been built, or only compile output directory if packaging hasn't happened yet. @@ -86,10 +90,10 @@ class ReactorReader this.session = session; this.projectsByGAV = session.getAllProjects().stream() - .collect( Collectors.toMap( projectIntoKey, Function.identity() ) ); + .collect( toMap( projectIntoKey, identity() ) ); this.projectsByGA = projectsByGAV.values().stream() - .collect( Collectors.groupingBy( projectIntoVersionlessKey ) ); + .collect( groupingBy( projectIntoVersionlessKey ) ); repository = new WorkspaceRepository( "reactor", new HashSet<>( projectsByGAV.keySet() ) ); } diff --git a/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java b/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java index 52f5e06..ad00a74 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java +++ b/maven-core/src/main/java/org/apache/maven/execution/ProfileActivation.java @@ -133,7 +133,7 @@ public class ProfileActivation { return this.activations.entrySet().stream() .filter( e -> predicate.test( e.getValue() ) ) - .map( e -> e.getKey() ) + .map( Map.Entry::getKey ) .collect( toSet() ); } diff --git a/maven-core/src/main/java/org/apache/maven/extension/internal/CoreExports.java b/maven-core/src/main/java/org/apache/maven/extension/internal/CoreExports.java index d72b3f9..2d976ae 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/internal/CoreExports.java +++ b/maven-core/src/main/java/org/apache/maven/extension/internal/CoreExports.java @@ -20,14 +20,16 @@ package org.apache.maven.extension.internal; */ import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import org.codehaus.plexus.classworlds.realm.ClassRealm; +import static java.util.function.Function.identity; +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toMap; + /** * Provides information about artifacts (identified by groupId:artifactId string key) and classpath elements exported by * Maven core itself and loaded Maven core extensions. @@ -47,13 +49,9 @@ public class CoreExports public CoreExports( ClassRealm realm, Set<String> exportedArtifacts, Set<String> exportedPackages ) { - Map<String, ClassLoader> packages = new LinkedHashMap<>(); - for ( String pkg : exportedPackages ) - { - packages.put( pkg, realm ); - } this.artifacts = Collections.unmodifiableSet( new HashSet<>( exportedArtifacts ) ); - this.packages = Collections.unmodifiableMap( new HashMap<>( packages ) ); + this.packages = exportedPackages.stream().collect( + collectingAndThen( toMap( identity(), v -> realm ), Collections::unmodifiableMap ) ); } /** diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java index e1ff314..4001a97 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; /** @@ -57,7 +58,7 @@ public class DefaultLifecycleMapping public DefaultLifecycleMapping( final List<Lifecycle> lifecycles ) { this.lifecycleMap = Collections.unmodifiableMap( - lifecycles.stream().collect( toMap( Lifecycle::getId, l -> l ) ) + lifecycles.stream().collect( toMap( Lifecycle::getId, identity() ) ) ); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java index 77d92a3..4fb1b26 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileActivationContext.java @@ -21,12 +21,13 @@ package org.apache.maven.model.profile; import java.io.File; import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toMap; + /** * Describes the environmental context used to determine the activation status of profiles. * @@ -230,8 +231,11 @@ public class DefaultProfileActivationContext { if ( projectProperties != null ) { - - this.projectProperties = Collections.unmodifiableMap( toMap( projectProperties ) ); + this.projectProperties = projectProperties.entrySet().stream() + .collect( + collectingAndThen( + toMap( k -> String.valueOf( k.getKey() ), v -> String.valueOf( v ) ), + Collections::unmodifiableMap ) ); } else { @@ -241,19 +245,4 @@ public class DefaultProfileActivationContext return this; } - private Map<String, String> toMap( Properties properties ) - { - if ( properties == null ) - { - return Collections.emptyMap(); - } - Map<String, String> map = new HashMap<>(); - Enumeration keys = properties.keys(); - while ( keys.hasMoreElements() ) - { - String key = (String) keys.nextElement(); - map.put( key, properties.getProperty( key ) ); - } - return map; - } }