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 b5abdace833f66d96ad1e6e2338c72a04d4c9f83 Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Mon Nov 25 20:37:04 2019 +0100 Second step. --- maven-utils/pom.xml | 14 ++++++ .../java/org/apache/maven/utils/Precondition.java | 56 +++++++++++++++++----- .../org/apache/maven/utils/PreconditionTest.java | 16 +++++++ 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/maven-utils/pom.xml b/maven-utils/pom.xml index 21e066d..3d3bd85 100644 --- a/maven-utils/pom.xml +++ b/maven-utils/pom.xml @@ -34,6 +34,20 @@ under the License. <name>Maven Utils</name> <dependencies> + + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + <version>5.5.2</version> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>3.14.0</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apiguardian</groupId> <artifactId>apiguardian-api</artifactId> 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 73b50a1..54f1399 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 @@ -1,6 +1,24 @@ package org.apache.maven.utils; -import com.sun.tools.javac.util.StringUtils; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import org.apiguardian.api.API; import java.util.List; @@ -19,7 +37,13 @@ public final class Precondition { // no-op } - +/* + int c = str != null && str.length() > 0 ? str.charAt( 0 ) : 0; + if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) ) + { + Validate.notBlank( str, message ); + } +*/ public static boolean notBlank(String str, String message) { for ( int i = 0; i < str.length(); i++ ) @@ -32,6 +56,14 @@ public final class Precondition throw new IllegalArgumentException( message ); } + public static boolean isBlank(String str, String message) + { + if ( str == null || str.trim().isEmpty() ) + { + return true; + } + return true; + } /** * assert that the given {@code obj} is not {@code null}. * @@ -113,13 +145,15 @@ public final class Precondition * @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 String requireNotEmpty(String str, String message) +// { +// requireNotNull( str, message ); +// if ( StringUtils.isBlank( str ) ) +// { +// throw new IllegalArgumentException( message ); +// } +// return str; +// } + +} diff --git a/maven-utils/src/test/java/org/apache/maven/utils/PreconditionTest.java b/maven-utils/src/test/java/org/apache/maven/utils/PreconditionTest.java new file mode 100644 index 0000000..d555c6c --- /dev/null +++ b/maven-utils/src/test/java/org/apache/maven/utils/PreconditionTest.java @@ -0,0 +1,16 @@ +package org.apache.maven.utils; + +import org.junit.jupiter.api.Test; + +import static org.apache.maven.utils.Precondition.notBlank; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +class PreconditionTest +{ + @Test + void first() + { + assertThatIllegalArgumentException() + .isThrownBy( () -> notBlank( "x", "Message" ) ); + } +} \ No newline at end of file