[MNG-7501] add relative path to pom.xml in module build start output

This commit is contained in:
Hervé Boutemy 2022-06-18 09:51:54 +02:00
parent d82ab09ae1
commit 4e88d62ab2
2 changed files with 66 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import static org.apache.maven.cli.CLIReportingUtils.formatDuration;
import static org.apache.maven.cli.CLIReportingUtils.formatTimestamp;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
import java.io.File;
import java.util.List;
import java.util.Objects;
@ -370,6 +371,15 @@ public class ExecutionEventLogger extends AbstractExecutionListener
infoMain( building + ( ( pad > 0 ) ? chars( ' ', pad ) : "" ) + progress );
}
// path to pom.xml
File currentPom = project.getFile();
if ( currentPom != null )
{
MavenSession session = event.getSession();
File rootBasedir = session.getTopLevelProject().getBasedir();
logger.info( " from " + rootBasedir.toPath().relativize( currentPom.toPath() ) );
}
// ----------[ packaging ]----------
prefix = chars( '-', Math.max( 0, ( lineLength - project.getPackaging().length() - 4 ) / 2 ) );
suffix = chars( '-', Math.max( 0, lineLength - project.getPackaging().length() - 4 - prefix.length() ) );

View File

@ -23,7 +23,11 @@ import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import org.apache.commons.io.FilenameUtils;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.junit.jupiter.api.AfterAll;
@ -55,6 +59,7 @@ class ExecutionEventLoggerTest
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 );
when( project.getGroupId() ).thenReturn( "org.apache.maven" );
@ -62,8 +67,15 @@ class ExecutionEventLoggerTest
when( project.getPackaging() ).thenReturn( "jar" );
when( project.getName() ).thenReturn( "Apache Maven Embedder" );
when( project.getVersion() ).thenReturn( "3.5.4-SNAPSHOT" );
when( project.getFile() ).thenReturn( new File( basedir, "maven-embedder/pom.xml" ) );
when( event.getProject() ).thenReturn( project );
MavenProject rootProject = mock( MavenProject.class );
when( rootProject.getBasedir() ).thenReturn( basedir );
MavenSession session = mock( MavenSession.class );
when( session.getTopLevelProject() ).thenReturn( rootProject );
when( event.getSession() ).thenReturn( session );
// execute
executionEventLogger.projectStarted( event );
@ -72,6 +84,7 @@ class ExecutionEventLoggerTest
inOrder.verify( logger ).info( "" );
inOrder.verify( logger ).info( "------------------< org.apache.maven:maven-embedder >-------------------" );
inOrder.verify( logger ).info( "Building Apache Maven Embedder 3.5.4-SNAPSHOT" );
inOrder.verify( logger ).info( adaptDirSeparator( " from maven-embedder/pom.xml" ) );
inOrder.verify( logger ).info( "--------------------------------[ jar ]---------------------------------" );
}
@ -83,6 +96,7 @@ class ExecutionEventLoggerTest
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 );
when( project.getGroupId() ).thenReturn( "org.apache.maven.plugins.overflow" );
@ -91,6 +105,12 @@ class ExecutionEventLoggerTest
when( project.getName() ).thenReturn( "Apache Maven Project Info Reports Plugin" );
when( project.getVersion() ).thenReturn( "3.0.0-SNAPSHOT" );
when( event.getProject() ).thenReturn( project );
when( project.getFile() ).thenReturn( new File( basedir, "pom.xml" ) );
when( project.getBasedir() ).thenReturn( basedir );
MavenSession session = mock( MavenSession.class );
when( session.getTopLevelProject() ).thenReturn( project );
when( event.getSession() ).thenReturn( session );
// execute
executionEventLogger.projectStarted( event );
@ -100,6 +120,7 @@ class ExecutionEventLoggerTest
inOrder.verify( logger ).info( "" );
inOrder.verify( logger ).info( "--< org.apache.maven.plugins.overflow:maven-project-info-reports-plugin >--" );
inOrder.verify( logger ).info( "Building Apache Maven Project Info Reports Plugin 3.0.0-SNAPSHOT" );
inOrder.verify( logger ).info( adaptDirSeparator( " from pom.xml" ) );
inOrder.verify( logger ).info( "----------------------------[ maven-plugin ]----------------------------" );
}
@ -139,4 +160,39 @@ class ExecutionEventLoggerTest
new ExecutionEventLogger( logger, 200 ).projectStarted( event );
Mockito.verify( logger ).info( "-----------------------------------------------------[ maven-plugin ]-----------------------------------------------------" );
}
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 );
when( project.getGroupId() ).thenReturn( "org.apache.maven" );
when( project.getArtifactId() ).thenReturn( "standalone-pom" );
when( project.getPackaging() ).thenReturn( "pom" );
when( project.getName() ).thenReturn( "Maven Stub Project (No POM)" );
when( project.getVersion() ).thenReturn( "1" );
when( event.getProject() ).thenReturn( project );
when( project.getFile() ).thenReturn( null );
when( project.getBasedir() ).thenReturn( basedir );
// execute
executionEventLogger.projectStarted( event );
// verify
InOrder inOrder = inOrder( logger );
inOrder.verify( logger ).info( "" );
inOrder.verify( logger ).info( "------------------< org.apache.maven:standalone-pom >-------------------" );
inOrder.verify( logger ).info( "Building Maven Stub Project (No POM) 1" );
inOrder.verify( logger ).info( "--------------------------------[ pom ]---------------------------------" );
}
private static String adaptDirSeparator( String path )
{
return FilenameUtils.separatorsToSystem( path );
}
}