From b31f3aeef3a7b9e6ef341af954b1cfafc1a629c6 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Sun, 10 Oct 2021 22:12:41 +0200 Subject: [PATCH] [MNG-7291] Avoid String concatenation in loops (#572) --- .../lifecycle/internal/MojoDescriptorCreator.java | 2 +- .../prefix/NoPluginFoundForPrefixException.java | 12 ++++++------ .../maven/model/building/DefaultModelBuilder.java | 10 ++++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java index e0647af17e..053d85163e 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java @@ -229,7 +229,7 @@ public class MojoDescriptorCreator resolvePluginVersion( plugin, session, project ); } - return pluginManager.getMojoDescriptor( plugin, goal, project.getRemotePluginRepositories(), + return pluginManager.getMojoDescriptor( plugin, goal.toString(), project.getRemotePluginRepositories(), session.getRepositorySession() ); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java b/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java index 6612913522..de53d51e6b 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java @@ -40,29 +40,29 @@ public class NoPluginFoundForPrefixException private static String format( LocalRepository localRepository, List remoteRepositories ) { - String repos = "["; + StringBuilder repos = new StringBuilder( "[" ); if ( localRepository != null ) { - repos += localRepository.getId() + " (" + localRepository.getBasedir() + ")"; + repos.append( localRepository.getId() ).append( " (" ).append( localRepository.getBasedir() ).append( ")" ); } if ( remoteRepositories != null && !remoteRepositories.isEmpty() ) { for ( RemoteRepository repository : remoteRepositories ) { - repos += ", "; + repos.append( ", " ); if ( repository != null ) { - repos += repository.getId() + " (" + repository.getUrl() + ")"; + repos.append( repository.getId() ).append( " (" ).append( repository.getUrl() ).append( ")" ); } } } - repos += "]"; + repos.append( "]" ); - return repos; + return repos.toString(); } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index a45fa2c26b..565c934c6c 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -1556,13 +1556,15 @@ public class DefaultModelBuilder if ( importIds.contains( imported ) ) { - String message = "The dependencies of type=pom and with scope=import form a cycle: "; + StringBuilder message = + new StringBuilder( "The dependencies of type=pom and with scope=import form a cycle: " ); for ( String modelId : importIds ) { - message += modelId + " -> "; + message.append( modelId ).append( " -> " ); } - message += imported; - problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ).setMessage( message ) ); + message.append( imported ); + problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE ).setMessage( + message.toString() ) ); return null; }