diff --git a/sbm-support-rewrite/pom.xml b/sbm-support-rewrite/pom.xml
index c34d8072b..47d1535fb 100644
--- a/sbm-support-rewrite/pom.xml
+++ b/sbm-support-rewrite/pom.xml
@@ -142,60 +142,71 @@
${rewrite.version}
- org.openrewrite.maven
- rewrite-maven-plugin
- ${rewrite-maven-plugin.version}
+ org.openrewrite
+ rewrite-properties
+ ${rewrite.version}
org.projectlombok
lombok
provided
+
+ org.apache.maven
+ maven-model
+ 3.9.1
+
+
+
+ org.openrewrite.maven
+ rewrite-maven-plugin
+ ${rewrite-maven-plugin.version}
+ test
+
org.apache.maven.wagon
wagon-http
${maven-wagon-http.version}
+ test
org.apache.maven.resolver
maven-resolver-transport-wagon
${maven-resolver.version}
+ test
org.apache.maven.resolver
maven-resolver-connector-basic
${maven-resolver.version}
+ test
org.apache.maven.resolver
maven-resolver-impl
${maven-resolver.version}
+ test
org.apache.maven
maven-resolver-provider
${maven.version}
+ test
org.apache.maven
maven-compat
${maven.version}
+ test
-
- org.apache.maven
- maven-embedder
- ${maven.version}
-
-
- org.sonatype.plexus
- plexus-cipher
-
-
-
+
+
+
org.codehaus.plexus
plexus-cipher
${plexus-cypher.version}
+ test
org.apache.maven.shared
@@ -207,6 +218,7 @@
javax.xml.bind
jaxb-api
${jaxb-api.version}
+ test
org.springframework.boot
@@ -219,6 +231,31 @@
${junit-pioneer.version}
test
+
+
+
+
+ org.codehaus.plexus
+ plexus-sec-dispatcher
+ 2.0
+
+
+
+ org.apache.maven
+ maven-embedder
+ ${maven.version}
+
+
+ org.sonatype.plexus
+ plexus-cipher
+
+
+
+
+ commons-cli
+ commons-cli
+ 1.4
+
@@ -377,37 +414,6 @@ limitations under the License.
-
- org.codehaus.mojo
- flatten-maven-plugin
- 1.4.1
-
-
- flatten
- process-resources
-
- flatten
-
-
- true
- oss
-
- remove
- remove
- remove
- remove
-
-
-
-
- flatten-clean
- clean
-
- clean
-
-
-
-
org.apache.maven.plugins
maven-release-plugin
@@ -432,37 +438,6 @@ limitations under the License.
-
- org.codehaus.mojo
- flatten-maven-plugin
- 1.4.1
-
-
- flatten
- process-resources
-
- flatten
-
-
- true
- oss
-
- remove
- remove
- remove
- remove
-
-
-
-
- flatten-clean
- clean
-
- clean
-
-
-
-
org.apache.maven.plugins
maven-release-plugin
@@ -474,37 +449,6 @@ limitations under the License.
true
-
- org.codehaus.mojo
- flatten-maven-plugin
- 1.4.1
-
-
- flatten
- process-resources
-
- flatten
-
-
- true
- oss
-
- remove
- remove
- remove
- remove
-
-
-
-
- flatten-clean
- clean
-
- clean
-
-
-
-
org.apache.maven.plugins
maven-release-plugin
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/BuildFileParser.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/BuildFileParser.java
index 0239cd850..cd11195b4 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/BuildFileParser.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/BuildFileParser.java
@@ -17,20 +17,14 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.maven.execution.MavenSession;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Parser;
import org.openrewrite.SourceFile;
import org.openrewrite.marker.Marker;
-import org.openrewrite.maven.MavenExecutionContextView;
-import org.openrewrite.maven.MavenMojoProjectParser;
import org.openrewrite.maven.MavenParser;
-import org.openrewrite.maven.cache.InMemoryMavenPomCache;
-import org.openrewrite.maven.cache.MavenPomCache;
import org.openrewrite.xml.tree.Xml;
import org.springframework.core.io.Resource;
import org.springframework.sbm.utils.ResourceUtil;
-import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.nio.file.Path;
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenMojoProjectParserPrivateMethods.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/HelperWithoutAGoodName.java
similarity index 84%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenMojoProjectParserPrivateMethods.java
rename to sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/HelperWithoutAGoodName.java
index aee9a7e4b..d6503c22a 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenMojoProjectParserPrivateMethods.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/HelperWithoutAGoodName.java
@@ -15,10 +15,7 @@
*/
package org.springframework.sbm.parsers;
-import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.maven.rtinfo.internal.DefaultRuntimeInformation;
-import org.apache.maven.settings.crypto.DefaultSettingsDecrypter;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Parser;
@@ -31,18 +28,12 @@
import org.openrewrite.marker.Generated;
import org.openrewrite.marker.Marker;
import org.openrewrite.marker.Markers;
-import org.openrewrite.maven.MavenMojoProjectParser;
-import org.openrewrite.maven.ResourceParser;
-import org.openrewrite.maven.tree.ResolvedDependency;
-import org.openrewrite.maven.utilities.MavenArtifactDownloader;
import org.openrewrite.xml.tree.Xml;
-import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
-import org.sonatype.plexus.components.cipher.PlexusCipherException;
-import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
import org.springframework.core.io.Resource;
import org.springframework.sbm.utils.ResourceUtil;
-import java.nio.file.*;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
@@ -53,12 +44,35 @@
* @author Fabian Krüger
*/
@Slf4j
-@RequiredArgsConstructor
-class MavenMojoProjectParserPrivateMethods {
+public class HelperWithoutAGoodName {
+ /**
+ * {@link MavenMojoProjectParser#addProvenance(Path, List, Collection)}
+ */
+ public UnaryOperator addProvenance(Path baseDir, List provenance, @Nullable Collection generatedSources) {
+// MavenMojoProjectParser mavenMojoProjectParser = createMavenMojoProjectParser(baseDir);
+// Method method = ReflectionUtils.findMethod(MavenMojoProjectParser.class, "addProvenance", Path.class, List.class, Collection.class);
+// ReflectionUtils.makeAccessible(method);
+// if(method == null) {
+// throw new IllegalStateException("Could not find method '%s' on %s while trying to call it.".formatted("addProvenance", MavenMojoProjectParser.class.getName()));
+// }
+// Object result = ReflectionUtils.invokeMethod(method, mavenMojoProjectParser, baseDir, provenance, generatedSources);
+// return (UnaryOperator) result;
+ return (s) -> {
+ Markers markers = s.getMarkers();
- private final MavenMojoProjectParserFactory mavenMojoProjectParserFactory;
- private final MavenArtifactDownloader artifactDownloader;
+ Marker marker;
+ for (Iterator var5 = provenance.iterator(); var5.hasNext(); markers = markers.addIfAbsent(marker)) {
+ marker = (Marker) var5.next();
+ }
+ if (generatedSources != null && generatedSources.contains(baseDir.resolve(s.getSourcePath()))) {
+ markers = markers.addIfAbsent(new Generated(Tree.randomId()));
+ }
+
+ return (T) s.withMarkers(markers);
+ };
+ }
/**
* process sources in src/main/java of current module.
@@ -141,6 +155,12 @@ public List processMainSources(
return sourceFiles;
}
+ @NotNull
+ private static JavaSourceSet sourceSet(String name, List dependencies, JavaTypeCache typeCache) {
+ return JavaSourceSet.build(name, dependencies, typeCache, false);
+ }
+
+
/**
* Calls {@link MavenMojoProjectParser#processTestSources(SbmMavenProject, JavaParser.Builder, ResourceParser, List, Set, ExecutionContext)}
*/
@@ -192,11 +212,6 @@ public List processTestSources(
return result;
}
- @NotNull
- private static JavaSourceSet sourceSet(String name, List dependencies, JavaTypeCache typeCache) {
- return JavaSourceSet.build(name, dependencies, typeCache, false);
- }
-
// FIXME: 945 take Java sources from resources
private static List listJavaSources(List resources, Path sourceDirectory) {
@@ -215,63 +230,4 @@ private static Predicate whenFileNameEndsWithJava() {
private static Predicate whenIn(Path sourceDirectory) {
return r -> ResourceUtil.getPath(r).toString().startsWith(sourceDirectory.toString());
}
-
-
- // TODO: 945 keep but move to a better class
-
- /**
- * {@link MavenMojoProjectParser#addProvenance(Path, List, Collection)}
- */
- public UnaryOperator addProvenance(Path baseDir, List provenance, @Nullable Collection generatedSources) {
-// MavenMojoProjectParser mavenMojoProjectParser = createMavenMojoProjectParser(baseDir);
-// Method method = ReflectionUtils.findMethod(MavenMojoProjectParser.class, "addProvenance", Path.class, List.class, Collection.class);
-// ReflectionUtils.makeAccessible(method);
-// if(method == null) {
-// throw new IllegalStateException("Could not find method '%s' on %s while trying to call it.".formatted("addProvenance", MavenMojoProjectParser.class.getName()));
-// }
-// Object result = ReflectionUtils.invokeMethod(method, mavenMojoProjectParser, baseDir, provenance, generatedSources);
-// return (UnaryOperator) result;
- return (s) -> {
- Markers markers = s.getMarkers();
-
- Marker marker;
- for (Iterator var5 = provenance.iterator(); var5.hasNext(); markers = markers.addIfAbsent(marker)) {
- marker = (Marker) var5.next();
- }
-
- if (generatedSources != null && generatedSources.contains(baseDir.resolve(s.getSourcePath()))) {
- markers = markers.addIfAbsent(new Generated(Tree.randomId()));
- }
-
- return (T) s.withMarkers(markers);
- };
- }
-
- private MavenMojoProjectParser createMavenMojoProjectParser(Path baseDir) {
- try {
- return mavenMojoProjectParserFactory.create(baseDir, new DefaultRuntimeInformation(), new DefaultSettingsDecrypter(new DefaultSecDispatcher(new DefaultPlexusCipher())));
- } catch (PlexusCipherException e) {
- throw new RuntimeException(e);
- }
- }
-
- private List downloadArtifacts(List dependencies) {
-
-// eventPublisher.publishEvent(new StartDownloadingDependenciesEvent(dependencies.size()));
-
-
- List paths = dependencies
- .stream()
- .filter(d -> d.getRepository() != null)
-// .peek(d -> eventPublisher.publishEvent(new StartDownloadingDependencyEvent(d.getRequested())))
-// .parallel()
- .map(artifactDownloader::downloadArtifact)
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
-
-// eventPublisher.publishEvent(new FinishedDownloadingDependencies());
-
- return paths;
- }
}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenConfigFileParser.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenConfigFileParser.java
index 2d2137b73..74f54743c 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenConfigFileParser.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenConfigFileParser.java
@@ -18,7 +18,6 @@
import org.apache.commons.cli.*;
import org.apache.maven.cli.CleanArgument;
import org.jetbrains.annotations.NotNull;
-import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenParserConfiguration.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenParserConfiguration.java
deleted file mode 100644
index dd9d93f1e..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenParserConfiguration.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.sbm.parsers;
-
-import org.springframework.boot.autoconfigure.AutoConfiguration;
-import org.springframework.context.annotation.Bean;
-
-/**
- * @author Fabian Krüger
- */
-@AutoConfiguration
-public class MavenParserConfiguration {
- @Bean
- MavenConfigFileParser configFileParser() {
- return new MavenConfigFileParser();
- }
-
- @Bean
- MavenExecutionRequestFactory requestFactory(MavenConfigFileParser configFileParser) {
- return new MavenExecutionRequestFactory(configFileParser);
- }
-
- @Bean
- MavenExecutor mavenExecutor(MavenExecutionRequestFactory requestFactory, MavenPlexusContainer plexusContainer) {
- return new MavenExecutor(requestFactory, plexusContainer);
- }
-
- @Bean
- MavenModelReader modelReader() {
- return new MavenModelReader();
- }
-
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/ProvenanceMarkerFactory.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/ProvenanceMarkerFactory.java
index e4e683244..5fbaebaf6 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/ProvenanceMarkerFactory.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/ProvenanceMarkerFactory.java
@@ -16,12 +16,7 @@
package org.springframework.sbm.parsers;
import lombok.RequiredArgsConstructor;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.rtinfo.RuntimeInformation;
-import org.apache.maven.rtinfo.internal.DefaultRuntimeInformation;
-import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.openrewrite.marker.Marker;
-import org.openrewrite.maven.MavenMojoProjectParser;
import org.springframework.core.io.Resource;
import org.springframework.sbm.utils.ResourceUtil;
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteParserConfiguration.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteParserConfiguration.java
index 4e155f21e..82f8bf20f 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteParserConfiguration.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteParserConfiguration.java
@@ -47,30 +47,29 @@
* @author Fabian Krüger
*/
@Slf4j
-@AutoConfiguration(after = {MavenParserConfiguration.class, ScopeConfiguration.class})
+@AutoConfiguration(after = {ScopeConfiguration.class})
@EnableConfigurationProperties(ParserProperties.class)
-@Import({ScanScope.class, ScopeConfiguration.class, MavenParserConfiguration.class})
+@Import({ScanScope.class, ScopeConfiguration.class})
public class RewriteParserConfiguration {
@Autowired
private ParserProperties parserProperties;
+// @Bean
+// ProvenanceMarkerFactory provenanceMarkerFactory(MavenMojoProjectParserFactory projectParserFactory) {
+// return new ProvenanceMarkerFactory(projectParserFactory);
+// }
+
@Bean
- MavenPlexusContainer plexusContainer() {
- return new MavenPlexusContainer();
+ MavenProvenanceMarkerFactory mavenProvenanceMarkerFactory() {
+ return new MavenProvenanceMarkerFactory();
}
-
@Bean
- MavenMojoProjectParserFactory projectParserFactory() {
- return new MavenMojoProjectParserFactory(parserProperties);
+ ProvenanceMarkerFactory provenanceMarkerFactory(MavenProvenanceMarkerFactory mavenPovenanceMarkerFactory) {
+ return new ProvenanceMarkerFactory(mavenPovenanceMarkerFactory);
}
-// @Bean
-// ProvenanceMarkerFactory provenanceMarkerFactory(MavenMojoProjectParserFactory projectParserFactory) {
-// return new ProvenanceMarkerFactory(projectParserFactory);
-// }
-
@Bean
@org.springframework.sbm.scopes.annotations.ScanScope
JavaParserBuilder javaParserBuilder() {
@@ -101,25 +100,14 @@ RewriteMavenArtifactDownloader artifactDownloader(MavenArtifactCache mavenArtifa
return new RewriteMavenArtifactDownloader(mavenArtifactCache, projectMetadata.getMavenSettings(), artifactDownloaderErrorConsumer);
}
- // FIXME: 945 remove
@Bean
- MavenMojoProjectParserPrivateMethods mavenMojoProjectParserPrivateMethods(MavenMojoProjectParserFactory parserFactory, MavenArtifactDownloader artifactDownloader) {
- return new MavenMojoProjectParserPrivateMethods(parserFactory, artifactDownloader);
+ HelperWithoutAGoodName helperWithoutAGoodName() {
+ return new HelperWithoutAGoodName();
}
@Bean
- SourceFileParser sourceFileParser(JavaParserBuilder javaParserBuilder, MavenMojoProjectParserPrivateMethods mavenMojoProjectParserPrivateMethods) {
- return new SourceFileParser(parserProperties, mavenMojoProjectParserPrivateMethods, javaParserBuilder);
- }
-
- @Bean
- MavenProvenanceMarkerFactory mavenProvenanceMarkerFactory(MavenMojoProjectParserFactory mavenMojoProjectParserFactory) {
- return new MavenProvenanceMarkerFactory();
- }
-
- @Bean
- ProvenanceMarkerFactory provenanceMarkerFactory(MavenProvenanceMarkerFactory mavenPovenanceMarkerFactory) {
- return new ProvenanceMarkerFactory(mavenPovenanceMarkerFactory);
+ SourceFileParser sourceFileParser(JavaParserBuilder javaParserBuilder, HelperWithoutAGoodName helperWithoutAGoodName) {
+ return new SourceFileParser(parserProperties, helperWithoutAGoodName);
}
@Bean
@@ -133,17 +121,18 @@ ParsingEventListener parsingEventListener(ApplicationEventPublisher eventPublish
return new RewriteParsingEventListenerAdapter(eventPublisher);
}
- @Bean
- RewriteMavenProjectParser rewriteMavenProjectParser(MavenPlexusContainer plexusContainer, ParsingEventListener parsingListener, MavenExecutor mavenExecutor, MavenMojoProjectParserFactory projectParserFactory, ScanScope scanScope, ConfigurableListableBeanFactory beanFactory, ExecutionContext executionContext) {
- return new RewriteMavenProjectParser(
- plexusContainer,
- parsingListener,
- mavenExecutor,
- projectParserFactory,
- scanScope,
- beanFactory,
- executionContext);
- }
+ // FIXME: 945
+// @Bean
+// RewriteMavenProjectParser rewriteMavenProjectParser(MavenPlexusContainer plexusContainer, ParsingEventListener parsingListener, MavenExecutor mavenExecutor, MavenMojoProjectParserFactory projectParserFactory, ScanScope scanScope, ConfigurableListableBeanFactory beanFactory, ExecutionContext executionContext) {
+// return new RewriteMavenProjectParser(
+// plexusContainer,
+// parsingListener,
+// mavenExecutor,
+// projectParserFactory,
+// scanScope,
+// beanFactory,
+// executionContext);
+// }
@Bean
MavenProjectAnalyzer mavenProjectAnalyzer(MavenArtifactDownloader artifactDownloader) {
@@ -152,7 +141,6 @@ MavenProjectAnalyzer mavenProjectAnalyzer(MavenArtifactDownloader artifactDownlo
@Bean
RewriteProjectParser rewriteProjectParser(
- MavenExecutor mavenExecutor,
ProvenanceMarkerFactory provenanceMarkerFactory,
BuildFileParser buildFileParser,
SourceFileParser sourceFileParser,
@@ -166,7 +154,6 @@ RewriteProjectParser rewriteProjectParser(
ExecutionContext executionContext,
MavenProjectAnalyzer mavenProjectAnalyzer) {
return new RewriteProjectParser(
- mavenExecutor,
provenanceMarkerFactory,
buildFileParser,
sourceFileParser,
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParser.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParser.java
index 478205f73..1a4881906 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParser.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParser.java
@@ -17,14 +17,10 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.marker.Marker;
-import org.openrewrite.maven.AbstractRewriteMojo;
import org.openrewrite.maven.MavenExecutionContextView;
import org.openrewrite.maven.tree.*;
import org.openrewrite.style.NamedStyles;
@@ -68,14 +64,12 @@
*
*
* @author Fabian Krüger
- * @see RewriteMavenProjectParser
* @see org.springframework.sbm.recipes.RewriteRecipeDiscovery
*/
@Slf4j
@RequiredArgsConstructor
public class RewriteProjectParser {
- private final MavenExecutor mavenExecutor;
private final ProvenanceMarkerFactory provenanceMarkerFactory;
private final BuildFileParser buildFileParser;
private final SourceFileParser sourceFileParser;
@@ -179,32 +173,4 @@ private static void addSourceFileToModel(Path baseDir, List sor
.filter(p -> ResourceUtil.getPath(p.getPomFile()).toString().equals(baseDir.resolve(s.getSourcePath()).toString()))
.forEach(p -> p.setSourceFile(s));
}
-
- private void withMavenSession(Path baseDir, Consumer consumer) {
- List goals = List.of("clean", "package");
- log.debug("Successfully finished goals %s".formatted(goals));
- mavenExecutor.onProjectSucceededEvent(baseDir, goals, event -> consumer.accept(event.getSession()));
- }
-
- @org.jetbrains.annotations.Nullable
- private static List autoDetectStyles(Stream sourceFilesStream) {
- RewriteMojo dummyRewriteMojo = new RewriteMojo();
- Method sourcesWithAutoDetectedStylesMethod = ReflectionUtils.findMethod(RewriteMojo.class, "sourcesWithAutoDetectedStyles");
- ReflectionUtils.makeAccessible(sourcesWithAutoDetectedStylesMethod);
- Object o = ReflectionUtils.invokeMethod(sourcesWithAutoDetectedStylesMethod, dummyRewriteMojo, sourceFilesStream);
- List sourceFiles = (List) o;
- return sourceFiles;
- }
-
- /**
- * Extending {@code AbstractRewriteMojo} to open up protected method for reuse
- */
- static class RewriteMojo extends AbstractRewriteMojo {
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- }
- }
-
}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteResourceParser.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteResourceParser.java
index ec24f6887..20fbebfd0 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteResourceParser.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteResourceParser.java
@@ -15,7 +15,7 @@
*/
package org.springframework.sbm.parsers;
-import org.apache.maven.plugin.logging.Log;
+import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Parser;
@@ -23,10 +23,8 @@
import org.openrewrite.hcl.HclParser;
import org.openrewrite.java.JavaParser;
import org.openrewrite.json.JsonParser;
-import org.openrewrite.maven.ResourceParser;
import org.openrewrite.properties.PropertiesParser;
import org.openrewrite.protobuf.ProtoParser;
-import org.openrewrite.python.PythonParser;
import org.openrewrite.quark.QuarkParser;
import org.openrewrite.text.PlainTextParser;
import org.openrewrite.xml.XmlParser;
@@ -44,11 +42,11 @@
* Code from https://github.com/fabapp2/rewrite-maven-plugin/blob/83d184ea9ffe3046429f16c91aa56a9610bae832/src/main/java/org/openrewrite/maven/ResourceParser.java
* The motivation was to decouple the parser from file access.
*/
-public class RewriteResourceParser extends ResourceParser { // TODO: Only extends from ResourceParser to keep method signatures for now
+@Slf4j
+public class RewriteResourceParser {
private static final Set DEFAULT_IGNORED_DIRECTORIES = new HashSet<>(Arrays.asList("build", "target", "out", ".sonar", ".gradle", ".idea", ".project", "node_modules", ".git", ".metadata", ".DS_Store"));
private final Path baseDir;
- private final Log logger;
private final Collection exclusions;
private final int sizeThresholdMb;
private final Collection excludedDirectories;
@@ -60,11 +58,16 @@ public class RewriteResourceParser extends ResourceParser { // TODO: Only extend
private final JavaParser.Builder extends JavaParser, ?> javaParserBuilder;
private final ExecutionContext executionContext;
- public RewriteResourceParser(Path baseDir, Log logger, Collection exclusions, Collection plainTextMasks, int sizeThresholdMb, Collection excludedDirectories,
- JavaParser.Builder extends JavaParser, ?> javaParserBuilder, ExecutionContext executionContext) {
- super(baseDir, logger, exclusions, plainTextMasks, sizeThresholdMb, excludedDirectories, javaParserBuilder);
+ public RewriteResourceParser(
+ Path baseDir,
+ Collection exclusions,
+ Collection plainTextMasks,
+ int sizeThresholdMb,
+ Collection excludedDirectories,
+ JavaParser.Builder extends JavaParser, ?> javaParserBuilder,
+ ExecutionContext executionContext
+ ) {
this.baseDir = baseDir;
- this.logger = logger;
this.javaParserBuilder = javaParserBuilder;
this.executionContext = executionContext;
this.exclusions = pathMatchers(baseDir, exclusions);
@@ -132,7 +135,7 @@ public Stream parseSourceFiles(
// FIXME: 945 only check threshold if value > 0 is given
long fileSize = ResourceUtil.contentLength(resource);
if (isOverSizeThreshold(fileSize)) {
- logger.info("Parsing as quark " + file + " as its size " + fileSize / (1024L * 1024L) +
+ log.info("Parsing as quark " + file + " as its size " + fileSize / (1024L * 1024L) +
"Mb exceeds size threshold " + sizeThresholdMb + "Mb");
quarkPaths.add(file);
} else if (isParsedAsPlainText(file)) {
@@ -163,8 +166,9 @@ public Stream parseSourceFiles(
ProtoParser protoParser = new ProtoParser();
List protoPaths = new ArrayList<>();
- PythonParser pythonParser = PythonParser.builder().build();
- List pythonPaths = new ArrayList<>();
+ // Python currently not supported
+// PythonParser pythonParser = PythonParser.builder().build();
+// List pythonPaths = new ArrayList<>();
HclParser hclParser = HclParser.builder().build();
List hclPaths = new ArrayList<>();
@@ -191,9 +195,9 @@ public Stream parseSourceFiles(
propertiesPaths.add(path);
} else if (protoParser.accept(path)) {
protoPaths.add(path);
- } else if(pythonParser.accept(path)) {
+ } /*else if(pythonParser.accept(path)) {
pythonPaths.add(path);
- } else if (hclParser.accept(path)) {
+ }*/ else if (hclParser.accept(path)) {
hclPaths.add(path);
} else if (quarkParser.accept(path)) {
quarkPaths.add(path);
@@ -238,11 +242,11 @@ public Stream parseSourceFiles(
alreadyParsed.addAll(protoPaths);
}
- if (!pythonPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, pythonPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) pythonParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(pythonPaths);
- }
+// if (!pythonPaths.isEmpty()) {
+// List inputs = getInputs(pathToResource, pythonPaths);
+// sourceFiles = Stream.concat(sourceFiles, (Stream) pythonParser.parseInputs(inputs, baseDir, ctx));
+// alreadyParsed.addAll(pythonPaths);
+// }
if (!hclPaths.isEmpty()) {
List inputs = getInputs(pathToResource, hclPaths);
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceFileParser.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceFileParser.java
index cbe6f3f17..eccdcbd7b 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceFileParser.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceFileParser.java
@@ -21,7 +21,6 @@
import org.openrewrite.SourceFile;
import org.openrewrite.java.JavaParser;
import org.openrewrite.marker.Marker;
-import org.openrewrite.maven.ResourceParser;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.xml.tree.Xml;
import org.springframework.core.io.Resource;
@@ -42,8 +41,7 @@
public class SourceFileParser {
private final ParserProperties parserProperties;
- private final MavenMojoProjectParserPrivateMethods mavenMojoProjectParserPrivateMethods;
- private final JavaParserBuilder javaParserBuilder;
+ private final HelperWithoutAGoodName mavenMojoProjectParserPrivateMethods;
public List parseOtherSourceFiles(
Path baseDir,
@@ -63,19 +61,15 @@ public List parseOtherSourceFiles(
if(markers == null || markers.isEmpty()) {
log.warn("Could not find provenance markers for resource '%s'".formatted(parserContext.getMatchingBuildFileResource(currentMavenProject)));
}
- List sourceFiles = parseModuleSourceFiles(resources, parserContext, currentMavenProject, moduleBuildFile, markers, styles, executionContext, baseDir);
+ List sourceFiles = parseModuleSourceFiles(resources, currentMavenProject, moduleBuildFile, markers, styles, executionContext, baseDir);
parsedSourceFiles.addAll(sourceFiles);
});
return new ArrayList<>(parsedSourceFiles);
}
- /**
- * {@link org.openrewrite.maven.MavenMojoProjectParser#listSourceFiles(SbmMavenProject, Xml.Document, List, List, ExecutionContext)}
- */
private List parseModuleSourceFiles(
List resources,
- ParserContext parserContext,
SbmMavenProject currentProject,
Xml.Document moduleBuildFile,
List provenanceMarkers,
@@ -104,7 +98,6 @@ private List parseModuleSourceFiles(
// FIXME: Why is skipResourceScanDirs required at all? Shouldn't the module know it's resources
RewriteResourceParser rp = new RewriteResourceParser(
baseDir,
- new Slf4jToMavenLoggerAdapter(log),
parserProperties.getIgnoredPathPatterns(),
parserProperties.getPlainTextMasks(),
parserProperties.getSizeThresholdMb(),
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/StyleDetector.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/StyleDetector.java
index a6c7e0031..fd38c5383 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/StyleDetector.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/StyleDetector.java
@@ -15,15 +15,20 @@
*/
package org.springframework.sbm.parsers;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import org.openrewrite.SourceFile;
-import org.openrewrite.maven.AbstractRewriteMojo;
-import org.springframework.stereotype.Component;
+import org.openrewrite.Tree;
+import org.openrewrite.internal.ListUtils;
+import org.openrewrite.java.style.Autodetect;
+import org.openrewrite.java.tree.JavaSourceFile;
+import org.openrewrite.marker.Marker;
+import org.openrewrite.style.NamedStyles;
+import org.openrewrite.xml.tree.Xml;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
-import java.util.List;
+import java.util.*;
+import java.util.function.UnaryOperator;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
@@ -31,18 +36,49 @@
*/
class StyleDetector {
- public List sourcesWithAutoDetectedStyles(Stream sourceFilesStream) {
- OpenedRewriteMojo m = new OpenedRewriteMojo();
- Method method = ReflectionUtils.findMethod(OpenedRewriteMojo.class, "sourcesWithAutoDetectedStyles", Stream.class);
- ReflectionUtils.makeAccessible(method);
- return (List) ReflectionUtils.invokeMethod(method, m, sourceFilesStream);
+
+ List sourcesWithAutoDetectedStyles(Stream sourceFiles) {
+ org.openrewrite.java.style.Autodetect.Detector javaDetector = org.openrewrite.java.style.Autodetect.detector();
+ org.openrewrite.xml.style.Autodetect.Detector xmlDetector = org.openrewrite.xml.style.Autodetect.detector();
+ List sourceFileList = sourceFiles
+ .peek(javaDetector::sample)
+ .peek(xmlDetector::sample)
+ .toList();
+
+ Map, NamedStyles> stylesByType = new HashMap<>();
+ stylesByType.put(JavaSourceFile.class, javaDetector.build());
+ stylesByType.put(Xml.Document.class, xmlDetector.build());
+
+ return ListUtils.map(sourceFileList, applyAutodetectedStyle(stylesByType));
}
- static class OpenedRewriteMojo extends AbstractRewriteMojo {
+ private UnaryOperator applyAutodetectedStyle(Map, NamedStyles> stylesByType) {
+ return (before) -> {
+ Iterator var2 = stylesByType.entrySet().iterator();
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- throw new UnsupportedOperationException();
- }
+ while(var2.hasNext()) {
+ Map.Entry, NamedStyles> styleTypeEntry = (Map.Entry)var2.next();
+ if (((Class)styleTypeEntry.getKey()).isAssignableFrom(before.getClass())) {
+ before = (SourceFile)before.withMarkers(before.getMarkers().add((Marker)styleTypeEntry.getValue()));
+ }
+ }
+
+ return before;
+ };
}
+
+// public List sourcesWithAutoDetectedStyles(Stream sourceFilesStream) {
+// OpenedRewriteMojo m = new OpenedRewriteMojo();
+// Method method = ReflectionUtils.findMethod(OpenedRewriteMojo.class, "sourcesWithAutoDetectedStyles", Stream.class);
+// ReflectionUtils.makeAccessible(method);
+// return (List) ReflectionUtils.invokeMethod(method, m, sourceFilesStream);
+// }
+//
+// static class OpenedRewriteMojo extends AbstractRewriteMojo {
+//
+// @Override
+// public void execute() throws MojoExecutionException, MojoFailureException {
+// throw new UnsupportedOperationException();
+// }
+// }
}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/recipes/RewriteRecipeDiscovery.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/recipes/RewriteRecipeDiscovery.java
index ffd0cabf2..008b53e5f 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/recipes/RewriteRecipeDiscovery.java
+++ b/sbm-support-rewrite/src/main/java/org/springframework/sbm/recipes/RewriteRecipeDiscovery.java
@@ -17,9 +17,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
import org.openrewrite.Recipe;
import org.openrewrite.Validated;
import org.openrewrite.config.ClasspathScanningLoader;
@@ -27,10 +24,8 @@
import org.openrewrite.config.RecipeDescriptor;
import org.openrewrite.config.ResourceLoader;
import org.openrewrite.internal.lang.Nullable;
-import org.openrewrite.maven.AbstractRewriteMojo;
import org.springframework.sbm.parsers.RecipeValidationErrorException;
import org.springframework.sbm.parsers.ParserProperties;
-import org.springframework.stereotype.Component;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -101,41 +96,41 @@ public List discoverFilteredRecipes(List activeRecipes, Properti
return recipes;
}
- public List discoverFilteredRecipes(List activeRecipes, MavenProject mavenProject) {
- if (activeRecipes.isEmpty()) {
- log.warn("No active recipes were provided.");
- return emptyList();
- }
-
- List recipes = new ArrayList<>();
-
- AbstractRewriteMojoHelper helper = new AbstractRewriteMojoHelper(mavenProject);
-
- Environment env =helper.environment(getClass().getClassLoader());
- Recipe recipe = env.activateAll();
-// Recipe recipe = env.activateRecipes(activeRecipes);
-
- if (recipe.getRecipeList().isEmpty()) {
- log.warn("No recipes were activated. None of the provided 'activeRecipes' matched any of the applicable recipes.");
- return emptyList();
- }
-
- Collection> validated = recipe.validateAll();
- List> failedValidations = validated.stream().map(Validated::failures)
- .flatMap(Collection::stream).collect(toList());
- if (!failedValidations.isEmpty()) {
- failedValidations.forEach(failedValidation -> log.error(
- "Recipe validation error in " + failedValidation.getProperty() + ": " +
- failedValidation.getMessage(), failedValidation.getException()));
- if (parserProperties.isFailOnInvalidActiveRecipes()) {
- throw new RecipeValidationErrorException("Recipe validation errors detected as part of one or more activeRecipe(s). Please check error logs.");
- } else {
- log.error("Recipe validation errors detected as part of one or more activeRecipe(s). Execution will continue regardless.");
- }
- }
-
- return recipes;
- }
+// public List discoverFilteredRecipes(List activeRecipes, MavenProject mavenProject) {
+// if (activeRecipes.isEmpty()) {
+// log.warn("No active recipes were provided.");
+// return emptyList();
+// }
+//
+// List recipes = new ArrayList<>();
+//
+// AbstractRewriteMojoHelper helper = new AbstractRewriteMojoHelper(mavenProject);
+//
+// Environment env = helper.environment(getClass().getClassLoader());
+// Recipe recipe = env.activateAll();
+//// Recipe recipe = env.activateRecipes(activeRecipes);
+//
+// if (recipe.getRecipeList().isEmpty()) {
+// log.warn("No recipes were activated. None of the provided 'activeRecipes' matched any of the applicable recipes.");
+// return emptyList();
+// }
+//
+// Collection> validated = recipe.validateAll();
+// List> failedValidations = validated.stream().map(Validated::failures)
+// .flatMap(Collection::stream).collect(toList());
+// if (!failedValidations.isEmpty()) {
+// failedValidations.forEach(failedValidation -> log.error(
+// "Recipe validation error in " + failedValidation.getProperty() + ": " +
+// failedValidation.getMessage(), failedValidation.getException()));
+// if (parserProperties.isFailOnInvalidActiveRecipes()) {
+// throw new RecipeValidationErrorException("Recipe validation errors detected as part of one or more activeRecipe(s). Please check error logs.");
+// } else {
+// log.error("Recipe validation errors detected as part of one or more activeRecipe(s). Execution will continue regardless.");
+// }
+// }
+//
+// return recipes;
+// }
public RecipeDescriptor findRecipeDescriptor(String anotherDummyRecipe) {
ResourceLoader resourceLoader = new ClasspathScanningLoader(new Properties(), new String[]{"io.example"});
@@ -166,69 +161,73 @@ public List findRecipesByTags(String tag) {
}
- class AbstractRewriteMojoHelper extends AbstractRewriteMojo {
-
- public AbstractRewriteMojoHelper(MavenProject mavenProject) {
- super.project = mavenProject;
- }
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Environment environment(@Nullable ClassLoader recipeClassLoader) {
- Environment.Builder env = Environment.builder(this.project.getProperties());
- if (recipeClassLoader == null) {
- env.scanRuntimeClasspath(new String[0]).scanUserHome();
- } else {
- env.load(new ClasspathScanningLoader(this.project.getProperties(), recipeClassLoader));
- }
-
-
- /*env.load(new ResourceLoader() {
- @Override
- public Collection listRecipes() {
- return List.of();
- }
-
- @Override
- public Collection listRecipeDescriptors() {
- return List.of();
- }
-
- @Override
- public Collection listStyles() {
- return List.of();
- }
-
- @Override
- public Collection listCategoryDescriptors() {
- return List.of();
- }
-
- @Override
- public Map> listContributors() {
- return Map.of();
- }
-
- @Override
- public Map> listRecipeExamples() {
- return Map.of();
- }
- });*/
- return env.build();
- }
-
- @Override
- protected Environment environment() throws MojoExecutionException {
- return super.environment();
- }
-
- @Override
- public Path repositoryRoot() {
- return super.repositoryRoot();
- }
- }
+// class AbstractRewriteMojoHelper extends AbstractRewriteMojo {
+//
+// public AbstractRewriteMojoHelper(MavenProject mavenProject) {
+// super.project = mavenProject;
+// }
+//
+// @Override
+// public void execute() throws MojoExecutionException, MojoFailureException {
+// throw new UnsupportedOperationException();
+// }
+//
+// @Override
+// public Environment environment(@Nullable ClassLoader recipeClassLoader) {
+// Environment.Builder env = Environment.builder(this.project.getProperties());
+// if (recipeClassLoader == null) {
+// env.scanRuntimeClasspath(new String[0]).scanUserHome();
+// } else {
+// env.load(new ClasspathScanningLoader(this.project.getProperties(), recipeClassLoader));
+// }
+//
+//
+// /*env.load(new ResourceLoader() {
+// @Override
+// public Collection listRecipes() {
+// return List.of();
+// }
+//
+// @Override
+// public Collection listRecipeDescriptors() {
+// return List.of();
+// }
+//
+// @Override
+// public Collection listStyles() {
+// return List.of();
+// }
+//
+// @Override
+// public Collection listCategoryDescriptors() {
+// return List.of();
+// }
+//
+// @Override
+// public Map> listContributors() {
+// return Map.of();
+// }
+//
+// @Override
+// public Map> listRecipeExamples() {
+// return Map.of();
+// }
+// });*/
+// return env.build();
+// }
+//
+//// @Override
+//// protected Environment environment() {
+//// try {
+//// return super.environment();
+//// } catch (MojoExecutionException e) {
+//// throw new RuntimeException(e);
+//// }
+//// }
+//
+// @Override
+// public Path repositoryRoot() {
+// return super.repositoryRoot();
+// }
+// }
}
diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/BuildFileParserTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/BuildFileParserTest.java
index 4fe9254f4..197436dd8 100644
--- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/BuildFileParserTest.java
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/BuildFileParserTest.java
@@ -15,7 +15,8 @@
*/
package org.springframework.sbm.parsers;
-import org.apache.maven.project.MavenProject;
+import org.apache.commons.cli.*;
+import org.apache.maven.cli.CleanArgument;
import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenExecutionRequestFactory.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenExecutionRequestFactory.java
similarity index 98%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenExecutionRequestFactory.java
rename to sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenExecutionRequestFactory.java
index 7d25a82df..988591c60 100644
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenExecutionRequestFactory.java
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenExecutionRequestFactory.java
@@ -15,6 +15,7 @@
*/
package org.springframework.sbm.parsers;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import lombok.RequiredArgsConstructor;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenExecutionResultException.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenExecutionResultException.java
similarity index 100%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenExecutionResultException.java
rename to sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenExecutionResultException.java
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenExecutor.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenExecutor.java
similarity index 100%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenExecutor.java
rename to sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenExecutor.java
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenMojoProjectParserFactory.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenMojoProjectParserFactory.java
similarity index 100%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenMojoProjectParserFactory.java
rename to sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenMojoProjectParserFactory.java
diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenMojoProjectParserPrivateMethods.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenMojoProjectParserPrivateMethods.java
new file mode 100644
index 000000000..7eadc5a1a
--- /dev/null
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenMojoProjectParserPrivateMethods.java
@@ -0,0 +1,64 @@
+/*
+ * 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.sbm.parsers;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.maven.rtinfo.internal.DefaultRuntimeInformation;
+import org.apache.maven.settings.crypto.DefaultSettingsDecrypter;
+import org.jetbrains.annotations.NotNull;
+import org.openrewrite.ExecutionContext;
+import org.openrewrite.Parser;
+import org.openrewrite.SourceFile;
+import org.openrewrite.Tree;
+import org.openrewrite.internal.lang.Nullable;
+import org.openrewrite.java.JavaParser;
+import org.openrewrite.java.internal.JavaTypeCache;
+import org.openrewrite.java.marker.JavaSourceSet;
+import org.openrewrite.marker.Generated;
+import org.openrewrite.marker.Marker;
+import org.openrewrite.marker.Markers;
+import org.openrewrite.maven.MavenMojoProjectParser;
+import org.openrewrite.maven.ResourceParser;
+import org.openrewrite.maven.tree.ResolvedDependency;
+import org.openrewrite.maven.utilities.MavenArtifactDownloader;
+import org.openrewrite.xml.tree.Xml;
+import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
+import org.sonatype.plexus.components.cipher.PlexusCipherException;
+import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
+import org.springframework.core.io.Resource;
+import org.springframework.sbm.utils.ResourceUtil;
+
+import java.nio.file.*;
+import java.util.*;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * @author Fabian Krüger
+ */
+@Slf4j
+@RequiredArgsConstructor
+class MavenMojoProjectParserPrivateMethods {
+
+ private final MavenMojoProjectParserFactory mavenMojoProjectParserFactory;
+ private final MavenArtifactDownloader artifactDownloader;
+
+
+
+}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenPlexusContainer.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenPlexusContainer.java
similarity index 100%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/MavenPlexusContainer.java
rename to sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/MavenPlexusContainer.java
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteMavenProjectParser.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParser.java
similarity index 100%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteMavenProjectParser.java
rename to sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParser.java
diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserIntegrationTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserIntegrationTest.java
index de0ca36f3..b9531e261 100644
--- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserIntegrationTest.java
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserIntegrationTest.java
@@ -22,6 +22,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.event.EventListener;
+import org.springframework.sbm.boot.autoconfigure.SbmSupportRewriteConfiguration;
import org.springframework.sbm.boot.autoconfigure.ScannerConfiguration;
import org.springframework.sbm.parsers.events.FinishedParsingResourceEvent;
@@ -34,7 +35,7 @@
/**
* @author Fabian Krüger
*/
-@SpringBootTest(classes = {ScannerConfiguration.class, RewriteMavenProjectParserIntegrationTest.TestEventListener.class})
+@SpringBootTest(classes = {SbmSupportRewriteConfiguration.class, SbmTestConfiguration.class})
public class RewriteMavenProjectParserIntegrationTest {
@Autowired
diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserTest.java
index 36917ee34..097668d07 100644
--- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserTest.java
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteMavenProjectParserTest.java
@@ -276,14 +276,13 @@ void parseMultiModule1_WithCustomParser() {
MavenArtifactCache mavenArtifactCache = new LocalMavenArtifactCache(Paths.get(System.getProperty("user.home"), ".m2", "repository"));
@Nullable MavenSettings mavenSettings = null;
Consumer onError = (t) -> {throw new RuntimeException(t);};
- MavenMojoProjectParserPrivateMethods mavenMojoParserPrivateMethods = new MavenMojoProjectParserPrivateMethods(mavenMojoProjectParserFactory, new RewriteMavenArtifactDownloader(mavenArtifactCache, mavenSettings, onError));
+ HelperWithoutAGoodName helperWithoutAGoodName = new HelperWithoutAGoodName();
JavaParserBuilder javaParserBuilder = new JavaParserBuilder();
RewriteProjectParser rpp = new RewriteProjectParser(
- new MavenExecutor(new MavenExecutionRequestFactory(new MavenConfigFileParser()), new MavenPlexusContainer()),
new ProvenanceMarkerFactory(new MavenProvenanceMarkerFactory()),
new BuildFileParser(),
- new SourceFileParser(parserProperties, mavenMojoParserPrivateMethods, javaParserBuilder),
+ new SourceFileParser(parserProperties, helperWithoutAGoodName),
new StyleDetector(),
parserProperties,
mock(ParsingEventListener.class),
diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserIntegrationTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserIntegrationTest.java
index 70bcd4abb..b2aa8f7d6 100644
--- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserIntegrationTest.java
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserIntegrationTest.java
@@ -22,7 +22,9 @@
import org.openrewrite.java.tree.J;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.core.io.Resource;
+import org.springframework.sbm.boot.autoconfigure.SbmSupportRewriteConfiguration;
import org.springframework.sbm.boot.autoconfigure.ScannerConfiguration;
import org.springframework.sbm.parsers.events.FinishedParsingResourceEvent;
import org.springframework.sbm.parsers.events.StartedParsingProjectEvent;
@@ -39,7 +41,7 @@
/**
* @author Fabian Krüger
*/
-@SpringBootTest(classes = {ScannerConfiguration.class})
+@SpringBootTest(classes = {SbmSupportRewriteConfiguration.class, SbmTestConfiguration.class})
public class RewriteProjectParserIntegrationTest {
@Autowired
diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserTest.java
index 08197e3c9..32792270b 100644
--- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserTest.java
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserTest.java
@@ -101,13 +101,12 @@ void parseSimpleMavenProject(@TempDir Path tempDir) {
Consumer onError = (t) -> {
throw new RuntimeException(t);
};
- MavenMojoProjectParserPrivateMethods mavenMojoParserPrivateMethods = new MavenMojoProjectParserPrivateMethods(mavenMojoProjectParserFactory, new RewriteMavenArtifactDownloader(mavenArtifactCache, mavenSettings, onError));
+ HelperWithoutAGoodName mavenMojoParserPrivateMethods = new HelperWithoutAGoodName();
ExecutionContext executionContext = new InMemoryExecutionContext(t -> {throw new RuntimeException(t);});
RewriteProjectParser projectParser = new RewriteProjectParser(
- new MavenExecutor(new MavenExecutionRequestFactory(new MavenConfigFileParser()), new MavenPlexusContainer()),
new ProvenanceMarkerFactory(new MavenProvenanceMarkerFactory()),
new BuildFileParser(),
- new SourceFileParser(parserProperties, mavenMojoParserPrivateMethods, new JavaParserBuilder()),
+ new SourceFileParser(parserProperties, mavenMojoParserPrivateMethods),
new StyleDetector(),
parserProperties,
mock(ParsingEventListener.class),
diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/SbmTestConfiguration.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/SbmTestConfiguration.java
new file mode 100644
index 000000000..c1b2ad37d
--- /dev/null
+++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/SbmTestConfiguration.java
@@ -0,0 +1,90 @@
+/*
+ * 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.sbm.parsers;
+
+import lombok.extern.slf4j.Slf4j;
+import org.openrewrite.ExecutionContext;
+import org.openrewrite.maven.utilities.MavenArtifactDownloader;
+import org.openrewrite.tree.ParsingEventListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
+import org.springframework.sbm.scopes.ScanScope;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * @author Fabian Krüger
+ */
+@TestConfiguration
+@Slf4j
+@Import(RewriteParserConfiguration.class)
+public class SbmTestConfiguration {
+
+ @Autowired
+ private ParserProperties parserProperties;
+
+ @Bean
+ MavenMojoProjectParserPrivateMethods mavenMojoProjectParserPrivateMethods(MavenMojoProjectParserFactory parserFactory, MavenArtifactDownloader artifactDownloader) {
+ return new MavenMojoProjectParserPrivateMethods(parserFactory, artifactDownloader);
+ }
+
+
+ @Bean
+ MavenConfigFileParser configFileParser() {
+ return new MavenConfigFileParser();
+ }
+
+ @Bean
+ MavenExecutionRequestFactory requestFactory(MavenConfigFileParser configFileParser) {
+ return new MavenExecutionRequestFactory(configFileParser);
+ }
+
+ @Bean
+ MavenExecutor mavenExecutor(MavenExecutionRequestFactory requestFactory, MavenPlexusContainer plexusContainer) {
+ return new MavenExecutor(requestFactory, plexusContainer);
+ }
+
+ @Bean
+ MavenMojoProjectParserFactory projectParserFactory() {
+ return new MavenMojoProjectParserFactory(parserProperties);
+ }
+
+ @Bean
+ MavenPlexusContainer plexusContainer() {
+ return new MavenPlexusContainer();
+ }
+
+ @Bean
+ MavenModelReader modelReader() {
+ return new MavenModelReader();
+ }
+
+ @Bean
+ RewriteMavenProjectParser rewriteMavenProjectParser(MavenPlexusContainer plexusContainer, ParsingEventListener parsingEventListenerAdapter, MavenExecutor mavenExecutor, MavenMojoProjectParserFactory mavenMojoProjectParserFactory, ScanScope scanScope, ConfigurableListableBeanFactory beanFactory, ExecutionContext executionContext) {
+ return new RewriteMavenProjectParser(
+ plexusContainer,
+ parsingEventListenerAdapter,
+ mavenExecutor,
+ mavenMojoProjectParserFactory,
+ scanScope,
+ beanFactory,
+ executionContext
+ );
+ }
+}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/Slf4jToMavenLoggerAdapter.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/Slf4jToMavenLoggerAdapter.java
similarity index 100%
rename from sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/Slf4jToMavenLoggerAdapter.java
rename to sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/Slf4jToMavenLoggerAdapter.java