Upgrade Rewrite dependencies to 7.32.1, 4.29 and 1.13

This commit is contained in:
aboyko
2022-11-03 16:34:36 -04:00
parent 2d6b8ca47d
commit de524da138
5 changed files with 45 additions and 22 deletions

View File

@@ -27,13 +27,21 @@
<artifactId>commons-java</artifactId>
<version>${project.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.classgraph/classgraph -->
<!-- ObjectDiff object becomes unresolved all of a sudden for JDT compiler as of rewrite 7.32.1. The dependency should come from rewrite -->
<!-- Try to remove in the future as it only seems to be required by Eclipse JDT. Maven build is happy without it -->
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.149</version>
<groupId>de.danielbechler</groupId>
<artifactId>java-object-diff</artifactId>
<version>0.95</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.149</version>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-properties</artifactId>

View File

@@ -10,6 +10,7 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.rewrite.config;
import static java.util.Collections.emptyList;
import static org.openrewrite.internal.RecipeIntrospectionUtils.constructRecipe;
import static org.openrewrite.internal.RecipeIntrospectionUtils.recipeDescriptorFromRecipe;
@@ -48,7 +49,7 @@ public class StsClasspathScanningLoader implements ResourceLoader, StsResourceLo
private final List<CodeActionRepository> codeActionRepos = new ArrayList<>();
public StsClasspathScanningLoader(Path p, Properties properties, ClassLoader classLoader) {
public StsClasspathScanningLoader(Path p, Properties properties, Collection<? extends ResourceLoader> dependencyResourceLoaders, ClassLoader classLoader) {
if (Files.isDirectory(p)) {
String dir = p.toString();
@@ -61,7 +62,7 @@ public class StsClasspathScanningLoader implements ResourceLoader, StsResourceLo
.acceptPaths(dir)
.ignoreParentClassLoaders()
.overrideClassLoaders(classLoader)
.acceptPaths("META-INF/rewrite"), properties, classLoader);
.acceptPaths("META-INF/rewrite"), properties, dependencyResourceLoaders, classLoader);
} else {
String jarName = p.toFile().getName();
@@ -75,14 +76,14 @@ public class StsClasspathScanningLoader implements ResourceLoader, StsResourceLo
.acceptJars(jarName)
.ignoreParentClassLoaders()
.overrideClassLoaders(classLoader)
.acceptPaths("META-INF/rewrite"), properties, classLoader);
.acceptPaths("META-INF/rewrite"), properties, dependencyResourceLoaders, classLoader);
}
}
public StsClasspathScanningLoader(Properties properties, String[] acceptPackages) {
scanClasses(new ClassGraph().acceptPackages(acceptPackages), getClass().getClassLoader());
scanYaml(new ClassGraph().acceptPaths("META-INF/rewrite"), properties, null);
scanYaml(new ClassGraph().acceptPaths("META-INF/rewrite"), properties, emptyList(), null);
}
/**
@@ -99,19 +100,19 @@ public class StsClasspathScanningLoader implements ResourceLoader, StsResourceLo
scanYaml(new ClassGraph()
.ignoreParentClassLoaders()
.overrideClassLoaders(classLoader)
.acceptPaths("META-INF/rewrite"), properties, classLoader);
.acceptPaths("META-INF/rewrite"), properties, emptyList(), classLoader);
}
/**
* This must be called _after_ scanClasses or the descriptors of declarative recipes will be missing any
* non-declarative recipes they depend on that would be discovered by scanClasses
*/
private void scanYaml(ClassGraph classGraph, Properties properties, @Nullable ClassLoader classLoader) {
private void scanYaml(ClassGraph classGraph, Properties properties, Collection<? extends ResourceLoader> dependencyResourceLoaders, @Nullable ClassLoader classLoader) {
try (ScanResult scanResult = classGraph.enableMemoryMapping().scan()) {
List<YamlResourceLoader> yamlResourceLoaders = new ArrayList<>();
scanResult.getResourcesWithExtension("yml").forEachInputStreamIgnoringIOException((res, input) -> {
yamlResourceLoaders.add(new YamlResourceLoader(input, res.getURI(), properties, classLoader));
yamlResourceLoaders.add(new YamlResourceLoader(input, res.getURI(), properties, classLoader, dependencyResourceLoaders));
});
// Extract in two passes so that the full list of recipes from all sources are known when computing recipe descriptors
// Otherwise recipes which include recipes from other sources in their recipeList will have incomplete descriptors

View File

@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.commons.rewrite.config;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
@@ -19,9 +20,12 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openrewrite.config.ClasspathScanningLoader;
import org.openrewrite.config.Environment;
import org.openrewrite.config.ResourceLoader;
import static java.util.Collections.emptyList;
public class StsEnvironment extends Environment {
final private Supplier<Stream<CodeActionRepository>> codeActionRepos;
@@ -51,12 +55,22 @@ public class StsEnvironment extends Environment {
}
@Override
public org.openrewrite.config.Environment.Builder scanJar(Path jar, ClassLoader classLoader) {
return load(new StsClasspathScanningLoader(jar, props, classLoader));
public Environment.Builder scanJar(Path jar, Collection<Path> dependencies, ClassLoader classLoader) {
List<ClasspathScanningLoader> list = new ArrayList<>();
for (Path dep : dependencies) {
ClasspathScanningLoader classpathScanningLoader = new ClasspathScanningLoader(dep, props, emptyList(), classLoader);
list.add(classpathScanningLoader);
}
return load(new StsClasspathScanningLoader(jar, props, list, classLoader), list);
}
public org.openrewrite.config.Environment.Builder scanPath(Path dir, ClassLoader classLoader) {
return load(new StsClasspathScanningLoader(dir, props, classLoader));
public org.openrewrite.config.Environment.Builder scanPath(Path dir, Collection<Path> dependencies, ClassLoader classLoader) {
List<ClasspathScanningLoader> list = new ArrayList<>();
for (Path dep : dependencies) {
ClasspathScanningLoader classpathScanningLoader = new ClasspathScanningLoader(dep, props, emptyList(), classLoader);
list.add(classpathScanningLoader);
}
return load(new StsClasspathScanningLoader(dir, props, list, classLoader));
}
@SuppressWarnings("unchecked")

View File

@@ -109,9 +109,9 @@
<commons-codec-version>1.13</commons-codec-version>
<!-- Rewrite specific properties -->
<rewrite-version>7.30.0</rewrite-version>
<rewrite-spring-version>4.27.0</rewrite-spring-version>
<rewrite-java-migration.version>1.11.0</rewrite-java-migration.version>
<rewrite-version>7.32.1</rewrite-version>
<rewrite-spring-version>4.29.0</rewrite-spring-version>
<rewrite-java-migration.version>1.13.0</rewrite-java-migration.version>
<signing.skip>true</signing.skip>
<signing.alias>vmware</signing.alias>

View File

@@ -232,7 +232,7 @@ public class RewriteRecipeRepository implements ApplicationContextAware {
if (pathStr.endsWith(".jar")) {
URLClassLoader classLoader = new URLClassLoader(new URL[] { f.toUri().toURL() },
getClass().getClassLoader());
builder.scanJar(f, classLoader);
builder.scanJar(f, Collections.emptyList(), classLoader);
} else if (pathStr.endsWith(".yml") || pathStr.endsWith(".yaml")) {
builder.load(new YamlResourceLoader(new FileInputStream(f.toFile()), f.toUri(), new Properties()));
}
@@ -245,7 +245,7 @@ public class RewriteRecipeRepository implements ApplicationContextAware {
Path d = Path.of(p);
if (Files.isDirectory(d)) {
URLClassLoader classLoader = new URLClassLoader(new URL[] { d.toUri().toURL()}, getClass().getClassLoader());
builder.scanPath(d, classLoader);
builder.scanPath(d, Collections.emptyList(), classLoader);
}
} catch (Exception e) {
log.error("Skipping folder " + p, e);