artifactDownloaderErrorConsumer() {
- return (t) -> {throw new RuntimeException(t);};
- }
-
- @Bean
- MavenModuleParser mavenModuleParser(ParserProperties parserProperties) {
- return new MavenModuleParser(parserProperties);
- }
-
- @Bean
- SourceFileParser sourceFileParser(MavenModuleParser mavenModuleParser) {
- return new SourceFileParser(mavenModuleParser);
- }
-
- @Bean
- StyleDetector styleDetector() {
- return new StyleDetector();
- }
-
- @Bean
- @ConditionalOnMissingBean(ParsingEventListener.class)
- ParsingEventListener parsingEventListener(ApplicationEventPublisher eventPublisher) {
- return new RewriteParsingEventListenerAdapter(eventPublisher);
- }
-
- // 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) {
- return new MavenProjectAnalyzer(artifactDownloader);
- }
-
- @Bean
- RewriteProjectParser rewriteProjectParser(
- ProvenanceMarkerFactory provenanceMarkerFactory,
- BuildFileParser buildFileParser,
- SourceFileParser sourceFileParser,
- StyleDetector styleDetector,
- ParserProperties parserProperties,
- ParsingEventListener parsingEventListener,
- ApplicationEventPublisher eventPublisher,
- ScanScope scanScope,
- ConfigurableListableBeanFactory beanFactory,
- ProjectScanner projectScanner,
- ExecutionContext executionContext,
- MavenProjectAnalyzer mavenProjectAnalyzer) {
- return new RewriteProjectParser(
- provenanceMarkerFactory,
- buildFileParser,
- sourceFileParser,
- styleDetector,
- parserProperties,
- parsingEventListener,
- eventPublisher,
- scanScope,
- beanFactory,
- projectScanner,
- executionContext,
- mavenProjectAnalyzer);
- }
-
- @Bean
- ParserPropertiesPostProcessor parserPropertiesPostProcessor() {
- return new ParserPropertiesPostProcessor();
- }
-
- @Bean
- @ConditionalOnMissingBean(MavenPomCache.class)
- MavenPomCache mavenPomCache(ParserProperties parserProperties) {
- MavenPomCache mavenPomCache = new InMemoryMavenPomCache();
- if (parserProperties.isPomCacheEnabled()) {
- if (!"64".equals(System.getProperty("sun.arch.data.model", "64"))) {
- log.warn("parser.isPomCacheEnabled was set to true but RocksdbMavenPomCache is not supported on 32-bit JVM. falling back to InMemoryMavenPomCache");
- } else {
- try {
- mavenPomCache = new CompositeMavenPomCache(
- new InMemoryMavenPomCache(),
- new RocksdbMavenPomCache(Path.of(parserProperties.getPomCacheDirectory()))
- );
- } catch (Exception e) {
- log.warn("Unable to initialize RocksdbMavenPomCache, falling back to InMemoryMavenPomCache");
- if (log.isDebugEnabled()) {
- StringWriter sw = new StringWriter();
- e.printStackTrace(new PrintWriter(sw));
- String exceptionAsString = sw.toString();
- log.debug(exceptionAsString);
- }
- }
- }
- }
- return mavenPomCache;
- }
-}
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
deleted file mode 100644
index 31f52e867..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParser.java
+++ /dev/null
@@ -1,148 +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 lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.jetbrains.annotations.NotNull;
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.SourceFile;
-import org.openrewrite.marker.Marker;
-import org.openrewrite.maven.MavenExecutionContextView;
-import org.openrewrite.maven.MavenSettings;
-import org.openrewrite.style.NamedStyles;
-import org.openrewrite.tree.ParsingEventListener;
-import org.openrewrite.tree.ParsingExecutionContextView;
-import org.openrewrite.xml.tree.Xml;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.core.io.Resource;
-import org.springframework.sbm.parsers.events.StartedParsingProjectEvent;
-import org.springframework.sbm.parsers.events.SuccessfullyParsedProjectEvent;
-import org.springframework.sbm.parsers.maven.BuildFileParser;
-import org.springframework.sbm.parsers.maven.MavenProjectAnalyzer;
-import org.springframework.sbm.parsers.maven.ProvenanceMarkerFactory;
-import org.springframework.sbm.scopes.ScanScope;
-
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Project parser parsing resources under a given {@link Path} to OpenRewrite abstract syntax tree (AST).
- * The implementation aims to produce the exact same result as the build tool plugins provided by OpenRewrite.
- * The AST is provided as {@code List<}{@link SourceFile}{@code >}.
- *
- *
- * This dummy code shows how the AST can be used to run OpenRewrite recipes:
- *
- *
{@code
- * Path projectBaseDir = ...
- * RewriteProjectParser parser = ...
- * RewriteRecipeDiscovery discovery = ...
- * RewriteProjectParsingResult parsingResult = parser.parse(projectBaseDir);
- * List ast = parsingResult.sourceFiles();
- * ExecutionContext ctx = parsingResult.executionContext();
- * List recipes = discovery.discoverRecipes();
- * RecipeRun recipeRun = recipes.get(0).run(ast, ctx);
- * }
- *
- *
- * @author Fabian Krüger
- * @see org.springframework.sbm.recipes.RewriteRecipeDiscovery
- */
-@Slf4j
-@RequiredArgsConstructor
-public class RewriteProjectParser {
-
- private final ProvenanceMarkerFactory provenanceMarkerFactory;
- private final BuildFileParser buildFileParser;
- private final SourceFileParser sourceFileParser;
- private final StyleDetector styleDetector;
- private final ParserProperties parserProperties;
- private final ParsingEventListener parsingEventListener;
- private final ApplicationEventPublisher eventPublisher;
- private final ScanScope scanScope;
- private final ConfigurableListableBeanFactory beanFactory;
- private final ProjectScanner scanner;
- private final ExecutionContext executionContext;
- private final MavenProjectAnalyzer mavenProjectAnalyzer;
-
-
- /**
- * Parse the given {@code baseDir} to OpenRewrite AST.
- */
- public RewriteProjectParsingResult parse(Path baseDir) {
- List resources = scanner.scan(baseDir);
- return this.parse(baseDir, resources);
- }
-
- /**
- * Parse given {@link Resource}s in {@code baseDir} to OpenRewrite AST representation.
- */
- public RewriteProjectParsingResult parse(Path givenBaseDir, List resources) {
- scanScope.clear(beanFactory);
-
- final Path baseDir = normalizePath(givenBaseDir);
-
- eventPublisher.publishEvent(new StartedParsingProjectEvent(resources));
-
- ParsingExecutionContextView.view(executionContext).setParsingListener(parsingEventListener);
-
- // TODO: "runPerSubmodule"
- // TODO: See ConfigurableRewriteMojo#getPlainTextMasks()
- // TODO: where to retrieve styles from? --> see AbstractRewriteMojo#getActiveStyles() & AbstractRewriteMojo#loadStyles()
- List styles = List.of();
-
- // Get the ordered otherSourceFiles of projects
- ParserContext parserContext = mavenProjectAnalyzer.createParserContext(baseDir, resources);
-
- // generate provenance
- Map> provenanceMarkers = provenanceMarkerFactory.generateProvenanceMarkers(baseDir, parserContext);
-
- // 127: parse build files
- // TODO: 945 this map is only used to lookup module pom by path in SourceFileParser. If possible provide the build file from ParserContext and remove this map.
- List parsedBuildFiles = buildFileParser.parseBuildFiles(baseDir, parserContext.getBuildFileResources(), parserContext.getActiveProfiles(), executionContext, parserProperties.isSkipMavenParsing(), provenanceMarkers);
- parserContext.setParsedBuildFiles(parsedBuildFiles);
-
- log.trace("Start to parse %d source files in %d modules".formatted(resources.size() + parsedBuildFiles.size(), parsedBuildFiles.size()));
- List otherSourceFiles = sourceFileParser.parseOtherSourceFiles(baseDir, parserContext, resources, provenanceMarkers, styles, executionContext);
-
- List sortedBuildFileDocuments = parserContext.getSortedBuildFileDocuments();
-
- List resultingList = new ArrayList<>();
- resultingList.addAll(sortedBuildFileDocuments);
- resultingList.addAll(otherSourceFiles);
- List sourceFiles = styleDetector.sourcesWithAutoDetectedStyles(resultingList.stream());
-
- eventPublisher.publishEvent(new SuccessfullyParsedProjectEvent(sourceFiles));
-
- return new RewriteProjectParsingResult(sourceFiles, executionContext);
- }
-
- @NotNull
- private static Path normalizePath(Path givenBaseDir) {
- if (!givenBaseDir.isAbsolute()) {
- givenBaseDir = givenBaseDir.toAbsolutePath().normalize();
- }
- final Path baseDir = givenBaseDir;
- return baseDir;
- }
-
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParsingResult.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParsingResult.java
deleted file mode 100644
index 4c5350949..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteProjectParsingResult.java
+++ /dev/null
@@ -1,27 +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.openrewrite.ExecutionContext;
-import org.openrewrite.SourceFile;
-
-import java.util.List;
-
-/**
- * @author Fabian Krüger
- */
-public record RewriteProjectParsingResult(List sourceFiles, ExecutionContext executionContext) {
-}
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
deleted file mode 100644
index 6d7e91c8f..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/RewriteResourceParser.java
+++ /dev/null
@@ -1,318 +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 lombok.extern.slf4j.Slf4j;
-import org.jetbrains.annotations.NotNull;
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.Parser;
-import org.openrewrite.SourceFile;
-import org.openrewrite.hcl.HclParser;
-import org.openrewrite.java.JavaParser;
-import org.openrewrite.json.JsonParser;
-import org.openrewrite.properties.PropertiesParser;
-import org.openrewrite.protobuf.ProtoParser;
-import org.openrewrite.quark.QuarkParser;
-import org.openrewrite.text.PlainTextParser;
-import org.openrewrite.xml.XmlParser;
-import org.openrewrite.yaml.YamlParser;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.sbm.utils.ResourceUtil;
-
-import java.nio.file.Path;
-import java.nio.file.PathMatcher;
-import java.nio.file.Paths;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-/**
- * 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.
- */
-@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 Collection exclusions;
- private final int sizeThresholdMb;
- private final Collection excludedDirectories;
- private final Collection plainTextMasks;
-
- /**
- * Sometimes java files will exist in the src/main/resources directory. For example, Drools:
- */
- private final JavaParser.Builder extends JavaParser, ?> javaParserBuilder;
- private final ExecutionContext executionContext;
-
- public RewriteResourceParser(
- Path baseDir,
- Collection exclusions,
- Collection plainTextMasks,
- int sizeThresholdMb,
- Collection excludedDirectories,
- JavaParser.Builder extends JavaParser, ?> javaParserBuilder,
- ExecutionContext executionContext
- ) {
- this.baseDir = baseDir;
- this.javaParserBuilder = javaParserBuilder;
- this.executionContext = executionContext;
- this.exclusions = pathMatchers(baseDir, exclusions);
- this.sizeThresholdMb = sizeThresholdMb;
- this.excludedDirectories = excludedDirectories;
- this.plainTextMasks = pathMatchers(baseDir, plainTextMasks);
- }
-
- private Collection pathMatchers(Path basePath, Collection pathExpressions) {
- return pathExpressions.stream()
- .map(o -> basePath.getFileSystem().getPathMatcher("glob:" + o))
- .collect(Collectors.toList());
- }
-
- public Stream parse(Path searchDir, List resources, Set alreadyParsed) {
- // TODO: 945 remove/clean this up
- List resourcesLeft = resources.stream()
- .filter(r -> alreadyParsed.stream().noneMatch(path -> ResourceUtil.getPath(r).toString().startsWith(path.toString())))
- .toList();
- return this.parseSourceFiles(searchDir, resourcesLeft, alreadyParsed, executionContext);
-
-
-//
-// Stream sourceFiles = Stream.empty();
-// if (!searchDir.toFile().exists()) {
-// return sourceFiles;
-// } else {
-// Consumer errorConsumer = (t) -> {
-// this.logger.debug("Error parsing", t);
-// };
-// InMemoryExecutionContext ctx = new InMemoryExecutionContext(errorConsumer);
-//
-// try {
-// sourceFiles = Stream.concat(sourceFiles, this.parseSourceFiles(searchDir, alreadyParsed, ctx));
-// return sourceFiles;
-// } catch (IOException var7) {
-// this.logger.error(var7.getMessage(), var7);
-// throw new UncheckedIOException(var7);
-// }
-// }
- }
-
- @SuppressWarnings({"DuplicatedCode", "unchecked"})
- public Stream parseSourceFiles(
- Path searchDir,
- List resources,
- Set alreadyParsed,
- ExecutionContext ctx) {
-
- List resourcesLeft = new ArrayList<>();
- List quarkPaths = new ArrayList<>();
- List plainTextPaths = new ArrayList<>();
-
- List filteredResources = resources
- .stream()
- .filter(r -> ResourceUtil.getPath(r).toString().startsWith(searchDir.toString()))
- .toList();
-
- filteredResources.forEach(resource -> {
- Path file = ResourceUtil.getPath(resource);
- Path dir = file.getParent();
- if (isExcluded(dir) || isIgnoredDirectory(searchDir, dir) || excludedDirectories.contains(dir) || alreadyParsed.contains(new FileSystemResource(dir)) || alreadyParsed.contains(resource)) {
- return;
- } else {
- // FIXME: 945 only check threshold if value > 0 is given
- long fileSize = ResourceUtil.contentLength(resource);
- if (isOverSizeThreshold(fileSize)) {
- 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)) {
- plainTextPaths.add(file);
- } else {
- resourcesLeft.add(file);
- }
- }
- });
-
- Stream sourceFiles = Stream.empty();
-
- JavaParser javaParser = javaParserBuilder.build();
- List javaPaths = new ArrayList<>();
-
- JsonParser jsonParser = new JsonParser();
- List jsonPaths = new ArrayList<>();
-
- XmlParser xmlParser = new XmlParser();
- List xmlPaths = new ArrayList<>();
-
- YamlParser yamlParser = new YamlParser();
- List yamlPaths = new ArrayList<>();
-
- PropertiesParser propertiesParser = new PropertiesParser();
- List propertiesPaths = new ArrayList<>();
-
- ProtoParser protoParser = new ProtoParser();
- List protoPaths = new ArrayList<>();
-
- // Python currently not supported
-// PythonParser pythonParser = PythonParser.builder().build();
-// List pythonPaths = new ArrayList<>();
-
- HclParser hclParser = HclParser.builder().build();
- List hclPaths = new ArrayList<>();
-
- PlainTextParser plainTextParser = new PlainTextParser();
-
- QuarkParser quarkParser = new QuarkParser();
-
- filteredResources
- .forEach(resource -> {
- // See https://github.com/quarkusio/quarkus/blob/main/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/resteasy-reactive-codestart/java/src/main/java/org/acme/%7Bresource.class-name%7D.tpl.qute.java
- // for an example of why we don't want qute files be parsed as java
- Path path = ResourceUtil.getPath(resource);
-// if (javaParser.accept(path) && !path.toString().endsWith(".qute.java")) {
-// javaPaths.add(path);
-// }
- if (jsonParser.accept(path)) {
- jsonPaths.add(path);
- } else if (xmlParser.accept(path)) {
- xmlPaths.add(path);
- } else if (yamlParser.accept(path)) {
- yamlPaths.add(path);
- } else if (propertiesParser.accept(path)) {
- propertiesPaths.add(path);
- } else if (protoParser.accept(path)) {
- protoPaths.add(path);
- } /*else if(pythonParser.accept(path)) {
- pythonPaths.add(path);
- }*/ else if (hclParser.accept(path)) {
- hclPaths.add(path);
- } else if (quarkParser.accept(path)) {
- quarkPaths.add(path);
- }
- });
-
- Map pathToResource = filteredResources.stream().collect(Collectors.toMap(r -> ResourceUtil.getPath(r), r -> r));
-
- if (!javaPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, javaPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) javaParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(javaPaths);
- }
-
- if (!jsonPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, jsonPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) jsonParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(jsonPaths);
- }
-
- if (!xmlPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, xmlPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) xmlParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(xmlPaths);
- }
-
- if (!yamlPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, yamlPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) yamlParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(yamlPaths);
- }
-
- if (!propertiesPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, propertiesPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) propertiesParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(propertiesPaths);
- }
-
- if (!protoPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, protoPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) protoParser.parseInputs(inputs, baseDir, ctx));
- 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 (!hclPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, hclPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) hclParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(hclPaths);
- }
-
- if (!plainTextPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, plainTextPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) plainTextParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(plainTextPaths);
- }
-
- if (!quarkPaths.isEmpty()) {
- List inputs = getInputs(pathToResource, quarkPaths);
- sourceFiles = Stream.concat(sourceFiles, (Stream) quarkParser.parseInputs(inputs, baseDir, ctx));
- alreadyParsed.addAll(quarkPaths);
- }
-
- return sourceFiles;
- }
-
- @NotNull
- private static List getInputs(Map pathResourceMap, List paths) {
- return paths.stream()
- .map(path -> new Parser.Input(path, () -> ResourceUtil.getInputStream(pathResourceMap.get(path)))).toList();
- }
-
- private boolean isOverSizeThreshold(long fileSize) {
- return sizeThresholdMb > 0 && fileSize > sizeThresholdMb * 1024L * 1024L;
- }
-
- private boolean isExcluded(Path path) {
- if (!exclusions.isEmpty()) {
- for (PathMatcher excluded : exclusions) {
- if (excluded.matches(baseDir.relativize(path))) {
- return true;
- }
- }
- }
- return false;
- }
-
- private boolean isParsedAsPlainText(Path path) {
- if (!plainTextMasks.isEmpty()) {
- Path computed = baseDir.relativize(path);
- if (!computed.startsWith("/")) {
- computed = Paths.get("/").resolve(computed);
- }
- for (PathMatcher matcher : plainTextMasks) {
- if (matcher.matches(computed)) {
- return true;
- }
- }
- }
- return false;
- }
-
- private boolean isIgnoredDirectory(Path searchDir, Path path) {
- for (Path pathSegment : searchDir.relativize(path)) {
- if (DEFAULT_IGNORED_DIRECTORIES.contains(pathSegment.toString())) {
- return true;
- }
- }
- return false;
- }
-}
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
deleted file mode 100644
index ec573f7a5..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceFileParser.java
+++ /dev/null
@@ -1,63 +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 lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.SourceFile;
-import org.openrewrite.marker.Marker;
-import org.openrewrite.style.NamedStyles;
-import org.openrewrite.xml.tree.Xml;
-import org.springframework.core.io.Resource;
-import org.springframework.sbm.parsers.maven.MavenModuleParser;
-
-import java.nio.file.Path;
-import java.util.*;
-
-/**
- * @author Fabian Krüger
- */
-@Slf4j
-
-@RequiredArgsConstructor
-public class SourceFileParser {
-
- private final MavenModuleParser moduleParser;
-
- public List parseOtherSourceFiles(
- Path baseDir,
- ParserContext parserContext,
- List resources,
- Map> provenanceMarkers,
- List styles,
- ExecutionContext executionContext) {
-
- Set parsedSourceFiles = new LinkedHashSet<>();
-
- parserContext.getSortedProjects().forEach(currentMavenProject -> {
- Xml.Document moduleBuildFile = currentMavenProject.getSourceFile();
- List markers = provenanceMarkers.get(currentMavenProject.getPomFilePath());
- if(markers == null || markers.isEmpty()) {
- log.warn("Could not find provenance markers for resource '%s'".formatted(parserContext.getMatchingBuildFileResource(currentMavenProject)));
- }
- List sourceFiles = moduleParser.parseModuleSourceFiles(resources, currentMavenProject, moduleBuildFile, markers, styles, executionContext, baseDir);
- parsedSourceFiles.addAll(sourceFiles);
- });
-
- return new ArrayList<>(parsedSourceFiles);
- }
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceSetParsingResult.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceSetParsingResult.java
deleted file mode 100644
index cba9db43b..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/SourceSetParsingResult.java
+++ /dev/null
@@ -1,27 +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.openrewrite.SourceFile;
-import org.openrewrite.java.tree.JavaType;
-
-import java.util.List;
-
-/**
- * @author Fabian Krüger
- */
-public record SourceSetParsingResult(List sourceFiles, List classpath) {
-}
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
deleted file mode 100644
index 6b51bf0b4..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/StyleDetector.java
+++ /dev/null
@@ -1,83 +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.openrewrite.SourceFile;
-import org.openrewrite.Tree;
-import org.openrewrite.internal.ListUtils;
-import org.openrewrite.java.tree.JavaSourceFile;
-import org.openrewrite.marker.Marker;
-import org.openrewrite.style.NamedStyles;
-import org.openrewrite.xml.tree.Xml;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.function.UnaryOperator;
-import java.util.stream.Stream;
-
-/**
- * @author Fabian Krüger
- */
-
-public class StyleDetector {
-
- 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));
- }
-
- private UnaryOperator applyAutodetectedStyle(Map, NamedStyles> stylesByType) {
- return (before) -> {
- Iterator var2 = stylesByType.entrySet().iterator();
-
- 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/parsers/events/FinishedParsingResourceEvent.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/FinishedParsingResourceEvent.java
deleted file mode 100644
index 65135eef2..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/FinishedParsingResourceEvent.java
+++ /dev/null
@@ -1,25 +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.events;
-
-import org.openrewrite.Parser;
-import org.openrewrite.SourceFile;
-
-/**
- * @author Fabian Krüger
- */
-public record FinishedParsingResourceEvent(Parser.Input input, SourceFile sourceFile){
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/IntermediateParsingEvent.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/IntermediateParsingEvent.java
deleted file mode 100644
index 8a2b036b5..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/IntermediateParsingEvent.java
+++ /dev/null
@@ -1,23 +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.events;
-
-/**
- * @author Fabian Krüger
- */
-public record IntermediateParsingEvent(String stateMessage) {
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/RewriteParsingEventListenerAdapter.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/RewriteParsingEventListenerAdapter.java
deleted file mode 100644
index 923194440..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/RewriteParsingEventListenerAdapter.java
+++ /dev/null
@@ -1,51 +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.events;
-
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.openrewrite.Parser;
-import org.openrewrite.SourceFile;
-import org.openrewrite.tree.ParsingEventListener;
-import org.springframework.context.ApplicationEventPublisher;
-
-/**
- * Adapter listening to OpenRewrite ParsingEvents and publishing them as Spring application events.
- *
- * @author Fabian Krüger
- */
-@Slf4j
-@RequiredArgsConstructor
-public class RewriteParsingEventListenerAdapter implements ParsingEventListener {
-
- private final ApplicationEventPublisher eventPublisher;
-
- @Override
- public void intermediateMessage(String stateMessage) {
- eventPublisher.publishEvent(new IntermediateParsingEvent(stateMessage));
- }
-
- @Override
- public void startedParsing(Parser.Input input) {
- eventPublisher.publishEvent(new StartedParsingResourceEvent(input));
- }
-
- @Override
- public void parsed(Parser.Input input, SourceFile sourceFile) {
- log.debug("Parsed %s to %s".formatted(input.getPath(), sourceFile.getSourcePath()));
- eventPublisher.publishEvent(new FinishedParsingResourceEvent(input, sourceFile));
- }
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/StartedParsingProjectEvent.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/StartedParsingProjectEvent.java
deleted file mode 100644
index d91d2fe77..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/StartedParsingProjectEvent.java
+++ /dev/null
@@ -1,26 +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.events;
-
-import org.springframework.core.io.Resource;
-
-import java.util.List;
-
-/**
- * @author Fabian Krüger
- */
-public record StartedParsingProjectEvent(List resources) {
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/StartedParsingResourceEvent.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/StartedParsingResourceEvent.java
deleted file mode 100644
index ac3d4db9f..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/StartedParsingResourceEvent.java
+++ /dev/null
@@ -1,24 +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.events;
-
-import org.openrewrite.Parser;
-
-/**
- * @author Fabian Krüger
- */
-public record StartedParsingResourceEvent(Parser.Input input){
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/SuccessfullyParsedProjectEvent.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/SuccessfullyParsedProjectEvent.java
deleted file mode 100644
index 3866603be..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/events/SuccessfullyParsedProjectEvent.java
+++ /dev/null
@@ -1,26 +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.events;
-
-import org.openrewrite.SourceFile;
-
-import java.util.List;
-
-/**
- * @author Fabian Krüger
- */
-public record SuccessfullyParsedProjectEvent(List sourceFiles) {
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/maven/BuildFileParser.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/maven/BuildFileParser.java
deleted file mode 100644
index 82f84440a..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/maven/BuildFileParser.java
+++ /dev/null
@@ -1,169 +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.maven;
-
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.Parser;
-import org.openrewrite.SourceFile;
-import org.openrewrite.marker.Marker;
-import org.openrewrite.maven.MavenParser;
-import org.openrewrite.xml.tree.Xml;
-import org.springframework.core.io.Resource;
-import org.springframework.sbm.utils.ResourceUtil;
-import org.springframework.util.Assert;
-
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static java.util.Collections.emptyList;
-
-/**
- * Copies behaviour from rewrite-maven-plugin:5.2.2
- *
- * @author Fabian Krüger
- */
-@Slf4j
-@RequiredArgsConstructor
-public class BuildFileParser {
-
- private final MavenSettingsInitializer mavenSettingsInitilizer;
-
- /**
- * Parse a list of Maven Pom files to a {@code List} of {@link Xml.Document}s.
- * The {@link Xml.Document}s get marked with {@link org.openrewrite.maven.tree.MavenResolutionResult} and the provided provenance markers.
- *
- * @param baseDir the {@link Path} to the root of the scanned project
- * @param buildFiles the list of resources for relevant pom files.
- * @param activeProfiles the active Maven profiles
- * @param executionContext the ExecutionContext to use
- * @param skipMavenParsing skip parsing Maven files
- * @param provenanceMarkers the map of markers to be added
- */
- public List parseBuildFiles(
- Path baseDir,
- List buildFiles,
- List activeProfiles,
- ExecutionContext executionContext,
- boolean skipMavenParsing,
- Map> provenanceMarkers
- ) {
- Assert.notNull(baseDir, "Base directory must be provided but was null.");
- Assert.notEmpty(buildFiles, "No build files provided.");
- List nonPomFiles = retrieveNonPomFiles(buildFiles);
- Assert.isTrue(nonPomFiles.isEmpty(), "Provided resources which are not Maven build files: '%s'".formatted(nonPomFiles.stream().map(r -> ResourceUtil.getPath(r).toAbsolutePath()).toList()));
- List resourcesWithoutProvenanceMarker = findResourcesWithoutProvenanceMarker(baseDir, buildFiles, provenanceMarkers);
- Assert.isTrue(resourcesWithoutProvenanceMarker.isEmpty(), "No provenance marker provided for these pom files %s".formatted(resourcesWithoutProvenanceMarker.stream().map(r -> ResourceUtil.getPath(r).toAbsolutePath()).toList()));
-
- if(skipMavenParsing) {
- log.info("Maven parsing skipped [parser.skipMavenParsing=true].");
- return List.of();
- }
-
- // 380 : 382
- // already
-// List upstreamPoms = collectUpstreamPomFiles(pomFiles);
-// pomFiles.addAll(upstreamPoms);
-
- // 383
- MavenParser.Builder mavenParserBuilder = MavenParser.builder().mavenConfig(baseDir.resolve(".mvn/maven.config"));
-
- // 385 : 387
- mavenSettingsInitilizer.initializeMavenSettings();
-
- // 395 : 398
- mavenParserBuilder.activeProfiles(activeProfiles.toArray(new String[]{}));
-
- // 400 : 402
- List parsedPoms = parsePoms(baseDir, buildFiles, mavenParserBuilder, executionContext)
- .map(pp -> this.markPomFile(pp, provenanceMarkers.getOrDefault(baseDir.resolve(pp.getSourcePath()), emptyList())))
- .toList();
-
- return parsedPoms;
- }
-
- private List findResourcesWithoutProvenanceMarker(Path baseDir, List buildFileResources, Map> provenanceMarkers) {
- return buildFileResources.stream()
- .filter(r -> !provenanceMarkers.containsKey(baseDir.resolve(ResourceUtil.getPath(r)).normalize()))
- .toList();
- }
-
- private static List retrieveNonPomFiles(List buildFileResources) {
- return buildFileResources.stream().filter(r -> !"pom.xml".equals(ResourceUtil.getPath(r).getFileName().toString())).toList();
- }
-
- private Xml.Document markPomFile(Xml.Document pp, List markers) {
- for (Marker marker : markers) {
- pp = pp.withMarkers(pp.getMarkers().addIfAbsent(marker));
- }
- return pp;
- }
-
- private Map createResult(Path basePath, List pomFiles, List parsedPoms) {
- return parsedPoms.stream()
- .map(pom -> mapResourceToDocument(basePath, pom, pomFiles))
- .collect(Collectors.toMap(e-> ResourceUtil.getPath(e.getKey()), e -> e.getValue()));
- }
-
- private Map.Entry mapResourceToDocument(Path basePath, SourceFile pom, List parsedPoms) {
- Xml.Document doc = (Xml.Document) pom;
- Resource resource = parsedPoms.stream()
- .filter(p -> ResourceUtil.getPath(p).toString().equals(basePath.resolve(pom.getSourcePath()).toAbsolutePath().normalize().toString()))
- .findFirst()
- .orElseThrow(() -> new IllegalStateException("Could not find matching path for Xml.Document '%s'".formatted(pom.getSourcePath().toAbsolutePath().normalize().toString())));
- return Map.entry(resource, doc);
- }
-
- private Stream parsePoms(Path baseDir, List pomFiles, MavenParser.Builder mavenParserBuilder, ExecutionContext executionContext) {
- Iterable pomFileInputs = pomFiles.stream()
- .map(p -> new Parser.Input(ResourceUtil.getPath(p), () -> ResourceUtil.getInputStream(p)))
- .toList();
- return mavenParserBuilder.build().parseInputs(pomFileInputs, baseDir, executionContext).map(Xml.Document.class::cast);
- }
-
- public List filterAndSortBuildFiles(List resources) {
- return resources.stream()
- .filter(r -> "pom.xml".equals(ResourceUtil.getPath(r).toFile().getName()))
- .filter(r -> filterTestResources(r))
- .sorted((r1, r2) -> {
-
- Path r1Path = ResourceUtil.getPath(r1);
- ArrayList r1PathParts = new ArrayList<>();
- r1Path.iterator().forEachRemaining(it -> r1PathParts.add(it.toString()));
-
- Path r2Path = ResourceUtil.getPath(r2);
- ArrayList r2PathParts = new ArrayList<>();
- r2Path.iterator().forEachRemaining(it -> r2PathParts.add(it.toString()));
- return Integer.compare(r1PathParts.size(), r2PathParts.size());
- })
- .toList();
- }
-
- private static boolean filterTestResources(Resource r) {
- String path = ResourceUtil.getPath(r).toString();
- boolean underTest = path.contains("src/test");
- if(underTest) {
- log.info("Ignore build file '%s' having 'src/test' in its path indicating it's a build file for tests.".formatted(path));
- }
- return !underTest;
- }
-
-}
diff --git a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/maven/MavenConfigFileParser.java b/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/maven/MavenConfigFileParser.java
deleted file mode 100644
index 29c4d13e2..000000000
--- a/sbm-support-rewrite/src/main/java/org/springframework/sbm/parsers/maven/MavenConfigFileParser.java
+++ /dev/null
@@ -1,350 +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.maven;
-
-import org.apache.commons.cli.*;
-import org.apache.maven.cli.CleanArgument;
-import org.jetbrains.annotations.NotNull;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-/**
- * Parse {@code .mvn/maven.config/} and provide access to relevant settings.
- * Code thankfully taken from org.apache.maven.cli.CLIManager.
- *
- * @author Fabian Krüger
- */
-class MavenConfigFileParser {
-
- private static final char ALTERNATE_POM_FILE = 'f';
-
- private static final char BATCH_MODE = 'B';
-
- private static final char SET_USER_PROPERTY = 'D';
-
- private static final char OFFLINE = 'o';
-
- private static final char QUIET = 'q';
-
- private static final char DEBUG = 'X';
-
- private static final char ERRORS = 'e';
-
- private static final char HELP = 'h';
-
- private static final char VERSION = 'v';
-
- private static final char SHOW_VERSION = 'V';
-
- private static final char NON_RECURSIVE = 'N';
-
- private static final char UPDATE_SNAPSHOTS = 'U';
-
- private static final char ACTIVATE_PROFILES = 'P';
-
- private static final String SUPRESS_SNAPSHOT_UPDATES = "nsu";
-
- private static final char CHECKSUM_FAILURE_POLICY = 'C';
-
- private static final char CHECKSUM_WARNING_POLICY = 'c';
-
- private static final char ALTERNATE_USER_SETTINGS = 's';
-
- private static final String ALTERNATE_GLOBAL_SETTINGS = "gs";
-
- private static final char ALTERNATE_USER_TOOLCHAINS = 't';
-
- private static final String ALTERNATE_GLOBAL_TOOLCHAINS = "gt";
-
- private static final String FAIL_FAST = "ff";
-
- private static final String FAIL_AT_END = "fae";
-
- private static final String FAIL_NEVER = "fn";
-
- private static final String RESUME_FROM = "rf";
-
- private static final String PROJECT_LIST = "pl";
-
- private static final String ALSO_MAKE = "am";
-
- private static final String ALSO_MAKE_DEPENDENTS = "amd";
-
- private static final String LOG_FILE = "l";
-
- private static final String ENCRYPT_MASTER_PASSWORD = "emp";
-
- private static final String ENCRYPT_PASSWORD = "ep";
-
- private static final String THREADS = "T";
-
- private static final String BUILDER = "b";
-
- private static final String NO_TRANSFER_PROGRESS = "ntp";
-
- private static final String COLOR = "color";
- private static final String MVN_MAVEN_CONFIG = ".mvn/maven.config";
- public List getActivatedProfiles(Path baseDir) {
- File configFile = baseDir.resolve(MVN_MAVEN_CONFIG).toFile();
- if (configFile.isFile()) {
- try (Stream lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) {
- String[] args = readFile(lines);
- return parse(args).stream()
- .filter(o -> String.valueOf(ACTIVATE_PROFILES).equals(o.getOpt()))
- .map(Option::getValue)
- .map(v -> v.split(","))
- .flatMap(Arrays::stream)
- .map(String::trim)
- .toList();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- } else {
- return List.of();
- }
- }
-
- public Map getUserProperties(Path baseDir) {
- File configFile = baseDir.resolve(MVN_MAVEN_CONFIG).toFile();
- if (configFile.isFile()) {
- try (Stream lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) {
- String[] args = readFile(lines);
- return parse(args).stream()
- .filter(o -> String.valueOf(SET_USER_PROPERTY).equals(o.getOpt()))
- .map(Option::getValue)
- .filter(v -> v.contains("="))
- .map(v -> v.split("="))
- .collect(Collectors.toMap(a -> a[0], a -> a[1]));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- } else {
- return Map.of();
- }
- }
-
- @NotNull
- private static String[] readFile(Stream lines) {
- return lines.filter(arg -> !arg.isEmpty() && !arg.startsWith("#"))
- .toArray(String[]::new);
- }
-
- public List