Skip to content

Commit 3c45670

Browse files
committed
[#239][#240] Updated classpath for maven plugin
1 parent 75ec3b9 commit 3c45670

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

atom-maven-plugin/src/main/java/com/pragmaticobjects/oo/atom/maven/BaseMojo.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.pragmaticobjects.oo.atom.codegen.cp.CpFromString;
77
import com.pragmaticobjects.oo.atom.codegen.stage.Stage;
88
import com.pragmaticobjects.oo.atom.instrumentation.ApplyStages;
9+
import io.vavr.collection.HashSet;
910
import org.apache.maven.artifact.Artifact;
1011
import org.apache.maven.plugin.AbstractMojo;
1112
import org.apache.maven.plugin.MojoExecutionException;
@@ -17,6 +18,7 @@
1718
import java.nio.file.Path;
1819
import java.util.Optional;
1920
import java.util.stream.Collectors;
21+
import org.apache.maven.plugin.descriptor.PluginDescriptor;
2022

2123
/**
2224
* Base Mojo for different instrumentations
@@ -31,13 +33,19 @@ public abstract class BaseMojo extends AbstractMojo {
3133
@Parameter
3234
private String[] excludePackages;
3335

34-
protected final void doInstrumentation(Stage stage, Path workingDirectory) throws MojoExecutionException, MojoFailureException {
35-
if(!project.getPackaging().equals("pom") || instrumentPomProjects) {
36-
String classPath = project.getArtifacts().stream()
36+
protected final ClassPath buildClassPath() {
37+
PluginDescriptor pluginDescriptor = (PluginDescriptor) this.getPluginContext().get("pluginDescriptor");
38+
String classPath = HashSet.ofAll(project.getArtifacts())
39+
.addAll(pluginDescriptor.getArtifacts())
3740
.map(Artifact::getFile)
3841
.map(File::toString)
3942
.collect(Collectors.joining(":"));
40-
ClassPath cp = new CpFromString(classPath);
43+
ClassPath cp = new CpFromString(classPath);
44+
return cp;
45+
}
46+
47+
protected final void doInstrumentation(Stage stage, ClassPath cp, Path workingDirectory) throws MojoExecutionException, MojoFailureException {
48+
if(!project.getPackaging().equals("pom") || instrumentPomProjects) {
4149
new ApplyStages(
4250
cp,
4351
workingDirectory,

atom-maven-plugin/src/main/java/com/pragmaticobjects/oo/atom/maven/InstrumentMojo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class InstrumentMojo extends BaseMojo {
5050
public final void execute() throws MojoExecutionException, MojoFailureException {
5151
doInstrumentation(
5252
new StandardInstrumentationStage(stubbedInstrumentation),
53+
buildClassPath(),
5354
Paths.get(outputDirectory)
5455
);
5556
}

atom-maven-plugin/src/main/java/com/pragmaticobjects/oo/atom/maven/InstrumentTestsMojo.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package com.pragmaticobjects.oo.atom.maven;
2525

26+
import com.pragmaticobjects.oo.atom.codegen.cp.CpCombined;
27+
import com.pragmaticobjects.oo.atom.codegen.cp.CpFromString;
2628
import com.pragmaticobjects.oo.atom.codegen.stage.StandardInstrumentationStage;
2729
import org.apache.maven.plugin.MojoExecutionException;
2830
import org.apache.maven.plugin.MojoFailureException;
@@ -40,8 +42,10 @@
4042
*/
4143
@Mojo(name = "instrument-tests", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, requiresDependencyResolution = ResolutionScope.TEST)
4244
public class InstrumentTestsMojo extends BaseMojo {
43-
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true, readonly = true)
45+
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true, readonly = true)
4446
protected String outputDirectory;
47+
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true, readonly = true)
48+
protected String testOutputDirectory;
4549

4650
@Parameter(defaultValue = "false", required = true, readonly = true)
4751
protected boolean stubbedInstrumentation;
@@ -50,7 +54,13 @@ public class InstrumentTestsMojo extends BaseMojo {
5054
public void execute() throws MojoExecutionException, MojoFailureException {
5155
doInstrumentation(
5256
new StandardInstrumentationStage(stubbedInstrumentation),
53-
Paths.get(outputDirectory)
57+
new CpCombined(
58+
buildClassPath(),
59+
new CpFromString(
60+
outputDirectory
61+
)
62+
),
63+
Paths.get(testOutputDirectory)
5464
);
5565
}
5666
}

0 commit comments

Comments
 (0)