Revert "[MNG-7098] Keep the project counter intact when resuming a multi-module project."

This reverts commit 4a06f1f5c3.
This commit is contained in:
Martin Kanters 2022-09-16 14:51:55 +02:00
parent 7e0e9f9fbe
commit 1ca65c79fa
2 changed files with 13 additions and 96 deletions

View File

@ -143,11 +143,7 @@ public class ExecutionEventLogger extends AbstractExecutionListener
project.getName(), chars( ' ', ( len > 0 ) ? len : 1 ), project.getPackaging() ); project.getName(), chars( ' ', ( len > 0 ) ? len : 1 ), project.getPackaging() );
} }
final List<MavenProject> allProjects = event.getSession().getAllProjects(); totalProjects = projects.size();
final int projectsSkipped = allProjects.size() - projects.size();
currentVisitedProjectCount = projectsSkipped;
totalProjects = allProjects.size();
} }
} }

View File

@ -19,16 +19,12 @@ package org.apache.maven.cli.event;
* under the License. * under the License.
*/ */
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.File; import java.io.File;
import com.google.common.collect.ImmutableList;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
@ -36,7 +32,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.logging.MessageUtils; import org.apache.maven.shared.utils.logging.MessageUtils;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -44,10 +39,6 @@ import org.slf4j.Logger;
class ExecutionEventLoggerTest class ExecutionEventLoggerTest
{ {
private Logger logger;
private ExecutionEventLogger executionEventLogger;
@BeforeAll @BeforeAll
public static void setUp() public static void setUp()
{ {
@ -60,17 +51,14 @@ class ExecutionEventLoggerTest
MessageUtils.setColorEnabled( true ); MessageUtils.setColorEnabled( true );
} }
@BeforeEach
void beforeEach() {
logger = mock( Logger.class );
when( logger.isInfoEnabled() ).thenReturn( true );
executionEventLogger = new ExecutionEventLogger( logger );
}
@Test @Test
void testProjectStarted() void testProjectStarted()
{ {
// prepare // prepare
Logger logger = mock( Logger.class );
when( logger.isInfoEnabled() ).thenReturn( true );
ExecutionEventLogger executionEventLogger = new ExecutionEventLogger( logger );
File basedir = new File( "" ).getAbsoluteFile(); File basedir = new File( "" ).getAbsoluteFile();
ExecutionEvent event = mock( ExecutionEvent.class ); ExecutionEvent event = mock( ExecutionEvent.class );
MavenProject project = mock( MavenProject.class ); MavenProject project = mock( MavenProject.class );
@ -104,6 +92,10 @@ class ExecutionEventLoggerTest
void testProjectStartedOverflow() void testProjectStartedOverflow()
{ {
// prepare // prepare
Logger logger = mock( Logger.class );
when( logger.isInfoEnabled() ).thenReturn( true );
ExecutionEventLogger executionEventLogger = new ExecutionEventLogger( logger );
File basedir = new File( "" ).getAbsoluteFile(); File basedir = new File( "" ).getAbsoluteFile();
ExecutionEvent event = mock( ExecutionEvent.class ); ExecutionEvent event = mock( ExecutionEvent.class );
MavenProject project = mock( MavenProject.class ); MavenProject project = mock( MavenProject.class );
@ -169,10 +161,13 @@ class ExecutionEventLoggerTest
Mockito.verify( logger ).info( "-----------------------------------------------------[ maven-plugin ]-----------------------------------------------------" ); Mockito.verify( logger ).info( "-----------------------------------------------------[ maven-plugin ]-----------------------------------------------------" );
} }
@Test
public void testProjectStartedNoPom() public void testProjectStartedNoPom()
{ {
// prepare // prepare
Logger logger = mock( Logger.class );
when( logger.isInfoEnabled() ).thenReturn( true );
ExecutionEventLogger executionEventLogger = new ExecutionEventLogger( logger );
File basedir = new File( "" ).getAbsoluteFile(); File basedir = new File( "" ).getAbsoluteFile();
ExecutionEvent event = mock( ExecutionEvent.class ); ExecutionEvent event = mock( ExecutionEvent.class );
MavenProject project = mock( MavenProject.class ); MavenProject project = mock( MavenProject.class );
@ -196,80 +191,6 @@ class ExecutionEventLoggerTest
inOrder.verify( logger ).info( "--------------------------------[ pom ]---------------------------------" ); inOrder.verify( logger ).info( "--------------------------------[ pom ]---------------------------------" );
} }
@Test
void testMultiModuleProjectProgress()
{
// prepare
MavenProject project1 = generateMavenProject("Apache Maven Embedder 1");
MavenProject project2 = generateMavenProject("Apache Maven Embedder 2");
MavenProject project3 = generateMavenProject("Apache Maven Embedder 3");
MavenSession session = mock( MavenSession.class );
when( session.getProjects() ).thenReturn( ImmutableList.of( project1, project2, project3 ) );
when( session.getAllProjects() ).thenReturn( ImmutableList.of( project1, project2, project3 ) );
ExecutionEvent sessionStartedEvent = mock( ExecutionEvent.class );
when( sessionStartedEvent.getSession() ).thenReturn( session );
ExecutionEvent projectStartedEvent1 = mock( ExecutionEvent.class );
when( projectStartedEvent1.getProject() ).thenReturn( project1 );
ExecutionEvent projectStartedEvent2 = mock( ExecutionEvent.class );
when( projectStartedEvent2.getProject() ).thenReturn( project2 );
ExecutionEvent projectStartedEvent3 = mock( ExecutionEvent.class );
when( projectStartedEvent3.getProject() ).thenReturn( project3 );
// execute
executionEventLogger.sessionStarted( sessionStartedEvent );
executionEventLogger.projectStarted( projectStartedEvent1 );
executionEventLogger.projectStarted( projectStartedEvent2 );
executionEventLogger.projectStarted( projectStartedEvent3 );
// verify
InOrder inOrder = inOrder( logger );
inOrder.verify( logger ).info( matches(".*Apache Maven Embedder 1.*\\[1\\/3\\]") );
inOrder.verify( logger ).info( matches(".*Apache Maven Embedder 2.*\\[2\\/3\\]") );
inOrder.verify( logger ).info( matches(".*Apache Maven Embedder 3.*\\[3\\/3\\]") );
}
@Test
void testMultiModuleProjectResumeFromProgress()
{
// prepare
MavenProject project1 = generateMavenProject("Apache Maven Embedder 1");
MavenProject project2 = generateMavenProject("Apache Maven Embedder 2");
MavenProject project3 = generateMavenProject("Apache Maven Embedder 3");
MavenSession session = mock( MavenSession.class );
when( session.getProjects() ).thenReturn( ImmutableList.of( project2, project3 ) );
when( session.getAllProjects() ).thenReturn( ImmutableList.of( project1, project2, project3 ) );
ExecutionEvent sessionStartedEvent = mock( ExecutionEvent.class );
when( sessionStartedEvent.getSession() ).thenReturn( session );
ExecutionEvent projectStartedEvent2 = mock( ExecutionEvent.class );
when( projectStartedEvent2.getProject() ).thenReturn( project2 );
ExecutionEvent projectStartedEvent3 = mock( ExecutionEvent.class );
when( projectStartedEvent3.getProject() ).thenReturn( project3 );
// execute
executionEventLogger.sessionStarted( sessionStartedEvent );
executionEventLogger.projectStarted( projectStartedEvent2 );
executionEventLogger.projectStarted( projectStartedEvent3 );
// verify
InOrder inOrder = inOrder( logger );
inOrder.verify( logger, never() ).info( matches(".*Apache Maven Embedder 1.*\\[1\\/3\\]") );
inOrder.verify( logger ).info( matches(".*Apache Maven Embedder 2.*\\[2\\/3\\]") );
inOrder.verify( logger ).info( matches(".*Apache Maven Embedder 3.*\\[3\\/3\\]") );
}
private static MavenProject generateMavenProject( String projectName )
{
MavenProject project = mock( MavenProject.class );
when( project.getPackaging() ).thenReturn( "jar" );
when( project.getVersion() ).thenReturn( "3.5.4-SNAPSHOT" );
when( project.getName() ).thenReturn( projectName );
return project;
}
private static String adaptDirSeparator( String path ) private static String adaptDirSeparator( String path )
{ {
return FilenameUtils.separatorsToSystem( path ); return FilenameUtils.separatorsToSystem( path );