diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index a6757fb13e..33fd43a355 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -99,10 +99,6 @@ under the License. org.eclipse.sisu org.eclipse.sisu.plexus - - org.codehaus.plexus - plexus-component-annotations - org.sonatype.plexus plexus-sec-dispatcher @@ -174,10 +170,6 @@ under the License. org.eclipse.sisu sisu-maven-plugin - - org.codehaus.plexus - plexus-component-metadata - org.codehaus.modello modello-maven-plugin diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index e1a4c2f593..fb78239233 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -146,7 +146,7 @@ public final class CLIReportingUtils for ( Throwable cause = e.getCause(); cause != null; cause = cause.getCause() ) { - logger.error( "Caused by: " + cause.getMessage() ); + logger.error( "Caused by: {}", cause.getMessage() ); } } } 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 4ee6aa810f..ff5fcc7fe1 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 @@ -569,7 +569,7 @@ public class MavenCli if ( slf4jLogger.isDebugEnabled() ) { - slf4jLogger.debug( "Message scheme: " + ( MessageUtils.isColorEnabled() ? "color" : "plain" ) ); + slf4jLogger.debug( "Message scheme: {}", ( MessageUtils.isColorEnabled() ? "color" : "plain" ) ); if ( MessageUtils.isColorEnabled() ) { MessageBuilder buff = MessageUtils.buffer(); @@ -767,7 +767,7 @@ public class MavenCli } catch ( Exception e ) { - slf4jLogger.warn( "Failed to read extensions descriptor " + extensionsFile + ": " + e.getMessage() ); + slf4jLogger.warn( "Failed to read extensions descriptor {}: {}", extensionsFile, e.getMessage() ); } return Collections.emptyList(); } @@ -795,11 +795,11 @@ public class MavenCli extRealm.setParentRealm( coreRealm ); - slf4jLogger.debug( "Populating class realm " + extRealm.getId() ); + slf4jLogger.debug( "Populating class realm {}", extRealm.getId() ); for ( File file : extClassPath ) { - slf4jLogger.debug( " Included " + file ); + slf4jLogger.debug( " Included {}", file ); extRealm.addURL( file.toURI().toURL() ); } @@ -848,7 +848,7 @@ public class MavenCli { File file = resolveFile( new File( jar ), cliRequest.workingDirectory ); - slf4jLogger.debug( " Included " + file ); + slf4jLogger.debug( " Included {}", file ); jars.add( file ); } @@ -983,13 +983,13 @@ public class MavenCli if ( !cliRequest.showErrors ) { - slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven with the " - + buffer().strong( "-e" ) + " switch." ); + slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven with the {} switch.", + buffer().strong( "-e" ) ); } if ( !slf4jLogger.isDebugEnabled() ) { - slf4jLogger.error( "Re-run Maven using the " + buffer().strong( "-X" ) - + " switch to enable full debug logging." ); + slf4jLogger.error( "Re-run Maven using the {} switch to enable full debug logging.", + buffer().strong( "-X" ) ); } if ( !references.isEmpty() ) @@ -1000,7 +1000,7 @@ public class MavenCli for ( Map.Entry entry : references.entrySet() ) { - slf4jLogger.error( buffer().strong( entry.getValue() ) + " " + entry.getKey() ); + slf4jLogger.error( "{} {}", buffer().strong( entry.getValue() ), entry.getKey() ); } } @@ -1257,11 +1257,10 @@ public class MavenCli eventSpyDispatcher.onEvent( toolchainsRequest ); - slf4jLogger.debug( - "Reading global toolchains from " + getLocation( toolchainsRequest.getGlobalToolchainsSource(), - globalToolchainsFile ) ); - slf4jLogger.debug( "Reading user toolchains from " + getLocation( toolchainsRequest.getUserToolchainsSource(), - userToolchainsFile ) ); + slf4jLogger.debug( "Reading global toolchains from {}", + getLocation( toolchainsRequest.getGlobalToolchainsSource(), globalToolchainsFile ) ); + slf4jLogger.debug( "Reading user toolchains from {}", + getLocation( toolchainsRequest.getUserToolchainsSource(), userToolchainsFile ) ); ToolchainsBuildingResult toolchainsResult = toolchainsBuilder.build( toolchainsRequest ); @@ -1277,7 +1276,7 @@ public class MavenCli for ( Problem problem : toolchainsResult.getProblems() ) { - slf4jLogger.warn( problem.getMessage() + " @ " + problem.getLocation() ); + slf4jLogger.warn( "{} @ {}", problem.getMessage(), problem.getLocation() ); } slf4jLogger.warn( "" ); @@ -1311,8 +1310,8 @@ public class MavenCli { if ( commandLine.hasOption( deprecatedOption ) ) { - slf4jLogger.warn( "Command line option -" + deprecatedOption - + " is deprecated and will be removed in future Maven versions." ); + slf4jLogger.warn( "Command line option -{} is deprecated and will be removed in future Maven versions.", + deprecatedOption ); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java index 2536a22ced..0a862c43b4 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java @@ -23,6 +23,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.List; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.commons.cli.CommandLine; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.bridge.MavenRepositorySystem; @@ -43,14 +47,14 @@ import org.apache.maven.settings.building.SettingsBuildingRequest; import org.apache.maven.settings.building.SettingsBuildingResult; import org.apache.maven.settings.building.SettingsProblem; import org.apache.maven.settings.crypto.SettingsDecrypter; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * SettingsXmlConfigurationProcessor */ -@Component( role = ConfigurationProcessor.class, hint = SettingsXmlConfigurationProcessor.HINT ) +@Named ( SettingsXmlConfigurationProcessor.HINT ) +@Singleton public class SettingsXmlConfigurationProcessor implements ConfigurationProcessor { @@ -65,13 +69,12 @@ public class SettingsXmlConfigurationProcessor public static final File DEFAULT_GLOBAL_SETTINGS_FILE = new File( System.getProperty( "maven.conf" ), "settings.xml" ); - @Requirement - private Logger logger; + private final Logger logger = LoggerFactory.getLogger( SettingsXmlConfigurationProcessor.class ); - @Requirement + @Inject private SettingsBuilder settingsBuilder; - @Requirement + @Inject private SettingsDecrypter settingsDecrypter; @Override @@ -132,10 +135,10 @@ public class SettingsXmlConfigurationProcessor request.getEventSpyDispatcher().onEvent( settingsRequest ); } - logger.debug( "Reading global settings from " - + getLocation( settingsRequest.getGlobalSettingsSource(), settingsRequest.getGlobalSettingsFile() ) ); - logger.debug( "Reading user settings from " - + getLocation( settingsRequest.getUserSettingsSource(), settingsRequest.getUserSettingsFile() ) ); + logger.debug( "Reading global settings from {}", + getLocation( settingsRequest.getGlobalSettingsSource(), settingsRequest.getGlobalSettingsFile() ) ); + logger.debug( "Reading user settings from {}", + getLocation( settingsRequest.getUserSettingsSource(), settingsRequest.getUserSettingsFile() ) ); SettingsBuildingResult settingsResult = settingsBuilder.build( settingsRequest ); @@ -153,7 +156,7 @@ public class SettingsXmlConfigurationProcessor for ( SettingsProblem problem : settingsResult.getProblems() ) { - logger.warn( problem.getMessage() + " @ " + problem.getLocation() ); + logger.warn( "{} @ {}", problem.getMessage(), problem.getLocation() ); } logger.warn( "" ); } @@ -234,7 +237,7 @@ public class SettingsXmlConfigurationProcessor { try { - request.addRemoteRepository( + request.addRemoteRepository( MavenRepositorySystem.buildArtifactRepository( remoteRepository ) ); } catch ( InvalidRepositoryException e ) @@ -242,20 +245,20 @@ public class SettingsXmlConfigurationProcessor // do nothing for now } } - + List pluginRepositories = rawProfile.getPluginRepositories(); for ( Repository pluginRepository : pluginRepositories ) { try { - request.addPluginArtifactRepository( + request.addPluginArtifactRepository( MavenRepositorySystem.buildArtifactRepository( pluginRepository ) ); } catch ( InvalidRepositoryException e ) { // do nothing for now } - } + } } } return request; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java index cb34d8ecee..17da65548a 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java @@ -115,8 +115,8 @@ public class ExecutionEventLogger for ( MavenProject project : projects ) { int len = LINE_LENGTH - project.getName().length() - project.getPackaging().length() - 2; - logger.info( project.getName() + chars( ' ', ( len > 0 ) ? len : 1 ) + '[' + project.getPackaging() - + ']' ); + logger.info( "{}{}[{}]", + project.getName(), chars( ' ', ( len > 0 ) ? len : 1 ), project.getPackaging() ); } totalProjects = projects.size(); @@ -267,9 +267,9 @@ public class ExecutionEventLogger String wallClock = session.getRequest().getDegreeOfConcurrency() > 1 ? " (Wall Clock)" : ""; - logger.info( "Total time: " + formatDuration( time ) + wallClock ); + logger.info( "Total time: {}{}", formatDuration( time ), wallClock ); - logger.info( "Finished at: " + formatTimestamp( finish ) ); + logger.info( "Finished at: {}", formatTimestamp( finish ) ); } @Override @@ -345,8 +345,8 @@ public class ExecutionEventLogger { if ( logger.isWarnEnabled() ) { - logger.warn( "Goal " + event.getMojoExecution().getGoal() - + " requires online mode for execution but Maven is currently offline, skipping" ); + logger.warn( "Goal {} requires online mode for execution but Maven is currently offline, skipping", + event.getMojoExecution().getGoal() ); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/UnsupportedSlf4jBindingConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/UnsupportedSlf4jBindingConfiguration.java index d269770852..4757cffabf 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/UnsupportedSlf4jBindingConfiguration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/UnsupportedSlf4jBindingConfiguration.java @@ -51,7 +51,7 @@ public class UnsupportedSlf4jBindingConfiguration @Override public void activate() { - logger.warn( "The SLF4J binding actually used is not supported by Maven: " + slf4jBinding ); + logger.warn( "The SLF4J binding actually used is not supported by Maven: {}", slf4jBinding ); logger.warn( "Maven supported bindings are:" ); String ls = System.getProperty( "line.separator" ); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java index 086e40677e..57e69ba14d 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java @@ -69,8 +69,8 @@ public class Slf4jMavenTransferListener throws TransferCancelledException { TransferResource resource = event.getResource(); - out.warn( event.getException().getMessage() + " from " + resource.getRepositoryId() + " for " - + resource.getRepositoryUrl() + resource.getResourceName() ); + out.warn( "{} from {} for {}{}", event.getException().getMessage(), resource.getRepositoryId(), + resource.getRepositoryUrl(), resource.getResourceName() ); } @Override diff --git a/maven-embedder/src/site/apt/logging.apt b/maven-embedder/src/site/apt/logging.apt index 800857c4f2..7ff312909f 100644 --- a/maven-embedder/src/site/apt/logging.apt +++ b/maven-embedder/src/site/apt/logging.apt @@ -64,28 +64,8 @@ Maven Logging * Getting Logger Instance - Plexus Logger and LoggerManager can be injected in Plexus component using Plexus annotations - -+------+ -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; - -@Component( role = MyComponent.class ) -public class DefaultMyComponent - implements MyComponent -{ - @Requirement - private Logger logger; - - @Requirement - private LoggerManager loggerManager; -} -+------+ - - Starting with Maven 3.1.0, SLF4J Logger can be used directly too, without Plexus. Of course, this will only work when run under - Maven 3.1.0, then this technique can be used safely only in Maven core components or in plugins/component not requiring - compatibility with previous Maven versions. + Starting with Maven 3.1.0, SLF4J Logger can be used directly. This technique can be used safely in Maven core + components or in plugins/component not requiring compatibility with previous Maven versions. +-----+ import org.slf4j.Logger;