mirror of https://github.com/apache/maven.git
[MNG-7098] Keep the project counter intact when resuming a multi-module project. (#804)
This commit is contained in:
parent
49d1ec1668
commit
c178b2fc1a
|
@ -143,7 +143,11 @@ public class ExecutionEventLogger extends AbstractExecutionListener
|
|||
project.getName(), chars( ' ', ( len > 0 ) ? len : 1 ), project.getPackaging() );
|
||||
}
|
||||
|
||||
totalProjects = projects.size();
|
||||
final List<MavenProject> allProjects = event.getSession().getAllProjects();
|
||||
final int projectsSkipped = allProjects.size() - projects.size();
|
||||
|
||||
currentVisitedProjectCount = projectsSkipped;
|
||||
totalProjects = allProjects.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,16 @@ package org.apache.maven.cli.event;
|
|||
* 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.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.maven.execution.ExecutionEvent;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
|
@ -32,6 +36,7 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.shared.utils.logging.MessageUtils;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -39,6 +44,10 @@ import org.slf4j.Logger;
|
|||
|
||||
class ExecutionEventLoggerTest
|
||||
{
|
||||
|
||||
private Logger logger;
|
||||
private ExecutionEventLogger executionEventLogger;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp()
|
||||
{
|
||||
|
@ -51,14 +60,17 @@ class ExecutionEventLoggerTest
|
|||
MessageUtils.setColorEnabled( true );
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
logger = mock( Logger.class );
|
||||
when( logger.isInfoEnabled() ).thenReturn( true );
|
||||
executionEventLogger = new ExecutionEventLogger( logger );
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProjectStarted()
|
||||
{
|
||||
// prepare
|
||||
Logger logger = mock( Logger.class );
|
||||
when( logger.isInfoEnabled() ).thenReturn( true );
|
||||
ExecutionEventLogger executionEventLogger = new ExecutionEventLogger( logger );
|
||||
|
||||
File basedir = new File( "" ).getAbsoluteFile();
|
||||
ExecutionEvent event = mock( ExecutionEvent.class );
|
||||
MavenProject project = mock( MavenProject.class );
|
||||
|
@ -92,10 +104,6 @@ class ExecutionEventLoggerTest
|
|||
void testProjectStartedOverflow()
|
||||
{
|
||||
// prepare
|
||||
Logger logger = mock( Logger.class );
|
||||
when( logger.isInfoEnabled() ).thenReturn( true );
|
||||
ExecutionEventLogger executionEventLogger = new ExecutionEventLogger( logger );
|
||||
|
||||
File basedir = new File( "" ).getAbsoluteFile();
|
||||
ExecutionEvent event = mock( ExecutionEvent.class );
|
||||
MavenProject project = mock( MavenProject.class );
|
||||
|
@ -161,13 +169,10 @@ class ExecutionEventLoggerTest
|
|||
Mockito.verify( logger ).info( "-----------------------------------------------------[ maven-plugin ]-----------------------------------------------------" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectStartedNoPom()
|
||||
{
|
||||
// prepare
|
||||
Logger logger = mock( Logger.class );
|
||||
when( logger.isInfoEnabled() ).thenReturn( true );
|
||||
ExecutionEventLogger executionEventLogger = new ExecutionEventLogger( logger );
|
||||
|
||||
File basedir = new File( "" ).getAbsoluteFile();
|
||||
ExecutionEvent event = mock( ExecutionEvent.class );
|
||||
MavenProject project = mock( MavenProject.class );
|
||||
|
@ -191,6 +196,80 @@ class ExecutionEventLoggerTest
|
|||
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 )
|
||||
{
|
||||
return FilenameUtils.separatorsToSystem( path );
|
||||
|
|
Loading…
Reference in New Issue