From a659ade9a0ec831137d1ba415a76cc467c6e0f01 Mon Sep 17 00:00:00 2001 From: Artem Krosheninnikov Date: Tue, 17 Dec 2019 11:30:28 +0300 Subject: [PATCH] [MNG-6827] Replace deprecated StringUtils#defaultString() from Plexus Utils This closes #302 --- .../maven/artifact/testutils/TestFileManager.java | 3 +-- .../internal/DefaultPluginDependenciesResolver.java | 11 ++++++----- .../project/DefaultProjectDependenciesResolver.java | 11 ++++++----- .../maven/model/validation/DefaultModelValidator.java | 7 ++++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java index 3cadd29da4..01a1f17454 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java @@ -44,9 +44,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import junit.framework.Assert; - import org.codehaus.plexus.util.FileUtils; +import org.junit.Assert; public class TestFileManager { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java index 808c09d9ad..8d16c61366 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.maven.RepositoryUtils; import org.apache.maven.model.Dependency; @@ -258,7 +259,7 @@ public class DefaultPluginDependenciesResolver { final String premanagedScope = DependencyManagerUtils.getPremanagedScope( node ); buffer.append( " (scope managed from " ); - buffer.append( StringUtils.defaultString( premanagedScope, "default" ) ); + buffer.append( Objects.toString( premanagedScope, "default" ) ); buffer.append( ')' ); } @@ -266,7 +267,7 @@ public class DefaultPluginDependenciesResolver { final String premanagedVersion = DependencyManagerUtils.getPremanagedVersion( node ); buffer.append( " (version managed from " ); - buffer.append( StringUtils.defaultString( premanagedVersion, "default" ) ); + buffer.append( Objects.toString( premanagedVersion, "default" ) ); buffer.append( ')' ); } @@ -274,7 +275,7 @@ public class DefaultPluginDependenciesResolver { final Boolean premanagedOptional = DependencyManagerUtils.getPremanagedOptional( node ); buffer.append( " (optionality managed from " ); - buffer.append( StringUtils.defaultString( premanagedOptional, "default" ) ); + buffer.append( Objects.toString( premanagedOptional, "default" ) ); buffer.append( ')' ); } @@ -285,7 +286,7 @@ public class DefaultPluginDependenciesResolver DependencyManagerUtils.getPremanagedExclusions( node ); buffer.append( " (exclusions managed from " ); - buffer.append( StringUtils.defaultString( premanagedExclusions, "default" ) ); + buffer.append( Objects.toString( premanagedExclusions, "default" ) ); buffer.append( ')' ); } @@ -296,7 +297,7 @@ public class DefaultPluginDependenciesResolver DependencyManagerUtils.getPremanagedProperties( node ); buffer.append( " (properties managed from " ); - buffer.append( StringUtils.defaultString( premanagedProperties, "default" ) ); + buffer.append( Objects.toString( premanagedProperties, "default" ) ); buffer.append( ')' ); } } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java index 0409fb885b..7500e43d2a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; @@ -269,7 +270,7 @@ public class DefaultProjectDependenciesResolver { final String premanagedScope = DependencyManagerUtils.getPremanagedScope( node ); buffer.append( " (scope managed from " ); - buffer.append( StringUtils.defaultString( premanagedScope, "default" ) ); + buffer.append( Objects.toString( premanagedScope, "default" ) ); buffer.append( ')' ); } @@ -277,7 +278,7 @@ public class DefaultProjectDependenciesResolver { final String premanagedVersion = DependencyManagerUtils.getPremanagedVersion( node ); buffer.append( " (version managed from " ); - buffer.append( StringUtils.defaultString( premanagedVersion, "default" ) ); + buffer.append( Objects.toString( premanagedVersion, "default" ) ); buffer.append( ')' ); } @@ -285,7 +286,7 @@ public class DefaultProjectDependenciesResolver { final Boolean premanagedOptional = DependencyManagerUtils.getPremanagedOptional( node ); buffer.append( " (optionality managed from " ); - buffer.append( StringUtils.defaultString( premanagedOptional, "default" ) ); + buffer.append( Objects.toString( premanagedOptional, "default" ) ); buffer.append( ')' ); } @@ -296,7 +297,7 @@ public class DefaultProjectDependenciesResolver DependencyManagerUtils.getPremanagedExclusions( node ); buffer.append( " (exclusions managed from " ); - buffer.append( StringUtils.defaultString( premanagedExclusions, "default" ) ); + buffer.append( Objects.toString( premanagedExclusions, "default" ) ); buffer.append( ')' ); } @@ -307,7 +308,7 @@ public class DefaultProjectDependenciesResolver DependencyManagerUtils.getPremanagedProperties( node ); buffer.append( " (properties managed from " ); - buffer.append( StringUtils.defaultString( premanagedProperties, "default" ) ); + buffer.append( Objects.toString( premanagedProperties, "default" ) ); buffer.append( ')' ); } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index cfa6e20f6c..ad7e3c7e5a 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -53,6 +53,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -527,12 +528,12 @@ public class DefaultModelValidator if ( equals( existing.getVersion(), dependency.getVersion() ) ) { msg = "duplicate declaration of version " - + StringUtils.defaultString( dependency.getVersion(), "(?)" ); + + Objects.toString( dependency.getVersion(), "(?)" ); } else { - msg = "version " + StringUtils.defaultString( existing.getVersion(), "(?)" ) + " vs " - + StringUtils.defaultString( dependency.getVersion(), "(?)" ); + msg = "version " + Objects.toString( existing.getVersion(), "(?)" ) + " vs " + + Objects.toString( dependency.getVersion(), "(?)" ); } addViolation( problems, errOn31, Version.V20, prefix + prefix2 + "(groupId:artifactId:type:classifier)",