Skip to content

Commit

Permalink
integrate spring-rewrite-commons
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 authored Jan 10, 2024
1 parent a3850af commit 6c077b7
Show file tree
Hide file tree
Showing 381 changed files with 499 additions and 13,959 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build-sbm-revamp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ jobs:
java-version: 17
cache: 'maven'

- name: sbm-support-rewrite (build + test)
working-directory: sbm-support-rewrite
run: mvn --batch-mode clean install

- name: clean
run: mvn clean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.project.resource.filter.GenericTypeListFilter;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
*/
package org.springframework.sbm.test;

import org.springframework.sbm.boot.autoconfigure.ScopeConfiguration;
import org.springframework.rewrite.boot.autoconfigure.ScopeConfiguration;
import org.springframework.rewrite.parsers.maven.MavenSettingsInitializer;
import org.springframework.rewrite.project.RewriteSourceFileWrapper;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoringFactory;
import org.springframework.sbm.parsers.maven.MavenSettingsInitializer;
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.engine.context.ProjectContextHolder;
import org.springframework.sbm.engine.context.RewriteJavaSearchActionDeserializer;
import org.springframework.sbm.engine.recipe.*;
import org.springframework.sbm.java.impl.RewriteJavaParser;
import org.springframework.sbm.java.util.BasePackageCalculator;
import org.springframework.sbm.project.RewriteSourceFileWrapper;
import org.springframework.sbm.project.resource.ProjectResourceSetHolder;
import org.springframework.sbm.project.resource.SbmApplicationProperties;
import org.springframework.sbm.project.resource.ResourceHelper;
import org.springframework.sbm.scopes.ExecutionScope;
import org.springframework.sbm.scopes.ScanScope;
import org.springframework.rewrite.scopes.ExecutionScope;
import org.springframework.rewrite.scopes.ScanScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
Expand Down
4 changes: 2 additions & 2 deletions components/sbm-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<version>0.15.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>sbm-support-rewrite</artifactId>
<groupId>org.springframework.rewrite</groupId>
<artifactId>spring-rewrite-commons-launcher</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.sbm.parsers.RewriteExecutionContext;
import org.springframework.sbm.scopes.annotations.ScanScope;
import org.springframework.rewrite.parsers.RewriteExecutionContext;
import org.springframework.rewrite.scopes.annotations.ScanScope;

import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package org.springframework.sbm.build.api;

import org.openrewrite.maven.tree.ResolvedDependency;
import org.openrewrite.maven.tree.Scope;

import org.springframework.sbm.project.resource.ProjectResource;
import org.springframework.rewrite.project.resource.ProjectResource;

import java.nio.file.Path;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import org.openrewrite.ExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.maven.tree.MavenResolutionResult;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.ProjectResourceSetFactory;
import org.springframework.rewrite.project.resource.RewriteMigrationResultMerger;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.project.resource.finder.ProjectResourceFinder;
import org.springframework.sbm.build.impl.JavaSourceSetImpl;
import org.springframework.sbm.build.impl.MavenBuildFileUtil;
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
Expand All @@ -29,11 +34,6 @@
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory;
import org.springframework.sbm.java.util.BasePackageCalculator;
import org.springframework.sbm.parsers.JavaParserBuilder;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.ProjectResourceSetFactory;
import org.springframework.sbm.project.resource.RewriteMigrationResultMerger;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.project.resource.finder.ProjectResourceFinder;

import java.nio.file.Path;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package org.springframework.sbm.build.api;

import org.openrewrite.ExecutionContext;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.project.resource.StringProjectResource;
import lombok.RequiredArgsConstructor;
import org.openrewrite.ExecutionContext;
import org.openrewrite.SourceFile;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.project.resource.StringProjectResource;

import java.nio.file.Path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/
package org.springframework.sbm.build.api;

import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.finder.ProjectResourceFinder;

import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.finder.ProjectResourceFinder;

public class RootBuildFileFilter implements ProjectResourceFinder<BuildFile> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.springframework.sbm.build.filter;

import org.springframework.rewrite.project.resource.finder.GenericTypeListFinder;
import org.springframework.sbm.build.api.BuildFile;
import org.springframework.sbm.project.resource.finder.GenericTypeListFinder;

