Skip to content

Commit

Permalink
fix local repository path
Browse files Browse the repository at this point in the history
cleanups
  • Loading branch information
fabapp2 committed Nov 7, 2023
1 parent 92811e6 commit 490e744
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.sbm.utils.ResourceUtil;
import org.springframework.stereotype.Component;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

Expand All @@ -45,7 +46,8 @@ public class MavenSettingsInitializer {
*/
public void initializeMavenSettings() {
String repo = "file://" + Path.of(System.getProperty("user.home")).resolve(".m2/repository") + "/";
MavenSettings mavenSettings = new MavenSettings(repo, null, null, null, null);
MavenRepository mavenRepository = new MavenRepository("local", new File(System.getProperty("user.home") + "/.m2/repository").toURI().toString(), "true", "true", true, null, null, false);
MavenSettings mavenSettings = new MavenSettings(repo, null, null, null, null, null);
// Read .m2/settings.xml
// TODO: Add support for global Maven settings (${maven.home}/conf/settings.xml).
Path mavenSettingsFile = Path.of(System.getProperty("user.home")).resolve(".m2/settings.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class JavaParserTest {
@Test
@DisplayName("shouldHaveTypeInUse")
@Disabled("Examination test")
@Disabled("Examination the JavaParser")
void shouldHaveTypeInUse() {

String localM2Repo = Path.of(System.getProperty("user.home")).resolve(".m2/repository").toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.apache.maven.shared.invoker.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.io.TempDir;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.mockito.Mockito;
import org.openrewrite.java.marker.JavaSourceSet;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
Expand All @@ -29,9 +27,7 @@
import org.openrewrite.maven.tree.MavenRepository;
import org.powermock.reflect.Whitebox;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.sbm.boot.autoconfigure.SbmSupportRewriteConfiguration;
Expand All @@ -40,17 +36,14 @@
import org.springframework.sbm.parsers.maven.RewriteMavenProjectParser;
import org.springframework.sbm.parsers.maven.SbmTestConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.FileSystemUtils;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import java.io.*;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -68,7 +61,7 @@
/**
* @author Fabian Krüger
*/
@SpringBootTest(classes = {MyTEstCOnfig.class, SbmSupportRewriteConfiguration.class, SbmTestConfiguration.class})
@SpringBootTest(classes = {MyTestConfig.class, SbmSupportRewriteConfiguration.class, SbmTestConfiguration.class})
@DirtiesContext // clear beans caching Maven settings
@Testcontainers
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand Down Expand Up @@ -379,7 +372,7 @@ private void deployDependency(Path pomXmlPath) throws MavenInvocationException {


@Configuration
class MyTEstCOnfig {
class MyTestConfig {
@Bean
MavenArtifactCache mavenArtifactCache() {
MavenArtifactCache mavenArtifactCache = new LocalMavenArtifactCache(Paths.get(System.getProperty("user.home"), ".m2", "repository")).orElse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

/**
* @author Fabian Krüger
Expand Down Expand Up @@ -59,25 +61,28 @@ public ParallelParsingResult parseParallel(Path baseDir, ParserProperties parser

threadPool.submit(() -> {
System.out.println("Start parsing with RewriteProjectParser");
RewriteProjectParsingResult tmpTestedParserResult = parseWithRewriteProjectParser(baseDir, parserProperties, executionContext);
testedParsingResultRef.set(tmpTestedParserResult);
latch.countDown();
Supplier<RewriteProjectParsingResult> s = () -> parseWithRewriteProjectParser(baseDir, parserProperties, executionContext);
handleResult(latch, s, testedParsingResultRef);
});

threadPool.submit(() -> {
System.out.println("Start parsing with RewriteMavenProjectParser");
RewriteProjectParsingResult tmpComparingParserResult = parseWithComparingParser(baseDir, parserProperties, executionContext);
comparingParsingResultRef.set(tmpComparingParserResult);
latch.countDown();
Supplier<RewriteProjectParsingResult> s = () -> parseWithComparingParser(baseDir, parserProperties, executionContext);
handleResult(latch, s, comparingParsingResultRef);
});

latch.await();
latch.await(60, TimeUnit.SECONDS);
return new ParallelParsingResult(comparingParsingResultRef.get(), testedParsingResultRef.get());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

private static void handleResult(CountDownLatch latch, Supplier<RewriteProjectParsingResult> s, AtomicReference<RewriteProjectParsingResult> ar) {
System.out.println("Start parsing with RewriteProjectParser");
ar.set(s.get());
latch.countDown();
}

public RewriteProjectParsingResult parseWithComparingParser(Path baseDir, ParserProperties parserProperties, ExecutionContext executionContext) {
RewriteMavenProjectParser comparingParser = new ComparingParserFactory().createComparingParser(parserProperties);
if (executionContext != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ private void compareMavenResolutionResultMarker(SoftAssertions softAssertions, M
List<MavenResolutionResult> comparingModules = comparing.getModules();
List<MavenResolutionResult> testedModules = tested.getModules();


// bring modules in same order
comparingModules.sort(Comparator.comparing(o -> o.getPom().getGav().toString()));
testedModules.sort(Comparator.comparing(o -> o.getPom().getGav().toString()));
Expand All @@ -259,6 +258,8 @@ private void compareMavenResolutionResultMarker(SoftAssertions softAssertions, M
compareMavenResolutionResultMarker(softAssertions, cm, testedMavenResolutionResult);
});

System.out.println(softAssertions.assertionErrorsCollected().size() + " assertions failed so far.");

Set<Scope> keys = comparing.getDependencies().keySet();
keys.forEach(k -> {
List<ResolvedDependency> comparingDependencies = comparing.getDependencies().get(k);
Expand All @@ -275,6 +276,8 @@ private void compareMavenResolutionResultMarker(SoftAssertions softAssertions, M
)
.isEqualTo(comparingDependencies);
});

System.out.println(softAssertions.assertionErrorsCollected().size() + " assertions failed so far.");
}

public ParserParityTestHelper withExecutionContextForComparingParser(ExecutionContext executionContext) {
Expand Down

0 comments on commit 490e744

Please sign in to comment.