From cbb12dbc3253989fbedbeeef8e8f6df46a2fa434 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Wed, 4 Dec 2024 19:47:17 +0100 Subject: [PATCH] [MSHARED-1455] Upgrade to Maven 4.0.0-rc-1 (#135) Switch to Maven 4.0rc1 and code cleanups --- pom.xml | 2 +- .../AbstractFilterReaderLineEnding.java | 4 +- .../maven/shared/filtering/BaseFilter.java | 17 ++-- .../filtering/DefaultMavenFileFilter.java | 8 +- .../filtering/DefaultMavenReaderFilter.java | 2 +- .../DefaultMavenResourcesFiltering.java | 6 +- .../shared/filtering/FilteringUtils.java | 4 +- .../InterpolatorFilterReaderLineEnding.java | 8 +- ...terInterpolatorFilterReaderLineEnding.java | 6 +- .../AbstractMavenFilteringRequestTest.java | 4 +- .../shared/filtering/BoundedReaderTest.java | 9 +- .../filtering/DefaultMavenFileFilterTest.java | 21 ++--- .../DefaultMavenResourcesFilteringTest.java | 51 +++++------ .../shared/filtering/EscapeStringTest.java | 4 +- .../shared/filtering/FilteringUtilsTest.java | 8 +- .../IncrementalResourceFilteringTest.java | 18 ++-- .../shared/filtering/InvalidMarkTest.java | 8 +- .../MuliLinesMavenResourcesFilteringTest.java | 2 +- .../shared/filtering/PropertyUtilsTest.java | 4 +- .../maven/shared/filtering/StubSession.java | 89 +++++++++++++------ .../TestIncrementalBuildContext.java | 17 ++-- .../filtering/TestReflectionProperties.java | 2 +- 22 files changed, 157 insertions(+), 137 deletions(-) diff --git a/pom.xml b/pom.xml index 183c454a..eea8669c 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ 17 - 4.0.0-beta-3 + 4.0.0-rc-1 3.0 5.10.1 diff --git a/src/main/java/org/apache/maven/shared/filtering/AbstractFilterReaderLineEnding.java b/src/main/java/org/apache/maven/shared/filtering/AbstractFilterReaderLineEnding.java index 5ef7b0ed..f47de4c8 100644 --- a/src/main/java/org/apache/maven/shared/filtering/AbstractFilterReaderLineEnding.java +++ b/src/main/java/org/apache/maven/shared/filtering/AbstractFilterReaderLineEnding.java @@ -41,7 +41,7 @@ public abstract class AbstractFilterReaderLineEnding extends FilterReader { */ private boolean preserveEscapeString = false; - protected LinkedHashSet delimiters = new LinkedHashSet<>(); + protected final LinkedHashSet delimiters = new LinkedHashSet<>(); /** * must always be bigger than escape string plus delimiters, but doesn't need to be exact @@ -66,7 +66,7 @@ public String getEscapeString() { */ public void setEscapeString(String escapeString) { // TODO NPE if escapeString is null ? - if (escapeString != null && escapeString.length() >= 1) { + if (escapeString != null && !escapeString.isEmpty()) { this.escapeString = escapeString; this.useEscape = true; calculateMarkLength(); diff --git a/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java b/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java index ec78069e..00a1a7cc 100644 --- a/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java +++ b/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java @@ -207,23 +207,23 @@ void loadProperties( private static final class Wrapper extends FilterWrapper { - private LinkedHashSet delimiters; + private final LinkedHashSet delimiters; - private Project project; + private final Project project; - private ValueSource propertiesValueSource; + private final ValueSource propertiesValueSource; - private List projectStartExpressions; + private final List projectStartExpressions; - private String escapeString; + private final String escapeString; - private boolean escapeWindowsPaths; + private final boolean escapeWindowsPaths; private final Session mavenSession; - private boolean supportMultiLineFiltering; + private final boolean supportMultiLineFiltering; - private Consumer interpolatorCustomizer; + private final Consumer interpolatorCustomizer; Wrapper( LinkedHashSet delimiters, @@ -302,6 +302,7 @@ private static Interpolator createInterpolator( public Object getValue(String expression) { Object value = super.getValue(expression); if (value instanceof Optional) { + //noinspection unchecked value = ((Optional) value).orElse(null); } return value; diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java index 7856705b..fab9657f 100644 --- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java +++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java @@ -83,15 +83,11 @@ public void copyFile(Path from, Path to, boolean filtering, List throws MavenFilteringException { try { if (filtering) { - if (getLogger().isDebugEnabled()) { - getLogger().debug("filtering " + from + " to " + to); - } + getLogger().debug("filtering {} to {}", from, to); FilterWrapper[] array = filterWrappers.toArray(new FilterWrapper[0]); FilteringUtils.copyFile(from, to, encoding, array, false); } else { - if (getLogger().isDebugEnabled()) { - getLogger().debug("copy " + from + " to " + to); - } + getLogger().debug("copy {} to {}", from, to); FilteringUtils.copyFile(from, to, encoding, new FilterWrapper[0], false); } diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilter.java index 41204efb..304e4482 100644 --- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilter.java +++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilter.java @@ -61,7 +61,7 @@ public Reader filter(MavenReaderFilterRequest mavenFileFilterRequest) throws Mav @Override public Reader filter(Reader from, boolean filtering, List filterWrappers) { - return filterWrap(from, filtering ? filterWrappers : Collections.emptyList()); + return filterWrap(from, filtering ? filterWrappers : Collections.emptyList()); } private static Reader filterWrap(Reader from, Iterable wrappers) { diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java index 4a6d4652..406330c3 100644 --- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java +++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java @@ -22,6 +22,7 @@ import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -123,7 +124,7 @@ public void filterResources(MavenResourcesExecution mavenResourcesExecution) thr if (mavenResourcesExecution.getEncoding() == null || mavenResourcesExecution.getEncoding().isEmpty()) { - LOGGER.warn("Using platform encoding (" + System.getProperty("file.encoding") + LOGGER.warn("Using platform encoding (" + Charset.defaultCharset().displayName() + " actually) to copy filtered resources, i.e. build is platform dependent!"); } else { LOGGER.debug("Using '" + mavenResourcesExecution.getEncoding() + "' encoding to copy filtered resources."); @@ -404,7 +405,7 @@ private Path getDestinationFile( return destinationFile; } - private String[] setupScanner(Resource resource, Scanner scanner, boolean addDefaultExcludes) { + private void setupScanner(Resource resource, Scanner scanner, boolean addDefaultExcludes) { String[] includes; if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) { includes = resource.getIncludes().toArray(EMPTY_STRING_ARRAY); @@ -421,7 +422,6 @@ private String[] setupScanner(Resource resource, Scanner scanner, boolean addDef if (addDefaultExcludes) { scanner.addDefaultExcludes(); } - return includes; } private void copyDirectoryLayout(Path sourceDirectory, Path destinationDirectory, Scanner scanner) diff --git a/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java b/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java index a0523f1f..aa12a5e7 100644 --- a/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java +++ b/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java @@ -82,7 +82,7 @@ public static String escapeWindowsPath(String val) { if (!isEmpty(val) && PATTERN.matcher(val).matches()) { // Adapted from StringUtils.replace in plexus-utils to accommodate pre-escaped backslashes. StringBuilder buf = new StringBuilder(val.length()); - int start = 0, end = 0; + int start = 0, end; while ((end = val.indexOf('\\', start)) != -1) { buf.append(val, start, end).append("\\\\"); start = end + 1; @@ -267,7 +267,7 @@ private static String buildRelativePath(String toPath, String fromPath, final ch } } - if (relativePath.length() != 0 && toTokeniser.hasMoreTokens()) { + if (!relativePath.isEmpty() && toTokeniser.hasMoreTokens()) { relativePath.append(separatorChar); } diff --git a/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java b/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java index be2c8e51..a6a39a00 100644 --- a/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java +++ b/src/main/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEnding.java @@ -40,7 +40,7 @@ public class InterpolatorFilterReaderLineEnding extends AbstractFilterReaderLine /** * Interpolator used to interpolate */ - private Interpolator interpolator; + private final Interpolator interpolator; private RecursionInterceptor recursionInterceptor; @@ -64,16 +64,16 @@ public class InterpolatorFilterReaderLineEnding extends AbstractFilterReaderLine */ public static final String DEFAULT_END_TOKEN = "}"; - private String beginToken; + private final String beginToken; - private String endToken; + private final String endToken; /** * true by default to preserve backward comp */ private boolean interpolateWithPrefixPattern = true; - private boolean supportMultiLineFiltering; + private final boolean supportMultiLineFiltering; private boolean eof = false; diff --git a/src/main/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEnding.java b/src/main/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEnding.java index e81edfc5..40213307 100644 --- a/src/main/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEnding.java +++ b/src/main/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEnding.java @@ -42,7 +42,7 @@ public class MultiDelimiterInterpolatorFilterReaderLineEnding extends AbstractFi /** * Interpolator used to interpolate */ - private Interpolator interpolator; + private final Interpolator interpolator; private RecursionInterceptor recursionInterceptor; @@ -75,7 +75,7 @@ public class MultiDelimiterInterpolatorFilterReaderLineEnding extends AbstractFi private String endToken; - private boolean supportMultiLineFiltering; + private final boolean supportMultiLineFiltering; private static final int MAXIMUM_BUFFER_SIZE = 8192; @@ -283,7 +283,7 @@ public int read() throws IOException { } // no match means no luck, reset and return - if (beginToken == null || beginToken.length() == 0 || endToken == null || endToken.length() == 0) { + if (beginToken == null || beginToken.isEmpty() || endToken == null || endToken.isEmpty()) { in.reset(); return in.read(); diff --git a/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java b/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java index 8f62de4c..9f0a6228 100644 --- a/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java @@ -30,8 +30,8 @@ */ public class AbstractMavenFilteringRequestTest { - private AbstractMavenFilteringRequest request = new AbstractMavenFilteringRequest(); - private LinkedHashSet delimiters = new LinkedHashSet<>(); + private final AbstractMavenFilteringRequest request = new AbstractMavenFilteringRequest(); + private final LinkedHashSet delimiters = new LinkedHashSet<>(); @Test public void setDelimitersShouldNotChangeAnythingIfUsingNull() { diff --git a/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java b/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java index 87d5d232..24a2df4b 100644 --- a/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.util.Arrays; import org.junit.jupiter.api.Test; @@ -45,9 +46,7 @@ public void readTillEnd() throws IOException { @Test public void readMulti() throws IOException { char[] cbuf = new char[4]; - for (int i = 0; i < cbuf.length; i++) { - cbuf[i] = 'X'; - } + Arrays.fill(cbuf, 'X'); try (BoundedReader mr = new BoundedReader(sr, 3)) { final int read = mr.read(cbuf, 0, 4); @@ -64,9 +63,7 @@ public void readMulti() throws IOException { public void readMultiWithOffset() throws IOException { char[] cbuf = new char[4]; - for (int i = 0; i < cbuf.length; i++) { - cbuf[i] = 'X'; - } + Arrays.fill(cbuf, 'X'); try (BoundedReader mr = new BoundedReader(sr, 3)) { final int read = mr.read(cbuf, 1, 2); diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java index 1fcf9fab..587f821d 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java @@ -57,7 +57,7 @@ public class DefaultMavenFileFilterTest { @Inject Injector container; - Path to = Paths.get(getBasedir(), "target/reflection-test.properties"); + final Path to = Paths.get(getBasedir(), "target/reflection-test.properties"); @BeforeEach protected void setUp() throws Exception { @@ -178,18 +178,15 @@ public void testLineWithSingleAtAndExpression() throws Exception { @Test void testInterpolatorCustomizer() throws MavenFilteringException, IOException { AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest(); - req.setInterpolatorCustomizer(i -> { - i.addValueSource(new AbstractValueSource(false) { - - @Override - public Object getValue(String expression) { - if (expression.equals("foo")) { - return "bar"; - } - return null; + req.setInterpolatorCustomizer(i -> i.addValueSource(new AbstractValueSource(false) { + @Override + public Object getValue(String expression) { + if (expression.equals("foo")) { + return "bar"; } - }); - }); + return null; + } + })); MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class); List wrappers = mavenFileFilter.getDefaultFilterWrappers(req); diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java index be08e6d2..11603683 100644 --- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java @@ -60,9 +60,9 @@ public class DefaultMavenResourcesFilteringTest { @Inject Injector container; - private Path outputDirectory = Paths.get(getBasedir(), "target/DefaultMavenResourcesFilteringTest"); - private Path baseDir = Paths.get(getBasedir()); - private ProjectStub mavenProject = new ProjectStub().setBasedir(baseDir); + private final Path outputDirectory = Paths.get(getBasedir(), "target/DefaultMavenResourcesFilteringTest"); + private final Path baseDir = Paths.get(getBasedir()); + private final ProjectStub mavenProject = new ProjectStub().setBasedir(baseDir); private MavenResourcesFiltering mavenResourcesFiltering; @BeforeEach @@ -137,7 +137,7 @@ public void testSessionFiltering() throws Exception { mre.setEncoding("UTF-8"); mre.setMavenProject(mavenProject); mre.setFilters(filtersFile); - mre.setNonFilteredFileExtensions(Collections.emptyList()); + mre.setNonFilteredFileExtensions(Collections.emptyList()); mre.setMavenSession(session); mre.setUseDefaultFilterWrappers(true); @@ -332,7 +332,7 @@ public void testNoFiltering() throws Exception { mre.setEncoding("UTF-8"); mre.setMavenProject(mavenProject); mre.setFilters(null); - mre.setNonFilteredFileExtensions(Collections.emptyList()); + mre.setNonFilteredFileExtensions(Collections.emptyList()); mre.setMavenSession(new StubSession()); mavenResourcesFiltering.filterResources(mre); @@ -386,7 +386,7 @@ public void testIncludeOneFile() throws Exception { mavenProject, "UTF-8", filtersFile, - Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -417,7 +417,7 @@ public void testIncludeOneFileAndDirectory() throws Exception { mavenProject, "UTF-8", filtersFile, - Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -461,7 +461,7 @@ public void testFlattenDirectoryStructure() throws Exception { mavenProject, "UTF-8", filtersFile, - Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setFlatten(true); mavenResourcesExecution.setOverwrite(true); @@ -478,7 +478,7 @@ public void testFlattenDirectoryStructure() throws Exception { } @Test - public void testFlattenDirectoryStructureWithoutOverride() throws Exception { + public void testFlattenDirectoryStructureWithoutOverride() { Path baseDir = Paths.get(getBasedir()); ProjectStub mavenProject = new ProjectStub().setBasedir(baseDir); mavenProject.setVersion("1.0"); @@ -507,7 +507,7 @@ public void testFlattenDirectoryStructureWithoutOverride() throws Exception { mavenProject, "UTF-8", filtersFile, - Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setFlatten(true); mavenResourcesExecution.setOverwrite(false); @@ -542,7 +542,7 @@ public void testExcludeOneFile() throws Exception { mavenProject, "UTF-8", filtersFile, - Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -590,7 +590,7 @@ public void testTargetAbsolutePath() throws Exception { mavenProject, "UTF-8", filtersFile, - Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -621,7 +621,7 @@ public void testTargetPath() throws Exception { mavenProject, "UTF-8", filtersFile, - Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -632,7 +632,6 @@ public void testTargetPath() throws Exception { assertEquals("includefile.txt", filename(files.get(0))); } - @SuppressWarnings("serial") @Test public void testEmptyDirectories() throws Exception { @@ -640,7 +639,7 @@ public void testEmptyDirectories() throws Exception { resources.add(new Resource() { { setDirectory(getBasedir() + "/src/test/units-files/includeEmptyDirs"); - setExcludes(Arrays.asList("**/.gitignore")); + setExcludes(List.of("**/.gitignore")); } }); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( @@ -648,8 +647,8 @@ public void testEmptyDirectories() throws Exception { outputDirectory, mavenProject, "UTF-8", - Collections.emptyList(), - Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setIncludeEmptyDirs(true); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -681,7 +680,6 @@ public void testEmptyDirectories() throws Exception { } } - @SuppressWarnings("serial") @Test public void testShouldReturnGitIgnoreFiles() throws Exception { createTestDataStructure(); @@ -695,7 +693,7 @@ public void testShouldReturnGitIgnoreFiles() throws Exception { resources.add(new Resource() { { setDirectory(getBasedir() + "/target/sourceTestGitIgnoreFile"); - setIncludes(Arrays.asList("**/*")); + setIncludes(List.of("**/*")); } }); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( @@ -774,7 +772,6 @@ private static void createTestDataStructure() throws IOException { /** * unit test for MSHARED-81 : https://issues.apache.org/jira/browse/MSHARED-81 */ - @SuppressWarnings("serial") @Test public void testMSHARED81() throws Exception { mavenProject.addProperty("escaped", "this is escaped"); @@ -896,8 +893,8 @@ public void testEdgeCases() throws Exception { output, mavenProject, "UTF-8", - Collections.emptyList(), - Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setIncludeEmptyDirs(true); mavenResourcesExecution.setEscapeString("\\"); @@ -916,7 +913,7 @@ public void testEdgeCases() throws Exception { Properties expectedNonFilteredResult = PropertyUtils.loadPropertyFile( Paths.get(getBasedir() + "/src/test/units-files/edge-cases/resources", "unfiltered.properties"), null); - assertTrue(nonFilteredResult.equals(expectedNonFilteredResult)); + assertEquals(nonFilteredResult, expectedNonFilteredResult); } // MSHARED-220: Apply filtering to filenames @@ -936,8 +933,8 @@ public void testFilterFileName() throws Exception { outputDirectory, mavenProject, "UTF-8", - Collections.emptyList(), - Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setFilterFilenames(true); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -967,8 +964,8 @@ public void testFilterPropertiesFiles() throws Exception { outputDirectory, mavenProject, "UTF-8", - Collections.emptyList(), - Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setPropertiesEncoding("ISO-8859-1"); mavenResourcesFiltering.filterResources(mavenResourcesExecution); diff --git a/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java b/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java index e800a8a0..5c39d4fe 100644 --- a/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java @@ -45,9 +45,9 @@ public class EscapeStringTest { @Inject Injector container; - Path outputDirectory = Paths.get(getBasedir(), "target/EscapeStringTest"); + final Path outputDirectory = Paths.get(getBasedir(), "target/EscapeStringTest"); - Path unitDirectory = Paths.get(getBasedir(), "src/test/units-files/escape-remove-char"); + final Path unitDirectory = Paths.get(getBasedir(), "src/test/units-files/escape-remove-char"); @BeforeEach protected void setUp() throws Exception { diff --git a/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java index 61553aa3..a4becde0 100644 --- a/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java @@ -38,13 +38,13 @@ * */ public class FilteringUtilsTest { - private static Path testDirectory = Paths.get(getBasedir(), "target/test-classes/"); + private static final Path testDirectory = Paths.get(getBasedir(), "target/test-classes/"); @Test public void testMSHARED1213CopyWithTargetAlreadyExisting0ByteFile() throws IOException { Path fromFile = Paths.get(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml"); Path toFile = testDirectory.resolve("MSHARED-1213-enunciate.xml"); - Files.write(toFile, "".getBytes(StandardCharsets.UTF_8)); + Files.writeString(toFile, ""); FilteringUtils.copyFile( fromFile, toFile, @@ -67,7 +67,7 @@ public Reader getReader(Reader fileReader) { public void testMSHARED1213CopyWithTargetAlreadyExistingJunkFile() throws IOException { Path fromFile = Paths.get(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml"); Path toFile = testDirectory.resolve("MSHARED-1213-enunciate.xml"); - Files.write(toFile, "junk".getBytes(StandardCharsets.UTF_8)); + Files.writeString(toFile, "junk"); FilteringUtils.copyFile( fromFile, toFile, @@ -142,7 +142,7 @@ public void testEscapeWindowsPathInvalidDriveLetter() { // MSHARED-179 @Test - public void testEscapeWindowsPathNotAtBeginning() throws Exception { + public void testEscapeWindowsPathNotAtBeginning() { assertEquals( "jdbc:derby:C:\\\\Users\\\\Administrator/test;create=true", FilteringUtils.escapeWindowsPath("jdbc:derby:C:\\Users\\Administrator/test;create=true")); diff --git a/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java index 53a36f07..62f4095a 100644 --- a/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java @@ -48,14 +48,14 @@ @MavenDITest public class IncrementalResourceFilteringTest { - Path baseDirectory = Paths.get(getBasedir()); - Path outputDirectory = baseDirectory.resolve("target/IncrementalResourceFilteringTest"); - Path unitDirectory = baseDirectory.resolve("src/test/units-files/incremental"); - Path filters = unitDirectory.resolve("filters.txt"); - Path inputFile01 = unitDirectory.resolve("files/file01.txt"); + final Path baseDirectory = Paths.get(getBasedir()); + final Path outputDirectory = baseDirectory.resolve("target/IncrementalResourceFilteringTest"); + final Path unitDirectory = baseDirectory.resolve("src/test/units-files/incremental"); + final Path filters = unitDirectory.resolve("filters.txt"); + final Path inputFile01 = unitDirectory.resolve("files/file01.txt"); Path inputFile02 = unitDirectory.resolve("files/file02.txt"); - Path outputFile01 = outputDirectory.resolve("file01.txt"); - Path outputFile02 = outputDirectory.resolve("file02.txt"); + final Path outputFile01 = outputDirectory.resolve("file01.txt"); + final Path outputFile02 = outputDirectory.resolve("file02.txt"); @Inject Injector container; @@ -67,7 +67,7 @@ protected void setUp() throws Exception { } @AfterEach - protected void tearDown() throws Exception { + protected void tearDown() { ThreadBuildContext.setThreadBuildContext(null); } @@ -201,7 +201,7 @@ private void filter(String time) throws Exception { mre.setEncoding("UTF-8"); mre.setMavenProject(mavenProject); mre.setFilters(filtersFile); - mre.setNonFilteredFileExtensions(Collections.emptyList()); + mre.setNonFilteredFileExtensions(Collections.emptyList()); mre.setMavenSession(new StubSession()); mre.setUseDefaultFilterWrappers(true); diff --git a/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java b/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java index c9860754..4f0e98be 100644 --- a/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java @@ -42,7 +42,7 @@ public class InvalidMarkTest { @Inject Injector container; - Path outputDirectory = Paths.get(getBasedir(), "target/LongLineTest"); + final Path outputDirectory = Paths.get(getBasedir(), "target/LongLineTest"); @BeforeEach protected void setUp() throws Exception { @@ -53,7 +53,7 @@ protected void setUp() throws Exception { } @Test - public void testEscape() throws Exception { + public void testEscape() { MavenResourcesFiltering mavenResourcesFiltering = container.getInstance(MavenResourcesFiltering.class); Resource resource = new Resource(); @@ -65,8 +65,8 @@ public void testEscape() throws Exception { outputDirectory, new ProjectStub().setBasedir(Paths.get(".")), "UTF-8", - Collections.emptyList(), - Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); try { diff --git a/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java index c8eeb3be..625649aa 100644 --- a/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java @@ -47,7 +47,7 @@ public class MuliLinesMavenResourcesFilteringTest { @Inject Injector container; - Path outputDirectory = Paths.get(getBasedir(), "target/MuliLinesMavenResourcesFilteringTest"); + final Path outputDirectory = Paths.get(getBasedir(), "target/MuliLinesMavenResourcesFilteringTest"); @BeforeEach protected void setUp() throws Exception { diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java index d1d967f8..b049731d 100644 --- a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java @@ -46,7 +46,7 @@ */ @MavenDITest public class PropertyUtilsTest { - private static Path testDirectory = Paths.get(getBasedir(), "target/test-classes/"); + private static final Path testDirectory = Paths.get(getBasedir(), "target/test-classes/"); @Test public void testBasic() throws Exception { @@ -82,7 +82,7 @@ public void testSystemProperties() throws Exception { } @Test - public void testException() throws Exception { + public void testException() { Path nonExistent = testDirectory.resolve("not_existent_file"); assertFalse(Files.exists(nonExistent), "property file exist: " + nonExistent); diff --git a/src/test/java/org/apache/maven/shared/filtering/StubSession.java b/src/test/java/org/apache/maven/shared/filtering/StubSession.java index 0fec2f06..1ae17ef9 100644 --- a/src/test/java/org/apache/maven/shared/filtering/StubSession.java +++ b/src/test/java/org/apache/maven/shared/filtering/StubSession.java @@ -30,15 +30,16 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nullable; import org.apache.maven.api.model.Repository; +import org.apache.maven.api.services.VersionResolverException; import org.apache.maven.api.settings.Settings; /** */ public class StubSession implements Session { - private Map userProperties; + private final Map userProperties; - private Map systemProperties; + private final Map systemProperties; private final Settings settings; @@ -198,102 +199,134 @@ public Artifact createArtifact( } @Override - public ArtifactCoordinate createArtifactCoordinate(String s, String s1, String s2, String s3) { + public ProducedArtifact createProducedArtifact(String s, String s1, String s2, String s3) { return null; } @Override - public ArtifactCoordinate createArtifactCoordinate(String coordString) { + public ProducedArtifact createProducedArtifact(String s, String s1, String s2, String s3, String s4, String s5) { return null; } @Override - public ArtifactCoordinate createArtifactCoordinate( - String s, String s1, String s2, String s3, String s4, String s5) { + public ArtifactCoordinates createArtifactCoordinates(String s, String s1, String s2, String s3) { return null; } @Override - public ArtifactCoordinate createArtifactCoordinate(Artifact artifact) { + public ArtifactCoordinates createArtifactCoordinates(String coordString) { return null; } @Override - public DependencyCoordinate createDependencyCoordinate(ArtifactCoordinate artifactCoordinate) { + public ArtifactCoordinates createArtifactCoordinates( + String s, String s1, String s2, String s3, String s4, String s5) { return null; } @Override - public DependencyCoordinate createDependencyCoordinate(Dependency dependency) { + public ArtifactCoordinates createArtifactCoordinates(Artifact artifact) { return null; } @Override - public Map.Entry resolveArtifact(Artifact artifact) { + public DependencyCoordinates createDependencyCoordinates(ArtifactCoordinates artifactCoordinate) { return null; } @Override - public Map.Entry resolveArtifact(ArtifactCoordinate coordinate) { + public DependencyCoordinates createDependencyCoordinates(Dependency dependency) { return null; } @Override - public Map resolveArtifacts(ArtifactCoordinate... artifactCoordinates) { + public DownloadedArtifact resolveArtifact(Artifact artifact) { return null; } @Override - public Map resolveArtifacts(Collection collection) { + public DownloadedArtifact resolveArtifact(Artifact artifact, List list) { return null; } @Override - public Map resolveArtifacts(Artifact... artifacts) { + public DownloadedArtifact resolveArtifact(ArtifactCoordinates coordinate) { return null; } @Override - public List flattenDependencies(Node node, PathScope scope) { + public DownloadedArtifact resolveArtifact(ArtifactCoordinates artifactCoordinates, List list) { return null; } @Override - public List resolveDependencies(DependencyCoordinate dependencyCoordinate) { + public Collection resolveArtifacts(ArtifactCoordinates... artifactCoordinates) { return null; } @Override - public List resolveDependencies(List dependencyCoordinates) { + public Collection resolveArtifacts(Collection collection) { return null; } @Override - public List resolveDependencies(Project project, PathScope scope) { + public Collection resolveArtifacts( + Collection collection, List list) { + return List.of(); + } + + @Override + public Collection resolveArtifacts(Artifact... artifacts) { + return null; + } + + @Override + public void installArtifacts(ProducedArtifact... producedArtifacts) {} + + @Override + public void installArtifacts(Collection collection) {} + + @Override + public void deployArtifact(RemoteRepository remoteRepository, ProducedArtifact... producedArtifacts) {} + + @Override + public void setArtifactPath(ProducedArtifact producedArtifact, Path path) {} + + @Override + public List flattenDependencies(Node node, PathScope scope) { return null; } @Override - public Version resolveVersion(ArtifactCoordinate artifact) { + public List resolveDependencies(DependencyCoordinates dependencyCoordinate) { return null; } @Override - public List resolveVersionRange(ArtifactCoordinate artifact) { + public List resolveDependencies(List dependencyCoordinates) { return null; } @Override - public void installArtifacts(Artifact... artifacts) {} + public List resolveDependencies(Project project, PathScope scope) { + return null; + } @Override - public void installArtifacts(Collection artifacts) {} + public Version resolveVersion(ArtifactCoordinates artifact) { + return null; + } @Override - public void deployArtifact(RemoteRepository repository, Artifact... artifacts) {} + public List resolveVersionRange(ArtifactCoordinates artifact) { + return null; + } @Override - public void setArtifactPath(Artifact artifact, Path path) {} + public List resolveVersionRange(ArtifactCoordinates artifactCoordinates, List list) + throws VersionResolverException { + return List.of(); + } @Override public Optional getArtifactPath(Artifact artifact) { @@ -306,17 +339,17 @@ public boolean isVersionSnapshot(String version) { } @Override - public Node collectDependencies(Artifact artifact) { + public Node collectDependencies(Artifact artifact, PathScope pathScope) { return null; } @Override - public Node collectDependencies(Project project) { + public Node collectDependencies(Project project, PathScope pathScope) { return null; } @Override - public Node collectDependencies(DependencyCoordinate dependencyCoordinate) { + public Node collectDependencies(DependencyCoordinates dependencyCoordinates, PathScope pathScope) { return null; } @@ -347,7 +380,7 @@ public VersionConstraint parseVersionConstraint(String s) { @Override public Map> resolveDependencies( - DependencyCoordinate dependencyCoordinate, PathScope scope, Collection desiredTypes) { + DependencyCoordinates dependencyCoordinates, PathScope scope, Collection desiredTypes) { return Map.of(); } diff --git a/src/test/java/org/apache/maven/shared/filtering/TestIncrementalBuildContext.java b/src/test/java/org/apache/maven/shared/filtering/TestIncrementalBuildContext.java index f04b8e56..95e1e328 100644 --- a/src/test/java/org/apache/maven/shared/filtering/TestIncrementalBuildContext.java +++ b/src/test/java/org/apache/maven/shared/filtering/TestIncrementalBuildContext.java @@ -51,9 +51,9 @@ public class TestIncrementalBuildContext implements BuildContext { private final Path basedir; - private final Set refresh = new HashSet(); - private final Set changedFiles = new HashSet(); - private final Set deletedFiles = new HashSet(); + private final Set refresh = new HashSet<>(); + private final Set changedFiles = new HashSet<>(); + private final Set deletedFiles = new HashSet<>(); private final Map context = new HashMap<>(); public TestIncrementalBuildContext(Path basedir, Set changedFiles) { @@ -71,7 +71,7 @@ public TestIncrementalBuildContext(Path basedir, Set changedFiles, Set getRefreshFiles() { */ @Override public boolean hasDelta(String relpath) { - Path resolved = basedir.resolve(relpath); - Path candidate = resolved; + Path candidate = basedir.resolve(relpath); boolean changed = false; while (candidate != null) { changed = changedFiles.contains(candidate) || deletedFiles.contains(candidate); @@ -100,7 +99,7 @@ public boolean hasDelta(String relpath) { @SuppressWarnings("unchecked") @Override - public boolean hasDelta(@SuppressWarnings("rawtypes") List relpaths) { + public boolean hasDelta(List relpaths) { return ((List) relpaths).stream().anyMatch(this::hasDelta); } @@ -200,9 +199,9 @@ public String[] getIncludedDirectories() { public String[] getIncludedFiles() { return files.stream() .filter(p -> p.startsWith(basedir)) - .map(p -> basedir.relativize(p)) + .map(basedir::relativize) .map(Path::toString) - .toArray(i -> new String[i]); + .toArray(String[]::new); } @Override diff --git a/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java index e078ba7d..6ffba4da 100644 --- a/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java +++ b/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java @@ -93,7 +93,7 @@ public void testSimpleNonFiltering() throws Exception { Properties reading = new Properties(); - try (InputStream readFileInputStream = Files.newInputStream(to); ) { + try (InputStream readFileInputStream = Files.newInputStream(to)) { reading.load(readFileInputStream); }