-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Extract Jax-RS recipes to run in OR
- Loading branch information
Showing
98 changed files
with
13,302 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2021 - 2022 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. | ||
--> | ||
|
||
<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.sbm</groupId>--> | ||
<!-- <artifactId>spring-boot-migrator</artifactId>--> | ||
<!-- <version>0.15.2-SNAPSHOT</version>--> | ||
<!-- <relativePath>../..</relativePath>--> | ||
<!-- </parent>--> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>jaxrs-recipes</artifactId> | ||
<version>0.15.2-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<jaxb-maven-plugin.version>2.5.0</jaxb-maven-plugin.version> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version> | ||
<java.version>17</java.version> | ||
<spring-shell.version>2.1.14</spring-shell.version> | ||
<openrewrite.version>8.29.0</openrewrite.version> | ||
<openrewrite.spring.version>4.32.0</openrewrite.spring.version> | ||
<rewrite-migrate-java.version>1.17.0</rewrite-migrate-java.version> | ||
<spring-boot.version>3.3.1</spring-boot.version> | ||
<progressbar.version>0.10.0</progressbar.version> | ||
<testcontainers.version>1.19.1</testcontainers.version> | ||
<maven-invoker.version>3.2.0</maven-invoker.version> | ||
<shrinkwrap.resolvers.version>3.1.4</shrinkwrap.resolvers.version> | ||
<lombok.version>1.18.30</lombok.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.csvParser.outputEncoding>UTF-8</project.csvParser.outputEncoding> | ||
<generated-sources.dir>src/generated/java</generated-sources.dir> | ||
<snakeyaml.version>1.33</snakeyaml.version> | ||
<spring-asciidoctor-backends.version>0.0.7</spring-asciidoctor-backends.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- Required or dependencies, previously transitively --> | ||
<dependency> | ||
<groupId>org.openrewrite</groupId> | ||
<artifactId>rewrite-core</artifactId> | ||
<version>${openrewrite.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openrewrite</groupId> | ||
<artifactId>rewrite-java</artifactId> | ||
<version>${openrewrite.version}</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>sbm-core</artifactId> | ||
<version>${project.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.openrewrite</groupId> | ||
<artifactId>rewrite-java</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.openrewrite</groupId> | ||
<artifactId>rewrite-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<!-- <dependency>--> | ||
<!-- <groupId>org.springframework.sbm</groupId>--> | ||
<!-- <artifactId>sbm-support-boot</artifactId>--> | ||
<!-- <version>0.15.2-SNAPSHOT</version>--> | ||
<!-- </dependency>--> | ||
|
||
<dependency> | ||
<groupId>com.tngtech.archunit</groupId> | ||
<artifactId>archunit-junit5</artifactId> | ||
<version>1.2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>sbm-support-jee</artifactId> | ||
<version>0.15.2-SNAPSHOT</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>sbm-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<!-- Override Jackson coming from spring boot --> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.fasterxml.jackson.dataformat</groupId>--> | ||
<!-- <artifactId>jackson-dataformat-xml</artifactId>--> | ||
<!-- <version>${jackson.version}</version>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.fasterxml.jackson.dataformat</groupId>--> | ||
<!-- <artifactId>jackson-dataformat-smile</artifactId>--> | ||
<!-- <version>${jackson.version}</version>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.fasterxml.jackson.core</groupId>--> | ||
<!-- <artifactId>jackson-core</artifactId>--> | ||
<!-- <version>${jackson.version}</version>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.fasterxml.jackson.core</groupId>--> | ||
<!-- <artifactId>jackson-databind</artifactId>--> | ||
<!-- <version>${jackson.version}</version>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.fasterxml.jackson.core</groupId>--> | ||
<!-- <artifactId>jackson-annotations</artifactId>--> | ||
<!-- <version>${jackson.version}</version>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.fasterxml.jackson.datatype</groupId>--> | ||
<!-- <artifactId>jackson-datatype-jdk8</artifactId>--> | ||
<!-- <version>${jackson.version}</version>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.fasterxml.jackson.dataformat</groupId>--> | ||
<!-- <artifactId>jackson-dataformat-yaml</artifactId>--> | ||
<!-- <version>${jackson.version}</version>--> | ||
<!-- </dependency>--> | ||
|
||
<!-- TODO: why? remove ? --> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjweaver</artifactId> | ||
<version>1.9.7</version> | ||
</dependency> | ||
|
||
<!-- TODO: remove as these are (probably) only required in sbm-spport-jee --> | ||
<dependency> | ||
<groupId>javax.xml.bind</groupId> | ||
<artifactId>jaxb-api</artifactId> | ||
<version>2.3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jaxb</groupId> | ||
<artifactId>jaxb-runtime</artifactId> | ||
<version>2.3.3</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>test-helper</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- <dependency>--> | ||
<!-- <groupId>org.springframework.sbm</groupId>--> | ||
<!-- <artifactId>sbm-openrewrite</artifactId>--> | ||
<!-- <type>test-jar</type>--> | ||
<!-- <version>${project.version}</version>--> | ||
<!-- <scope>test</scope>--> | ||
<!-- </dependency>--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>recipe-test-support</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>sbm-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.sbm</groupId> | ||
<artifactId>sbm-core</artifactId> | ||
<version>0.15.2-SNAPSHOT</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openrewrite</groupId> | ||
<artifactId>rewrite-core</artifactId> | ||
<version>8.29.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<!-- <dependency>--> | ||
<!-- <groupId>org.junit-pioneer</groupId>--> | ||
<!-- <artifactId>junit-pioneer</artifactId>--> | ||
<!-- <version>2.1.0</version>--> | ||
<!-- <scope>test</scope>--> | ||
<!-- </dependency>--> | ||
</dependencies> | ||
<!-- <build>--> | ||
<!-- <plugins>--> | ||
<!-- <plugin>--> | ||
<!-- <groupId>org.apache.maven.plugins</groupId>--> | ||
<!-- <artifactId>maven-jar-plugin</artifactId>--> | ||
<!-- <version>3.3.0</version>--> | ||
<!-- <executions>--> | ||
<!-- <execution>--> | ||
<!-- <phase>package</phase>--> | ||
<!-- <goals>--> | ||
<!-- <goal>test-jar</goal>--> | ||
<!-- </goals>--> | ||
<!-- </execution>--> | ||
<!-- </executions>--> | ||
<!-- </plugin>--> | ||
<!-- </plugins>--> | ||
<!-- </build>--> | ||
</project> |
123 changes: 123 additions & 0 deletions
123
components/jaxrs-recipes/src/main/java/example/recipe/SbmAdapterRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* 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 example.recipe; | ||
|
||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.openrewrite.*; | ||
import org.openrewrite.internal.lang.Nullable; | ||
import org.springframework.rewrite.parser.JavaParserBuilder; | ||
import org.springframework.rewrite.resource.ProjectResourceSet; | ||
import org.springframework.rewrite.resource.ProjectResourceSetFactory; | ||
import org.springframework.rewrite.resource.RewriteMigrationResultMerger; | ||
import org.springframework.rewrite.resource.RewriteSourceFileWrapper; | ||
import org.springframework.sbm.engine.context.ProjectContext; | ||
import org.springframework.sbm.engine.context.ProjectContextFactory; | ||
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory; | ||
import org.springframework.sbm.java.refactoring.JavaRefactoringFactoryImpl; | ||
import org.springframework.sbm.java.util.BasePackageCalculator; | ||
import org.springframework.sbm.jee.jaxrs.actions.ConvertJaxRsAnnotations; | ||
import org.springframework.sbm.project.resource.ProjectResourceSetHolder; | ||
import org.springframework.sbm.project.resource.ProjectResourceWrapper; | ||
import org.springframework.sbm.project.resource.ProjectResourceWrapperRegistry; | ||
import org.springframework.sbm.project.resource.SbmApplicationProperties; | ||
|
||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Fabian Krüger | ||
*/ | ||
public class SbmAdapterRecipe extends Recipe { | ||
|
||
|
||
|
||
@Override | ||
public @NlsRewrite.DisplayName String getDisplayName() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public @NlsRewrite.Description String getDescription() { | ||
return ""; | ||
} | ||
|
||
public SbmAdapterRecipe() { | ||
|
||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return new TreeVisitor<Tree, ExecutionContext>() { | ||
|
||
private ProjectResourceSetFactory projectResourceSetFactory; | ||
private ProjectContextFactory projectContextFactory; | ||
|
||
@Override | ||
public void visit(@Nullable List<? extends Tree> nodes, ExecutionContext executionContext) { | ||
|
||
// create the required classes | ||
initBeans(executionContext); | ||
|
||
// transform nodes to SourceFiles | ||
List<SourceFile> sourceFiles = nodes.stream().filter(SourceFile.class::isInstance).map(SourceFile.class::cast).toList(); | ||
|
||
// FIXME: base dir calculation is fake | ||
Path baseDir = executionContext.getMessage("base.dir"); | ||
|
||
// Create the SBM resource set abstraction | ||
ProjectResourceSet projectResourceSet = projectResourceSetFactory.create(baseDir, sourceFiles); | ||
// Create the SBM ProjectContext | ||
ProjectContext pc = projectContextFactory.createProjectContext(baseDir, projectResourceSet); | ||
|
||
// Execute the SBM Action = the JAXRS Recipe | ||
new ConvertJaxRsAnnotations().apply(pc); | ||
|
||
// Merge back result | ||
List<? extends Tree> modifiedNodes = merge(nodes, pc.getProjectResources()); | ||
|
||
// Process other | ||
super.visit(modifiedNodes, executionContext); | ||
} | ||
|
||
private void initBeans(ExecutionContext executionContext) { | ||
RewriteSourceFileWrapper sourceFileWrapper = new RewriteSourceFileWrapper(); | ||
SbmApplicationProperties sbmApplicationProperties = new SbmApplicationProperties(); | ||
JavaParserBuilder parserBuilder = new JavaParserBuilder(); | ||
List<ProjectResourceWrapper> projectResourceWrappers = new ArrayList<>(); | ||
|
||
RewriteMigrationResultMerger merger = new RewriteMigrationResultMerger(sourceFileWrapper); | ||
ProjectResourceSetHolder holder = new ProjectResourceSetHolder(executionContext, merger); | ||
|
||
projectResourceSetFactory = new ProjectResourceSetFactory(new RewriteMigrationResultMerger(sourceFileWrapper), sourceFileWrapper, executionContext); | ||
ProjectResourceWrapperRegistry registry = new ProjectResourceWrapperRegistry(projectResourceWrappers); | ||
JavaRefactoringFactory refactoringFactory = new JavaRefactoringFactoryImpl(holder, executionContext); | ||
BasePackageCalculator calculator = new BasePackageCalculator(sbmApplicationProperties); | ||
|
||
ProjectResourceSetFactory resourceSetFactory = new ProjectResourceSetFactory(merger, sourceFileWrapper, executionContext); | ||
|
||
projectContextFactory = new ProjectContextFactory(registry, holder, refactoringFactory, calculator, parserBuilder, executionContext, merger, resourceSetFactory); | ||
} | ||
}; | ||
} | ||
|
||
private List<? extends Tree> merge(List<? extends Tree> nodes, ProjectResourceSet projectResources) { | ||
// merge the changed results into the given list and return the result | ||
return new ArrayList<>(); | ||
} | ||
|
||
} |
Oops, something went wrong.