Skip to content

Commit 606471e

Browse files
author
Vincent Potucek
committed
[POC] rewrite-maven-plugin: Introduce OpenRewrite by Moderne
1 parent 3e9c164 commit 606471e

File tree

6 files changed

+91
-23
lines changed

6 files changed

+91
-23
lines changed

compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public void putRemoteFile(
537537
// We do this in here so we can checksum the artifact metadata too, otherwise it could be metadata itself
538538
for (String extension : checksums.keySet()) {
539539
// TODO shouldn't need a file intermediary - improve wagon to take a stream
540-
File temp = File.createTempFile("maven-artifact", null);
540+
File temp = Files.createTempFile("maven-artifact", null).toFile();
541541
temp.deleteOnExit();
542542
byte[] bytes = sums.get(extension).getBytes(StandardCharsets.UTF_8);
543543
Files.write(

compat/maven-compat/src/test/java/org/apache/maven/artifact/testutils/TestFileManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.file.Files;
2324
import java.util.ArrayList;
2425
import java.util.Iterator;
2526
import java.util.List;
@@ -91,7 +92,7 @@ public synchronized File createTempDir() {
9192
}
9293

9394
public synchronized File createTempFile() throws IOException {
94-
File tempFile = File.createTempFile(baseFilename, fileSuffix);
95+
File tempFile = Files.createTempFile(baseFilename, fileSuffix).toFile();
9596
tempFile.deleteOnExit();
9697
markForDeletion(tempFile);
9798

compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.file.Files;
2324

2425
import org.codehaus.plexus.util.Os;
2526
import org.junit.jupiter.api.Test;
@@ -64,7 +65,7 @@ void testWindowsPaths() throws Exception {
6465
}
6566

6667
private File createTempFile(String name) throws IOException {
67-
File tempFile = File.createTempFile(name, ".xml");
68+
File tempFile = Files.createTempFile(name, ".xml").toFile();
6869
tempFile.deleteOnExit();
6970
return tempFile;
7071
}

impl/maven-core/src/test/java/org/apache/maven/graph/ProjectSelectorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.file.Files;
2324
import java.util.ArrayList;
2425
import java.util.Collections;
2526
import java.util.HashSet;
@@ -85,7 +86,8 @@ void isMatchingProjectMatchOnSelectorReturnsTrue(String selector) {
8586

8687
@Test
8788
void isMatchingProjectMatchOnFileReturnsTrue() throws IOException {
88-
final File tempFile = File.createTempFile("maven-core-unit-test-pom", ".xml");
89+
final File tempFile =
90+
Files.createTempFile("maven-core-unit-test-pom", ".xml").toFile();
8991
final String selector = tempFile.getName();
9092
final MavenProject mavenProject = createMavenProject("maven-core");
9193
mavenProject.setFile(tempFile);

its/core-it-suite/src/test/resources/mng-0612/plugin/src/main/java/org/apache/maven/its/it0125/DependenciesMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939

4040
import java.io.BufferedWriter;
4141
import java.io.File;
42-
import java.io.FileWriter;
4342
import java.io.IOException;
43+
import java.nio.file.Files;
4444
import java.util.Iterator;
4545
import java.util.Set;
4646

@@ -78,7 +78,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
7878
}
7979

8080
try {
81-
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
81+
BufferedWriter writer = Files.newBufferedWriter(file.toPath());
8282

8383
for (Iterator iterator = artifacts.iterator(); iterator.hasNext(); ) {
8484
Artifact artifact = (Artifact) iterator.next();

pom.xml

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -714,21 +714,21 @@ under the License.
714714
<artifactId>modello-maven-plugin</artifactId>
715715
<configuration>
716716
<licenseText>Licensed to the Apache Software Foundation (ASF) under one
717-
or more contributor license agreements. See the NOTICE file
718-
distributed with this work for additional information
719-
regarding copyright ownership. The ASF licenses this file
720-
to you under the Apache License, Version 2.0 (the
721-
"License"); you may not use this file except in compliance
722-
with the License. You may obtain a copy of the License at
717+
or more contributor license agreements. See the NOTICE file
718+
distributed with this work for additional information
719+
regarding copyright ownership. The ASF licenses this file
720+
to you under the Apache License, Version 2.0 (the
721+
"License"); you may not use this file except in compliance
722+
with the License. You may obtain a copy of the License at
723723

724-
http://www.apache.org/licenses/LICENSE-2.0
724+
http://www.apache.org/licenses/LICENSE-2.0
725725

726-
Unless required by applicable law or agreed to in writing,
727-
software distributed under the License is distributed on an
728-
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
729-
KIND, either express or implied. See the License for the
730-
specific language governing permissions and limitations
731-
under the License.</licenseText>
726+
Unless required by applicable law or agreed to in writing,
727+
software distributed under the License is distributed on an
728+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
729+
KIND, either express or implied. See the License for the
730+
specific language governing permissions and limitations
731+
under the License.</licenseText>
732732
</configuration>
733733
</plugin>
734734
<!-- enforce backwards compatibility -->
@@ -807,9 +807,59 @@ under the License.</licenseText>
807807
</dependency>
808808
</dependencies>
809809
</plugin>
810+
<plugin>
811+
<groupId>org.openrewrite.maven</groupId>
812+
<artifactId>rewrite-maven-plugin</artifactId>
813+
<version>6.8.1</version>
814+
<configuration>
815+
<activeRecipes>
816+
<!-- Issue: https://github.com/apache/maven/pull/2277 -->
817+
<!-- Fix: https://github.com/openrewrite/rewrite-static-analysis/pull/558 -->
818+
<!-- <recipe>org.openrewrite.staticanalysis.ReplaceCollectToListWithToList</recipe> -->
819+
<!-- <recipe>org.openrewrite.staticanalysis.ReplaceCollectToListWithToList</recipe> -->
820+
<!-- <recipe>org.openrewrite.staticanalysis.RemoveUnusedPrivateFields</recipe> -->
821+
<!-- <recipe>org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods</recipe> -->
822+
<!-- <recipe>org.openrewrite.staticanalysis.UnnecessaryThrows</recipe> -->
823+
<!-- <recipe>org.openrewrite.java.ShortenFullyQualifiedTypeReferences</recipe> -->
824+
<!-- Issue: https://github.com/apache/maven/pull/2338 -->
825+
<!-- Fix: https://github.com/openrewrite/rewrite-static-analysis/pull/560 -->
826+
<!-- <recipe>org.openrewrite.staticanalysis.RemoveUnusedParams</recipe> -->
827+
<recipe>org.openrewrite.java.security.JavaSecurityBestPractices</recipe>
828+
<recipe>org.openrewrite.staticanalysis.RemoveUnusedLocalVariables</recipe>
829+
</activeRecipes>
830+
<exportDatatables>true</exportDatatables>
831+
<failOnDryRunResults>true</failOnDryRunResults>
832+
</configuration>
833+
<dependencies>
834+
<dependency>
835+
<groupId>org.openrewrite.recipe</groupId>
836+
<artifactId>rewrite-static-analysis</artifactId>
837+
<version>2.9.0</version>
838+
</dependency>
839+
<dependency>
840+
<groupId>org.openrewrite.recipe</groupId>
841+
<artifactId>rewrite-java-security</artifactId>
842+
<version>3.8.0</version>
843+
</dependency>
844+
</dependencies>
845+
<executions>
846+
<execution>
847+
<id>rewrite-maven-plugin</id>
848+
<goals>
849+
<goal>run</goal>
850+
</goals>
851+
<phase>verify</phase>
852+
</execution>
853+
</executions>
854+
</plugin>
810855
</plugins>
811856
</pluginManagement>
812857
<plugins>
858+
<!-- undo-->
859+
<plugin>
860+
<groupId>org.openrewrite.maven</groupId>
861+
<artifactId>rewrite-maven-plugin</artifactId>
862+
</plugin>
813863
<plugin>
814864
<groupId>io.github.olamy.maven.plugins</groupId>
815865
<artifactId>jacoco-aggregator-maven-plugin</artifactId>
@@ -822,10 +872,10 @@ under the License.</licenseText>
822872
<configuration>
823873
<asfExtOptions>
824874
<charter>The mission of the Apache Maven project is to create and maintain software
825-
libraries that provide a widely-used project build tool, targeting mainly Java
826-
development. Apache Maven promotes the use of dependencies via a
827-
standardized coordinates system, binary plugins, and a standard build
828-
lifecycle.</charter>
875+
libraries that provide a widely-used project build tool, targeting mainly Java
876+
development. Apache Maven promotes the use of dependencies via a
877+
standardized coordinates system, binary plugins, and a standard build
878+
lifecycle.</charter>
829879
</asfExtOptions>
830880
</configuration>
831881
</plugin>
@@ -1170,5 +1220,19 @@ under the License.</licenseText>
11701220
</plugins>
11711221
</build>
11721222
</profile>
1223+
<profile>
1224+
<id>rewrite</id>
1225+
<activation>
1226+
<activeByDefault>true</activeByDefault>
1227+
</activation>
1228+
<build>
1229+
<plugins>
1230+
<plugin>
1231+
<groupId>org.openrewrite.maven</groupId>
1232+
<artifactId>rewrite-maven-plugin</artifactId>
1233+
</plugin>
1234+
</plugins>
1235+
</build>
1236+
</profile>
11731237
</profiles>
11741238
</project>

0 commit comments

Comments
 (0)