From e6c897efb68badf15ac26852f4f80d1dc37d5922 Mon Sep 17 00:00:00 2001 From: Lipmanpoi Date: Sat, 17 Aug 2019 01:44:56 +0800 Subject: [PATCH] [MNG-6855] Simplify some code Closes #279 --- .../version/PluginVersionResolutionException.java | 12 ++++++------ .../maven/repository/ArtifactTransferEvent.java | 5 ++--- .../cli/transfer/AbstractMavenTransferListener.java | 2 +- .../maven/model/building/DefaultModelBuilder.java | 8 ++++---- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java index dd14b307b9..c1b5ccfd09 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java @@ -82,29 +82,29 @@ public class PluginVersionResolutionException 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-core/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java b/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java index c8150ec3f9..f560c54ba6 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java +++ b/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java @@ -330,11 +330,10 @@ public class ArtifactTransferEvent { return false; } - else if ( !source.equals( other.source ) ) + else { - return false; + return source.equals( other.source ); } - return true; } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java index 984902e807..72bffc338c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java @@ -192,7 +192,7 @@ public abstract class AbstractMavenTransferListener public String formatProgress( long progressedSize, long size ) { Validate.isTrue( progressedSize >= 0L, "progressed file size cannot be negative: %s", progressedSize ); - Validate.isTrue( size >= 0L && progressedSize <= size || size < 0L, + Validate.isTrue( size < 0L || progressedSize <= size, "progressed file size cannot be greater than size: %s > %s", progressedSize, size ); if ( size >= 0L && progressedSize != size ) 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 6676d3a935..2d01e1262d 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 @@ -360,15 +360,15 @@ public class DefaultModelBuilder } else if ( !parentIds.add( parentData.getId() ) ) { - String message = "The parents form a cycle: "; + StringBuilder message = new StringBuilder( "The parents form a cycle: " ); for ( String modelId : parentIds ) { - message += modelId + " -> "; + message.append( modelId ).append( " -> " ); } - message += parentData.getId(); + message.append( parentData.getId() ); problems.add( new ModelProblemCollectorRequest( ModelProblem.Severity.FATAL, ModelProblem.Version.BASE ) - .setMessage( message ) ); + .setMessage( message.toString() ) ); throw problems.newModelBuildingException(); }