From 1f84f8f29631fcd50873ae9cd89f9e8a7600e349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20He=CC=81ritier?= Date: Tue, 11 Jun 2013 22:19:20 +0200 Subject: [PATCH] Code cleanup - Maven requires Java 5+ : Replace String.indexOf() by String.contains() --- .../versioning/DefaultArtifactVersion.java | 4 ++-- .../AbstractStringBasedModelInterpolator.java | 2 +- .../DefaultArtifactCollectorTest.java | 4 ++-- .../PluginParameterExpressionEvaluator.java | 2 +- .../internal/ConcurrentBuildLoggerTest.java | 2 +- .../AbstractStringBasedModelInterpolator.java | 2 +- .../activation/FileProfileActivator.java | 2 +- .../validation/DefaultModelValidatorTest.java | 24 +++++++++---------- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java index db71dc700c..856eb13777 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java @@ -143,7 +143,7 @@ public class DefaultArtifactVersion } } - if ( ( part1.indexOf( "." ) < 0 ) && !part1.startsWith( "0" ) ) + if ( ( !part1.contains( "." ) ) && !part1.startsWith( "0" ) ) { try { @@ -178,7 +178,7 @@ public class DefaultArtifactVersion } // string tokenzier won't detect these and ignores them - if ( part1.indexOf( ".." ) >= 0 || part1.startsWith( "." ) || part1.endsWith( "." ) ) + if ( part1.contains( ".." ) || part1.startsWith( "." ) || part1.endsWith( "." ) ) { fallback = true; } diff --git a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java index 102e391cc3..e5b6b0f09b 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java @@ -290,7 +290,7 @@ public abstract class AbstractStringBasedModelInterpolator List postProcessors, boolean debug ) throws ModelInterpolationException { - if ( src.indexOf( "${" ) < 0 ) + if ( !src.contains( "${" ) ) { return src; } diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java index 2bb8c93223..7c48507df2 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/resolver/DefaultArtifactCollectorTest.java @@ -712,8 +712,8 @@ public class DefaultArtifactCollectorTest } catch ( OverConstrainedVersionException e ) { - assertTrue( "Versions unordered", e.getMessage().indexOf( "[3.2.1-v3235e, 3.3.0-v3346]" ) != -1 ); - assertTrue( "DependencyTrail unresolved", e.getMessage().indexOf( "Path to dependency:" ) != -1 ); + assertTrue( "Versions unordered", e.getMessage().contains( "[3.2.1-v3235e, 3.3.0-v3346]" ) ); + assertTrue( "DependencyTrail unresolved", e.getMessage().contains( "Path to dependency:" ) ); } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java index 5c703ce5bb..b4b9492603 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java @@ -172,7 +172,7 @@ public class PluginParameterExpressionEvaluator } // Was not an expression - if ( expression.indexOf( "$$" ) > -1 ) + if ( expression.contains( "$$" ) ) { return expression.replaceAll( "\\$\\$", "\\$" ); } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrentBuildLoggerTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrentBuildLoggerTest.java index 115c0d38fa..7eb7348667 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrentBuildLoggerTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrentBuildLoggerTest.java @@ -69,6 +69,6 @@ public class ConcurrentBuildLoggerTest b1.addWait( A, aPlan.next(), System.currentTimeMillis() ); b2.addWait( A, aPlan.next(), System.currentTimeMillis() ); final String response = concurrentBuildLogger.toGraph(); - assertTrue( response.indexOf( "digraph" ) >= 0 ); + assertTrue( response.contains( "digraph" ) ); } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java index 57e11c3c21..f025036141 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java @@ -216,7 +216,7 @@ public abstract class AbstractStringBasedModelInterpolator List postProcessors, ModelProblemCollector problems ) { - if ( src.indexOf( "${" ) < 0 ) + if ( !src.contains( "${" ) ) { return src; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java index b4ecf26177..bcad941702 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java @@ -113,7 +113,7 @@ public class FileProfileActivator } } ); } - else if ( path.indexOf( "${basedir}" ) >= 0 ) + else if ( path.contains( "${basedir}" ) ) { return false; } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index 7af3ee55d5..065a06f103 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -131,7 +131,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 1, 0 ); - assertTrue( result.getErrors().get( 0 ).indexOf( "modelVersion" ) > -1 ); + assertTrue( result.getErrors().get( 0 ).contains( "modelVersion" ) ); } public void testMissingArtifactId() @@ -193,7 +193,7 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 1, 0 ); - assertTrue( result.getErrors().get( 0 ).indexOf( "Aggregator projects require 'pom' as packaging." ) > -1 ); + assertTrue( result.getErrors().get( 0 ).contains( "Aggregator projects require 'pom' as packaging." ) ); } public void testMissingDependencyArtifactId() @@ -203,8 +203,8 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 1, 0 ); - assertTrue( result.getErrors().get( 0 ).indexOf( - "'dependencies.dependency.artifactId' for groupId:null:jar is missing" ) > -1 ); + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencies.dependency.artifactId' for groupId:null:jar is missing" ) ); } public void testMissingDependencyGroupId() @@ -214,8 +214,8 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 1, 0 ); - assertTrue( result.getErrors().get( 0 ).indexOf( - "'dependencies.dependency.groupId' for null:artifactId:jar is missing" ) > -1 ); + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencies.dependency.groupId' for null:artifactId:jar is missing" ) ); } public void testMissingDependencyVersion() @@ -225,8 +225,8 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 1, 0 ); - assertTrue( result.getErrors().get( 0 ).indexOf( - "'dependencies.dependency.version' for groupId:artifactId:jar is missing" ) > -1 ); + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencies.dependency.version' for groupId:artifactId:jar is missing" ) ); } public void testMissingDependencyManagementArtifactId() @@ -236,8 +236,8 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 1, 0 ); - assertTrue( result.getErrors().get( 0 ).indexOf( - "'dependencyManagement.dependencies.dependency.artifactId' for groupId:null:jar is missing" ) > -1 ); + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencyManagement.dependencies.dependency.artifactId' for groupId:null:jar is missing" ) ); } public void testMissingDependencyManagementGroupId() @@ -247,8 +247,8 @@ public class DefaultModelValidatorTest assertViolations( result, 0, 1, 0 ); - assertTrue( result.getErrors().get( 0 ).indexOf( - "'dependencyManagement.dependencies.dependency.groupId' for null:artifactId:jar is missing" ) > -1 ); + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencyManagement.dependencies.dependency.groupId' for null:artifactId:jar is missing" ) ); } public void testMissingAll()