public class BuildFileProjectResourceFinder extends GenericTypeListFinder<BuildFile> {
public BuildFileProjectResourceFinder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
package org.springframework.sbm.build.impl;

import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.SourceFile;
import org.openrewrite.java.tree.J;
import org.springframework.rewrite.project.resource.ProjectResource;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.sbm.build.api.JavaSourceSet;
import org.springframework.sbm.java.api.JavaSource;
import org.springframework.sbm.java.api.JavaSourceLocation;
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
import org.springframework.sbm.java.refactoring.JavaRefactoringFactory;
import org.springframework.sbm.java.util.BasePackageCalculator;
import org.springframework.sbm.parsers.JavaParserBuilder;
import org.springframework.sbm.project.resource.ProjectResource;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.openrewrite.Recipe;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.tree.J;

import java.nio.file.Files;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@
import org.openrewrite.maven.MavenVisitor;
import org.openrewrite.maven.tree.MavenResolutionResult;
import org.openrewrite.xml.tree.Xml;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
import org.springframework.rewrite.project.resource.ProjectResourceSet;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.support.openrewrite.GenericOpenRewriteRecipe;

import javax.print.Doc;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* This class provides a facade to apply OpenRewrite {@code Recipe}s and {@code Visitor}s to the project Maven build files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@
import org.openrewrite.maven.tree.*;
import org.openrewrite.xml.tree.Content;
import org.openrewrite.xml.tree.Xml;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.sbm.build.api.BuildFile;
import org.springframework.sbm.build.api.DependenciesChangedEvent;
import org.springframework.rewrite.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.support.openrewrite.GenericOpenRewriteRecipe;
import org.springframework.sbm.build.api.Dependency;
import org.springframework.sbm.build.api.ParentDeclaration;
import org.springframework.sbm.build.api.Plugin;
import org.springframework.sbm.build.api.RepositoryDefinition;
import org.springframework.sbm.build.api.RewriteMavenParentDeclaration;
import org.springframework.sbm.build.api.*;
import org.springframework.sbm.build.impl.inner.PluginRepositoryHandler;
import org.springframework.sbm.build.migration.recipe.AddMavenPlugin;
import org.springframework.sbm.build.migration.recipe.RemoveMavenPlugin;
import org.springframework.sbm.build.migration.visitor.AddOrUpdateDependencyManagement;
import org.springframework.sbm.java.impl.ClasspathRegistry;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
import org.springframework.util.Assert;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -898,15 +893,35 @@ public void removePlugins(String... coordinates) {
Recipe recipe;
String coordinate = iterator.next();
String[] split = coordinate.split(":");
recipe = new RemoveMavenPlugin(split[0], split[1]);
List<Recipe> recipes = new ArrayList<>();
recipes.add(new RemoveMavenPlugin(split[0], split[1]));
while (iterator.hasNext()) {
coordinate = iterator.next();
split = coordinate.split(":");
recipe.getRecipeList().add(new RemoveMavenPlugin(split[0], split[1]));
recipes.add(new RemoveMavenPlugin(split[0], split[1]));
}

List<SourceFile> sourceFile = List.of(getSourceFile());
LargeSourceSet sourceSet = new InMemoryLargeSourceSet(sourceFile);

recipe = new Recipe() {

@Override
public String getDisplayName() {
return "Aggregated Recipes";
}

@Override
public String getDescription() {
return getDisplayName();
}

@Override
public List<Recipe> getRecipeList() {
return recipes;
}
};

List<Result> run = recipe.run(sourceSet, executionContext).getChangeset().getAllResults();
if (!run.isEmpty()) {
replaceWith(run.get(0).getAfter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,26 @@
*/
package org.springframework.sbm.build.impl;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import lombok.*;
import org.openrewrite.maven.ChangePluginConfiguration;
import org.openrewrite.maven.internal.MavenXmlMapper;
import org.openrewrite.xml.tree.Xml;
import org.openrewrite.xml.tree.Xml.Document;

import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.build.api.Plugin;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;

import java.util.*;
import java.util.stream.Collectors;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.openrewrite.SourceFile;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.maven.MavenParser;
import org.springframework.sbm.parsers.maven.MavenSettingsInitializer;
import org.springframework.rewrite.parsers.maven.MavenSettingsInitializer;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AddMavenPlugin() {

@Override
public void apply(ProjectContext context) {
context.getBuildFile().addPlugin(plugin);
context.getApplicationModules().getRootModule().getBuildFile().addPlugin(plugin);
}

private class DefaultMultiModuleHandler implements MultiModuleHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import org.openrewrite.Parser;
import org.openrewrite.SourceFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.rewrite.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoringFactory;
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.parsers.maven.RewriteMavenArtifactDownloader;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import org.openrewrite.xml.tree.Xml;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.annotation.Order;
import org.springframework.rewrite.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoring;
import org.springframework.sbm.build.impl.MavenBuildFileRefactoringFactory;
import org.springframework.sbm.build.impl.OpenRewriteMavenBuildFile;
import org.springframework.sbm.parsers.maven.RewriteMavenArtifactDownloader;
import org.springframework.sbm.project.resource.ProjectResourceWrapper;
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.stereotype.Component;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.sbm.common.api.TextResource;

import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
import org.springframework.rewrite.project.resource.RewriteSourceFileHolder;
import org.openrewrite.text.PlainText;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package org.springframework.sbm.common.migration.actions;

import lombok.Setter;
import org.springframework.sbm.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import org.springframework.rewrite.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.project.resource.ProjectResource;
import org.springframework.rewrite.project.resource.ProjectResource;

/**
* Delete files matching path pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.springframework.sbm.common.migration.actions;

import org.springframework.rewrite.project.resource.ProjectResource;
import org.springframework.rewrite.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import org.springframework.sbm.engine.recipe.AbstractAction;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.ProjectResource;
import org.springframework.sbm.project.resource.finder.PathPatternMatchingProjectResourceFinder;
import lombok.Getter;
import lombok.Setter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.springframework.sbm.common.migration.conditions;

import lombok.*;
import org.springframework.sbm.utils.OsAgnosticPathMatcher;
import org.springframework.rewrite.utils.OsAgnosticPathMatcher;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.engine.recipe.Condition;
import org.springframework.util.PathMatcher;
Expand Down
Loading

0 comments on commit 6c077b7

Please sign in to comment.