Skip to content
Open
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
19 changes: 19 additions & 0 deletions rules-openrewrite/addon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<openrewrite.version>7.15.0</openrewrite.version>
</properties>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>

<!-- Local Dependencies -->
Expand All @@ -27,6 +34,7 @@
<artifactId>rewrite-migrate-java</artifactId>
<version>0.8.0</version>
</dependency>
<!--
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
Expand All @@ -37,6 +45,17 @@
<artifactId>rewrite-java-8</artifactId>
<version>${openrewrite.version}</version>
</dependency>
-->
<dependency>
<groupId>com.github.mrizzi.rewrite</groupId>
<artifactId>rewrite-java</artifactId>
<version>windup-changes-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.mrizzi.rewrite</groupId>
<artifactId>rewrite-java-8</artifactId>
<version>windup-changes-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.context.EvaluationContext;
import org.openrewrite.ExecutionContext;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.Result;
import org.openrewrite.SourceFile;
import org.openrewrite.config.Environment;
import org.openrewrite.config.ResourceLoader;
import org.openrewrite.config.YamlResourceLoader;
import org.openrewrite.java.Java8Parser;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.tree.J;

Expand Down Expand Up @@ -104,7 +106,8 @@ public void perform(GraphRewrite event, EvaluationContext context)

Recipe recipe = env.activateRecipes("org.konveyor.tackle.JavaxToJakarta");

JavaParser javaParser = WindupJava8Parser.builder().build();
// JavaParser javaParser = WindupJava8Parser.builder().build();
JavaParser javaParser = Java8Parser.builder().build();
// TODO change this temporary solution (just for running the test) with something that
// retrieves all the ".java" files available within the input path
Path sourceRoot = Paths.get(inputFilePath);
Expand All @@ -116,9 +119,10 @@ public void perform(GraphRewrite event, EvaluationContext context)
} catch (IOException e) {
throw new Exception("Unable to list Java source files", e);
}
List<J.CompilationUnit> fileList = javaParser.parse(inputPaths, null, new InMemoryExecutionContext());
ExecutionContext ctx = new InMemoryExecutionContext(Throwable::printStackTrace);
List<J.CompilationUnit> fileList = javaParser.parse(inputPaths, null, ctx);

List<Result> results = recipe.run(fileList);
List<Result> results = recipe.run(fileList, ctx);
LOG.info(String.format("%d files changed", results.size()));
results.forEach(result -> LOG.info(result.toString()));
// TODO should results be stored into the graph in some way?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jboss.windup.rules.apps.openrewrite;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -9,6 +10,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.openrewrite.ExecutionContext;
Expand Down Expand Up @@ -67,7 +69,7 @@ static synchronized void lazyInitClassLoaders() {
ClassLoader appClassLoader = WindupJava8Parser.class.getClassLoader();

// based on https://developer.jboss.org/thread/202247
toolsAwareClassLoader = new URLClassLoader(new URL[]{appClassLoader.getResource("/")}, toolsClassLoader) {
toolsAwareClassLoader = new URLClassLoader(Collections.list(appClassLoader.getResources("")).toArray(new URL[]{}), toolsClassLoader) {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (!name.contains("ReloadableJava8") &&
Expand Down Expand Up @@ -96,6 +98,8 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
};
} catch (MalformedURLException e) {
throw new IllegalStateException("To use WindupJava8Parser, you must run the process with a JDK and not a JRE.", e);
} catch (IOException e) {
e.printStackTrace();
}
}

Expand Down