This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch mvn4rc1 in repository https://gitbox.apache.org/repos/asf/maven-filtering.git
commit 99eac8c5d99db5d9a8f2b1640979cc9b27747295 Author: Sylwester Lachiewicz <slachiew...@apache.org> AuthorDate: Fri Nov 29 01:25:54 2024 +0100 Code cleanups --- .../filtering/AbstractFilterReaderLineEnding.java | 4 +- .../apache/maven/shared/filtering/BaseFilter.java | 17 ++++---- .../shared/filtering/DefaultMavenFileFilter.java | 8 +--- .../shared/filtering/DefaultMavenReaderFilter.java | 2 +- .../filtering/DefaultMavenResourcesFiltering.java | 6 +-- .../maven/shared/filtering/FilteringUtils.java | 4 +- .../InterpolatorFilterReaderLineEnding.java | 8 ++-- ...elimiterInterpolatorFilterReaderLineEnding.java | 6 +-- .../AbstractMavenFilteringRequestTest.java | 4 +- .../maven/shared/filtering/BoundedReaderTest.java | 9 ++-- .../filtering/DefaultMavenFileFilterTest.java | 21 ++++----- .../DefaultMavenResourcesFilteringTest.java | 51 ++++++++++------------ .../maven/shared/filtering/EscapeStringTest.java | 4 +- .../maven/shared/filtering/FilteringUtilsTest.java | 8 ++-- .../IncrementalResourceFilteringTest.java | 18 ++++---- .../maven/shared/filtering/InvalidMarkTest.java | 8 ++-- .../MuliLinesMavenResourcesFilteringTest.java | 2 +- .../maven/shared/filtering/PropertyUtilsTest.java | 4 +- .../apache/maven/shared/filtering/StubSession.java | 4 +- .../filtering/TestIncrementalBuildContext.java | 17 ++++---- .../shared/filtering/TestReflectionProperties.java | 2 +- 21 files changed, 97 insertions(+), 110 deletions(-) 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 5ef7b0e..f47de4c 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<DelimiterSpecification> delimiters = new LinkedHashSet<>(); + protected final LinkedHashSet<DelimiterSpecification> delimiters = new LinkedHashSet<>(); /** * must always be bigger than escape string plus delimiters, but doesn't need to be exact @@ -66,7 +66,7 @@ public abstract class AbstractFilterReaderLineEnding extends FilterReader { */ 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 ec78069..00a1a7c 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 @@ class BaseFilter implements DefaultFilterInfo { private static final class Wrapper extends FilterWrapper { - private LinkedHashSet<String> delimiters; + private final LinkedHashSet<String> delimiters; - private Project project; + private final Project project; - private ValueSource propertiesValueSource; + private final ValueSource propertiesValueSource; - private List<String> projectStartExpressions; + private final List<String> 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<Interpolator> interpolatorCustomizer; + private final Consumer<Interpolator> interpolatorCustomizer; Wrapper( LinkedHashSet<String> delimiters, @@ -302,6 +302,7 @@ class BaseFilter implements DefaultFilterInfo { 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 7856705..fab9657 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 class DefaultMavenFileFilter extends BaseFilter implements MavenFileFilte 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 41204ef..304e448 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 class DefaultMavenReaderFilter extends BaseFilter implements MavenReaderF @Override public Reader filter(Reader from, boolean filtering, List<FilterWrapper> filterWrappers) { - return filterWrap(from, filtering ? filterWrappers : Collections.<FilterWrapper>emptyList()); + return filterWrap(from, filtering ? filterWrappers : Collections.emptyList()); } private static Reader filterWrap(Reader from, Iterable<FilterWrapper> 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 4a6d465..406330c 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.IOException; 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 class DefaultMavenResourcesFiltering implements MavenResourcesFiltering { 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 @@ public class DefaultMavenResourcesFiltering implements MavenResourcesFiltering { 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 @@ public class DefaultMavenResourcesFiltering implements MavenResourcesFiltering { 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 a0523f1..aa12a5e 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 final class FilteringUtils { 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 @@ public final class FilteringUtils { } } - 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 be2c8e5..a6a39a0 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 e81edfc..4021330 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 class MultiDelimiterInterpolatorFilterReaderLineEnding extends AbstractFi } // 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 8f62de4..9f0a622 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 @@ import static org.hamcrest.MatcherAssert.assertThat; */ public class AbstractMavenFilteringRequestTest { - private AbstractMavenFilteringRequest request = new AbstractMavenFilteringRequest(); - private LinkedHashSet<String> delimiters = new LinkedHashSet<>(); + private final AbstractMavenFilteringRequest request = new AbstractMavenFilteringRequest(); + private final LinkedHashSet<String> 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 87d5d23..24a2df4 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.BufferedReader; 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 class BoundedReaderTest { @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 class BoundedReaderTest { 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 1fcf9fa..587f821 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 class DefaultMavenFileFilterTest { @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<FilterWrapper> 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 be08e6d..1160368 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 class DefaultMavenResourcesFilteringTest { mre.setEncoding("UTF-8"); mre.setMavenProject(mavenProject); mre.setFilters(filtersFile); - mre.setNonFilteredFileExtensions(Collections.<String>emptyList()); + mre.setNonFilteredFileExtensions(Collections.emptyList()); mre.setMavenSession(session); mre.setUseDefaultFilterWrappers(true); @@ -332,7 +332,7 @@ public class DefaultMavenResourcesFilteringTest { mre.setEncoding("UTF-8"); mre.setMavenProject(mavenProject); mre.setFilters(null); - mre.setNonFilteredFileExtensions(Collections.<String>emptyList()); + mre.setNonFilteredFileExtensions(Collections.emptyList()); mre.setMavenSession(new StubSession()); mavenResourcesFiltering.filterResources(mre); @@ -386,7 +386,7 @@ public class DefaultMavenResourcesFilteringTest { mavenProject, "UTF-8", filtersFile, - Collections.<String>emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -417,7 +417,7 @@ public class DefaultMavenResourcesFilteringTest { mavenProject, "UTF-8", filtersFile, - Collections.<String>emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -461,7 +461,7 @@ public class DefaultMavenResourcesFilteringTest { mavenProject, "UTF-8", filtersFile, - Collections.<String>emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setFlatten(true); mavenResourcesExecution.setOverwrite(true); @@ -478,7 +478,7 @@ public class DefaultMavenResourcesFilteringTest { } @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 class DefaultMavenResourcesFilteringTest { mavenProject, "UTF-8", filtersFile, - Collections.<String>emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setFlatten(true); mavenResourcesExecution.setOverwrite(false); @@ -542,7 +542,7 @@ public class DefaultMavenResourcesFilteringTest { mavenProject, "UTF-8", filtersFile, - Collections.<String>emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -590,7 +590,7 @@ public class DefaultMavenResourcesFilteringTest { mavenProject, "UTF-8", filtersFile, - Collections.<String>emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -621,7 +621,7 @@ public class DefaultMavenResourcesFilteringTest { mavenProject, "UTF-8", filtersFile, - Collections.<String>emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -632,7 +632,6 @@ public class DefaultMavenResourcesFilteringTest { assertEquals("includefile.txt", filename(files.get(0))); } - @SuppressWarnings("serial") @Test public void testEmptyDirectories() throws Exception { @@ -640,7 +639,7 @@ public class DefaultMavenResourcesFilteringTest { 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 class DefaultMavenResourcesFilteringTest { outputDirectory, mavenProject, "UTF-8", - Collections.<String>emptyList(), - Collections.<String>emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setIncludeEmptyDirs(true); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -681,7 +680,6 @@ public class DefaultMavenResourcesFilteringTest { } } - @SuppressWarnings("serial") @Test public void testShouldReturnGitIgnoreFiles() throws Exception { createTestDataStructure(); @@ -695,7 +693,7 @@ public class DefaultMavenResourcesFilteringTest { resources.add(new Resource() { { setDirectory(getBasedir() + "/target/sourceTestGitIgnoreFile"); - setIncludes(Arrays.asList("**/*")); + setIncludes(List.of("**/*")); } }); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( @@ -774,7 +772,6 @@ public class DefaultMavenResourcesFilteringTest { /** * 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 class DefaultMavenResourcesFilteringTest { output, mavenProject, "UTF-8", - Collections.<String>emptyList(), - Collections.<String>emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setIncludeEmptyDirs(true); mavenResourcesExecution.setEscapeString("\\"); @@ -916,7 +913,7 @@ public class DefaultMavenResourcesFilteringTest { 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 class DefaultMavenResourcesFilteringTest { outputDirectory, mavenProject, "UTF-8", - Collections.<String>emptyList(), - Collections.<String>emptyList(), + Collections.emptyList(), + Collections.emptyList(), new StubSession()); mavenResourcesExecution.setFilterFilenames(true); mavenResourcesFiltering.filterResources(mavenResourcesExecution); @@ -967,8 +964,8 @@ public class DefaultMavenResourcesFilteringTest { outputDirectory, mavenProject, "UTF-8", - Collections.<String>emptyList(), - Collections.<String>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 e800a8a..5c39d4f 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 61553aa..a4becde 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 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * */ 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 class FilteringUtilsTest { 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 class FilteringUtilsTest { // 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 53a36f0..62f4095 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 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @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 @@ public class IncrementalResourceFilteringTest { } @AfterEach - protected void tearDown() throws Exception { + protected void tearDown() { ThreadBuildContext.setThreadBuildContext(null); } @@ -201,7 +201,7 @@ public class IncrementalResourceFilteringTest { mre.setEncoding("UTF-8"); mre.setMavenProject(mavenProject); mre.setFilters(filtersFile); - mre.setNonFilteredFileExtensions(Collections.<String>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 c986075..4f0e98b 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 @@ public class InvalidMarkTest { } @Test - public void testEscape() throws Exception { + public void testEscape() { MavenResourcesFiltering mavenResourcesFiltering = container.getInstance(MavenResourcesFiltering.class); Resource resource = new Resource(); @@ -65,8 +65,8 @@ public class InvalidMarkTest { outputDirectory, new ProjectStub().setBasedir(Paths.get(".")), "UTF-8", - Collections.<String>emptyList(), - Collections.<String>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 c8eeb3b..625649a 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 d1d967f..b049731 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 @@ import static org.mockito.Mockito.verify; */ @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 class PropertyUtilsTest { } @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 d63a299..1ae17ef 100644 --- a/src/test/java/org/apache/maven/shared/filtering/StubSession.java +++ b/src/test/java/org/apache/maven/shared/filtering/StubSession.java @@ -37,9 +37,9 @@ import org.apache.maven.api.settings.Settings; */ public class StubSession implements Session { - private Map<String, String> userProperties; + private final Map<String, String> userProperties; - private Map<String, String> systemProperties; + private final Map<String, String> systemProperties; private final Settings settings; 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 f04b8e5..95e1e32 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 @@ import org.sonatype.plexus.build.incremental.BuildContext; public class TestIncrementalBuildContext implements BuildContext { private final Path basedir; - private final Set<Path> refresh = new HashSet<Path>(); - private final Set<Path> changedFiles = new HashSet<Path>(); - private final Set<Path> deletedFiles = new HashSet<Path>(); + private final Set<Path> refresh = new HashSet<>(); + private final Set<Path> changedFiles = new HashSet<>(); + private final Set<Path> deletedFiles = new HashSet<>(); private final Map<String, Object> context = new HashMap<>(); public TestIncrementalBuildContext(Path basedir, Set<Path> changedFiles) { @@ -71,7 +71,7 @@ public class TestIncrementalBuildContext implements BuildContext { public static void checkPath(Path path) { if (!path.isAbsolute()) { - throw new IllegalStateException(String.format("Absolute path are expected. Failing path %s" + path)); + throw new IllegalStateException(String.format("Absolute path are expected. Failing path %s", path)); } } @@ -85,8 +85,7 @@ public class TestIncrementalBuildContext implements BuildContext { */ @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 class TestIncrementalBuildContext implements BuildContext { @SuppressWarnings("unchecked") @Override - public boolean hasDelta(@SuppressWarnings("rawtypes") List relpaths) { + public boolean hasDelta(List relpaths) { return ((List<String>) relpaths).stream().anyMatch(this::hasDelta); } @@ -200,9 +199,9 @@ public class TestIncrementalBuildContext implements BuildContext { 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 e078ba7..6ffba4d 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 class TestReflectionProperties { Properties reading = new Properties(); - try (InputStream readFileInputStream = Files.newInputStream(to); ) { + try (InputStream readFileInputStream = Files.newInputStream(to)) { reading.load(readFileInputStream); }