From 419bdb27150207c66c34abc9fe0cb9535842ad63 Mon Sep 17 00:00:00 2001 From: harrisric <48761651+harrisric@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:53:01 +0000 Subject: [PATCH 1/2] Ignore additional classpath on usecase when using the plugin It is not appropriate for the plugin to assume that an arbitrary classpath will be present (particularly if used in CI-type pipelines). In order for the before refactor classes to compile the classpath will already need to include the class path. If the 'after' classpath needs to be different either the project pom can be amended upfront or else the plugin can be declared with additional dependencies. --- .../java/org/alfasoftware/astra/RefactorMojo.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java b/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java index 0261868..9023e62 100644 --- a/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java +++ b/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java @@ -59,18 +59,16 @@ public class RefactorMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException { - List testClasspathElements; - try { + List testClasspathElements; + try { testClasspathElements = project.getTestClasspathElements(); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Unable to resolve test class path for the project", e); } - // remove anything within this projects target directory as it has been + // remove anything within this projects target directory as this will invalidate it testClasspathElements.removeIf(s -> s.startsWith(targetDirectory)); - // might need to add source from other projects if running multi-module?? - UseCase useCaseInstance = getUseCaseInstance(); AstraCore.run(sourceDirectory.getAbsolutePath(), new UseCase() { @@ -86,9 +84,7 @@ public Predicate getPrefilteringPredicate() { @Override public Set getAdditionalClassPathEntries() { - HashSet additionalClassPath = new HashSet<>(useCaseInstance.getAdditionalClassPathEntries()); - additionalClassPath.addAll(testClasspathElements); - return additionalClassPath; + return Set.of(); } }); From e235b7fb172f6500f4e134440374cd4465ef17e3 Mon Sep 17 00:00:00 2001 From: harrisric <48761651+harrisric@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:31:49 +0000 Subject: [PATCH 2/2] Update astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java Co-authored-by: Joseph Hoare --- .../src/main/java/org/alfasoftware/astra/RefactorMojo.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java b/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java index 9023e62..ce24237 100644 --- a/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java +++ b/astra-maven-plugin/src/main/java/org/alfasoftware/astra/RefactorMojo.java @@ -84,7 +84,9 @@ public Predicate getPrefilteringPredicate() { @Override public Set getAdditionalClassPathEntries() { + // This is a Maven plugin that can access the full classpath required for the source code Astra is running over - no additional help required. return Set.of(); + } });