diff --git a/pom.xml b/pom.xml index e09ce3de..b01cc2ae 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,11 @@ 2.4.2 true + + org.jspecify + jspecify + 1.0.0 + commons-io @@ -90,12 +95,6 @@ junit-jupiter-api test - - com.google.code.findbugs - jsr305 - 3.0.2 - provided - diff --git a/src/main/java/org/apache/maven/shared/utils/PathTool.java b/src/main/java/org/apache/maven/shared/utils/PathTool.java index 6338a937..0b5b93ff 100644 --- a/src/main/java/org/apache/maven/shared/utils/PathTool.java +++ b/src/main/java/org/apache/maven/shared/utils/PathTool.java @@ -18,12 +18,12 @@ */ package org.apache.maven.shared.utils; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.io.File; import java.util.StringTokenizer; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + /** *

Path tool contains static methods to assist in determining path-related * information such as relative paths.

@@ -198,8 +198,8 @@ public static String getRelativeFilePath(final String oldPath, final String newP * terminated with a forward slash. A zero-length string is * returned if: the filename is zero-length. */ - @Nonnull - private static String determineRelativePath(@Nonnull String filename, @Nonnull String separator) { + @NonNull + private static String determineRelativePath(@NonNull String filename, @NonNull String separator) { if (filename.length() == 0) { return ""; } @@ -264,9 +264,9 @@ static String uppercaseDrive(@Nullable String path) { return path; } - @Nonnull + @NonNull private static String buildRelativePath( - @Nonnull String toPath, @Nonnull String fromPath, final char separatorChar) { + @NonNull String toPath, @NonNull String fromPath, final char separatorChar) { // use tokeniser to traverse paths and for lazy checking StringTokenizer toTokeniser = new StringTokenizer(toPath, String.valueOf(separatorChar)); StringTokenizer fromTokeniser = new StringTokenizer(fromPath, String.valueOf(separatorChar)); diff --git a/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java b/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java index 0730828c..199def0d 100644 --- a/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java @@ -18,9 +18,6 @@ */ package org.apache.maven.shared.utils; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -28,6 +25,9 @@ import java.net.URL; import java.util.Properties; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + /** * Static utility methods for loading properties. */ @@ -49,7 +49,7 @@ public PropertyUtils() {} * instead of an empty {@code Properties} instance when the given {@code URL} is {@code null}. */ @Deprecated - public static java.util.Properties loadProperties(@Nonnull URL url) { + public static java.util.Properties loadProperties(@NonNull URL url) { try (InputStream in = url.openStream()) { return loadProperties(in); } catch (Exception e) { @@ -66,7 +66,7 @@ public static java.util.Properties loadProperties(@Nonnull URL url) { * instead of an empty {@code Properties} instance when the given {@code File} is {@code null}. */ @Deprecated - public static Properties loadProperties(@Nonnull File file) { + public static Properties loadProperties(@NonNull File file) { try (InputStream in = new FileInputStream(file)) { return loadProperties(in); } catch (Exception e) { @@ -113,7 +113,7 @@ public static Properties loadProperties(@Nullable InputStream is) { * @return the loaded properties or an empty {@code Properties} instance if properties fail to load * @since 3.1.0 */ - @Nonnull + @NonNull public static Properties loadOptionalProperties(final @Nullable URL url) { Properties properties = new Properties(); @@ -138,7 +138,7 @@ public static Properties loadOptionalProperties(final @Nullable URL url) { * @return the loaded properties or an empty {@code Properties} instance if properties fail to load * @since 3.1.0 */ - @Nonnull + @NonNull public static Properties loadOptionalProperties(final @Nullable File file) { Properties properties = new Properties(); if (file != null) { @@ -162,7 +162,7 @@ public static Properties loadOptionalProperties(final @Nullable File file) { * @return the loaded properties or an empty {@code Properties} instance if properties fail to load * @since 3.1.0 */ - @Nonnull + @NonNull public static Properties loadOptionalProperties(final @Nullable InputStream inputStream) { Properties properties = new Properties(); diff --git a/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java b/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java index cb0921c2..a75b0bbb 100644 --- a/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java +++ b/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java @@ -18,8 +18,6 @@ */ package org.apache.maven.shared.utils; -import javax.annotation.Nonnull; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -33,6 +31,7 @@ import java.nio.charset.Charset; import org.apache.commons.io.input.XmlStreamReader; +import org.jspecify.annotations.NonNull; /** * Utility to create Readers from streams, with explicit encoding choice: platform default, @@ -115,7 +114,7 @@ public class ReaderFactory { * @deprecated use {@code org.apache.commons.io.input.XmlStreamReader} instead */ @Deprecated - public static Reader newXmlReader(@Nonnull InputStream in) throws IOException { + public static Reader newXmlReader(@NonNull InputStream in) throws IOException { return new XmlStreamReader(in); } @@ -128,7 +127,7 @@ public static Reader newXmlReader(@Nonnull InputStream in) throws IOException { * @deprecated use {}@code org.apache.commons.io.input.XmlStreamReader} instead */ @Deprecated - public static Reader newXmlReader(@Nonnull File file) throws IOException { + public static Reader newXmlReader(@NonNull File file) throws IOException { return new XmlStreamReader(file); } @@ -141,7 +140,7 @@ public static Reader newXmlReader(@Nonnull File file) throws IOException { * @deprecated use {@code org.apache.commons.io.input.XmlStreamReader} instead */ @Deprecated - public static Reader newXmlReader(@Nonnull URL url) throws IOException { + public static Reader newXmlReader(@NonNull URL url) throws IOException { return new XmlStreamReader(url); } @@ -155,7 +154,7 @@ public static Reader newXmlReader(@Nonnull URL url) throws IOException { * @deprecated always specify an encoding. Do not depend on the default platform character set. */ @Deprecated - public static Reader newPlatformReader(@Nonnull File file) throws FileNotFoundException { + public static Reader newPlatformReader(@NonNull File file) throws FileNotFoundException { return new FileReader(file); } @@ -172,7 +171,7 @@ public static Reader newPlatformReader(@Nonnull File file) throws FileNotFoundEx * @deprecated use {@code new InputStreamReader(in, encoding)} instead */ @Deprecated - public static Reader newReader(@Nonnull InputStream in, @Nonnull String encoding) + public static Reader newReader(@NonNull InputStream in, @NonNull String encoding) throws UnsupportedEncodingException { return new InputStreamReader(in, encoding); } @@ -192,7 +191,7 @@ public static Reader newReader(@Nonnull InputStream in, @Nonnull String encoding * or {@code new Files.newBufferedReader} instead */ @Deprecated - public static Reader newReader(@Nonnull File file, @Nonnull String encoding) + public static Reader newReader(@NonNull File file, @NonNull String encoding) throws FileNotFoundException, UnsupportedEncodingException { return new InputStreamReader(new FileInputStream(file), encoding); } @@ -211,7 +210,7 @@ public static Reader newReader(@Nonnull File file, @Nonnull String encoding) * @deprecated This method does not use HTTP headers to detect the resource's encoding. */ @Deprecated - public static Reader newReader(@Nonnull URL url, @Nonnull String encoding) throws IOException { + public static Reader newReader(@NonNull URL url, @NonNull String encoding) throws IOException { return new InputStreamReader(url.openStream(), encoding); } } diff --git a/src/main/java/org/apache/maven/shared/utils/StringUtils.java b/src/main/java/org/apache/maven/shared/utils/StringUtils.java index 8e89c4f8..f953da9d 100644 --- a/src/main/java/org/apache/maven/shared/utils/StringUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/StringUtils.java @@ -18,15 +18,15 @@ */ package org.apache.maven.shared.utils; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.util.Arrays; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + /** *

Common String manipulation routines.

* @@ -74,7 +74,7 @@ public StringUtils() {} * @deprecated use {@link #trim(String)} instead. */ @Deprecated - @Nonnull + @NonNull public static String clean(String str) { return (str == null ? "" : str.trim()); } @@ -101,8 +101,8 @@ public static String trim(String str) { * @param str String target to delete whitespace from * @return the String without whitespace */ - @Nonnull - public static String deleteWhitespace(@Nonnull String str) { + @NonNull + public static String deleteWhitespace(@NonNull String str) { StringBuilder buffer = new StringBuilder(); int sz = str.length(); for (int i = 0; i < sz; i++) { @@ -461,9 +461,9 @@ public static String mid(String str, int pos, int len) { * String.split()) splits on a regular expression so while it can * do anything this method does, it is not a drop-in replacement. */ - @Nonnull + @NonNull @Deprecated - public static String[] split(@Nonnull String str) { + public static String[] split(@NonNull String str) { return split(str, null, -1); } @@ -476,9 +476,9 @@ public static String[] split(@Nonnull String str) { * String.split()) splits on a regular expression so while it can * do anything this method does, it is not a drop-in replacement. */ - @Nonnull + @NonNull @Deprecated - public static String[] split(@Nonnull String text, @Nullable String separator) { + public static String[] split(@NonNull String text, @Nullable String separator) { return split(text, separator, -1); } @@ -503,9 +503,9 @@ public static String[] split(@Nonnull String text, @Nullable String separator) { * String.split()) splits on a regular expression so while it can * do anything this method does, it is not a drop-in replacement. */ - @Nonnull + @NonNull @Deprecated - public static String[] split(@Nonnull String str, @Nullable String separator, int max) { + public static String[] split(@NonNull String str, @Nullable String separator, int max) { StringTokenizer tok; if (separator == null) { // Null separator means we're using StringTokenizer's default @@ -554,8 +554,8 @@ public static String[] split(@Nonnull String str, @Nullable String separator, in * @param array the array of values to concatenate. * @return the concatenated string. */ - @Nonnull - public static String concatenate(@Nonnull Object... array) { + @NonNull + public static String concatenate(@NonNull Object... array) { return join(array, ""); } @@ -572,8 +572,8 @@ public static String concatenate(@Nonnull Object... array) { * @deprecated use java.lang.String.join() instead */ @Deprecated - @Nonnull - public static String join(@Nonnull Object[] array, @Nullable String separator) { + @NonNull + public static String join(@NonNull Object[] array, @Nullable String separator) { if (separator == null) { separator = ""; } @@ -603,8 +603,8 @@ public static String join(@Nonnull Object[] array, @Nullable String separator) { * @deprecated use java.lang.String.join() instead */ @Deprecated - @Nonnull - public static String join(@Nonnull Iterator iterator, String separator) { + @NonNull + public static String join(@NonNull Iterator iterator, String separator) { if (separator == null) { separator = ""; } @@ -738,8 +738,8 @@ public static String replace(@Nullable String text, @Nullable String repl, @Null * @return String with overlaid text * @throws NullPointerException if text or overlay is null */ - @Nonnull - public static String overlayString(@Nonnull String text, @Nonnull String overlay, int start, int end) { + @NonNull + public static String overlayString(@NonNull String text, @NonNull String overlay, int start, int end) { if (overlay == null) { throw new NullPointerException("overlay is null"); } @@ -764,8 +764,8 @@ public static String overlayString(@Nonnull String text, @Nonnull String overlay * @return String containing centered String * @throws NullPointerException if str is null */ - @Nonnull - public static String center(@Nonnull String str, int size) { + @NonNull + public static String center(@NonNull String str, int size) { return center(str, size, " "); } @@ -781,8 +781,8 @@ public static String center(@Nonnull String str, int size) { * @throws NullPointerException if str or delim is null * @throws ArithmeticException if delim is the empty String */ - @Nonnull - public static String center(@Nonnull String str, int size, @Nonnull String delim) { + @NonNull + public static String center(@NonNull String str, int size, @NonNull String delim) { int sz = str.length(); int p = size - sz; if (p < 1) { @@ -803,8 +803,8 @@ public static String center(@Nonnull String str, int size, @Nonnull String delim * @return String without chomped newline * @throws NullPointerException if str is null */ - @Nonnull - public static String chomp(@Nonnull String str) { + @NonNull + public static String chomp(@NonNull String str) { return chomp(str, "\n"); } @@ -817,8 +817,8 @@ public static String chomp(@Nonnull String str) { * @return String without chomped ending * @throws NullPointerException if str or sep is null */ - @Nonnull - public static String chomp(@Nonnull String str, @Nonnull String sep) { + @NonNull + public static String chomp(@NonNull String str, @NonNull String sep) { int idx = str.lastIndexOf(sep); if (idx != -1) { return str.substring(0, idx); @@ -835,8 +835,8 @@ public static String chomp(@Nonnull String str, @Nonnull String sep) { * @return String without chomped ending * @throws NullPointerException if str is null */ - @Nonnull - public static String chompLast(@Nonnull String str) { + @NonNull + public static String chompLast(@NonNull String str) { return chompLast(str, "\n"); } @@ -848,8 +848,8 @@ public static String chompLast(@Nonnull String str) { * @return String without chomped ending * @throws NullPointerException if str or sep is null */ - @Nonnull - public static String chompLast(@Nonnull String str, @Nonnull String sep) { + @NonNull + public static String chompLast(@NonNull String str, @NonNull String sep) { if (str.length() == 0) { return str; } @@ -870,8 +870,8 @@ public static String chompLast(@Nonnull String str, @Nonnull String sep) { * @return String chomped * @throws NullPointerException if str or sep is null */ - @Nonnull - public static String getChomp(@Nonnull String str, @Nonnull String sep) { + @NonNull + public static String getChomp(@NonNull String str, @NonNull String sep) { int idx = str.lastIndexOf(sep); if (idx == str.length() - sep.length()) { return sep; @@ -891,8 +891,8 @@ public static String getChomp(@Nonnull String str, @Nonnull String sep) { * @return String without chomped beginning * @throws NullPointerException if str or sep is null */ - @Nonnull - public static String prechomp(@Nonnull String str, @Nonnull String sep) { + @NonNull + public static String prechomp(@NonNull String str, @NonNull String sep) { int idx = str.indexOf(sep); if (idx != -1) { return str.substring(idx + sep.length()); @@ -910,8 +910,8 @@ public static String prechomp(@Nonnull String str, @Nonnull String sep) { * @return String prechomped * @throws NullPointerException if str or sep is null */ - @Nonnull - public static String getPrechomp(@Nonnull String str, @Nonnull String sep) { + @NonNull + public static String getPrechomp(@NonNull String str, @NonNull String sep) { int idx = str.indexOf(sep); if (idx != -1) { return str.substring(0, idx + sep.length()); @@ -933,8 +933,8 @@ public static String getPrechomp(@Nonnull String str, @Nonnull String sep) { * @return String without last character * @throws NullPointerException if str is null */ - @Nonnull - public static String chop(@Nonnull String str) { + @NonNull + public static String chop(@NonNull String str) { if ("".equals(str)) { return ""; } @@ -960,8 +960,8 @@ public static String chop(@Nonnull String str) { * @return String without newline * @throws NullPointerException if str is null */ - @Nonnull - public static String chopNewline(@Nonnull String str) { + @NonNull + public static String chopNewline(@NonNull String str) { int lastIdx = str.length() - 1; char last = str.charAt(lastIdx); if (last == '\n') { @@ -989,8 +989,8 @@ public static String chopNewline(@Nonnull String str) { * @return String with escaped values * @throws NullPointerException if str is null */ - @Nonnull - public static String escape(@Nonnull String str) { + @NonNull + public static String escape(@NonNull String str) { // improved with code from cybertiger@cyberiantiger.org // unicode from him, and defaul for < 32's. int sz = str.length(); @@ -1074,8 +1074,8 @@ else if (ch < 32) { * @throws NegativeArraySizeException if repeat < 0 * @throws NullPointerException if str is null */ - @Nonnull - public static String repeat(@Nonnull String str, int repeat) { + @NonNull + public static String repeat(@NonNull String str, int repeat) { StringBuilder buffer = new StringBuilder(repeat * str.length()); for (int i = 0; i < repeat; i++) { buffer.append(str); @@ -1093,8 +1093,8 @@ public static String repeat(@Nonnull String str, int repeat) { * @return right padded String * @throws NullPointerException if str is null */ - @Nonnull - public static String rightPad(@Nonnull String str, int size) { + @NonNull + public static String rightPad(@NonNull String str, int size) { return rightPad(str, size, " "); } @@ -1110,8 +1110,8 @@ public static String rightPad(@Nonnull String str, int size) { * @throws NullPointerException if str or delim is null * @throws ArithmeticException if delim is the empty String */ - @Nonnull - public static String rightPad(@Nonnull String str, int size, @Nonnull String delim) { + @NonNull + public static String rightPad(@NonNull String str, int size, @NonNull String delim) { size = (size - str.length()) / delim.length(); if (size > 0) { str += repeat(delim, size); @@ -1129,8 +1129,8 @@ public static String rightPad(@Nonnull String str, int size, @Nonnull String del * @return left padded String * @throws NullPointerException if str or delim is null */ - @Nonnull - public static String leftPad(@Nonnull String str, int size) { + @NonNull + public static String leftPad(@NonNull String str, int size) { return leftPad(str, size, " "); } @@ -1144,8 +1144,8 @@ public static String leftPad(@Nonnull String str, int size) { * @throws NullPointerException if str or delim is null * @throws ArithmeticException if delim is the empty string */ - @Nonnull - public static String leftPad(@Nonnull String str, int size, @Nonnull String delim) { + @NonNull + public static String leftPad(@NonNull String str, int size, @NonNull String delim) { size = (size - str.length()) / delim.length(); if (size > 0) { str = repeat(delim, size) + str; @@ -1477,7 +1477,7 @@ public static String uncapitaliseAllWords(String str) { * @return the String that was nested, or null * @throws NullPointerException if tag is null */ - public static String getNestedString(String str, @Nonnull String tag) { + public static String getNestedString(String str, @NonNull String tag) { return getNestedString(str, tag, tag); } @@ -1490,7 +1490,7 @@ public static String getNestedString(String str, @Nonnull String tag) { * @return the String that was nested, or null * @throws NullPointerException if open or close is null */ - public static String getNestedString(String str, @Nonnull String open, @Nonnull String close) { + public static String getNestedString(String str, @NonNull String open, @NonNull String close) { if (str == null) { return null; } @@ -1514,7 +1514,7 @@ public static String getNestedString(String str, @Nonnull String open, @Nonnull * @return the number of occurrences, 0 if the String is null * @throws NullPointerException if sub is null */ - public static int countMatches(@Nullable String str, @Nonnull String sub) { + public static int countMatches(@Nullable String str, @NonNull String sub) { if (sub.equals("")) { return 0; } @@ -1684,7 +1684,7 @@ public static boolean isNumeric(String str) { * @deprecated use {@code java.lang.Objects.toString()} */ @Deprecated - @Nonnull + @NonNull public static String defaultString(Object obj) { return defaultString(obj, ""); } @@ -1702,8 +1702,8 @@ public static String defaultString(Object obj) { * @deprecated use {@code java.lang.Objects.toString()} */ @Deprecated - @Nonnull - public static String defaultString(Object obj, @Nonnull String defaultString) { + @NonNull + public static String defaultString(Object obj, @NonNull String defaultString) { return (obj == null) ? defaultString : obj.toString(); } @@ -1736,8 +1736,8 @@ public static String reverse(String str) { * @param delimiter the delimiter to use * @return the reversed String */ - @Nonnull - public static String reverseDelimitedString(@Nonnull String str, String delimiter) { + @NonNull + public static String reverseDelimitedString(@NonNull String str, String delimiter) { // could implement manually, but simple way is to reuse other, // probably slower, methods. String[] strs = split(str, delimiter); @@ -1750,7 +1750,7 @@ public static String reverseDelimitedString(@Nonnull String str, String delimite * * @param array the array to reverse */ - private static void reverseArray(@Nonnull String... array) { + private static void reverseArray(@NonNull String... array) { int i = 0; int j = array.length - 1; String tmp; @@ -1779,8 +1779,8 @@ private static void reverseArray(@Nonnull String... array) { * @param maxWidth maximum length of result string * @return The abbreviated string. */ - @Nonnull - public static String abbreviate(@Nonnull String s, int maxWidth) { + @NonNull + public static String abbreviate(@NonNull String s, int maxWidth) { return abbreviate(s, 0, maxWidth); } @@ -1799,8 +1799,8 @@ public static String abbreviate(@Nonnull String s, int maxWidth) { * @param maxWidth maximum length of result string * @return The abbreviated string. */ - @Nonnull - public static String abbreviate(@Nonnull String s, int offset, int maxWidth) { + @NonNull + public static String abbreviate(@NonNull String s, int offset, int maxWidth) { if (maxWidth < 4) { throw new IllegalArgumentException("Minimum abbreviation width is 4"); } @@ -1840,7 +1840,7 @@ public static String abbreviate(@Nonnull String s, int offset, int maxWidth) { * @param s2 The second string. * @return the portion of s2 where it differs from s1; returns the empty string ("") if they are equal */ - public static String difference(@Nonnull String s1, @Nonnull String s2) { + public static String difference(@NonNull String s1, @NonNull String s2) { int at = differenceAt(s1, s2); if (at == -1) { return ""; @@ -1858,7 +1858,7 @@ public static String difference(@Nonnull String s1, @Nonnull String s2) { * @param s2 The second string. * @return the index where s2 and s1 begin to differ; -1 if they are equal */ - public static int differenceAt(@Nonnull String s1, @Nonnull String s2) { + public static int differenceAt(@NonNull String s1, @NonNull String s2) { int i; for (i = 0; (i < s1.length()) && (i < s2.length()); ++i) { if (s1.charAt(i) != s2.charAt(i)) { @@ -1880,7 +1880,7 @@ public static int differenceAt(@Nonnull String s1, @Nonnull String s2) { * @param namespace The namespace which contains the replacements. * @return the interpolated text. */ - public static String interpolate(String text, @Nonnull Map namespace) { + public static String interpolate(String text, @NonNull Map namespace) { for (Map.Entry entry : namespace.entrySet()) { String key = entry.getKey().toString(); @@ -1914,8 +1914,8 @@ public static String interpolate(String text, @Nonnull Map namespace) { * @param replaceThis The things which should be replaced. * @return humped String */ - @Nonnull - public static String removeAndHump(@Nonnull String data, @Nonnull String replaceThis) { + @NonNull + public static String removeAndHump(@NonNull String data, @NonNull String replaceThis) { String temp; StringBuilder out = new StringBuilder(); @@ -1942,8 +1942,8 @@ public static String removeAndHump(@Nonnull String data, @Nonnull String replace * @throws NullPointerException if data is null * @throws IndexOutOfBoundsException if data is empty */ - @Nonnull - public static String capitalizeFirstLetter(@Nonnull String data) { + @NonNull + public static String capitalizeFirstLetter(@NonNull String data) { char firstChar = data.charAt(0); char titleCase = Character.toTitleCase(firstChar); if (firstChar == titleCase) { @@ -1964,8 +1964,8 @@ public static String capitalizeFirstLetter(@Nonnull String data) { * @throws NullPointerException if data is null * @throws IndexOutOfBoundsException if data is empty */ - @Nonnull - public static String lowercaseFirstLetter(@Nonnull String data) { + @NonNull + public static String lowercaseFirstLetter(@NonNull String data) { char firstLetter = Character.toLowerCase(data.substring(0, 1).charAt(0)); String restLetters = data.substring(1); @@ -1980,8 +1980,8 @@ public static String lowercaseFirstLetter(@Nonnull String data) { * @param view the view * @return deHumped String */ - @Nonnull - public static String addAndDeHump(@Nonnull String view) { + @NonNull + public static String addAndDeHump(@NonNull String view) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < view.length(); i++) { @@ -2027,7 +2027,7 @@ public static String quoteAndEscape(@Nullable String source, char quoteChar) { * @see #quoteAndEscape(String, char, char[], char[], char, boolean) * */ - public static String quoteAndEscape(@Nullable String source, char quoteChar, @Nonnull char[] quotingTriggers) { + public static String quoteAndEscape(@Nullable String source, char quoteChar, @NonNull char[] quotingTriggers) { return quoteAndEscape(source, quoteChar, new char[] {quoteChar}, quotingTriggers, '\\', false); } @@ -2044,7 +2044,7 @@ public static String quoteAndEscape(@Nullable String source, char quoteChar, @No public static String quoteAndEscape( @Nullable String source, char quoteChar, - @Nonnull final char[] escapedChars, + @NonNull final char[] escapedChars, char escapeChar, boolean force) { return quoteAndEscape(source, quoteChar, escapedChars, new char[] {' '}, escapeChar, force); @@ -2062,8 +2062,8 @@ public static String quoteAndEscape( public static String quoteAndEscape( @Nullable String source, char quoteChar, - @Nonnull final char[] escapedChars, - @Nonnull final char[] quotingTriggers, + @NonNull final char[] escapedChars, + @NonNull final char[] quotingTriggers, char escapeChar, boolean force) { if (source == null) { @@ -2105,7 +2105,7 @@ public static String quoteAndEscape( * @param escapeChar prefix for escaping a character * @return the String escaped */ - public static String escape(@Nullable String source, @Nonnull final char[] escapedChars, char escapeChar) { + public static String escape(@Nullable String source, @NonNull final char[] escapedChars, char escapeChar) { if (source == null) { return null; } @@ -2136,8 +2136,8 @@ public static String escape(@Nullable String source, @Nonnull final char[] escap * @return a string with unique whitespace * */ - @Nonnull - public static String removeDuplicateWhitespace(@Nonnull String s) { + @NonNull + public static String removeDuplicateWhitespace(@NonNull String s) { StringBuilder result = new StringBuilder(); int length = s.length(); boolean isPreviousWhiteSpace = false; diff --git a/src/main/java/org/apache/maven/shared/utils/WriterFactory.java b/src/main/java/org/apache/maven/shared/utils/WriterFactory.java index 5088914b..c84315c5 100644 --- a/src/main/java/org/apache/maven/shared/utils/WriterFactory.java +++ b/src/main/java/org/apache/maven/shared/utils/WriterFactory.java @@ -18,8 +18,6 @@ */ package org.apache.maven.shared.utils; -import javax.annotation.Nonnull; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -32,6 +30,7 @@ import java.nio.charset.Charset; import org.apache.maven.shared.utils.xml.XmlStreamWriter; +import org.jspecify.annotations.NonNull; /** * Utility to create Writers, with explicit encoding choice: platform default, @@ -115,7 +114,7 @@ public class WriterFactory { * @deprecated use {@code org.apache.commons.io.input.XmlStreamWriter} instead */ @Deprecated - public static XmlStreamWriter newXmlWriter(@Nonnull OutputStream out) throws IOException { + public static XmlStreamWriter newXmlWriter(@NonNull OutputStream out) throws IOException { return new XmlStreamWriter(out); } @@ -129,7 +128,7 @@ public static XmlStreamWriter newXmlWriter(@Nonnull OutputStream out) throws IOE * @deprecated use {@code org.apache.commons.io.input.XmlStreamWriter} instead */ @Deprecated - public static XmlStreamWriter newXmlWriter(@Nonnull File file) throws IOException { + public static XmlStreamWriter newXmlWriter(@NonNull File file) throws IOException { return new XmlStreamWriter(file); } @@ -141,7 +140,7 @@ public static XmlStreamWriter newXmlWriter(@Nonnull File file) throws IOExceptio * @deprecated always specify an encoding. Do not depend on the default platform character set. */ @Deprecated - public static Writer newPlatformWriter(@Nonnull OutputStream out) { + public static Writer newPlatformWriter(@NonNull OutputStream out) { return new OutputStreamWriter(out); } @@ -154,7 +153,7 @@ public static Writer newPlatformWriter(@Nonnull OutputStream out) { * @deprecated always specify an encoding. Do not depend on the default platform character set. */ @Deprecated - public static Writer newPlatformWriter(@Nonnull File file) throws IOException { + public static Writer newPlatformWriter(@NonNull File file) throws IOException { return new FileWriter(file); } @@ -171,7 +170,7 @@ public static Writer newPlatformWriter(@Nonnull File file) throws IOException { * @deprecated use {@code new OutputStreamWriter(out, encoding)} instead */ @Deprecated - public static Writer newWriter(@Nonnull OutputStream out, @Nonnull String encoding) + public static Writer newWriter(@NonNull OutputStream out, @NonNull String encoding) throws UnsupportedEncodingException { return new OutputStreamWriter(out, encoding); } @@ -190,7 +189,7 @@ public static Writer newWriter(@Nonnull OutputStream out, @Nonnull String encodi * @deprecated use {@code java.nio.file.Files.newBufferedWriter()} instead */ @Deprecated - public static Writer newWriter(@Nonnull File file, @Nonnull String encoding) + public static Writer newWriter(@NonNull File file, @NonNull String encoding) throws UnsupportedEncodingException, FileNotFoundException { return newWriter(new FileOutputStream(file), encoding); } diff --git a/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java b/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java index 04f5cd6a..99fd1e62 100644 --- a/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java @@ -18,9 +18,6 @@ */ package org.apache.maven.shared.utils.cli; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.io.InputStream; import java.nio.charset.Charset; import java.util.ArrayList; @@ -33,6 +30,8 @@ import org.apache.maven.shared.utils.Os; import org.apache.maven.shared.utils.StringUtils; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; /** * @author Trygve Laugstøl @@ -73,7 +72,7 @@ public String getOutput() { * @return return code. * @throws CommandLineException in case of a problem. */ - public static int executeCommandLine(@Nonnull Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr) + public static int executeCommandLine(@NonNull Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException { return executeCommandLine(cl, null, systemOut, systemErr, 0); } @@ -87,7 +86,7 @@ public static int executeCommandLine(@Nonnull Commandline cl, StreamConsumer sys * @throws CommandLineException in case of a problem. */ public static int executeCommandLine( - @Nonnull Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) + @NonNull Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr, int timeoutInSeconds) throws CommandLineException { return executeCommandLine(cl, null, systemOut, systemErr, timeoutInSeconds); } @@ -101,7 +100,7 @@ public static int executeCommandLine( * @throws CommandLineException in case of a problem. */ public static int executeCommandLine( - @Nonnull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr) + @NonNull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr) throws CommandLineException { return executeCommandLine(cl, systemIn, systemOut, systemErr, 0); } @@ -116,7 +115,7 @@ public static int executeCommandLine( * @throws CommandLineException or CommandLineTimeOutException if time out occurs */ public static int executeCommandLine( - @Nonnull Commandline cl, + @NonNull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, @@ -137,7 +136,7 @@ public static int executeCommandLine( * @throws CommandLineException or CommandLineTimeOutException if time out occurs */ public static int executeCommandLine( - @Nonnull Commandline cl, + @NonNull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, @@ -161,7 +160,7 @@ public static int executeCommandLine( * @throws CommandLineException or CommandLineTimeOutException if time out occurs */ public static int executeCommandLine( - @Nonnull Commandline cl, + @NonNull Commandline cl, InputStream systemIn, StreamConsumer systemOut, StreamConsumer systemErr, @@ -189,7 +188,7 @@ public static int executeCommandLine( * @throws CommandLineException or CommandLineTimeOutException if time out occurs */ public static CommandLineCallable executeCommandLineAsCallable( - @Nonnull final Commandline cl, + @NonNull final Commandline cl, @Nullable final InputStream systemIn, final StreamConsumer systemOut, final StreamConsumer systemErr, @@ -216,7 +215,7 @@ public static CommandLineCallable executeCommandLineAsCallable( * @throws CommandLineException or CommandLineTimeOutException if time out occurs */ public static CommandLineCallable executeCommandLineAsCallable( - @Nonnull final Commandline cl, + @NonNull final Commandline cl, @Nullable final InputStream systemIn, final StreamConsumer systemOut, final StreamConsumer systemErr, diff --git a/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java b/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java index 03a79ca1..cbe6c18e 100644 --- a/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java +++ b/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java @@ -18,8 +18,6 @@ */ package org.apache.maven.shared.utils.cli; -import javax.annotation.Nullable; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -27,6 +25,8 @@ import java.io.Reader; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + /** * Class to pump the error stream during Process's runtime. Copied from the Ant built-in task. * diff --git a/src/main/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractor.java b/src/main/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractor.java index 1c6965ea..f8c58de2 100644 --- a/src/main/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractor.java +++ b/src/main/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractor.java @@ -18,9 +18,6 @@ */ package org.apache.maven.shared.utils.introspection; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -30,6 +27,8 @@ import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.utils.introspection.MethodMap.AmbiguousException; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; /** *

Using simple dotted expressions to extract the values from an Object instance, @@ -141,7 +140,7 @@ private ReflectionValueExtractor() {} * @return the object defined by the expression * @throws IntrospectionException if any */ - public static Object evaluate(@Nonnull String expression, @Nullable Object root) throws IntrospectionException { + public static Object evaluate(@NonNull String expression, @Nullable Object root) throws IntrospectionException { return evaluate(expression, root, true); } @@ -163,7 +162,7 @@ public static Object evaluate(@Nonnull String expression, @Nullable Object root) * @return the object defined by the expression * @throws IntrospectionException if any */ - public static Object evaluate(@Nonnull String expression, @Nullable Object root, boolean trimRootToken) + public static Object evaluate(@NonNull String expression, @Nullable Object root, boolean trimRootToken) throws IntrospectionException { Object value = root; diff --git a/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java b/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java index aad7a017..77dc97c4 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java +++ b/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java @@ -18,9 +18,6 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.io.File; import java.nio.file.Files; import java.util.ArrayList; @@ -29,6 +26,9 @@ import java.util.List; import java.util.Set; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + /** *

Class for scanning a directory for files/directories which match certain criteria.

*

@@ -279,7 +279,7 @@ public void setBasedir(final String basedir) { * * @param basedir The base directory for scanning. Should not be null. */ - public void setBasedir(@Nonnull final File basedir) { + public void setBasedir(@NonNull final File basedir) { this.basedir = basedir; } @@ -553,7 +553,7 @@ private void slowScan() { * @see #dirsExcluded * @see #slowScan */ - private void scandir(@Nonnull final File dir, @Nonnull final String vpath, final boolean fast) { + private void scandir(@NonNull final File dir, @NonNull final String vpath, final boolean fast) { String[] newfiles = dir.list(); if (newfiles == null) { @@ -698,7 +698,7 @@ private boolean isIncluded(final String name) { * @return true when the name matches against the start of at least one include pattern, or * false otherwise. */ - private boolean couldHoldIncluded(@Nonnull final String name) { + private boolean couldHoldIncluded(@NonNull final String name) { return includesPatterns.matchesPatternStart(name, isCaseSensitive); } @@ -709,7 +709,7 @@ private boolean couldHoldIncluded(@Nonnull final String name) { * @return true when the name matches against at least one exclude pattern, or false * otherwise. */ - private boolean isExcluded(@Nonnull final String name) { + private boolean isExcluded(@NonNull final String name) { return excludesPatterns.matches(name, isCaseSensitive); } diff --git a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java index 1996e0bc..682c4dac 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java @@ -18,10 +18,6 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.annotation.WillClose; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -55,6 +51,8 @@ import org.apache.commons.io.IOUtils; import org.apache.maven.shared.utils.Os; import org.apache.maven.shared.utils.StringUtils; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; /** * This class provides basic facilities for manipulating files and file paths. @@ -131,7 +129,7 @@ protected FileUtils() { * @return the default excludes pattern * @see DirectoryScanner#DEFAULTEXCLUDES */ - @Nonnull + @NonNull public static String[] getDefaultExcludes() { return DirectoryScanner.DEFAULTEXCLUDES; } @@ -140,7 +138,7 @@ public static String[] getDefaultExcludes() { * @return the default excludes pattern as list * @see #getDefaultExcludes() */ - @Nonnull + @NonNull public static List getDefaultExcludesAsList() { return Arrays.asList(getDefaultExcludes()); } @@ -150,7 +148,7 @@ public static List getDefaultExcludesAsList() { * @see DirectoryScanner#DEFAULTEXCLUDES * @see StringUtils#join(Object[], String) */ - @Nonnull + @NonNull public static String getDefaultExcludesAsString() { return StringUtils.join(DirectoryScanner.DEFAULTEXCLUDES, ","); } @@ -164,8 +162,8 @@ public static String getDefaultExcludesAsString() { * @deprecated use {@code Paths.get(path).getParent().getName()} */ @Deprecated - @Nonnull - public static String dirname(@Nonnull String path) { + @NonNull + public static String dirname(@NonNull String path) { int i = path.lastIndexOf(File.separator); return (i >= 0 ? path.substring(0, i) : ""); } @@ -178,8 +176,8 @@ public static String dirname(@Nonnull String path) { * @deprecated use {@code Paths.get(path).getName()} */ @Deprecated - @Nonnull - public static String filename(@Nonnull String path) { + @NonNull + public static String filename(@NonNull String path) { int i = path.lastIndexOf(File.separator); return (i >= 0 ? path.substring(i + 1) : path); } @@ -193,8 +191,8 @@ public static String filename(@Nonnull String path) { * @deprecated use {@code org.apache.commons.io.FilenameUtils.getExtension} */ @Deprecated - @Nonnull - public static String extension(@Nonnull String path) { + @NonNull + public static String extension(@NonNull String path) { // Ensure the last dot is after the last file separator int lastSep = path.lastIndexOf(File.separatorChar); int lastDot; @@ -222,7 +220,7 @@ public static String extension(@Nonnull String path) { * @deprecated use {@code java.io.File.exists()} */ @Deprecated - public static boolean fileExists(@Nonnull String fileName) { + public static boolean fileExists(@NonNull String fileName) { File file = new File(fileName); return file.exists(); } @@ -236,8 +234,8 @@ public static boolean fileExists(@Nonnull String fileName) { * @deprecated use {@code new String(java.nio.files.Files.readAllBytes(file))} */ @Deprecated - @Nonnull - public static String fileRead(@Nonnull String file) throws IOException { + @NonNull + public static String fileRead(@NonNull String file) throws IOException { return fileRead(file, null); } @@ -249,8 +247,8 @@ public static String fileRead(@Nonnull String file) throws IOException { * @deprecated use {@code new String(java.nio.files.Files.readAllBytes(Paths.get(file)), encoding)} */ @Deprecated - @Nonnull - private static String fileRead(@Nonnull String file, @Nullable String encoding) throws IOException { + @NonNull + private static String fileRead(@NonNull String file, @Nullable String encoding) throws IOException { return fileRead(new File(file), encoding); } @@ -263,8 +261,8 @@ private static String fileRead(@Nonnull String file, @Nullable String encoding) * @deprecated use {@code new String(java.nio.files.Files.readAllBytes(file.toPath()))} */ @Deprecated - @Nonnull - public static String fileRead(@Nonnull File file) throws IOException { + @NonNull + public static String fileRead(@NonNull File file) throws IOException { return fileRead(file, null); } @@ -276,8 +274,8 @@ public static String fileRead(@Nonnull File file) throws IOException { * @deprecated use {@code new String(java.nio.files.Files.readAllBytes(file.toPath()), encoding)} */ @Deprecated - @Nonnull - public static String fileRead(@Nonnull File file, @Nullable String encoding) throws IOException { + @NonNull + public static String fileRead(@NonNull File file, @Nullable String encoding) throws IOException { Charset charset = charset(encoding); StringBuilder buf = new StringBuilder(); @@ -302,8 +300,8 @@ public static String fileRead(@Nonnull File file, @Nullable String encoding) thr * @deprecated use {@code java.nio.files.Files.readAllLines()} */ @Deprecated - @Nonnull - public static String[] fileReadArray(@Nonnull File file) throws IOException { + @NonNull + public static String[] fileReadArray(@NonNull File file) throws IOException { List lines = loadFile(file); return lines.toArray(new String[lines.size()]); @@ -320,7 +318,7 @@ public static String[] fileReadArray(@Nonnull File file) throws IOException { * StandardOpenOption.APPEND, StandardOpenOption.CREATE)} */ @Deprecated - public static void fileAppend(@Nonnull String fileName, @Nonnull String data) throws IOException { + public static void fileAppend(@NonNull String fileName, @NonNull String data) throws IOException { fileAppend(fileName, null, data); } @@ -335,7 +333,7 @@ public static void fileAppend(@Nonnull String fileName, @Nonnull String data) th * StandardOpenOption.APPEND, StandardOpenOption.CREATE)} */ @Deprecated - public static void fileAppend(@Nonnull String fileName, @Nullable String encoding, @Nonnull String data) + public static void fileAppend(@NonNull String fileName, @Nullable String encoding, @NonNull String data) throws IOException { Charset charset = charset(encoding); @@ -355,7 +353,7 @@ public static void fileAppend(@Nonnull String fileName, @Nullable String encodin * data.getBytes(), StandardOpenOption.CREATE)} */ @Deprecated - public static void fileWrite(@Nonnull String fileName, @Nonnull String data) throws IOException { + public static void fileWrite(@NonNull String fileName, @NonNull String data) throws IOException { fileWrite(fileName, null, data); } @@ -370,7 +368,7 @@ public static void fileWrite(@Nonnull String fileName, @Nonnull String data) thr * data.getBytes(encoding), StandardOpenOption.CREATE)} */ @Deprecated - public static void fileWrite(@Nonnull String fileName, @Nullable String encoding, @Nonnull String data) + public static void fileWrite(@NonNull String fileName, @Nullable String encoding, @NonNull String data) throws IOException { File file = new File(fileName); fileWrite(file, encoding, data); @@ -387,7 +385,7 @@ public static void fileWrite(@Nonnull String fileName, @Nullable String encoding * data.getBytes(encoding), StandardOpenOption.CREATE)} */ @Deprecated - public static void fileWrite(@Nonnull File file, @Nullable String encoding, @Nonnull String data) + public static void fileWrite(@NonNull File file, @Nullable String encoding, @NonNull String data) throws IOException { Charset charset = charset(encoding); @@ -407,7 +405,7 @@ public static void fileWrite(@Nonnull File file, @Nullable String encoding, @Non * data.getBytes(encoding), StandardOpenOption.CREATE)} */ @Deprecated - public static void fileWriteArray(@Nonnull File file, @Nullable String... data) throws IOException { + public static void fileWriteArray(@NonNull File file, @Nullable String... data) throws IOException { fileWriteArray(file, null, data); } @@ -422,7 +420,7 @@ public static void fileWriteArray(@Nonnull File file, @Nullable String... data) * data.getBytes(encoding), StandardOpenOption.CREATE)} */ @Deprecated - public static void fileWriteArray(@Nonnull File file, @Nullable String encoding, @Nullable String... data) + public static void fileWriteArray(@NonNull File file, @Nullable String encoding, @Nullable String... data) throws IOException { Charset charset = charset(encoding); @@ -441,7 +439,7 @@ public static void fileWriteArray(@Nonnull File file, @Nullable String encoding, * @deprecated use {@code Files.delete(Paths.get(fileName))} */ @Deprecated - public static void fileDelete(@Nonnull String fileName) { + public static void fileDelete(@NonNull String fileName) { File file = new File(fileName); deleteLegacyStyle(file); } @@ -455,7 +453,7 @@ public static void fileDelete(@Nonnull String fileName) { * @param extensions an array of expected extensions * @return an array of files for the wanted extensions */ - public static String[] getFilesFromExtension(@Nonnull String directory, @Nonnull String... extensions) { + public static String[] getFilesFromExtension(@NonNull String directory, @NonNull String... extensions) { List files = new ArrayList<>(); File currentDir = new File(directory); @@ -501,8 +499,8 @@ public static String[] getFilesFromExtension(@Nonnull String directory, @Nonnull /** * Private helper method for getFilesFromExtension() */ - @Nonnull - private static List blendFilesToList(@Nonnull List v, @Nonnull String... files) { + @NonNull + private static List blendFilesToList(@NonNull List v, @NonNull String... files) { Collections.addAll(v, files); return v; @@ -513,7 +511,7 @@ private static List blendFilesToList(@Nonnull List v, @Nonnull S * Note that if the file does not have an extension, an empty string * ("") is matched for. */ - private static boolean isValidFile(@Nonnull String file, @Nonnull String... extensions) { + private static boolean isValidFile(@NonNull String file, @NonNull String... extensions) { String extension = extension(file); // ok.. now that we have the "extension" go through the current know @@ -537,7 +535,7 @@ private static boolean isValidFile(@Nonnull String file, @Nonnull String... exte * @deprecated use {@code java.nio.file.Files.createDirectories(Paths.get(dir))} */ @Deprecated - public static void mkdir(@Nonnull String dir) { + public static void mkdir(@NonNull String dir) { File file = new File(dir); if (Os.isFamily(Os.FAMILY_WINDOWS) && !isValidWindowsFileName(file)) { @@ -562,7 +560,7 @@ public static void mkdir(@Nonnull String dir) { * @deprecated use {@code org.apache.commons.io.FileUtils.contentEquals()} */ @Deprecated - public static boolean contentEquals(@Nonnull final File file1, @Nonnull final File file2) throws IOException { + public static boolean contentEquals(@NonNull final File file1, @NonNull final File file2) throws IOException { final boolean file1Exists = file1.exists(); if (file1Exists != file2.exists()) { return false; @@ -616,8 +614,8 @@ public static File toFile(@Nullable final URL url) { * @return the array of URLs * @throws IOException if an error occurs */ - @Nonnull - public static URL[] toURLs(@Nonnull final File... files) throws IOException { + @NonNull + public static URL[] toURLs(@NonNull final File... files) throws IOException { final URL[] urls = new URL[files.length]; for (int i = 0; i < urls.length; i++) { @@ -640,8 +638,8 @@ public static URL[] toURLs(@Nonnull final File... files) throws IOException { * @deprecated use {@code org.apache.commons.io.FilenameUtils.removeExtension()} */ @Deprecated - @Nonnull - public static String removeExtension(@Nonnull final String filename) { + @NonNull + public static String removeExtension(@NonNull final String filename) { String ext = extension(filename); if ("".equals(ext)) { @@ -666,8 +664,8 @@ public static String removeExtension(@Nonnull final String filename) { * @deprecated use {@code org.apache.commons.io.FilenameUtils.getExtension()} */ @Deprecated - @Nonnull - public static String getExtension(@Nonnull final String filename) { + @NonNull + public static String getExtension(@NonNull final String filename) { return extension(filename); } @@ -686,7 +684,7 @@ public static String getExtension(@Nonnull final String filename) { * @deprecated use {@code org.apache.commons.io.FileUtils.copyFileToDirectory()} */ @Deprecated - public static void copyFileToDirectory(@Nonnull final File source, @Nonnull final File destinationDirectory) + public static void copyFileToDirectory(@NonNull final File source, @NonNull final File destinationDirectory) throws IOException { if (destinationDirectory.exists() && !destinationDirectory.isDirectory()) { throw new IOException("Destination is not a directory"); @@ -710,7 +708,7 @@ public static void copyFileToDirectory(@Nonnull final File source, @Nonnull fina * occurs during copying */ private static void copyFileToDirectoryIfModified( - @Nonnull final File source, @Nonnull final File destinationDirectory) throws IOException { + @NonNull final File source, @NonNull final File destinationDirectory) throws IOException { if (destinationDirectory.exists() && !destinationDirectory.isDirectory()) { throw new IllegalArgumentException("Destination is not a directory"); } @@ -733,7 +731,7 @@ private static void copyFileToDirectoryIfModified( * StandardCopyOption.REPLACE_EXISTING)} */ @Deprecated - public static void copyFile(@Nonnull final File source, @Nonnull final File destination) throws IOException { + public static void copyFile(@NonNull final File source, @NonNull final File destination) throws IOException { // check source exists if (!source.exists()) { final String message = "File " + source + " does not exist"; @@ -761,7 +759,7 @@ public static void copyFile(@Nonnull final File source, @Nonnull final File dest } } - private static void mkdirsFor(@Nonnull File destination) { + private static void mkdirsFor(@NonNull File destination) { // does destination directory exist ? if (destination.getParentFile() != null && !destination.getParentFile().exists()) { //noinspection ResultOfMethodCallIgnored @@ -769,7 +767,7 @@ private static void mkdirsFor(@Nonnull File destination) { } } - private static void doCopyFile(@Nonnull File source, @Nonnull File destination) throws IOException { + private static void doCopyFile(@NonNull File source, @NonNull File destination) throws IOException { try (FileInputStream fis = new FileInputStream(source); FileOutputStream fos = new FileOutputStream(destination); @@ -800,7 +798,7 @@ private static void doCopyFile(@Nonnull File source, @Nonnull File destination) * @throws IOException if source does not exist, destination cannot be * written to, or an IO error occurs during copying. */ - private static boolean copyFileIfModified(@Nonnull final File source, @Nonnull final File destination) + private static boolean copyFileIfModified(@NonNull final File source, @NonNull final File destination) throws IOException { if (destination.lastModified() < source.lastModified()) { copyFile(source, destination); @@ -828,7 +826,7 @@ private static boolean copyFileIfModified(@Nonnull final File source, @Nonnull f * @deprecated use {@code java.nio.Files.copy(source.openStream(), destination.toPath(), * StandardCopyOption.REPLACE_EXISTING)} */ - public static void copyURLToFile(@Nonnull final URL source, @Nonnull final File destination) throws IOException { + public static void copyURLToFile(@NonNull final URL source, @NonNull final File destination) throws IOException { copyStreamToFile(source.openStream(), destination); } @@ -851,7 +849,7 @@ public static void copyURLToFile(@Nonnull final URL source, @Nonnull final File * StandardCopyOption.REPLACE_EXISTING)} */ @Deprecated - private static void copyStreamToFile(@Nonnull @WillClose final InputStream source, @Nonnull final File destination) + private static void copyStreamToFile(@NonNull final InputStream source, @NonNull final File destination) throws IOException { // does destination directory exist ? if (destination.getParentFile() != null && !destination.getParentFile().exists()) { @@ -891,8 +889,8 @@ private static void copyStreamToFile(@Nonnull @WillClose final InputStream sourc * @deprecated use {@code org.apache.commons.io.FileNameUtils.normalize()} */ @Deprecated - @Nonnull - public static String normalize(@Nonnull final String path) { + @NonNull + public static String normalize(@NonNull final String path) { String normalized = path; // Resolve occurrences of "//" in the normalized path while (true) { @@ -938,8 +936,8 @@ public static String normalize(@Nonnull final String path) { * @param filename absolute or relative file path to resolve * @return the canonical File of filename */ - @Nonnull - public static File resolveFile(final File baseFile, @Nonnull String filename) { + @NonNull + public static File resolveFile(final File baseFile, @NonNull String filename) { String filenm = filename; if ('/' != File.separatorChar) { filenm = filename.replace('/', File.separatorChar); @@ -1005,7 +1003,7 @@ public static File resolveFile(final File baseFile, @Nonnull String filename) { * @deprecated use {@code org.apache.commons.io.FileUtils.deleteQuietly()} */ @Deprecated - public static void forceDelete(@Nonnull final String file) throws IOException { + public static void forceDelete(@NonNull final String file) throws IOException { forceDelete(new File(file)); } @@ -1017,7 +1015,7 @@ public static void forceDelete(@Nonnull final String file) throws IOException { * @deprecated use {@code org.apache.commons.io.FileUtils.deleteQuietly()} */ @Deprecated - public static void forceDelete(@Nonnull final File file) throws IOException { + public static void forceDelete(@NonNull final File file) throws IOException { if (file.isDirectory()) { deleteDirectory(file); } else { @@ -1041,7 +1039,7 @@ public static void forceDelete(@Nonnull final File file) throws IOException { * @deprecated use {@code java.nio.files.Files.delete(file.toPath())} */ @Deprecated - public static void delete(@Nonnull File file) throws IOException { + public static void delete(@NonNull File file) throws IOException { Files.delete(file.toPath()); } @@ -1051,7 +1049,7 @@ public static void delete(@Nonnull File file) throws IOException { * @deprecated use {@code java.nio.files.Files.delete(file.toPath())} */ @Deprecated - public static boolean deleteLegacyStyle(@Nonnull File file) { + public static boolean deleteLegacyStyle(@NonNull File file) { try { Files.delete(file.toPath()); return true; @@ -1068,7 +1066,7 @@ public static boolean deleteLegacyStyle(@Nonnull File file) { * @param file a file * @throws IOException if any */ - private static boolean deleteFile(@Nonnull File file) throws IOException { + private static boolean deleteFile(@NonNull File file) throws IOException { if (file.isDirectory()) { throw new IOException("File " + file + " isn't a file."); } @@ -1099,7 +1097,7 @@ private static boolean deleteFile(@Nonnull File file) throws IOException { * @deprecated use {@code org.apache.commons.io.FileUtils.forceMkdir()} */ @Deprecated - public static void forceMkdir(@Nonnull final File file) throws IOException { + public static void forceMkdir(@NonNull final File file) throws IOException { if (Os.isFamily(Os.FAMILY_WINDOWS) && !isValidWindowsFileName(file)) { throw new IllegalArgumentException( "The file (" + file.getAbsolutePath() + ") cannot contain any of the following characters: \n" @@ -1128,7 +1126,7 @@ public static void forceMkdir(@Nonnull final File file) throws IOException { * @deprecated use {@code org.apache.commons.io.FileUtils.deleteDirectory()} */ @Deprecated - public static void deleteDirectory(@Nonnull final String directory) throws IOException { + public static void deleteDirectory(@NonNull final String directory) throws IOException { deleteDirectory(new File(directory)); } @@ -1140,7 +1138,7 @@ public static void deleteDirectory(@Nonnull final String directory) throws IOExc * @deprecated use {@code org.apache.commons.io.FileUtils.deleteDirectory()} */ @Deprecated - public static void deleteDirectory(@Nonnull final File directory) throws IOException { + public static void deleteDirectory(@NonNull final File directory) throws IOException { if (!directory.exists()) { return; } @@ -1168,7 +1166,7 @@ public static void deleteDirectory(@Nonnull final File directory) throws IOExcep * @deprecated use {@code org.apache.commons.io.FileUtils.cleanDirectory()} */ @Deprecated - public static void cleanDirectory(@Nonnull final File directory) throws IOException { + public static void cleanDirectory(@NonNull final File directory) throws IOException { if (!directory.exists()) { final String message = directory + " does not exist"; throw new IllegalArgumentException(message); @@ -1208,7 +1206,7 @@ public static void cleanDirectory(@Nonnull final File directory) throws IOExcept * @deprecated use {@code org.apache.commons.io.FileUtils.sizeOf()} */ @Deprecated - public static long sizeOfDirectory(@Nonnull final String directory) { + public static long sizeOfDirectory(@NonNull final String directory) { return sizeOfDirectory(new File(directory)); } @@ -1220,7 +1218,7 @@ public static long sizeOfDirectory(@Nonnull final String directory) { * @deprecated use {@code org.apache.commons.io.FileUtils.sizeOf()} */ @Deprecated - public static long sizeOfDirectory(@Nonnull final File directory) { + public static long sizeOfDirectory(@NonNull final File directory) { if (!directory.exists()) { final String message = directory + " does not exist"; throw new IllegalArgumentException(message); @@ -1262,8 +1260,8 @@ public static long sizeOfDirectory(@Nonnull final File directory) { * @see #getFileNames(File, String, String, boolean) * @throws IOException never */ - @Nonnull - public static List getFiles(@Nonnull File directory, @Nullable String includes, @Nullable String excludes) + @NonNull + public static List getFiles(@NonNull File directory, @Nullable String includes, @Nullable String excludes) throws IOException { return getFiles(directory, includes, excludes, true); } @@ -1283,9 +1281,9 @@ public static List getFiles(@Nonnull File directory, @Nullable String incl * @throws IOException never * @see #getFileNames(File, String, String, boolean) */ - @Nonnull + @NonNull public static List getFiles( - @Nonnull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir) + @NonNull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir) throws IOException { List fileNames = getFileNames(directory, includes, excludes, includeBasedir); @@ -1311,9 +1309,9 @@ public static List getFiles( * @return a list of file names * @throws IOException never */ - @Nonnull + @NonNull public static List getFileNames( - @Nonnull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir) + @NonNull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir) throws IOException { return getFileNames(directory, includes, excludes, includeBasedir, true); } @@ -1331,9 +1329,9 @@ public static List getFileNames( * @param includeBasedir true to include the base directory at the start of each path * @return a list of relative paths of files */ - @Nonnull + @NonNull private static List getFileNames( - @Nonnull File directory, + @NonNull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir, @@ -1353,9 +1351,9 @@ private static List getFileNames( * @return a list of relative paths of directories * @throws IOException never */ - @Nonnull + @NonNull public static List getDirectoryNames( - @Nonnull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir) + @NonNull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir) throws IOException { return getDirectoryNames(directory, includes, excludes, includeBasedir, true); } @@ -1372,9 +1370,9 @@ public static List getDirectoryNames( * @return a list of relative paths of directories * @throws IOException never */ - @Nonnull + @NonNull public static List getDirectoryNames( - @Nonnull File directory, + @NonNull File directory, @Nullable String includes, @Nullable String excludes, boolean includeBasedir, @@ -1396,7 +1394,7 @@ public static List getDirectoryNames( * @param getDirectories true to include directories in the list * @return a list of relative paths */ - @Nonnull + @NonNull public static List getFileAndDirectoryNames( File directory, @Nullable String includes, @@ -1460,7 +1458,7 @@ public static List getFileAndDirectoryNames( * @deprecated use {@code org.apache.commons.io.FileUtils.copyDirectory()} */ @Deprecated - public static void copyDirectory(@Nonnull File sourceDirectory, @Nonnull File destinationDirectory) + public static void copyDirectory(@NonNull File sourceDirectory, @NonNull File destinationDirectory) throws IOException { Objects.requireNonNull(sourceDirectory); Objects.requireNonNull(destinationDirectory); @@ -1487,8 +1485,8 @@ public static void copyDirectory(@Nonnull File sourceDirectory, @Nonnull File de */ @Deprecated public static void copyDirectory( - @Nonnull File sourceDirectory, - @Nonnull File destinationDirectory, + @NonNull File sourceDirectory, + @NonNull File destinationDirectory, @Nullable String includes, @Nullable String excludes) throws IOException { @@ -1519,14 +1517,14 @@ public static void copyDirectory( * @deprecated use {@code org.apache.commons.io.FileUtils.copyDirectory()} */ @Deprecated - public static void copyDirectoryStructure(@Nonnull File sourceDirectory, @Nonnull File destinationDirectory) + public static void copyDirectoryStructure(@NonNull File sourceDirectory, @NonNull File destinationDirectory) throws IOException { copyDirectoryStructure(sourceDirectory, destinationDirectory, destinationDirectory, false); } private static void copyDirectoryStructure( - @Nonnull File sourceDirectory, - @Nonnull File destinationDirectory, + @NonNull File sourceDirectory, + @NonNull File destinationDirectory, File rootDestinationDirectory, boolean onlyModifiedFiles) throws IOException { @@ -1603,7 +1601,7 @@ private static void copyDirectoryStructure( * @deprecated use {@code java.nio.Files.move()} */ @Deprecated - public static void rename(@Nonnull File from, @Nonnull File to) throws IOException { + public static void rename(@NonNull File from, @NonNull File to) throws IOException { if (to.exists() && !deleteLegacyStyle(to)) { throw new IOException("Failed to delete " + to + " while trying to rename " + from); } @@ -1644,7 +1642,7 @@ public static void rename(@Nonnull File from, @Nonnull File to) throws IOExcepti * @deprecated use {@code java.nio.Files.createTempFile()} */ @Deprecated - public static File createTempFile(@Nonnull String prefix, @Nonnull String suffix, @Nullable File parentDir) { + public static File createTempFile(@NonNull String prefix, @NonNull String suffix, @Nullable File parentDir) { File result; String parent = System.getProperty("java.io.tmpdir"); if (parentDir != null) { @@ -1681,7 +1679,7 @@ private static int positiveRandom(Random rand) { */ @Deprecated public static void copyFile( - @Nonnull File from, @Nonnull File to, @Nullable String encoding, @Nullable FilterWrapper... wrappers) + @NonNull File from, @NonNull File to, @Nullable String encoding, @Nullable FilterWrapper... wrappers) throws IOException { copyFile(from, to, encoding, wrappers, false); } @@ -1715,8 +1713,8 @@ public abstract static class FilterWrapper { */ @Deprecated public static void copyFile( - @Nonnull File from, - @Nonnull File to, + @NonNull File from, + @NonNull File to, @Nullable String encoding, @Nullable FilterWrapper[] wrappers, boolean overwrite) @@ -1810,7 +1808,7 @@ public static void copyFile( * @param source the file to copy permissions from. * @param destination the file to copy permissions to. */ - private static void copyFilePermissions(@Nonnull File source, @Nonnull File destination) throws IOException { + private static void copyFilePermissions(@NonNull File source, @NonNull File destination) throws IOException { try { // attempt to copy posix file permissions Files.setPosixFilePermissions(destination.toPath(), Files.getPosixFilePermissions(source.toPath())); @@ -1831,8 +1829,8 @@ private static void copyFilePermissions(@Nonnull File source, @Nonnull File dest * @deprecated assumes the platform default character set */ @Deprecated - @Nonnull - public static List loadFile(@Nonnull File file) throws IOException { + @NonNull + public static List loadFile(@NonNull File file) throws IOException { List lines = new ArrayList<>(); if (file.exists()) { @@ -1871,7 +1869,7 @@ private static Charset charset(String encoding) { * true if the Os is not Windows or if the file path respect the Windows constraints. * @see #INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME */ - private static boolean isValidWindowsFileName(@Nonnull File f) { + private static boolean isValidWindowsFileName(@NonNull File f) { if (Os.isFamily(Os.FAMILY_WINDOWS)) { if (StringUtils.indexOfAny(f.getName(), INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME) != -1) { return false; @@ -1894,7 +1892,7 @@ private static boolean isValidWindowsFileName(@Nonnull File f) { * @deprecated use {@code java.nio.file.Files.isSymbolicLink(file.toPath())} */ @Deprecated - public static boolean isSymbolicLink(@Nonnull final File file) throws IOException { + public static boolean isSymbolicLink(@NonNull final File file) throws IOException { return Files.isSymbolicLink(file.toPath()); } @@ -1908,7 +1906,7 @@ public static boolean isSymbolicLink(@Nonnull final File file) throws IOExceptio * @deprecated use {@code java.nio.file.Files.isSymbolicLink(file.toPath())} */ @Deprecated - public static boolean isSymbolicLinkForSure(@Nonnull final File file) throws IOException { + public static boolean isSymbolicLinkForSure(@NonNull final File file) throws IOException { return Files.isSymbolicLink(file.toPath()); } @@ -1922,8 +1920,8 @@ public static boolean isSymbolicLinkForSure(@Nonnull final File file) throws IOE * @see Files#createSymbolicLink(Path, Path, FileAttribute[]) which creates a new symbolic link but does * not replace existing symbolic links */ - @Nonnull - public static File createSymbolicLink(@Nonnull File symlink, @Nonnull File target) throws IOException { + @NonNull + public static File createSymbolicLink(@NonNull File symlink, @NonNull File target) throws IOException { final Path symlinkPath = symlink.toPath(); if (Files.exists(symlinkPath)) { diff --git a/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java b/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java index bb90a270..1515a869 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java +++ b/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java @@ -18,9 +18,6 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -35,6 +32,9 @@ import java.io.Writer; import java.nio.channels.Channel; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + /** *

General IO Stream manipulation.

*

@@ -133,7 +133,7 @@ private IOUtil() {} * Java 9 and later {@code InputStream.transferTo()}. */ @Deprecated - public static void copy(@Nonnull final InputStream input, @Nonnull final OutputStream output) throws IOException { + public static void copy(@NonNull final InputStream input, @NonNull final OutputStream output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); } @@ -150,7 +150,7 @@ public static void copy(@Nonnull final InputStream input, @Nonnull final OutputS * Java 9 and later {@code InputStream.transferTo()}. */ @Deprecated - public static void copy(@Nonnull final InputStream input, @Nonnull final OutputStream output, final int bufferSize) + public static void copy(@NonNull final InputStream input, @NonNull final OutputStream output, final int bufferSize) throws IOException { final byte[] buffer = new byte[bufferSize]; int n; @@ -167,7 +167,7 @@ public static void copy(@Nonnull final InputStream input, @Nonnull final OutputS * @throws IOException in case of failure * @deprecated use {@code org.apache.commons.io.IOUtils.copy()}. */ @Deprecated - public static void copy(@Nonnull final Reader input, @Nonnull final Writer output) throws IOException { + public static void copy(@NonNull final Reader input, @NonNull final Writer output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); } @@ -181,7 +181,7 @@ public static void copy(@Nonnull final Reader input, @Nonnull final Writer outpu * @deprecated use {@code org.apache.commons.io.IOUtils.copy()}. */ @Deprecated - public static void copy(@Nonnull final Reader input, @Nonnull final Writer output, final int bufferSize) + public static void copy(@NonNull final Reader input, @NonNull final Writer output, final int bufferSize) throws IOException { final char[] buffer = new char[bufferSize]; int n; @@ -211,7 +211,7 @@ public static void copy(@Nonnull final Reader input, @Nonnull final Writer outpu * @deprecated use {@code org.apache.commons.io.IOUtils.copy()}. */ @Deprecated - public static void copy(@Nonnull final InputStream input, @Nonnull final Writer output) throws IOException { + public static void copy(@NonNull final InputStream input, @NonNull final Writer output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); } @@ -227,7 +227,7 @@ public static void copy(@Nonnull final InputStream input, @Nonnull final Writer * @deprecated use {@code org.apache.commons.io.IOUtils.copy()}. */ @Deprecated - public static void copy(@Nonnull final InputStream input, @Nonnull final Writer output, final int bufferSize) + public static void copy(@NonNull final InputStream input, @NonNull final Writer output, final int bufferSize) throws IOException { final InputStreamReader in = new InputStreamReader(input); copy(in, output, bufferSize); @@ -247,7 +247,7 @@ public static void copy(@Nonnull final InputStream input, @Nonnull final Writer */ @Deprecated public static void copy( - @Nonnull final InputStream input, @Nonnull final Writer output, @Nonnull final String encoding) + @NonNull final InputStream input, @NonNull final Writer output, @NonNull final String encoding) throws IOException { final InputStreamReader in = new InputStreamReader(input, encoding); copy(in, output); @@ -268,9 +268,9 @@ public static void copy( */ @Deprecated public static void copy( - @Nonnull final InputStream input, - @Nonnull final Writer output, - @Nonnull final String encoding, + @NonNull final InputStream input, + @NonNull final Writer output, + @NonNull final String encoding, final int bufferSize) throws IOException { final InputStreamReader in = new InputStreamReader(input, encoding); @@ -290,8 +290,8 @@ public static void copy( * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static String toString(@Nonnull final InputStream input) throws IOException { + @NonNull + public static String toString(@NonNull final InputStream input) throws IOException { return toString(input, DEFAULT_BUFFER_SIZE); } @@ -306,8 +306,8 @@ public static String toString(@Nonnull final InputStream input) throws IOExcepti * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static String toString(@Nonnull final InputStream input, final int bufferSize) throws IOException { + @NonNull + public static String toString(@NonNull final InputStream input, final int bufferSize) throws IOException { final StringWriter sw = new StringWriter(); copy(input, sw, bufferSize); return sw.toString(); @@ -325,8 +325,8 @@ public static String toString(@Nonnull final InputStream input, final int buffer * @deprecated use {@code org.apache.commons.io.IOUtils.toString()}. */ @Deprecated - @Nonnull - public static String toString(@Nonnull final InputStream input, @Nonnull final String encoding) throws IOException { + @NonNull + public static String toString(@NonNull final InputStream input, @NonNull final String encoding) throws IOException { return toString(input, encoding, DEFAULT_BUFFER_SIZE); } @@ -343,9 +343,9 @@ public static String toString(@Nonnull final InputStream input, @Nonnull final S * @deprecated use {@code org.apache.commons.io.IOUtils.toString()}. */ @Deprecated - @Nonnull + @NonNull public static String toString( - @Nonnull final InputStream input, @Nonnull final String encoding, final int bufferSize) throws IOException { + @NonNull final InputStream input, @NonNull final String encoding, final int bufferSize) throws IOException { final StringWriter sw = new StringWriter(); copy(input, sw, encoding, bufferSize); return sw.toString(); @@ -363,8 +363,8 @@ public static String toString( * @deprecated use {@code org.apache.commons.io.IOUtils.readFully()}. */ @Deprecated - @Nonnull - public static byte[] toByteArray(@Nonnull final InputStream input) throws IOException { + @NonNull + public static byte[] toByteArray(@NonNull final InputStream input) throws IOException { return toByteArray(input, DEFAULT_BUFFER_SIZE); } @@ -378,8 +378,8 @@ public static byte[] toByteArray(@Nonnull final InputStream input) throws IOExce * @deprecated use {@code org.apache.commons.io.IOUtils.readFully()}. */ @Deprecated - @Nonnull - public static byte[] toByteArray(@Nonnull final InputStream input, final int bufferSize) throws IOException { + @NonNull + public static byte[] toByteArray(@NonNull final InputStream input, final int bufferSize) throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output, bufferSize); return output.toByteArray(); @@ -403,7 +403,7 @@ public static byte[] toByteArray(@Nonnull final InputStream input, final int buf * @deprecated always specify a character encoding */ @Deprecated - public static void copy(@Nonnull final Reader input, @Nonnull final OutputStream output) throws IOException { + public static void copy(@NonNull final Reader input, @NonNull final OutputStream output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); } @@ -418,7 +418,7 @@ public static void copy(@Nonnull final Reader input, @Nonnull final OutputStream * @deprecated always specify a character encoding */ @Deprecated - public static void copy(@Nonnull final Reader input, @Nonnull final OutputStream output, final int bufferSize) + public static void copy(@NonNull final Reader input, @NonNull final OutputStream output, final int bufferSize) throws IOException { final OutputStreamWriter out = new OutputStreamWriter(output); copy(input, out, bufferSize); @@ -438,8 +438,8 @@ public static void copy(@Nonnull final Reader input, @Nonnull final OutputStream * @deprecated use {@code org.apache.commons.io.IOUtils.toString()}. */ @Deprecated - @Nonnull - public static String toString(@Nonnull final Reader input) throws IOException { + @NonNull + public static String toString(@NonNull final Reader input) throws IOException { return toString(input, DEFAULT_BUFFER_SIZE); } @@ -453,8 +453,8 @@ public static String toString(@Nonnull final Reader input) throws IOException { * @deprecated use {@code org.apache.commons.io.IOUtils.toString()}. */ @Deprecated - @Nonnull - public static String toString(@Nonnull final Reader input, final int bufferSize) throws IOException { + @NonNull + public static String toString(@NonNull final Reader input, final int bufferSize) throws IOException { final StringWriter sw = new StringWriter(); copy(input, sw, bufferSize); return sw.toString(); @@ -472,8 +472,8 @@ public static String toString(@Nonnull final Reader input, final int bufferSize) * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static byte[] toByteArray(@Nonnull final Reader input) throws IOException { + @NonNull + public static byte[] toByteArray(@NonNull final Reader input) throws IOException { return toByteArray(input, DEFAULT_BUFFER_SIZE); } @@ -487,8 +487,8 @@ public static byte[] toByteArray(@Nonnull final Reader input) throws IOException * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static byte[] toByteArray(@Nonnull final Reader input, final int bufferSize) throws IOException { + @NonNull + public static byte[] toByteArray(@NonNull final Reader input, final int bufferSize) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output, bufferSize); return output.toByteArray(); @@ -511,7 +511,7 @@ public static byte[] toByteArray(@Nonnull final Reader input, final int bufferSi * @deprecated always specify a character encoding */ @Deprecated - public static void copy(@Nonnull final String input, @Nonnull final OutputStream output) throws IOException { + public static void copy(@NonNull final String input, @NonNull final OutputStream output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); } @@ -526,7 +526,7 @@ public static void copy(@Nonnull final String input, @Nonnull final OutputStream * @deprecated always specify a character encoding */ @Deprecated - public static void copy(@Nonnull final String input, @Nonnull final OutputStream output, final int bufferSize) + public static void copy(@NonNull final String input, @NonNull final OutputStream output, final int bufferSize) throws IOException { final StringReader in = new StringReader(input); final OutputStreamWriter out = new OutputStreamWriter(output); @@ -548,7 +548,7 @@ public static void copy(@Nonnull final String input, @Nonnull final OutputStream * @deprecated use {@code org.apache.commons.io.IOUtils.write()}. */ @Deprecated - public static void copy(@Nonnull final String input, @Nonnull final Writer output) throws IOException { + public static void copy(@NonNull final String input, @NonNull final Writer output) throws IOException { output.write(input); } @@ -564,8 +564,8 @@ public static void copy(@Nonnull final String input, @Nonnull final Writer outpu * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static byte[] toByteArray(@Nonnull final String input) throws IOException { + @NonNull + public static byte[] toByteArray(@NonNull final String input) throws IOException { return toByteArray(input, DEFAULT_BUFFER_SIZE); } @@ -579,8 +579,8 @@ public static byte[] toByteArray(@Nonnull final String input) throws IOException * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static byte[] toByteArray(@Nonnull final String input, final int bufferSize) throws IOException { + @NonNull + public static byte[] toByteArray(@NonNull final String input, final int bufferSize) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output, bufferSize); return output.toByteArray(); @@ -605,7 +605,7 @@ public static byte[] toByteArray(@Nonnull final String input, final int bufferSi * @deprecated always specify a character encoding */ @Deprecated - public static void copy(@Nonnull final byte[] input, @Nonnull final Writer output) throws IOException { + public static void copy(@NonNull final byte[] input, @NonNull final Writer output) throws IOException { copy(input, output, DEFAULT_BUFFER_SIZE); } @@ -621,7 +621,7 @@ public static void copy(@Nonnull final byte[] input, @Nonnull final Writer outpu * @deprecated always specify a character encoding */ @Deprecated - public static void copy(@Nonnull final byte[] input, @Nonnull final Writer output, final int bufferSize) + public static void copy(@NonNull final byte[] input, @NonNull final Writer output, final int bufferSize) throws IOException { final ByteArrayInputStream in = new ByteArrayInputStream(input); copy(in, output, bufferSize); @@ -640,7 +640,7 @@ public static void copy(@Nonnull final byte[] input, @Nonnull final Writer outpu * @deprecated use {@code org.apache.commons.io.IOUtils.write()}. */ @Deprecated - public static void copy(@Nonnull final byte[] input, @Nonnull final Writer output, final String encoding) + public static void copy(@NonNull final byte[] input, @NonNull final Writer output, final String encoding) throws IOException { final ByteArrayInputStream in = new ByteArrayInputStream(input); copy(in, output, encoding); @@ -661,9 +661,9 @@ public static void copy(@Nonnull final byte[] input, @Nonnull final Writer outpu */ @Deprecated public static void copy( - @Nonnull final byte[] input, - @Nonnull final Writer output, - @Nonnull final String encoding, + @NonNull final byte[] input, + @NonNull final Writer output, + @NonNull final String encoding, final int bufferSize) throws IOException { final ByteArrayInputStream in = new ByteArrayInputStream(input); @@ -682,8 +682,8 @@ public static void copy( * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static String toString(@Nonnull final byte[] input) throws IOException { + @NonNull + public static String toString(@NonNull final byte[] input) throws IOException { return toString(input, DEFAULT_BUFFER_SIZE); } @@ -698,8 +698,8 @@ public static String toString(@Nonnull final byte[] input) throws IOException { * @deprecated always specify a character encoding */ @Deprecated - @Nonnull - public static String toString(@Nonnull final byte[] input, final int bufferSize) throws IOException { + @NonNull + public static String toString(@NonNull final byte[] input, final int bufferSize) throws IOException { final StringWriter sw = new StringWriter(); copy(input, sw, bufferSize); return sw.toString(); @@ -717,8 +717,8 @@ public static String toString(@Nonnull final byte[] input, final int bufferSize) * @deprecated use {@code new String(input, encoding)} */ @Deprecated - @Nonnull - public static String toString(@Nonnull final byte[] input, @Nonnull final String encoding) throws IOException { + @NonNull + public static String toString(@NonNull final byte[] input, @NonNull final String encoding) throws IOException { return toString(input, encoding, DEFAULT_BUFFER_SIZE); } @@ -735,8 +735,8 @@ public static String toString(@Nonnull final byte[] input, @Nonnull final String * @deprecated use {@code new String(input, encoding)} */ @Deprecated - @Nonnull - public static String toString(@Nonnull final byte[] input, @Nonnull final String encoding, final int bufferSize) + @NonNull + public static String toString(@NonNull final byte[] input, @NonNull final String encoding, final int bufferSize) throws IOException { final StringWriter sw = new StringWriter(); copy(input, sw, encoding, bufferSize); @@ -755,7 +755,7 @@ public static String toString(@Nonnull final byte[] input, @Nonnull final String * @deprecated inline this method */ @Deprecated - public static void copy(@Nonnull final byte[] input, @Nonnull final OutputStream output) throws IOException { + public static void copy(@NonNull final byte[] input, @NonNull final OutputStream output) throws IOException { output.write(input); } @@ -769,7 +769,7 @@ public static void copy(@Nonnull final byte[] input, @Nonnull final OutputStream * @deprecated use {@code org.apache.commons.io.IOUtils.contentEquals()} */ @Deprecated - public static boolean contentEquals(@Nonnull final InputStream input1, @Nonnull final InputStream input2) + public static boolean contentEquals(@NonNull final InputStream input1, @NonNull final InputStream input2) throws IOException { final InputStream bufferedInput1 = new BufferedInputStream(input1); final InputStream bufferedInput2 = new BufferedInputStream(input2); diff --git a/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java b/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java index 1aa87d88..1ec64432 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java +++ b/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java @@ -18,12 +18,12 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; - import java.io.File; import java.io.IOException; import java.nio.file.Files; +import org.jspecify.annotations.NonNull; + /** * Java7 feature detection * @@ -37,7 +37,7 @@ public class Java7Support { * @param file The file to check for being a symbolic link. * @return true if the file is a symlink false otherwise. */ - public static boolean isSymLink(@Nonnull File file) { + public static boolean isSymLink(@NonNull File file) { return Files.isSymbolicLink(file.toPath()); } @@ -46,8 +46,8 @@ public static boolean isSymLink(@Nonnull File file) { * @return The file. * @throws IOException in case of error. */ - @Nonnull - public static File readSymbolicLink(@Nonnull File symlink) throws IOException { + @NonNull + public static File readSymbolicLink(@NonNull File symlink) throws IOException { return Files.readSymbolicLink(symlink.toPath()).toFile(); } @@ -56,7 +56,7 @@ public static File readSymbolicLink(@Nonnull File symlink) throws IOException { * @return true if exist false otherwise. * @throws IOException in case of failure. */ - public static boolean exists(@Nonnull File file) throws IOException { + public static boolean exists(@NonNull File file) throws IOException { return Files.exists(file.toPath()); } @@ -66,8 +66,8 @@ public static boolean exists(@Nonnull File file) throws IOException { * @return The linked file. * @throws IOException in case of an error. */ - @Nonnull - public static File createSymbolicLink(@Nonnull File symlink, @Nonnull File target) throws IOException { + @NonNull + public static File createSymbolicLink(@NonNull File symlink, @NonNull File target) throws IOException { return FileUtils.createSymbolicLink(symlink, target); } @@ -76,7 +76,7 @@ public static File createSymbolicLink(@Nonnull File symlink, @Nonnull File targe * @param file the file to delete * @throws IOException in case of error. */ - public static void delete(@Nonnull File file) throws IOException { + public static void delete(@NonNull File file) throws IOException { Files.delete(file.toPath()); } diff --git a/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java b/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java index 75ad557f..2b57c019 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java +++ b/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.java @@ -18,14 +18,14 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; - import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.util.regex.Pattern; +import org.jspecify.annotations.NonNull; + /** *

Describes a match target for SelectorUtils.

*

@@ -46,7 +46,7 @@ public class MatchPattern { private final String[] tokenized; - private MatchPattern(@Nonnull String source, @Nonnull String separator) { + private MatchPattern(@NonNull String source, @NonNull String separator) { regexPattern = SelectorUtils.isRegexPrefixedPattern(source) ? source.substring( SelectorUtils.REGEX_HANDLER_PREFIX.length(), @@ -88,7 +88,7 @@ boolean matchPath(String str, String[] strDirs, boolean isCaseSensitive) { * @param isCaseSensitive Check case sensitive or not. * @return true in case of matching pattern. */ - public boolean matchPatternStart(@Nonnull String str, boolean isCaseSensitive) { + public boolean matchPatternStart(@NonNull String str, boolean isCaseSensitive) { if (regexPattern != null) { // FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgment until we have // a file to deal with, or we can definitely say this is an exclusion... @@ -116,7 +116,7 @@ public boolean startsWith(String string) { return source.startsWith(string); } - static String[] tokenizePathToString(@Nonnull String path, @Nonnull String separator) { + static String[] tokenizePathToString(@NonNull String path, @NonNull String separator) { List ret = new ArrayList<>(); StringTokenizer st = new StringTokenizer(path, separator); while (st.hasMoreTokens()) { diff --git a/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java b/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java index f083aa5b..78bbf217 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java +++ b/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.java @@ -18,10 +18,10 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; - import java.io.File; +import org.jspecify.annotations.NonNull; + /** * A list of patterns to be matched * @@ -32,7 +32,7 @@ public class MatchPatterns { private final MatchPattern[] patterns; - private MatchPatterns(@Nonnull MatchPattern... patterns) { + private MatchPatterns(@NonNull MatchPattern... patterns) { this.patterns = patterns; } @@ -44,7 +44,7 @@ private MatchPatterns(@Nonnull MatchPattern... patterns) { * @param isCaseSensitive If the comparison is case sensitive * @return true if any of the supplied patterns match */ - public boolean matches(@Nonnull String name, boolean isCaseSensitive) { + public boolean matches(@NonNull String name, boolean isCaseSensitive) { String[] tokenized = MatchPattern.tokenizePathToString(name, File.separator); for (MatchPattern pattern : patterns) { if (pattern.matchPath(name, tokenized, isCaseSensitive)) { @@ -59,7 +59,7 @@ public boolean matches(@Nonnull String name, boolean isCaseSensitive) { * @param isCaseSensitive being case sensetive. * @return true if any of the supplied patterns match start. */ - public boolean matchesPatternStart(@Nonnull String name, boolean isCaseSensitive) { + public boolean matchesPatternStart(@NonNull String name, boolean isCaseSensitive) { for (MatchPattern includesPattern : patterns) { if (includesPattern.matchPatternStart(name, isCaseSensitive)) { return true; @@ -72,7 +72,7 @@ public boolean matchesPatternStart(@Nonnull String name, boolean isCaseSensitive * @param sources The sources * @return Converted match patterns. */ - public static MatchPatterns from(@Nonnull String... sources) { + public static MatchPatterns from(@NonNull String... sources) { final int length = sources.length; MatchPattern[] result = new MatchPattern[length]; for (int i = 0; i < length; i++) { diff --git a/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java b/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java index 007d292a..f4e62930 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java @@ -18,13 +18,13 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; - import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; +import org.jspecify.annotations.NonNull; + /** *

This is a utility class used by selectors and DirectoryScanner. The * functionality more properly belongs just to selectors, but unfortunately @@ -513,12 +513,12 @@ private static List tokenizePath(String path, String separator) { } static boolean matchAntPathPatternStart( - @Nonnull MatchPattern pattern, @Nonnull String str, @Nonnull String separator, boolean isCaseSensitive) { + @NonNull MatchPattern pattern, @NonNull String str, @NonNull String separator, boolean isCaseSensitive) { return !separatorPatternStartSlashMismatch(pattern, str, separator) && matchAntPathPatternStart(pattern.getTokenizedPathString(), str, separator, isCaseSensitive); } - private static String[] tokenizePathToString(@Nonnull String path, @Nonnull String separator) { + private static String[] tokenizePathToString(@NonNull String path, @NonNull String separator) { List ret = new ArrayList<>(); StringTokenizer st = new StringTokenizer(path, separator); while (st.hasMoreTokens()) { @@ -528,13 +528,13 @@ private static String[] tokenizePathToString(@Nonnull String path, @Nonnull Stri } private static boolean matchAntPathPatternStart( - @Nonnull String[] patDirs, @Nonnull String str, @Nonnull String separator, boolean isCaseSensitive) { + @NonNull String[] patDirs, @NonNull String str, @NonNull String separator, boolean isCaseSensitive) { String[] strDirs = tokenizePathToString(str, separator); return matchAntPathPatternStart(patDirs, strDirs, isCaseSensitive); } private static boolean matchAntPathPatternStart( - @Nonnull String[] patDirs, @Nonnull String[] tokenizedFileName, boolean isCaseSensitive) { + @NonNull String[] patDirs, @NonNull String[] tokenizedFileName, boolean isCaseSensitive) { int patIdxStart = 0; int patIdxEnd = patDirs.length - 1; @@ -558,7 +558,7 @@ private static boolean matchAntPathPatternStart( } private static boolean separatorPatternStartSlashMismatch( - @Nonnull MatchPattern matchPattern, @Nonnull String str, @Nonnull String separator) { + @NonNull MatchPattern matchPattern, @NonNull String str, @NonNull String separator) { return str.startsWith(separator) != matchPattern.startsWith(separator); } @@ -683,9 +683,9 @@ static boolean isAntPrefixedPattern(String pattern) { } static boolean matchAntPathPattern( - @Nonnull MatchPattern matchPattern, - @Nonnull String str, - @Nonnull String separator, + @NonNull MatchPattern matchPattern, + @NonNull String str, + @NonNull String separator, boolean isCaseSensitive) { if (separatorPatternStartSlashMismatch(matchPattern, str, separator)) { return false; diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java index 2ba422da..c6cedd03 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java @@ -18,8 +18,6 @@ */ package org.apache.maven.shared.utils.xml; -import javax.annotation.Nonnull; - import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; @@ -29,6 +27,8 @@ import java.util.List; import java.util.Map; +import org.jspecify.annotations.NonNull; + /** * A reimplementation of Plexus Xpp3Dom based on the public interface of Plexus Xpp3Dom. * @@ -109,7 +109,7 @@ public Xpp3Dom(Xpp3Dom source) { * @param src The source Dom. * @param name The name of the Dom. */ - public Xpp3Dom(@Nonnull Xpp3Dom src, String name) { + public Xpp3Dom(@NonNull Xpp3Dom src, String name) { this.name = name; int size = src.getChildCount(); @@ -137,7 +137,7 @@ public String getName() { /** * @return The current value. */ - @Nonnull + @NonNull public String getValue() { return value; } @@ -145,7 +145,7 @@ public String getValue() { /** * @param value The value to be set. */ - public void setValue(@Nonnull String value) { + public void setValue(@NonNull String value) { this.value = value; } @@ -169,7 +169,7 @@ public String getAttribute(String nameParameter) { * @param nameParameter The name of the attribute. * @param valueParameter The value of the attribute. */ - public void setAttribute(@Nonnull String nameParameter, @Nonnull String valueParameter) { + public void setAttribute(@NonNull String nameParameter, @NonNull String valueParameter) { if (valueParameter == null) { throw new NullPointerException("value can not be null"); } diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java index aeadbb2e..a97e408e 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java @@ -18,9 +18,6 @@ */ package org.apache.maven.shared.utils.xml; -import javax.annotation.Nonnull; -import javax.annotation.WillClose; - import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -30,6 +27,7 @@ import java.util.List; import org.apache.maven.shared.utils.xml.pull.XmlPullParserException; +import org.jspecify.annotations.NonNull; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -48,7 +46,7 @@ public class Xpp3DomBuilder { * @return the built DOM * @throws XmlPullParserException in case of an error */ - public static Xpp3Dom build(@WillClose @Nonnull Reader reader) throws XmlPullParserException { + public static Xpp3Dom build(@NonNull Reader reader) throws XmlPullParserException { return build(reader, false); } @@ -58,7 +56,7 @@ public static Xpp3Dom build(@WillClose @Nonnull Reader reader) throws XmlPullPar * @return the built DOM * @throws XmlPullParserException in case of an error */ - public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String encoding) throws XmlPullParserException { + public static Xpp3Dom build(InputStream is, @NonNull String encoding) throws XmlPullParserException { return build(is, encoding, false); } @@ -71,8 +69,7 @@ public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String encoding) * @deprecated use the two-arg variant */ @Deprecated - public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String encoding, boolean noop) - throws XmlPullParserException { + public static Xpp3Dom build(InputStream is, @NonNull String encoding, boolean noop) throws XmlPullParserException { try { Reader reader = new InputStreamReader(is, encoding); return build(reader); @@ -89,7 +86,7 @@ public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String encoding, * @deprecated use {#build(java.io.Reader)} */ @Deprecated - public static Xpp3Dom build(@WillClose Reader in, boolean noop) throws XmlPullParserException { + public static Xpp3Dom build(Reader in, boolean noop) throws XmlPullParserException { try (Reader reader = in) { DocHandler docHandler = parseSax(new InputSource(reader)); reader.close(); @@ -99,7 +96,7 @@ public static Xpp3Dom build(@WillClose Reader in, boolean noop) throws XmlPullPa } } - private static DocHandler parseSax(@Nonnull InputSource inputSource) throws XmlPullParserException { + private static DocHandler parseSax(@NonNull InputSource inputSource) throws XmlPullParserException { try { DocHandler ch = new DocHandler(); XMLReader parser = createXmlReader(); diff --git a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java index 9f5baf30..796f671a 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java @@ -18,8 +18,6 @@ */ package org.apache.maven.shared.utils.io; -import javax.annotation.Nonnull; - import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -44,6 +42,7 @@ import org.apache.commons.io.IOUtils; import org.apache.maven.shared.utils.Os; import org.apache.maven.shared.utils.testhelpers.FileTestHelper; +import org.jspecify.annotations.NonNull; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -490,7 +489,7 @@ public Reader getReader(Reader reader) { }; } - private File write(@Nonnull String name, long lastModified, @Nonnull String text) throws IOException { + private File write(@NonNull String name, long lastModified, @NonNull String text) throws IOException { final File file = new File(tempFolder, name); try (Writer writer = new FileWriter(file)) { writer.write(text); @@ -500,7 +499,7 @@ private File write(@Nonnull String name, long lastModified, @Nonnull String text return file; } - private static void assertFileContent(@Nonnull File file, @Nonnull String expected) throws IOException { + private static void assertFileContent(@NonNull File file, @NonNull String expected) throws IOException { try (Reader in = new FileReader(file)) { assertEquals(expected, IOUtils.toString(in), "Expected " + file.getPath() + " to contain: " + expected); }