Skip to content

[POC] Migrate to Java 21 - code #2281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'temurin'

- name: Checkout maven
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Do you like Apache Maven? Then [donate back to the ASF](https://www.apache.org/f
Quick Build
-------
If you want to bootstrap Maven, you'll need:
- Java 17+
- Java 21+
- Maven 3.6.3 or later
- Run Maven, specifying a location into which the completed Maven distro should be installed:
```
Expand Down
3 changes: 3 additions & 0 deletions apache-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ under the License.
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

<!-- DI Runtime -->
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.9.0.M3</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<version>0.9.0.M3</version>
<classifier>no_asm</classifier>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion apache-maven/src/assembly/maven/bin/mvn
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ else
fi

if ! "$JAVACMD" --enable-native-access=ALL-UNNAMED -version >/dev/null 2>&1; then
echo "Error: Apache Maven 4.x requires Java 17 or newer to run." >&2
echo "Error: Apache Maven 4.x requires Java 21 or newer to run." >&2
"$JAVACMD" -version >&2
echo "Please upgrade your Java installation or set JAVA_HOME to point to a compatible JDK." >&2
exit 1
Expand Down
4 changes: 2 additions & 2 deletions apache-maven/src/assembly/maven/bin/mvn.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ if not exist "%JAVACMD%" (
goto error
)

@REM Check Java version by testing the Java 17+ flag
@REM Check Java version by testing the Java 21+ flag
"%JAVACMD%" --enable-native-access=ALL-UNNAMED -version >nul 2>&1
if ERRORLEVEL 1 (
echo Error: Apache Maven 4.x requires Java 17 or newer to run. >&2
echo Error: Apache Maven 4.x requires Java 21 or newer to run. >&2
"%JAVACMD%" -version >&2
echo Please upgrade your Java installation or set JAVA_HOME to point to a compatible JDK. >&2
goto error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ default MessageBuilder newline() {

/**
* Append formatted content to the buffer.
* @see String#format(String, Object...)
* @see String#formatted(Object...)
*
* @param pattern a <a href="../util/Formatter.html#syntax">format string</a>
* @param args arguments referenced by the format specifiers in the format string
* @return the current builder
*/
@Nonnull
default MessageBuilder format(String pattern, Object... args) {
return append(String.format(pattern, args));
return append(pattern.formatted(args));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private boolean dropProblemWithLowerSeverity(BuilderProblem.Severity severity) {
List<P> problems = getProblems(s);
while (!problems.isEmpty()) {
try {
return problems.remove(0) != null;
return problems.removeFirst() != null;
} catch (IndexOutOfBoundsException e) {
// empty, continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface VersionRangeResolverResult extends Result<VersionRangeResolverR
default Optional<Version> getLowestVersion() {
return getVersions().isEmpty()
? Optional.empty()
: Optional.of(getVersions().get(0));
: Optional.of(getVersions().getFirst());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -44,7 +43,7 @@ class SourcesTest {

@Test
void testFromPath() {
Path path = Paths.get("/tmp");
Path path = Path.of("/tmp");
Source source = Sources.fromPath(path);

assertNotNull(source);
Expand All @@ -54,7 +53,7 @@ void testFromPath() {

@Test
void testBuildSource() {
Path path = Paths.get("/tmp");
Path path = Path.of("/tmp");
ModelSource source = Sources.buildSource(path);

assertNotNull(source);
Expand All @@ -64,7 +63,7 @@ void testBuildSource() {

@Test
void testResolvedSource() {
Path path = Paths.get("/tmp");
Path path = Path.of("/tmp");
String location = "custom-location";
ModelSource source = Sources.resolvedSource(path, location);

Expand All @@ -77,7 +76,7 @@ void testResolvedSource() {
@Test
void testPathSourceFunctionality() {
// Test basic source functionality
Path path = Paths.get("/tmp");
Path path = Path.of("/tmp");
Sources.PathSource source = (Sources.PathSource) Sources.fromPath(path);

assertEquals(path.normalize(), source.getPath());
Expand All @@ -91,9 +90,9 @@ void testPathSourceFunctionality() {
@Test
void testBuildPathSourceFunctionality() {
// Test build source functionality
Path basePath = Paths.get("/tmp");
Path basePath = Path.of("/tmp");
ModelSource.ModelLocator locator = mock(ModelSource.ModelLocator.class);
Path resolvedPath = Paths.get("/tmp/subproject/pom.xml");
Path resolvedPath = Path.of("/tmp/subproject/pom.xml");
when(locator.locateExistingPom(any(Path.class))).thenReturn(resolvedPath);

Sources.BuildPathSource source = (Sources.BuildPathSource) Sources.buildSource(basePath);
Expand All @@ -109,7 +108,7 @@ void testBuildPathSourceFunctionality() {
@Test
void testResolvedPathSourceFunctionality() {
// Test resolved source functionality
Path path = Paths.get("/tmp");
Path path = Path.of("/tmp");
String location = "custom-location";
Sources.ResolvedPathSource source = (Sources.ResolvedPathSource) Sources.resolvedSource(path, location);

Expand Down
7 changes: 7 additions & 0 deletions api/maven-api-di/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@
<properties>
<maven.compiler.proc>none</maven.compiler.proc>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ public interface StringFormatter {

@Override
public String toString() {
return String.format("%s @ %d:%d", source != null ? source.getLocation() : "n/a", lineNumber, columnNumber);
return "%s @ %d:%d".formatted(source != null ? source.getLocation() : "n/a", lineNumber, columnNumber);
}
}
2 changes: 1 addition & 1 deletion api/maven-api-model/src/main/mdo/maven.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@

<p>If a target version, different from the base version, is specified for resources or script files,
then this value modifies the directory where the files will be copied.
For example, if {@code targetVersion} is 17, then the {@code foo/bar.properties}
For example, if {@code targetVersion} is 21, then the {@code foo/bar.properties}
resource file will be copied as {@code META-INF/versions/17/foo/bar.properties}.</p>

<p>This element can be combined with the {@code module} element for specifying sources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.maven.artifact.repository;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -48,7 +47,7 @@ public interface ArtifactRepository {
String getBasedir();

default Path getBasedirPath() {
return Paths.get(getBasedir());
return Path.of(getBasedir());
}

String getProtocol();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void normalize() {
if (i == size() - 1 || get(i + 1).getType() == STRING_ITEM) {
remove(i);
} else if (get(i + 1).getType() == LIST_ITEM) {
Item item = ((ListItem) get(i + 1)).get(0);
Item item = ((ListItem) get(i + 1)).getFirst();
if (item.getType() == COMBINATION_ITEM || item.getType() == STRING_ITEM) {
remove(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.regex.Pattern;
Expand All @@ -36,15 +35,15 @@ class ComparableVersionIT {

@Test
void test() throws Exception {
Files.walkFileTree(Paths.get("target"), new SimpleFileVisitor<Path>() {
Files.walkFileTree(Path.of("target"), new SimpleFileVisitor<Path>() {
Pattern mavenArtifactJar = Pattern.compile("maven-artifact-[\\d.]+(-SNAPSHOT)?\\.jar");

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String filename = file.getFileName().toString();
if (mavenArtifactJar.matcher(filename).matches()) {
Process p = Runtime.getRuntime().exec(new String[] {
Paths.get(System.getProperty("java.home"), "bin/java").toString(),
Path.of(System.getProperty("java.home"), "bin/java").toString(),
"-jar",
file.toAbsolutePath().toString(),
"5.32",
Expand All @@ -64,7 +63,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
if (Paths.get("target").equals(dir)) {
if (Path.of("target").equals(dir)) {
return FileVisitResult.CONTINUE;
} else {
return FileVisitResult.SKIP_SUBTREE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void testMng6964() {
@Test
void testLocaleIndependent() {
Locale orig = Locale.getDefault();
Locale[] locales = {Locale.ENGLISH, new Locale("tr"), Locale.getDefault()};
Locale[] locales = {Locale.ENGLISH, Locale.of("tr"), Locale.getDefault()};
try {
for (Locale locale : locales) {
Locale.setDefault(locale);
Expand Down
Loading