PluginLoader: Make Logger private

Several classes are reusing the PluginLoader's Logger instance.

Make the instance private and replace those usages with own instances.

Change-Id: I4a12a9752ab8e7a586adf0af69df0a8929414cc9
This commit is contained in:
David Pursehouse
2017-07-27 08:42:16 +01:00
parent 2cd97871ff
commit 1e158a9589
6 changed files with 26 additions and 11 deletions

View File

@@ -155,7 +155,7 @@ class AutoRegisterModules {
Export export = clazz.getAnnotation(Export.class);
if (export == null) {
PluginLoader.log.warn(
log.warn(
String.format(
"In plugin %s asm incorrectly parsed %s with @Export(\"%s\")",
pluginName, clazz.getName(), def.annotationValue));
@@ -192,7 +192,7 @@ class AutoRegisterModules {
if (listen != null) {
listen(clazz, clazz);
} else {
PluginLoader.log.warn(
log.warn(
String.format(
"In plugin %s asm incorrectly parsed %s with @Listen", pluginName, clazz.getName()));
}

View File

@@ -18,8 +18,12 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.jar.JarFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class CleanupHandle {
private static final Logger log = LoggerFactory.getLogger(CleanupHandle.class);
private final Path tmp;
private final JarFile jarFile;
@@ -32,13 +36,13 @@ class CleanupHandle {
try {
jarFile.close();
} catch (IOException err) {
PluginLoader.log.error("Cannot close " + jarFile.getName(), err);
log.error("Cannot close " + jarFile.getName(), err);
}
try {
Files.deleteIfExists(tmp);
PluginLoader.log.info("Cleaned plugin " + tmp.getFileName());
log.info("Cleaned plugin " + tmp.getFileName());
} catch (IOException e) {
PluginLoader.log.warn(
log.warn(
"Cannot delete "
+ tmp.toAbsolutePath()
+ ", retrying to delete it on termination of the virtual machine",

View File

@@ -50,8 +50,11 @@ import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JarScanner implements PluginContentScanner, AutoCloseable {
private static final Logger log = LoggerFactory.getLogger(JarScanner.class);
private static final int SKIP_ALL =
ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES;
private final JarFile jarFile;
@@ -88,7 +91,7 @@ public class JarScanner implements PluginContentScanner, AutoCloseable {
} catch (IOException err) {
throw new InvalidPluginException("Cannot auto-register", err);
} catch (RuntimeException err) {
PluginLoader.log.warn(
log.warn(
String.format(
"Plugin %s has invalid class file %s inside of %s",
pluginName, entry.getName(), jarFile.getName()),
@@ -100,7 +103,7 @@ public class JarScanner implements PluginContentScanner, AutoCloseable {
if (def.isConcrete()) {
rawMap.put(def.annotationName, def);
} else {
PluginLoader.log.warn(
log.warn(
String.format(
"Plugin %s tries to @%s(\"%s\") abstract class %s",
pluginName, def.annotationName, def.annotationValue, def.className));
@@ -148,7 +151,7 @@ public class JarScanner implements PluginContentScanner, AutoCloseable {
try {
new ClassReader(read(jarFile, entry)).accept(def, SKIP_ALL);
} catch (RuntimeException err) {
PluginLoader.log.warn(
log.warn(
String.format("Jar %s has invalid class file %s", jarFile.getName(), entry.getName()),
err);
continue;

View File

@@ -20,9 +20,13 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
class PluginCleanerTask implements Runnable {
private static final Logger log = LoggerFactory.getLogger(PluginCleanerTask.class);
private final WorkQueue workQueue;
private final PluginLoader loader;
private volatile int pending;
@@ -54,7 +58,7 @@ class PluginCleanerTask implements Runnable {
if (0 < left) {
long waiting = TimeUtil.nowMs() - start;
PluginLoader.log.warn(
log.warn(
String.format(
"%d plugins still waiting to be reclaimed after %d minutes",
pending, TimeUnit.MILLISECONDS.toMinutes(waiting)));

View File

@@ -71,7 +71,7 @@ import org.slf4j.LoggerFactory;
@Singleton
public class PluginLoader implements LifecycleListener {
static final Logger log = LoggerFactory.getLogger(PluginLoader.class);
private static final Logger log = LoggerFactory.getLogger(PluginLoader.class);
public String getPluginName(Path srcPath) {
return MoreObjects.firstNonNull(getGerritPluginName(srcPath), nameOf(srcPath));

View File

@@ -32,8 +32,12 @@ import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.eclipse.jgit.internal.storage.file.FileSnapshot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ServerPlugin extends Plugin {
private static final Logger log = LoggerFactory.getLogger(ServerPlugin.class);
private final Manifest manifest;
private final PluginContentScanner scanner;
private final Path dataDir;
@@ -174,7 +178,7 @@ public class ServerPlugin extends Plugin {
} else if ("restart".equalsIgnoreCase(v)) {
return false;
} else {
PluginLoader.log.warn(
log.warn(
String.format(
"Plugin %s has invalid Gerrit-ReloadMode %s; assuming restart", getName(), v));
return false;