diff --git a/aether-impl/src/main/java/org/eclipse/aether/internal/impl/LoggerFactoryProvider.java b/aether-impl/src/main/java/org/eclipse/aether/internal/impl/LoggerFactoryProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..168cb9f3b4b4ac17473b6b39358e6583a1cb0a59 --- /dev/null +++ b/aether-impl/src/main/java/org/eclipse/aether/internal/impl/LoggerFactoryProvider.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.impl; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.eclipse.aether.spi.log.LoggerFactory; +import org.eclipse.aether.spi.log.NullLoggerFactory; + +/** + * Helps Sisu-based applications to pick the right logger factory depending on the classpath. + */ +@Named +@Singleton +public class LoggerFactoryProvider + implements Provider +{ + + @Inject + @Named( "slf4j" ) + private Provider slf4j; + + public LoggerFactory get() + { + try + { + LoggerFactory factory = slf4j.get(); + if ( factory != null ) + { + return factory; + } + } + catch ( LinkageError e ) + { + // fall through + } + catch ( RuntimeException e ) + { + // fall through + } + return NullLoggerFactory.INSTANCE; + } + +} diff --git a/aether-impl/src/main/java/org/eclipse/aether/internal/impl/slf4j/Slf4jLoggerFactory.java b/aether-impl/src/main/java/org/eclipse/aether/internal/impl/slf4j/Slf4jLoggerFactory.java index 31328d05196f11a521b46c389a06c74c1d36cb1f..763d67fce6fc23bd1afeb9ee166f6aa460bb2d9c 100644 --- a/aether-impl/src/main/java/org/eclipse/aether/internal/impl/slf4j/Slf4jLoggerFactory.java +++ b/aether-impl/src/main/java/org/eclipse/aether/internal/impl/slf4j/Slf4jLoggerFactory.java @@ -24,7 +24,7 @@ import org.slf4j.spi.LocationAwareLogger; /** * A logger factory that delegates to SLF4J logging. */ -@Named +@Named( "slf4j" ) public class Slf4jLoggerFactory implements LoggerFactory, Service {