Skip to content

Commit

Permalink
[JENKINS-49896] Add support for invoker:integration-test in addition …
Browse files Browse the repository at this point in the history
…to invoker:run
  • Loading branch information
Cyrille Le Clerc committed Mar 10, 2018
1 parent 421d8c0 commit 2d4516d
Show file tree
Hide file tree
Showing 4 changed files with 729 additions and 27 deletions.
Expand Up @@ -55,6 +55,7 @@ public class InvokerRunsPublisher extends MavenPublisher {
protected static final String GROUP_ID = "org.apache.maven.plugins";
protected static final String ARTIFACT_ID = "maven-invoker-plugin";
protected static final String RUN_GOAL = "run";
protected static final String INTEGRATION_TEST_GOAL = "integration-test";

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -84,11 +85,14 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
listener = new StreamBuildListener((OutputStream) System.err);
}

List<Element> invokerRunEvents = XmlUtils.getExecutionEvents(mavenSpyLogsElt, GROUP_ID, ARTIFACT_ID, RUN_GOAL);
List<Element> invokerRunRunEvents = XmlUtils.getExecutionEvents(mavenSpyLogsElt, GROUP_ID, ARTIFACT_ID, RUN_GOAL);
List<Element> invokerRunIntegrationTestEvents = XmlUtils.getExecutionEvents(mavenSpyLogsElt, GROUP_ID, ARTIFACT_ID, INTEGRATION_TEST_GOAL);

if (invokerRunEvents.isEmpty()) {
if (invokerRunRunEvents.isEmpty() && invokerRunIntegrationTestEvents.isEmpty()) {
if (LOGGER.isLoggable(Level.FINE)) {
listener.getLogger().println("[withMaven] invokerPublisher - No " + GROUP_ID + ":" + ARTIFACT_ID + ":" + RUN_GOAL + " execution found");
listener.getLogger().println("[withMaven] invokerPublisher - " +
"No " + GROUP_ID + ":" + ARTIFACT_ID + ":" + RUN_GOAL +
" or " + GROUP_ID + ":" + ARTIFACT_ID + ":" + INTEGRATION_TEST_GOAL + " execution found");
}
return;
}
Expand All @@ -103,7 +107,8 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
}


executeReporter(context, listener, invokerRunEvents);
executeReporter(context, listener, invokerRunRunEvents);
executeReporter(context, listener, invokerRunIntegrationTestEvents);
}

private void executeReporter(StepContext context, TaskListener listener, List<Element> testEvents) throws IOException, InterruptedException {
Expand Down
Expand Up @@ -6,7 +6,6 @@
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand All @@ -23,37 +22,29 @@
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
*/
public class InvokerRunsPublisherTest {
Document doc;

@Before
public void before() throws Exception {
String mavenSpyLogs = "org/jenkinsci/plugins/pipeline/maven/maven-spy-maven-invoker-plugin-integration-tests.xml";
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(mavenSpyLogs);
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
}

/*
<ExecutionEvent type="MojoSucceeded" class="org.apache.maven.lifecycle.internal.DefaultExecutionEvent" _time="2018-03-06 23:49:30.662">
<project baseDir="/path/to/khmarbaise/maui/src/main/resources/mp-it-1" file="/path/to/khmarbaise/maui/src/main/resources/mp-it-1/pom.xml" groupId="com.soebes.maven.guide.mp.it" name="Maven Plugin Integration Test" artifactId="mp-it-1" version="0.1-SNAPSHOT">
<build sourceDirectory="/path/to/khmarbaise/maui/src/main/resources/mp-it-1/src/main/java" directory="/path/to/khmarbaise/maui/src/main/resources/mp-it-1/target"/>
</project>
<plugin executionId="integration-test" goal="run" lifecyclePhase="integration-test" groupId="org.apache.maven.plugins" artifactId="maven-invoker-plugin" version="3.0.1">
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>/path/to/khmarbaise/maui/src/main/resources/mp-it-1/target/it</cloneProjectsTo>
<reportsDirectory>${invoker.reportsDirectory}</reportsDirectory>
</plugin>
</ExecutionEvent>
*/
@Test
public void test_relative_path_and_absolute_path_and_variabilized_path_run_goal() throws Exception {
String mavenSpyLogs = "org/jenkinsci/plugins/pipeline/maven/maven-spy-maven-invoker-plugin-run.xml";
test_relative_path_and_absolute_path_and_variabilized_path_run_goal(mavenSpyLogs, InvokerRunsPublisher.RUN_GOAL);
}
@Test
public void test_relative_path_and_absolute_path_and_variabilized_path_integration_test_goal() throws Exception {
String mavenSpyLogs = "org/jenkinsci/plugins/pipeline/maven/maven-spy-maven-invoker-plugin-integration-test.xml";
test_relative_path_and_absolute_path_and_variabilized_path_run_goal(mavenSpyLogs, InvokerRunsPublisher.INTEGRATION_TEST_GOAL);
}

/**
* projectsDirectory = src/it -> relative path
* cloneProjectsTo = /path/to/khmarbaise/maui/src/main/resources/mp-it-1/target/it -> absolute path
* reportsDirectory = ${invoker.reportsDirectory} -> variabilized path
*/
@Test
public void test_relative_path_and_absolute_path_and_variabilized_path() {
protected void test_relative_path_and_absolute_path_and_variabilized_path_run_goal(String mavenSpyLogs, String goal) throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(mavenSpyLogs);
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
InvokerRunsPublisher invokerRunsPublisher = new InvokerRunsPublisher();
List<Element> invokerRunEvents = XmlUtils.getExecutionEvents(doc.getDocumentElement(), InvokerRunsPublisher.GROUP_ID, InvokerRunsPublisher.ARTIFACT_ID, InvokerRunsPublisher.RUN_GOAL);
List<Element> invokerRunEvents = XmlUtils.getExecutionEvents(doc.getDocumentElement(), InvokerRunsPublisher.GROUP_ID, InvokerRunsPublisher.ARTIFACT_ID, goal);

FilePath workspace = new FilePath(new File("/path/to/khmarbaise/maui/src/main/resources/mp-it-1"));
TaskListener listener = new StreamTaskListener(System.out, StandardCharsets.UTF_8);
Expand Down

0 comments on commit 2d4516d

Please sign in to comment.