diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 4d142ee4c9..4767b13ddd 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -596,7 +596,7 @@ public class MavenCli populateProperties( cliRequest.commandLine, cliRequest.systemProperties, cliRequest.userProperties ); } - private PlexusContainer container( CliRequest cliRequest ) + PlexusContainer container( CliRequest cliRequest ) throws Exception { if ( cliRequest.classWorld == null ) @@ -1201,7 +1201,7 @@ public class MavenCli } } - private void toolchains( CliRequest cliRequest ) + void toolchains( CliRequest cliRequest ) throws Exception { File userToolchainsFile; @@ -1265,7 +1265,7 @@ public class MavenCli ToolchainsBuildingResult toolchainsResult = toolchainsBuilder.build( toolchainsRequest ); - eventSpyDispatcher.onEvent( toolchainsRequest ); + eventSpyDispatcher.onEvent( toolchainsResult ); executionRequestPopulator.populateFromToolchains( cliRequest.request, toolchainsResult.getEffectiveToolchains() ); diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index 933ee75466..2e4362c1a3 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -24,14 +24,24 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import java.io.File; import org.apache.commons.cli.ParseException; +import org.apache.maven.Maven; +import org.apache.maven.eventspy.internal.EventSpyDispatcher; import org.apache.maven.shared.utils.logging.MessageUtils; +import org.apache.maven.toolchain.building.ToolchainsBuildingRequest; +import org.apache.maven.toolchain.building.ToolchainsBuildingResult; +import org.codehaus.plexus.PlexusContainer; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.InOrder; public class MavenCliTest { @@ -295,4 +305,32 @@ public class MavenCliTest // noop } } + + /** + * Verifies MNG-6558 + */ + @Test + public void testToolchainsBuildingEvents() throws Exception { + final EventSpyDispatcher eventSpyDispatcherMock = mock(EventSpyDispatcher.class); + MavenCli customizedMavenCli = new MavenCli() { + @Override + protected void customizeContainer(PlexusContainer container) { + super.customizeContainer(container); + container.addComponent(eventSpyDispatcherMock, "org.apache.maven.eventspy.internal.EventSpyDispatcher"); + container.addComponent(mock(Maven.class), "org.apache.maven.Maven"); + } + }; + + CliRequest cliRequest = new CliRequest(new String[]{}, null); + + customizedMavenCli.cli(cliRequest); + customizedMavenCli.logging(cliRequest); + customizedMavenCli.container(cliRequest); + customizedMavenCli.toolchains(cliRequest); + + InOrder orderdEventSpyDispatcherMock = inOrder(eventSpyDispatcherMock); + orderdEventSpyDispatcherMock.verify(eventSpyDispatcherMock, times(1)).onEvent(any(ToolchainsBuildingRequest.class)); + orderdEventSpyDispatcherMock.verify(eventSpyDispatcherMock, times(1)).onEvent(any(ToolchainsBuildingResult.class)); + } + }