Skip to content

Commit

Permalink
Use the new plugin Log api
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 1, 2022
1 parent 51cf058 commit 502f62e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ under the License.
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Version;
import org.apache.maven.api.plugin.Log;
import org.apache.maven.api.plugin.Mojo;
import org.apache.maven.api.Session;
import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.Parameter;
import org.apache.maven.api.services.VersionParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract class for Deploy mojo's.
Expand All @@ -39,7 +39,8 @@ public abstract class AbstractDeployMojo

private static final String FIXED_MAVEN_VERSION = "3.9.0";

protected final Logger logger = LoggerFactory.getLogger( getClass() );
@Component
protected Log logger;

/**
* Flag whether Maven is currently in online/offline mode.
Expand Down Expand Up @@ -109,7 +110,7 @@ protected Session getSession()
return session;
}

protected Logger getLog()
protected Log getLog()
{
return logger;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private Path readingPomFromJarFile()
.orElse( null );
if ( entry != null )
{
logger.debug( "Using " + entry.getName() + " as pomFile" );
getLog().debug( "Using " + entry.getName() + " as pomFile" );

try ( InputStream pomInputStream = jarFile.getInputStream( entry ) )
{
Expand All @@ -226,7 +226,7 @@ private Path readingPomFromJarFile()
}
else
{
logger.info( "pom.xml not found in " + file.getFileName() );
getLog().info( "pom.xml not found in " + file.getFileName() );
}
}
}
Expand All @@ -244,7 +244,7 @@ public void execute()
if ( !Files.exists( file ) )
{
String message = "The specified file '" + file + "' does not exist";
logger.error( message );
getLog().error( message );
throw new MojoException( message );
}

Expand Down Expand Up @@ -312,12 +312,12 @@ public void execute()
artifactManager.setPath( pomArtifact, deployedPom );
if ( generatePom )
{
logger.debug( "Deploying generated POM" );
getLog().debug( "Deploying generated POM" );
deployables.add( pomArtifact );
}
else
{
logger.debug( "Skipping deploying POM" );
getLog().debug( "Skipping deploying POM" );
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void execute()
|| ( "snapshots".equals( skip ) && session.isVersionSnapshot( project.getVersion() ) )
)
{
logger.info( "Skipping artifact deployment" );
getLog().info( "Skipping artifact deployment" );
putState( State.SKIPPED );
}
else
Expand All @@ -202,7 +202,7 @@ public void execute()
}
else
{
logger.info( "Deferring deploy for " + project.getGroupId()
getLog().info( "Deferring deploy for " + project.getGroupId()
+ ":" + project.getArtifactId() + ":" + project.getVersion() + " at end" );
putState( State.TO_BE_DEPLOYED, processProject( project
) );
Expand Down Expand Up @@ -325,7 +325,7 @@ else if ( !isSnapshot && altReleaseDeploymentRepository != null )

if ( altDeploymentRepo != null )
{
logger.info( "Using alternate deployment repository " + altDeploymentRepo );
getLog().info( "Using alternate deployment repository " + altDeploymentRepo );

Matcher matcher = ALT_LEGACY_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );

Expand All @@ -337,7 +337,7 @@ else if ( !isSnapshot && altReleaseDeploymentRepository != null )

if ( "default".equals( layout ) )
{
logger.warn( "Using legacy syntax for alternative repository. "
getLog().warn( "Using legacy syntax for alternative repository. "
+ "Use \"" + id + "::" + url + "\" instead." );
repo = createDeploymentArtifactRepository( id, url );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
import org.apache.maven.api.plugin.testing.stubs.ArtifactStub;
import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
import org.apache.maven.api.plugin.testing.stubs.SessionStub;
import org.apache.maven.internal.impl.DefaultLog;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.LoggerFactory;

import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
Expand Down Expand Up @@ -298,6 +300,7 @@ class TestDeployMojo extends DeployMojo
{
super();
this.session = DeployMojoTest.this.session;
this.logger = new DefaultLog( LoggerFactory.getLogger( "anonymous" ) );
}
}

Expand Down

0 comments on commit 502f62e

Please sign in to comment.