Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.stream.Stream;

import org.apache.maven.api.Lifecycle;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;

Expand All @@ -39,26 +41,43 @@ public class BuildStep {
public static final int SCHEDULED = 2;
public static final int EXECUTED = 3;
public static final int FAILED = 4;
public static final int SKIPPED = 5;

public static final String PLAN = "$plan$";
public static final String SETUP = "$setup$";
public static final String TEARDOWN = "$teardown$";

@Nonnull
final MavenProject project;

@Nonnull
final String name;

@Nullable
final Lifecycle.Phase phase;

final Map<Integer, Map<String, MojoExecution>> mojos = new TreeMap<>();
final Collection<BuildStep> predecessors = new HashSet<>();
final Collection<BuildStep> successors = new HashSet<>();
final AtomicInteger status = new AtomicInteger();
final AtomicBoolean skip = new AtomicBoolean();
volatile Exception exception;

public BuildStep(String name, MavenProject project, Lifecycle.Phase phase) {
this.name = name;
this.project = project;
this.name = Objects.requireNonNull(name, "name cannot be null");
this.project = Objects.requireNonNull(project, "project cannot be null");
this.phase = phase;
}

public boolean isCreated() {
return status.get() == CREATED;
}

public boolean isDone() {
int state = status.get();
return state == EXECUTED || state == FAILED || state == SKIPPED;
}

public Stream<BuildStep> allPredecessors() {
return preds(new HashSet<>()).stream();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import org.junit.jupiter.api.Test;

public class MavenITmng8648ProjectStartedEventsTest extends AbstractMavenIntegrationTestCase {
public class MavenITmng8648ProjectEventsTest extends AbstractMavenIntegrationTestCase {

public MavenITmng8648ProjectStartedEventsTest() {
public MavenITmng8648ProjectEventsTest() {
super("[4.0.0-rc-4,)");
}

Expand All @@ -40,16 +40,28 @@ public void test() throws Exception {
File projectDir = extractResources("/mng-8648/project");

verifier = newVerifier(projectDir.getAbsolutePath());
verifier.addCliArguments("compile", "-b", "concurrent");
verifier.execute();
verifier.verifyErrorFreeLog();
verifier.addCliArguments("compile", "-b", "concurrent", "-T5");
try {
verifier.execute();
} catch (VerificationException expected) {
}

verifier.verifyTextInLog("org.apache.maven.its.mng8648:root:pom:1-SNAPSHOT started");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:root:pom:1-SNAPSHOT finished");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-a:jar:1-SNAPSHOT started");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-a:jar:1-SNAPSHOT finished");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-b:jar:1-SNAPSHOT started");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-b:jar:1-SNAPSHOT finished");
// The root project is marked as successful with the traditional builder
// With the concurrent builder, it gets no finish event and in the reactor summary it is listed as "skipped"
verifier.verifyTextInLog("org.apache.maven.its.mng8648:root:pom:1-SNAPSHOT ProjectStarted");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:root:pom:1-SNAPSHOT ProjectSucceeded");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-a:jar:1-SNAPSHOT ProjectStarted");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-a:jar:1-SNAPSHOT ProjectSucceeded");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-b:jar:1-SNAPSHOT ProjectStarted");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-b:jar:1-SNAPSHOT ProjectSucceeded");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-c:jar:1-SNAPSHOT ProjectStarted");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-c:jar:1-SNAPSHOT ProjectFailed");
// With the traditional builder, project D is not reported at all (it is never even started),
// and in the reactor summary it is listed as "skipped".
// With the concurrent builder, it should be started and later reported as "skipped"
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-d:jar:1-SNAPSHOT ProjectStarted");
verifier.verifyTextInLog("org.apache.maven.its.mng8648:subproject-d:jar:1-SNAPSHOT ProjectSkipped");
// Make sure there's no problem with the event spy
verifier.verifyTextNotInLog("Failed to notify spy org.apache.maven.its.mng8648.ProjectEventSpy");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public TestSuiteOrdering() {
suite.addTestSuite(MavenITmng8598JvmConfigSubstitutionTest.class);
suite.addTestSuite(MavenITmng8653AfterAndEachPhasesWithConcurrentBuilderTest.class);
suite.addTestSuite(MavenITmng5668AfterPhaseExecutionTest.class);
suite.addTestSuite(MavenITmng8648ProjectStartedEventsTest.class);
suite.addTestSuite(MavenITmng8648ProjectEventsTest.class);
suite.addTestSuite(MavenITmng8645ConsumerPomDependencyManagementTest.class);
suite.addTestSuite(MavenITmng8594AtFileTest.class);
suite.addTestSuite(MavenITmng8561SourceRootTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ public void onEvent(Object event) {
MavenProject project = executionEvent.getProject();
switch (executionEvent.getType()) {
case ProjectStarted:
System.out.println(project.getId() + " started");
projects.put(project.getId(), project);
System.out.println(project.getId() + " " + executionEvent.getType());
MavenProject existing = projects.put(project.getId(), project);
if (existing != null) {
throw new IllegalStateException("Project " + project.getId() + " was already started");
}
break;
case ProjectSucceeded:
case ProjectFailed:
case ProjectSkipped:
System.out.println(project.getId() + " " + executionEvent.getType());
MavenProject mavenProject = projects.get(project.getId());
System.out.println(project.getId() + " finished");
if (mavenProject == null) {
throw new IllegalStateException("Project " + project.getId() + " was never started");
}
Expand Down
2 changes: 2 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8648/project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
<modules>
<module>subproject-a</module>
<module>subproject-b</module>
<module>subproject-c</module>
<module>subproject-d</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.its.mng8648</groupId>
<artifactId>root</artifactId>
<version>1-SNAPSHOT</version>
</parent>
<artifactId>subproject-c</artifactId>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class Foo implements Object {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.its.mng8648</groupId>
<artifactId>root</artifactId>
<version>1-SNAPSHOT</version>
</parent>
<artifactId>subproject-d</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>subproject-c</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>