Updated Branches: refs/heads/master 915b1553f -> 39e11cf2e
extracted Slf4jConfiguration interface and corresponding implementation to clearly separate code depending on slf4j binding still need to add automatic selection of implementation Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/39e11cf2 Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/39e11cf2 Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/39e11cf2 Branch: refs/heads/master Commit: 39e11cf2e51a41fc47001f0fe59da251dab87587 Parents: 73ffdaf Author: Hervé Boutemy <[email protected]> Authored: Sun Dec 16 01:57:36 2012 +0100 Committer: Hervé Boutemy <[email protected]> Committed: Sun Dec 16 01:57:36 2012 +0100 ---------------------------------------------------------------------- .../main/java/org/apache/maven/cli/MavenCli.java | 12 ++- .../cli/logging/AbstractSlf4jConfiguration.java | 46 +++++++++++ .../maven/cli/logging/Slf4jConfiguration.java | 35 ++++++++ .../cli/logging/impl/Slf4jSimpleConfiguration.java | 62 +++++++++++++++ 4 files changed, 151 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java ---------------------------------------------------------------------- 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 e744e65..e3c62f8 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 @@ -39,8 +39,10 @@ import org.apache.maven.InternalErrorException; import org.apache.maven.Maven; import org.apache.maven.cli.event.DefaultEventSpyContext; import org.apache.maven.cli.event.ExecutionEventLogger; +import org.apache.maven.cli.logging.Slf4jConfiguration; import org.apache.maven.cli.logging.Slf4jLoggerManager; import org.apache.maven.cli.logging.Slf4jStdoutLogger; +import org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration; import org.apache.maven.cli.transfer.ConsoleMavenTransferListener; import org.apache.maven.cli.transfer.QuietMavenTransferListener; import org.apache.maven.cli.transfer.Slf4jMavenTransferListener; @@ -131,6 +133,8 @@ public class MavenCli private DefaultSecDispatcher dispatcher; + private Slf4jConfiguration slf4jConfiguration = new Slf4jSimpleConfiguration(); + public MavenCli() { this( null ); @@ -306,24 +310,24 @@ public class MavenCli if ( cliRequest.debug ) { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "debug" ); + slf4jConfiguration.setRootLoggerLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG ); } else if ( cliRequest.quiet ) { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_ERROR ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "error" ); + slf4jConfiguration.setRootLoggerLevel( MavenExecutionRequest.LOGGING_LEVEL_ERROR ); } else { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_INFO ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "info" ); + slf4jConfiguration.setRootLoggerLevel( MavenExecutionRequest.LOGGING_LEVEL_INFO ); } if ( cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) ) { File logFile = new File( cliRequest.commandLine.getOptionValue( CLIManager.LOG_FILE ) ); logFile = resolveFile( logFile, cliRequest.workingDirectory ); - System.setProperty( "org.slf4j.simpleLogger.logFile", logFile.getAbsolutePath() ); + slf4jConfiguration.setLoggerFile( logFile ); try { PrintStream ps = new PrintStream( new FileOutputStream( logFile ) ); http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/maven-embedder/src/main/java/org/apache/maven/cli/logging/AbstractSlf4jConfiguration.java ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/AbstractSlf4jConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/AbstractSlf4jConfiguration.java new file mode 100644 index 0000000..2b2ef6d --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/AbstractSlf4jConfiguration.java @@ -0,0 +1,46 @@ +package org.apache.maven.cli.logging; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Abstract implementation. + * + * @author Hervé Boutemy + */ +public class AbstractSlf4jConfiguration + implements Slf4jConfiguration +{ + private final Logger logger = LoggerFactory.getLogger( AbstractSlf4jConfiguration.class ); + + public void setRootLoggerLevel( int level ) + { + logger.warn( "setRootLoggerLevel: operation not supported" ); + } + + public void setLoggerFile( File output ) + { + logger.warn( "setLoggerFile: operation not supported" ); + } +} http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java new file mode 100644 index 0000000..c988bd8 --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java @@ -0,0 +1,35 @@ +package org.apache.maven.cli.logging; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +/** + * Interface for configuration operations on loggers, which are not available in slf4j, then require per-slf4f-binding + * implementation. + * + * @author Hervé Boutemy + */ +public interface Slf4jConfiguration +{ + void setRootLoggerLevel( int level ); + + void setLoggerFile( File output ); +} http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java new file mode 100644 index 0000000..c5d60d8 --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java @@ -0,0 +1,62 @@ +package org.apache.maven.cli.logging.impl; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import org.apache.maven.cli.logging.AbstractSlf4jConfiguration; +import org.apache.maven.cli.logging.Slf4jConfiguration; +import org.apache.maven.execution.MavenExecutionRequest; +import org.codehaus.plexus.component.annotations.Component; + +/** + * Configuration for slf4j-simple. + * + * @author Hervé Boutemy + */ +@Component( role = Slf4jConfiguration.class ) +public class Slf4jSimpleConfiguration + extends AbstractSlf4jConfiguration +{ + public void setRootLoggerLevel( int level ) + { + String value = "info"; + switch ( level ) + { + case MavenExecutionRequest.LOGGING_LEVEL_DEBUG: + value = "debug"; + break; + + case MavenExecutionRequest.LOGGING_LEVEL_INFO: + value = "info"; + break; + + case MavenExecutionRequest.LOGGING_LEVEL_ERROR: + value = "error"; + break; + } + System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", value ); + } + + public void setLoggerFile( File output ) + { + System.setProperty( "org.slf4j.simpleLogger.logFile", output.getAbsolutePath() ); + } +}
