Extract test helper module
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -18,6 +18,8 @@
|
||||
<module>spring-rewrite-commons-starters</module>
|
||||
<module>spring-rewrite-commons-gradle</module>
|
||||
<module>spring-rewrite-commons-plugin-invoker</module>
|
||||
<module>spring-rewrite-commons-utils</module>
|
||||
<module>spring-rewrite-commons-test</module>
|
||||
</modules>
|
||||
|
||||
<organization>
|
||||
@@ -129,6 +131,11 @@
|
||||
<artifactId>rewrite-core</artifactId>
|
||||
<version>${rewrite.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.rewrite</groupId>
|
||||
<artifactId>spring-rewrite-commons-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.rewrite</groupId>
|
||||
<artifactId>spring-rewrite-commons-examples</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.rewrite.example</groupId>
|
||||
<artifactId>plugin-invoker-boot-upgrade-examples</artifactId>
|
||||
<name>plugin-invoker-boot-upgrade-examples</name>
|
||||
<description>plugin-invoker-boot-upgrade-examples</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.rewrite</groupId>
|
||||
<artifactId>spring-rewrite-commons-plugin-invoker-polyglot</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.rewrite</groupId>
|
||||
<artifactId>spring-rewrite-commons-utils</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2021 - 2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.rewrite;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.rewrite.plugin.polyglot.RewritePlugin;
|
||||
import org.springframework.rewrite.plugin.shared.PluginInvocationResult;
|
||||
import org.springframework.rewrite.utils.GitHub;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@SpringBootApplication
|
||||
public class BootUpgradeWithRewritePluginExample implements ApplicationRunner {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BootUpgradeWithRewritePluginExample.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
String repo = args.getNonOptionArgs().get(0);
|
||||
String gitHash = args.getNonOptionArgs().get(1);
|
||||
String token = args.getNonOptionArgs().get(2);
|
||||
Path projectDir = Path.of(args.getNonOptionArgs().get(3));
|
||||
|
||||
Git clone = GitHub.clone(repo, projectDir, token);
|
||||
GitHub.checkoutCommit(clone, gitHash);
|
||||
|
||||
PluginInvocationResult pluginInvocationResult = RewritePlugin.run()
|
||||
.gradlePluginVersion("latest.release")
|
||||
.recipes("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2")
|
||||
.dependencies("org.openrewrite.recipe:rewrite-migrate-java:LATEST",
|
||||
"org.openrewrite.recipe:rewrite-hibernate:LATEST",
|
||||
"org.openrewrite.recipe:rewrite-java-dependencies:LATEST",
|
||||
"org.openrewrite.recipe:rewrite-testing-frameworks:LATEST",
|
||||
"org.openrewrite.recipe:rewrite-static-analysis:LATEST", "org.openrewrite:rewrite-kotlin:LATEST",
|
||||
"org.openrewrite.recipe:rewrite-spring:LATEST")
|
||||
.onDir(projectDir);
|
||||
|
||||
System.out.println(pluginInvocationResult.capturedOutput());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
spring.application.name=plugin-invoker-boot-upgrade-examples
|
||||
@@ -20,6 +20,7 @@
|
||||
<module>boot-3-upgrade-atomic-example</module>
|
||||
<module>boot-3-upgrade-iterative-example</module>
|
||||
<module>list-applicable-recipes-example</module>
|
||||
<module>plugin-invoker-boot-upgrade-examples</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
||||
50
spring-rewrite-commons-test/pom.xml
Normal file
50
spring-rewrite-commons-test/pom.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.rewrite</groupId>
|
||||
<artifactId>spring-rewrite-commons</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>spring-rewrite-commons-test</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.rewrite</groupId>
|
||||
<artifactId>spring-rewrite-commons-utils</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
<!-- Using shaded JGit from OR -->
|
||||
<dependency>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-core</artifactId>
|
||||
<version>${rewrite.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit-pioneer</groupId>
|
||||
<artifactId>junit-pioneer</artifactId>
|
||||
<version>${junit-pioneer.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
29
spring-rewrite-commons-utils/pom.xml
Normal file
29
spring-rewrite-commons-utils/pom.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.rewrite</groupId>
|
||||
<artifactId>spring-rewrite-commons</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>spring-rewrite-commons-utils</artifactId>
|
||||
|
||||
<name>Utils</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jgit</groupId>
|
||||
<artifactId>org.eclipse.jgit</artifactId>
|
||||
<version>5.13.0.202109080827-r</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2021 - 2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.rewrite.utils;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* @author Fabian Krüger
|
||||
*/
|
||||
public class GitHub {
|
||||
|
||||
public static Git clone(String repositoryUrl, Path targetDir, String token) {
|
||||
try {
|
||||
Git git = Git.cloneRepository()
|
||||
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(token, ""))
|
||||
.setURI(repositoryUrl)
|
||||
.setDirectory(targetDir.toFile())
|
||||
.call();
|
||||
return git;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkoutCommit(Git git, String startingGitHash) {
|
||||
try {
|
||||
Ref ref = git.checkout().setName(startingGitHash).call();
|
||||
}
|
||||
catch (GitAPIException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user