Skip to content

Commit

Permalink
[MSHARED-1455] Upgrade to Maven 4.0.0-rc-1 (#135)
Browse files Browse the repository at this point in the history
Switch to Maven 4.0rc1 and code cleanups
  • Loading branch information
slachiewicz authored Dec 4, 2024
1 parent 8324f22 commit cbb12db
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 137 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

<properties>
<javaVersion>17</javaVersion>
<mavenVersion>4.0.0-beta-3</mavenVersion>
<mavenVersion>4.0.0-rc-1</mavenVersion>

<hamcrestVersion>3.0</hamcrestVersion>
<junitVersion>5.10.1</junitVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/org/apache/maven/shared/filtering/BaseFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,23 @@ void loadProperties(

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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,11 @@ public void copyFile(Path from, Path to, boolean filtering, List<FilterWrapper>
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Reader filter(MavenReaderFilterRequest mavenFileFilterRequest) throws Mav

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class InterpolatorFilterReaderLineEnding extends AbstractFilterReaderLine
/**
* Interpolator used to interpolate
*/
private Interpolator interpolator;
private final Interpolator interpolator;

private RecursionInterceptor recursionInterceptor;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class MultiDelimiterInterpolatorFilterReaderLineEnding extends AbstractFi
/**
* Interpolator used to interpolate
*/
private Interpolator interpolator;
private final Interpolator interpolator;

private RecursionInterceptor recursionInterceptor;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<FilterWrapper> wrappers = mavenFileFilter.getDefaultFilterWrappers(req);
Expand Down
Loading

0 comments on commit cbb12db

Please sign in to comment.