Skip to content

Commit 0b50f08

Browse files
author
Vincent Potucek
committed
Migrate to Java 21 - code
1 parent 6019307 commit 0b50f08

File tree

220 files changed

+1065
-1022
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+1065
-1022
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set up JDK
3434
uses: actions/setup-java@v4
3535
with:
36-
java-version: 17
36+
java-version: 21
3737
distribution: 'temurin'
3838

3939
- name: Checkout maven

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Do you like Apache Maven? Then [donate back to the ASF](https://www.apache.org/f
6666
Quick Build
6767
-------
6868
If you want to bootstrap Maven, you'll need:
69-
- Java 17+
69+
- Java 21+
7070
- Maven 3.6.3 or later
7171
- Run Maven, specifying a location into which the completed Maven distro should be installed:
7272
```

apache-maven/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,19 @@ under the License.
118118
<dependency>
119119
<groupId>javax.annotation</groupId>
120120
<artifactId>javax.annotation-api</artifactId>
121+
<version>1.3.2</version>
121122
</dependency>
122123

123124
<!-- DI Runtime -->
124125
<dependency>
125126
<groupId>org.eclipse.sisu</groupId>
126127
<artifactId>org.eclipse.sisu.plexus</artifactId>
128+
<version>0.9.0.M3</version>
127129
</dependency>
128130
<dependency>
129131
<groupId>org.eclipse.sisu</groupId>
130132
<artifactId>org.eclipse.sisu.inject</artifactId>
133+
<version>0.9.0.M3</version>
131134
<classifier>no_asm</classifier>
132135
</dependency>
133136
<dependency>

apache-maven/src/assembly/maven/bin/mvn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ else
108108
fi
109109

110110
if ! "$JAVACMD" --enable-native-access=ALL-UNNAMED -version >/dev/null 2>&1; then
111-
echo "Error: Apache Maven 4.x requires Java 17 or newer to run." >&2
111+
echo "Error: Apache Maven 4.x requires Java 21 or newer to run." >&2
112112
"$JAVACMD" -version >&2
113113
echo "Please upgrade your Java installation or set JAVA_HOME to point to a compatible JDK." >&2
114114
exit 1

apache-maven/src/assembly/maven/bin/mvn.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ if not exist "%JAVACMD%" (
7070
goto error
7171
)
7272

73-
@REM Check Java version by testing the Java 17+ flag
73+
@REM Check Java version by testing the Java 21+ flag
7474
"%JAVACMD%" --enable-native-access=ALL-UNNAMED -version >nul 2>&1
7575
if ERRORLEVEL 1 (
76-
echo Error: Apache Maven 4.x requires Java 17 or newer to run. >&2
76+
echo Error: Apache Maven 4.x requires Java 21 or newer to run. >&2
7777
"%JAVACMD%" -version >&2
7878
echo Please upgrade your Java installation or set JAVA_HOME to point to a compatible JDK. >&2
7979
goto error

api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ default MessageBuilder newline() {
245245

246246
/**
247247
* Append formatted content to the buffer.
248-
* @see String#format(String, Object...)
248+
* @see String#formatted(Object...)
249249
*
250250
* @param pattern a <a href="../util/Formatter.html#syntax">format string</a>
251251
* @param args arguments referenced by the format specifiers in the format string
252252
* @return the current builder
253253
*/
254254
@Nonnull
255255
default MessageBuilder format(String pattern, Object... args) {
256-
return append(String.format(pattern, args));
256+
return append(pattern.formatted(args));
257257
}
258258

259259
/**

api/maven-api-core/src/main/java/org/apache/maven/api/services/ProblemCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private boolean dropProblemWithLowerSeverity(BuilderProblem.Severity severity) {
274274
List<P> problems = getProblems(s);
275275
while (!problems.isEmpty()) {
276276
try {
277-
return problems.remove(0) != null;
277+
return problems.removeFirst() != null;
278278
} catch (IndexOutOfBoundsException e) {
279279
// empty, continue
280280
}

api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionRangeResolverResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public interface VersionRangeResolverResult extends Result<VersionRangeResolverR
6565
default Optional<Version> getLowestVersion() {
6666
return getVersions().isEmpty()
6767
? Optional.empty()
68-
: Optional.of(getVersions().get(0));
68+
: Optional.of(getVersions().getFirst());
6969
}
7070

7171
/**

api/maven-api-core/src/test/java/org/apache/maven/api/services/SourcesTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.InputStream;
2323
import java.nio.file.Files;
2424
import java.nio.file.Path;
25-
import java.nio.file.Paths;
2625

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

4544
@Test
4645
void testFromPath() {
47-
Path path = Paths.get("/tmp");
46+
Path path = Path.of("/tmp");
4847
Source source = Sources.fromPath(path);
4948

5049
assertNotNull(source);
@@ -54,7 +53,7 @@ void testFromPath() {
5453

5554
@Test
5655
void testBuildSource() {
57-
Path path = Paths.get("/tmp");
56+
Path path = Path.of("/tmp");
5857
ModelSource source = Sources.buildSource(path);
5958

6059
assertNotNull(source);
@@ -64,7 +63,7 @@ void testBuildSource() {
6463

6564
@Test
6665
void testResolvedSource() {
67-
Path path = Paths.get("/tmp");
66+
Path path = Path.of("/tmp");
6867
String location = "custom-location";
6968
ModelSource source = Sources.resolvedSource(path, location);
7069

@@ -77,7 +76,7 @@ void testResolvedSource() {
7776
@Test
7877
void testPathSourceFunctionality() {
7978
// Test basic source functionality
80-
Path path = Paths.get("/tmp");
79+
Path path = Path.of("/tmp");
8180
Sources.PathSource source = (Sources.PathSource) Sources.fromPath(path);
8281

8382
assertEquals(path.normalize(), source.getPath());
@@ -91,9 +90,9 @@ void testPathSourceFunctionality() {
9190
@Test
9291
void testBuildPathSourceFunctionality() {
9392
// Test build source functionality
94-
Path basePath = Paths.get("/tmp");
93+
Path basePath = Path.of("/tmp");
9594
ModelSource.ModelLocator locator = mock(ModelSource.ModelLocator.class);
96-
Path resolvedPath = Paths.get("/tmp/subproject/pom.xml");
95+
Path resolvedPath = Path.of("/tmp/subproject/pom.xml");
9796
when(locator.locateExistingPom(any(Path.class))).thenReturn(resolvedPath);
9897

9998
Sources.BuildPathSource source = (Sources.BuildPathSource) Sources.buildSource(basePath);
@@ -109,7 +108,7 @@ void testBuildPathSourceFunctionality() {
109108
@Test
110109
void testResolvedPathSourceFunctionality() {
111110
// Test resolved source functionality
112-
Path path = Paths.get("/tmp");
111+
Path path = Path.of("/tmp");
113112
String location = "custom-location";
114113
Sources.ResolvedPathSource source = (Sources.ResolvedPathSource) Sources.resolvedSource(path, location);
115114

api/maven-api-di/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@
3333
<properties>
3434
<maven.compiler.proc>none</maven.compiler.proc>
3535
</properties>
36+
<dependencies>
37+
<dependency>
38+
<groupId>jakarta.annotation</groupId>
39+
<artifactId>jakarta.annotation-api</artifactId>
40+
<version>1.3.5</version>
41+
</dependency>
42+
</dependencies>
3643
</project>

api/maven-api-model/src/main/java/org/apache/maven/api/model/InputLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,6 @@ public interface StringFormatter {
201201

202202
@Override
203203
public String toString() {
204-
return String.format("%s @ %d:%d", source != null ? source.getLocation() : "n/a", lineNumber, columnNumber);
204+
return "%s @ %d:%d".formatted(source != null ? source.getLocation() : "n/a", lineNumber, columnNumber);
205205
}
206206
}

api/maven-api-model/src/main/mdo/maven.mdo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@
21072107
21082108
<p>If a target version, different from the base version, is specified for resources or script files,
21092109
then this value modifies the directory where the files will be copied.
2110-
For example, if {@code targetVersion} is 17, then the {@code foo/bar.properties}
2110+
For example, if {@code targetVersion} is 21, then the {@code foo/bar.properties}
21112111
resource file will be copied as {@code META-INF/versions/17/foo/bar.properties}.</p>
21122112
21132113
<p>This element can be combined with the {@code module} element for specifying sources,

compat/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.artifact.repository;
2020

2121
import java.nio.file.Path;
22-
import java.nio.file.Paths;
2322
import java.util.List;
2423

2524
import org.apache.maven.artifact.Artifact;
@@ -48,7 +47,7 @@ public interface ArtifactRepository {
4847
String getBasedir();
4948

5049
default Path getBasedirPath() {
51-
return Paths.get(getBasedir());
50+
return Path.of(getBasedir());
5251
}
5352

5453
String getProtocol();

compat/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ void normalize() {
543543
if (i == size() - 1 || get(i + 1).getType() == STRING_ITEM) {
544544
remove(i);
545545
} else if (get(i + 1).getType() == LIST_ITEM) {
546-
Item item = ((ListItem) get(i + 1)).get(0);
546+
Item item = ((ListItem) get(i + 1)).getFirst();
547547
if (item.getType() == COMBINATION_ITEM || item.getType() == STRING_ITEM) {
548548
remove(i);
549549
}

compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionIT.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.nio.file.FileVisitResult;
2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
26-
import java.nio.file.Paths;
2726
import java.nio.file.SimpleFileVisitor;
2827
import java.nio.file.attribute.BasicFileAttributes;
2928
import java.util.regex.Pattern;
@@ -36,15 +35,15 @@ class ComparableVersionIT {
3635

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

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

6564
@Override
6665
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
67-
if (Paths.get("target").equals(dir)) {
66+
if (Path.of("target").equals(dir)) {
6867
return FileVisitResult.CONTINUE;
6968
} else {
7069
return FileVisitResult.SKIP_SUBTREE;

compat/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void testMng6964() {
437437
@Test
438438
void testLocaleIndependent() {
439439
Locale orig = Locale.getDefault();
440-
Locale[] locales = {Locale.ENGLISH, new Locale("tr"), Locale.getDefault()};
440+
Locale[] locales = {Locale.ENGLISH, Locale.of("tr"), Locale.getDefault()};
441441
try {
442442
for (Locale locale : locales) {
443443
Locale.setDefault(locale);

0 commit comments

Comments
 (0)