This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch MNG-6825 in repository https://gitbox.apache.org/repos/asf/maven.git
commit bdf20861783e273d799f9ac84d8a634e9a4f26fc Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Sun Dec 15 04:28:57 2019 +0100 WIP - Continued - Fixed Checkstyle issues. --- .../maven/execution/DefaultRuntimeInformation.java | 6 +- .../rtinfo/internal/DefaultRuntimeInformation.java | 4 +- .../java/org/apache/maven/utils/Precondition.java | 98 ++++++++++++---------- .../java/org/apache/maven/utils/StringUtils.java | 29 +++++-- 4 files changed, 79 insertions(+), 58 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java index 7767aff..cf93b0d 100644 --- a/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java +++ b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java @@ -34,8 +34,7 @@ import org.codehaus.plexus.util.StringUtils; */ @Deprecated @Component( role = RuntimeInformation.class ) -public class DefaultRuntimeInformation - implements RuntimeInformation, Initializable +public class DefaultRuntimeInformation implements RuntimeInformation, Initializable { @Requirement @@ -48,8 +47,7 @@ public class DefaultRuntimeInformation return applicationVersion; } - public void initialize() - throws InitializationException + public void initialize() throws InitializationException { String mavenVersion = rtInfo.getMavenVersion(); diff --git a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java index 754cd9f..348bc68 100644 --- a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java +++ b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java @@ -69,7 +69,7 @@ public class DefaultRuntimeInformation else { logger.warn( - "Could not locate " + resource + " on classpath, Maven runtime information not available" ); + "Could not locate " + resource + " on classpath, Maven runtime information not available" ); } } catch ( IOException e ) @@ -120,7 +120,7 @@ public class DefaultRuntimeInformation try { String mavenVersion = getMavenVersion(); - Precondition.isTrue( Precondition.isNotEmpty( mavenVersion ), "Could not determine current Maven version" ); + Precondition.isTrue( isNotEmpty( mavenVersion ), "Could not determine current Maven version" ); current = versionScheme.parseVersion( mavenVersion ); } diff --git a/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java b/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java index 258e5a2..22abeeb 100644 --- a/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java +++ b/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java @@ -45,10 +45,12 @@ public final class Precondition * @param message The message will be part of the exception. * @return The supplied object as convenient. */ - public static < T > T requireNotNull(T obj, String message) + public static <T> T requireNotNull( T obj, String message ) { if ( obj == null ) + { throw new IllegalArgumentException( message ); + } return obj; } @@ -59,7 +61,7 @@ public final class Precondition * @param message The message will be part of the exception. * @return The supplied object as convenient. */ - public static < T > List< T > requireNotEmpty(List< T > obj, String message) + public static <T> List<T> requireNotEmpty( List<T> obj, String message ) { if ( obj.isEmpty() ) { @@ -71,12 +73,11 @@ public final class Precondition /** * assert that the given {@code longValue} is greater than {@code 0}. * - * @param longValue The instance which should be not {@code null} - * and has to be greater than {@code 0}. + * @param longValue The instance which should be not {@code null} and has to be greater than {@code 0}. * @param message The message will be part of the exception. * @return The supplied object as convenient. */ - public static Long requireGreaterThanZero(Long longValue, String message) + public static Long requireGreaterThanZero( Long longValue, String message ) { if ( longValue == null ) { @@ -90,7 +91,7 @@ public final class Precondition return longValue; } - public static Long requireGreaterOrEqualZero(Long longValue, String message) + public static Long requireGreaterOrEqualZero( Long longValue, String message ) { if ( longValue == null ) { @@ -120,7 +121,8 @@ public final class Precondition } } - public static Long greaterOrEqualToZero(Long currentValue, String message, final long value) { + public static Long greaterOrEqualToZero( Long currentValue, String message, final long value ) + { if ( currentValue == null ) { throw new IllegalArgumentException( String.format( message, value ) ); @@ -133,7 +135,8 @@ public final class Precondition return currentValue; } - public static Long requireGreaterThanZero(Long longValue, String message, final long value) { + public static Long requireGreaterThanZero( Long longValue, String message, final long value ) + { if ( longValue == null ) { throw new IllegalArgumentException( String.format( message, value ) ); @@ -149,12 +152,11 @@ public final class Precondition /** * assert that the given {@code integerValue} is greater than {@code 0}. * - * @param integerValue The instance which should be not {@code null} - * and has to be greater than {@code 0}. + * @param integerValue The instance which should be not {@code null} and has to be greater than {@code 0}. * @param message The message will be part of the exception. * @return The supplied object as convenient. */ - public static Integer requireGreaterThanZero(Integer integerValue, String message) + public static Integer requireGreaterThanZero( Integer integerValue, String message ) { if ( integerValue == null ) { @@ -168,22 +170,22 @@ public final class Precondition return integerValue; } -// /** -// * assert that the given {@code str} is not {@code null} and not {@code empty}. -// * -// * @param str The str which should not be {@code null} and not be empty. -// * @param message The message for the exception in case of {@code null}. -// * @return The supplied object as convenient. -// */ -// public static String requireNotEmpty(String str, String message) -// { -// requireNotNull( str, message ); -// if ( StringUtils.isBlank( str ) ) -// { -// throw new IllegalArgumentException( message ); -// } -// return str; -// } + // /** + // * assert that the given {@code str} is not {@code null} and not {@code empty}. + // * + // * @param str The str which should not be {@code null} and not be empty. + // * @param message The message for the exception in case of {@code null}. + // * @return The supplied object as convenient. + // */ + // public static String requireNotEmpty(String str, String message) + // { + // requireNotNull( str, message ); + // if ( StringUtils.isBlank( str ) ) + // { + // throw new IllegalArgumentException( message ); + // } + // return str; + // } public static boolean isNotEmpty( String str ) @@ -191,24 +193,28 @@ public final class Precondition return ( ( str != null ) && ( !str.isEmpty() ) ); } - public static boolean isNotBlank(final CharSequence cs) { - return !isBlank(cs); + public static boolean isNotBlank( final CharSequence cs ) + { + return !isBlank( cs ); } - public static boolean isBlank(final CharSequence cs) { - int strLen; - if (cs == null || (strLen = cs.length()) == 0) { + public static boolean isBlank( final CharSequence cs ) + { + if ( cs == null || ( cs.length() ) == 0 ) + { return true; } - for (int i = 0; i < strLen; i++) { - if (!Character.isWhitespace(cs.charAt(i))) { + for ( int i = 0; i < cs.length(); i++ ) + { + if ( !Character.isWhitespace( cs.charAt( i ) ) ) + { return false; } } return true; } - public static boolean notBlank(String str, String message) + public static boolean notBlank( String str, String message ) { for ( int i = 0; i < str.length(); i++ ) { @@ -221,7 +227,7 @@ public final class Precondition } - public static boolean isBlank(String str, String message) + public static boolean isBlank( String str, String message ) { if ( str == null || str.trim().isEmpty() ) { @@ -230,21 +236,27 @@ public final class Precondition return true; } - public static boolean isEmpty(final CharSequence cs) { + public static boolean isEmpty( final CharSequence cs ) + { return cs == null || cs.length() == 0; } - public static boolean isDigits(final String str) { - return isNumeric(str); + public static boolean isDigits( final String str ) + { + return isNumeric( str ); } - public static boolean isNumeric(final CharSequence cs) { - if (isEmpty(cs)) { + public static boolean isNumeric( final CharSequence cs ) + { + if ( isEmpty( cs ) ) + { return false; } final int sz = cs.length(); - for (int i = 0; i < sz; i++) { - if (!Character.isDigit(cs.charAt(i))) { + for ( int i = 0; i < sz; i++ ) + { + if ( !Character.isDigit( cs.charAt( i ) ) ) + { return false; } } diff --git a/maven-utils/src/main/java/org/apache/maven/utils/StringUtils.java b/maven-utils/src/main/java/org/apache/maven/utils/StringUtils.java index ff3c6ae..f9ca6de 100644 --- a/maven-utils/src/main/java/org/apache/maven/utils/StringUtils.java +++ b/maven-utils/src/main/java/org/apache/maven/utils/StringUtils.java @@ -24,29 +24,40 @@ import org.apiguardian.api.API; import static org.apache.maven.utils.Precondition.isEmpty; import static org.apiguardian.api.API.Status.INTERNAL; +/** + * @author Karl Heinz Marbaise + */ @API( status = INTERNAL, since = "3.7.0" ) public final class StringUtils { + public static final String EMPTY = ""; + public static final int INDEX_NOT_FOUND = -1; private StringUtils() { // intentionally empty. } - public static final String EMPTY = ""; - public static final int INDEX_NOT_FOUND = -1; - - public static String substringAfterLast(final String str, final String separator) { - if ( isEmpty(str)) { + /** + * @param str The string. + * @param separator The separator. + * @return The substring. + */ + public static String substringAfterLast( final String str, final String separator ) + { + if ( isEmpty( str ) ) + { return str; } - if (isEmpty(separator)) { + if ( isEmpty( separator ) ) + { return EMPTY; } - final int pos = str.lastIndexOf(separator); - if (pos == INDEX_NOT_FOUND || pos == str.length() - separator.length()) { + final int pos = str.lastIndexOf( separator ); + if ( pos == INDEX_NOT_FOUND || pos == str.length() - separator.length() ) + { return EMPTY; } - return str.substring(pos + separator.length()); + return str.substring( pos + separator.length() ); }