diff --git a/pom.xml b/pom.xml index 2d56f23..a69eabb 100644 --- a/pom.xml +++ b/pom.xml @@ -165,6 +165,12 @@ plexus-classworlds 2.4 + + + io.airlift + log + 0.124 + diff --git a/resolver-integration/pom.xml b/resolver-integration/pom.xml index bf6b98a..a8281d3 100644 --- a/resolver-integration/pom.xml +++ b/resolver-integration/pom.xml @@ -7,7 +7,6 @@ 1.4-SNAPSHOT - io.airlift.resolver resolver-integration jar diff --git a/resolver/pom.xml b/resolver/pom.xml index 5acb687..275b10c 100644 --- a/resolver/pom.xml +++ b/resolver/pom.xml @@ -7,7 +7,6 @@ 1.4-SNAPSHOT - io.airlift.resolver resolver @@ -99,20 +98,15 @@ - org.slf4j - slf4j-api + io.airlift + log + org.testng testng test - - - org.slf4j - slf4j-nop - test - diff --git a/resolver/src/main/java/io/airlift/resolver/ArtifactResolver.java b/resolver/src/main/java/io/airlift/resolver/ArtifactResolver.java index 8b5e1cd..2095909 100644 --- a/resolver/src/main/java/io/airlift/resolver/ArtifactResolver.java +++ b/resolver/src/main/java/io/airlift/resolver/ArtifactResolver.java @@ -15,9 +15,6 @@ import com.google.common.collect.ImmutableList; -import io.airlift.resolver.internal.ConsoleRepositoryListener; -import io.airlift.resolver.internal.ConsoleTransferListener; -import io.airlift.resolver.internal.Slf4jLoggerManager; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; @@ -221,7 +218,7 @@ private static PlexusContainer container() // NOTE: To avoid inconsistencies, we'll use the Thread context class loader exclusively for lookups container.setLookupRealm(null); - container.setLoggerManager(new Slf4jLoggerManager()); + container.setLoggerManager(new JdkLoggerManager()); container.getLoggerManager().setThresholds(Logger.LEVEL_INFO); return container; diff --git a/resolver/src/main/java/io/airlift/resolver/internal/ConsoleRepositoryListener.java b/resolver/src/main/java/io/airlift/resolver/ConsoleRepositoryListener.java similarity index 50% rename from resolver/src/main/java/io/airlift/resolver/internal/ConsoleRepositoryListener.java rename to resolver/src/main/java/io/airlift/resolver/ConsoleRepositoryListener.java index 13e39cc..7225ff6 100644 --- a/resolver/src/main/java/io/airlift/resolver/internal/ConsoleRepositoryListener.java +++ b/resolver/src/main/java/io/airlift/resolver/ConsoleRepositoryListener.java @@ -11,113 +11,119 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.resolver.internal; +package io.airlift.resolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.airlift.log.Logger; import org.sonatype.aether.AbstractRepositoryListener; import org.sonatype.aether.RepositoryEvent; /** * A simplistic repository listener that logs events to the console. */ -public class ConsoleRepositoryListener +class ConsoleRepositoryListener extends AbstractRepositoryListener { - private final Logger logger; - - public ConsoleRepositoryListener() - { - this(LoggerFactory.getLogger(ConsoleRepositoryListener.class)); - } - - public ConsoleRepositoryListener(Logger logger) - { - this.logger = logger; - } + private static final Logger log = Logger.get(ConsoleRepositoryListener.class); + @Override public void artifactDeployed(RepositoryEvent event) { - logger.debug("Deployed " + event.getArtifact() + " to " + event.getRepository()); + log.debug("Deployed %s to %s", event.getArtifact(), event.getRepository()); } + @Override public void artifactDeploying(RepositoryEvent event) { - logger.debug("Deploying " + event.getArtifact() + " to " + event.getRepository()); + log.debug("Deploying %s to %s", event.getArtifact(), event.getRepository()); } + @Override public void artifactDescriptorInvalid(RepositoryEvent event) { - logger.debug("Invalid artifact descriptor for " + event.getArtifact() + ": " + event.getException().getMessage()); + log.debug("Invalid artifact descriptor for %s: %s", event.getArtifact(), event.getException().getMessage()); } + @Override public void artifactDescriptorMissing(RepositoryEvent event) { - logger.debug("Missing artifact descriptor for " + event.getArtifact()); + log.debug("Missing artifact descriptor for %s", event.getArtifact()); } + @Override public void artifactInstalled(RepositoryEvent event) { - logger.debug("Installed " + event.getArtifact() + " to " + event.getFile()); + log.debug("Installed %s to %s", event.getArtifact(), event.getFile()); } + @Override public void artifactInstalling(RepositoryEvent event) { - logger.debug("Installing " + event.getArtifact() + " to " + event.getFile()); + log.debug("Installing %s to %s", event.getArtifact(), event.getFile()); } + @Override public void artifactResolved(RepositoryEvent event) { - logger.debug("Resolved artifact " + event.getArtifact() + " from " + event.getRepository()); + log.debug("Resolved artifact %s from %s", event.getArtifact(), event.getRepository()); } + @Override public void artifactDownloading(RepositoryEvent event) { - logger.debug("Downloading artifact " + event.getArtifact() + " from " + event.getRepository()); + log.debug("Downloading artifact %s from %s", event.getArtifact(), event.getRepository()); } + @Override public void artifactDownloaded(RepositoryEvent event) { - logger.debug("Downloaded artifact " + event.getArtifact() + " from " + event.getRepository()); + log.debug("Downloaded artifact %s from %s", event.getArtifact(), event.getRepository()); } + @Override public void artifactResolving(RepositoryEvent event) { - logger.debug("Resolving artifact " + event.getArtifact()); + log.debug("Resolving artifact %s", event.getArtifact()); } + @Override public void metadataDeployed(RepositoryEvent event) { - logger.debug("Deployed " + event.getMetadata() + " to " + event.getRepository()); + log.debug("Deployed %s to %s", event.getMetadata(), event.getRepository()); } + @Override public void metadataDeploying(RepositoryEvent event) { - logger.debug("Deploying " + event.getMetadata() + " to " + event.getRepository()); + log.debug("Deploying %s to %s", event.getMetadata(), event.getRepository()); } + @Override public void metadataInstalled(RepositoryEvent event) { - logger.debug("Installed " + event.getMetadata() + " to " + event.getFile()); + log.debug("Installed %s to %s", event.getMetadata(), event.getFile()); } + @Override public void metadataInstalling(RepositoryEvent event) { - logger.debug("Installing " + event.getMetadata() + " to " + event.getFile()); + log.debug("Installing %s to %s", event.getMetadata(), event.getFile()); } + @Override public void metadataInvalid(RepositoryEvent event) { - logger.debug("Invalid metadata " + event.getMetadata()); + log.debug("Invalid metadata %s", event.getMetadata()); } + @Override public void metadataResolved(RepositoryEvent event) { - logger.debug("Resolved metadata " + event.getMetadata() + " from " + event.getRepository()); + log.debug("Resolved metadata %s from %s", event.getMetadata(), event.getRepository()); } + @Override public void metadataResolving(RepositoryEvent event) { - logger.debug("Resolving metadata " + event.getMetadata() + " from " + event.getRepository()); + log.debug("Resolving metadata %s from %s", event.getMetadata(), event.getRepository()); } } diff --git a/resolver/src/main/java/io/airlift/resolver/internal/ConsoleTransferListener.java b/resolver/src/main/java/io/airlift/resolver/ConsoleTransferListener.java similarity index 75% rename from resolver/src/main/java/io/airlift/resolver/internal/ConsoleTransferListener.java rename to resolver/src/main/java/io/airlift/resolver/ConsoleTransferListener.java index c6fa1ad..4e6c367 100644 --- a/resolver/src/main/java/io/airlift/resolver/internal/ConsoleTransferListener.java +++ b/resolver/src/main/java/io/airlift/resolver/ConsoleTransferListener.java @@ -11,10 +11,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.resolver.internal; +package io.airlift.resolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.airlift.log.Logger; import org.sonatype.aether.transfer.AbstractTransferListener; import org.sonatype.aether.transfer.TransferEvent; import org.sonatype.aether.transfer.TransferResource; @@ -26,27 +25,17 @@ /** * A simplistic transfer listener that logs uploads/downloads. */ -public class ConsoleTransferListener +class ConsoleTransferListener extends AbstractTransferListener { - private final Logger logger; - - public ConsoleTransferListener() - { - this(LoggerFactory.getLogger(ConsoleTransferListener.class)); - } - - public ConsoleTransferListener(Logger logger) - { - this.logger = logger; - } + private static final Logger log = Logger.get(ConsoleTransferListener.class); @Override public void transferInitiated(TransferEvent event) { String message = event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading" : "Downloading"; - logger.debug(message + ": " + event.getResource().getRepositoryUrl() + event.getResource().getResourceName()); + log.debug("%s: %s%s", message, event.getResource().getRepositoryUrl(), event.getResource().getResourceName()); } @Override @@ -71,19 +60,20 @@ public void transferSucceeded(TransferEvent event) throughput = " at " + format.format(kbPerSec) + " KB/sec"; } - logger.debug(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput + ")"); + log.debug("%s: %s%s (%s%s)", type, resource.getRepositoryUrl(), resource.getResourceName(), len, throughput); } } @Override public void transferFailed(TransferEvent event) { - logger.debug("transfer failed", event.getException()); + log.debug(event.getException(), "Transfer failed"); } + @Override public void transferCorrupted(TransferEvent event) { - logger.debug("transfer corrupted", event.getException()); + log.debug(event.getException(), "Transfer corrupted"); } protected long toKB(long bytes) diff --git a/resolver/src/main/java/io/airlift/resolver/internal/Slf4jLogger.java b/resolver/src/main/java/io/airlift/resolver/JdkLogger.java similarity index 62% rename from resolver/src/main/java/io/airlift/resolver/internal/Slf4jLogger.java rename to resolver/src/main/java/io/airlift/resolver/JdkLogger.java index 1c3df09..b2f2066 100644 --- a/resolver/src/main/java/io/airlift/resolver/internal/Slf4jLogger.java +++ b/resolver/src/main/java/io/airlift/resolver/JdkLogger.java @@ -16,104 +16,123 @@ * specific language governing permissions and limitations * under the License. */ -package io.airlift.resolver.internal; +package io.airlift.resolver; import org.codehaus.plexus.logging.Logger; +import static java.util.logging.Level.FINE; +import static java.util.logging.Level.INFO; +import static java.util.logging.Level.SEVERE; +import static java.util.logging.Level.WARNING; + /** - * Adapt an SLF4J logger to a Plexus logger, ignoring Plexus logger API parts that are not classical and - * probably not really used. - * - * @author Jason van Zyl + * Adapt JDK logger to a Plexus logger, ignoring Plexus logger API parts that are not classical and + * probably not really used. This is based on Slf4jLogger by Json van Zyl. */ -public class Slf4jLogger +class JdkLogger implements Logger { - private final org.slf4j.Logger logger; + private final java.util.logging.Logger logger; - public Slf4jLogger(org.slf4j.Logger logger) + public JdkLogger(java.util.logging.Logger logger) { this.logger = logger; } + @Override public void debug(String message) { - logger.debug(message); + logger.log(FINE, message); } + @Override public void debug(String message, Throwable throwable) { - logger.debug(message, throwable); + logger.log(FINE, message, throwable); } + @Override public boolean isDebugEnabled() { - return logger.isDebugEnabled(); + return logger.isLoggable(FINE); } + @Override public void info(String message) { - logger.info(message); + logger.log(INFO, message); } + @Override public void info(String message, Throwable throwable) { - logger.info(message, throwable); + logger.log(INFO, message, throwable); } + @Override public boolean isInfoEnabled() { - return logger.isInfoEnabled(); + return logger.isLoggable(INFO); } + @Override public void warn(String message) { - logger.warn(message); + logger.log(WARNING, message); } + @Override public void warn(String message, Throwable throwable) { - logger.warn(message, throwable); + logger.log(WARNING, message, throwable); } + @Override public boolean isWarnEnabled() { - return logger.isWarnEnabled(); + return logger.isLoggable(WARNING); } + @Override public void error(String message) { - logger.error(message); + logger.log(SEVERE, message); } + @Override public void error(String message, Throwable throwable) { - logger.error(message, throwable); + logger.log(SEVERE, message, throwable); } + @Override public boolean isErrorEnabled() { - return logger.isErrorEnabled(); + return logger.isLoggable(SEVERE); } + @Override public void fatalError(String message) { - logger.error(message); + error(message); } + @Override public void fatalError(String message, Throwable throwable) { - logger.error(message, throwable); + error(message, throwable); } + @Override public boolean isFatalErrorEnabled() { - return logger.isErrorEnabled(); + return isErrorEnabled(); } /** * Warning: ignored (always return 0 == Logger.LEVEL_DEBUG). */ + @Override public int getThreshold() { return 0; @@ -122,6 +141,7 @@ public int getThreshold() /** * Warning: ignored. */ + @Override public void setThreshold(int threshold) { } @@ -129,11 +149,13 @@ public void setThreshold(int threshold) /** * Warning: ignored (always return null). */ + @Override public Logger getChildLogger(String name) { return null; } + @Override public String getName() { return logger.getName(); diff --git a/resolver/src/main/java/io/airlift/resolver/internal/Slf4jLoggerManager.java b/resolver/src/main/java/io/airlift/resolver/JdkLoggerManager.java similarity index 79% rename from resolver/src/main/java/io/airlift/resolver/internal/Slf4jLoggerManager.java rename to resolver/src/main/java/io/airlift/resolver/JdkLoggerManager.java index 7422b9e..f2f3101 100644 --- a/resolver/src/main/java/io/airlift/resolver/internal/Slf4jLoggerManager.java +++ b/resolver/src/main/java/io/airlift/resolver/JdkLoggerManager.java @@ -16,33 +16,25 @@ * specific language governing permissions and limitations * under the License. */ -package io.airlift.resolver.internal; +package io.airlift.resolver; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; -import org.slf4j.ILoggerFactory; -import org.slf4j.LoggerFactory; + +import static java.util.logging.Logger.getLogger; /** - * Use an SLF4J {@link org.slf4j.ILoggerFactory} as a backing for a Plexus {@link org.codehaus.plexus.logging.LoggerManager}, + * Use JDK logging as a backing for a Plexus {@link LoggerManager}, * ignoring Plexus logger API parts that are not classical and probably not really used. - * - * @author Jason van Zyl - * @since 3.1 + * This is based on Slf4jLoggerManager by Json van Zyl. */ -public class Slf4jLoggerManager +class JdkLoggerManager implements LoggerManager { - private final ILoggerFactory loggerFactory; - - public Slf4jLoggerManager() - { - loggerFactory = LoggerFactory.getILoggerFactory(); - } - + @Override public Logger getLoggerForComponent(String role) { - return new Slf4jLogger(loggerFactory.getLogger(role)); + return new JdkLogger(getLogger(role)); } /** @@ -50,18 +42,14 @@ public Logger getLoggerForComponent(String role) * Warning: this does not conform to logger name as class name convention. * (and what about null and default hint equivalence?) */ + @Override public Logger getLoggerForComponent(String role, String hint) { return (null == hint ? getLoggerForComponent(role) - : new Slf4jLogger(loggerFactory.getLogger(role + '.' + hint))); + : new JdkLogger(getLogger(role + '.' + hint))); } - // - // Trying to give loggers back is a bad idea. Ceki said so :-) - // notice to self: what was this method supposed to do? - // - /** * Warning: ignored. */ @@ -99,6 +87,7 @@ public int getThreshold(String role, String roleHint) /** * Warning: ignored. */ + @Override public void returnComponentLogger(String role) { } @@ -106,6 +95,7 @@ public void returnComponentLogger(String role) /** * Warning: ignored. */ + @Override public void returnComponentLogger(String role, String hint) { } @@ -113,6 +103,7 @@ public void returnComponentLogger(String role, String hint) /** * Warning: ignored (always return 0). */ + @Override public int getThreshold() { return 0; @@ -121,6 +112,7 @@ public int getThreshold() /** * Warning: ignored. */ + @Override public void setThreshold(int threshold) { } @@ -128,6 +120,7 @@ public void setThreshold(int threshold) /** * Warning: ignored. */ + @Override public void setThresholds(int threshold) { } @@ -135,6 +128,7 @@ public void setThresholds(int threshold) /** * Warning: ignored (always return 0). */ + @Override public int getActiveLoggerCount() { return 0;