Skip to content

Commit

Permalink
Adopted changes in sbm-core
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Nov 7, 2023
1 parent 73a9586 commit 4f8c3ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Stream<SourceFile> parse(String... sources) {

@Override
public Stream<SourceFile> parse(ExecutionContext ctx, String... sources) {
mavenSettingsInitializer.initializeMavenSettings(ctx);
mavenSettingsInitializer.initializeMavenSettings();
return parser.parse(ctx, sources);
}

Expand All @@ -88,7 +88,7 @@ public Stream<SourceFile> parseInputs(Iterable<Input> sources, @Nullable Path re
if (relativeTo != null) {
initMavenParser(ctx, relativeTo);
} else {
mavenSettingsInitializer.initializeMavenSettings(ctx);
mavenSettingsInitializer.initializeMavenSettings();
}
return parser.parseInputs(sources, relativeTo, ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@
import org.openrewrite.maven.tree.ResolvedDependency;
import org.openrewrite.maven.tree.Scope;
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.sbm.parsers.maven.MavenPasswordDecrypter;
import org.springframework.sbm.parsers.maven.MavenSettingsInitializer;
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.parsers.RewriteExecutionContext;
import org.springframework.sbm.scopes.ProjectMetadata;

import java.util.List;
import java.util.Set;
Expand All @@ -34,7 +39,7 @@

public class ClasspathRegistryTest {
@Test
void classpathRegistryShouldKeepOnlyExternalDependencies() {
void classpathRegistryShouldKeepOnlyExternalDependencies() throws PlexusCipherException {

@Language("xml")
String parentPom =
Expand Down Expand Up @@ -105,7 +110,7 @@ void classpathRegistryShouldKeepOnlyExternalDependencies() {

ExecutionContext executionContext = new RewriteExecutionContext();
List<Xml.Document> poms = new RewriteMavenParser(
new MavenSettingsInitializer(),
new MavenSettingsInitializer(new MavenPasswordDecrypter(new DefaultSecDispatcher(new DefaultPlexusCipher())), executionContext, new ProjectMetadata()),
executionContext
).parse(parentPom, pom1, pom2)
.map(Xml.Document.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@

import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.openrewrite.ExecutionContext;
import org.openrewrite.java.marker.JavaProject;
import org.openrewrite.java.marker.JavaVersion;
import org.openrewrite.marker.BuildTool;
import org.openrewrite.marker.Marker;
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.sbm.parsers.maven.MavenPasswordDecrypter;
import org.springframework.sbm.parsers.maven.MavenSettingsInitializer;
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.parsers.RewriteExecutionContext;
import org.springframework.sbm.scopes.ProjectMetadata;

import java.nio.file.Path;
import java.util.List;
Expand All @@ -34,7 +40,7 @@
class JavaProvenanceMarkerFactoryTest {

@Test
void test() {
void test() throws PlexusCipherException {
JavaProvenanceMarkerFactory sut = new JavaProvenanceMarkerFactory();

String pomXmlSource =
Expand Down Expand Up @@ -63,7 +69,8 @@ void test() {
"</project>";

Path projectDirectory = Path.of("./faked-project-dir/pom.xml");
Xml.Document maven = new RewriteMavenParser(new MavenSettingsInitializer(), new RewriteExecutionContext()).parse(pomXmlSource).toList().get(0).withSourcePath(Path.of("pom.xml"));
ExecutionContext executionContext = new RewriteExecutionContext();
Xml.Document maven = new RewriteMavenParser(new MavenSettingsInitializer(new MavenPasswordDecrypter(new DefaultSecDispatcher(new DefaultPlexusCipher())), executionContext, new ProjectMetadata()), new RewriteExecutionContext()).parse(pomXmlSource).toList().get(0).withSourcePath(Path.of("pom.xml"));

List<Marker> javaProvenanceMarkers = sut.createJavaProvenanceMarkers(maven, projectDirectory, new RewriteExecutionContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public class MavenSettingsInitializer {
private final MavenPasswordDecrypter mavenPasswordDecrypter;
private final ExecutionContext executionContext;
private final ProjectMetadata projectMetadata;
/**
* @deprecated initialization in ExecutionoContext is done in ProjectParser
*/

public void initializeMavenSettings() {
String repo = "file:" + Path.of(System.getProperty("user.home")).resolve(".m2/repository") + "/";
MavenRepository mavenRepository = new MavenRepository("local", repo, "true", "true", true, null, null, false);
Expand Down

0 comments on commit 4f8c3ef

Please sign in to comment.