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); Export export = clazz.getAnnotation(Export.class);
if (export == null) { if (export == null) {
PluginLoader.log.warn( log.warn(
String.format( String.format(
"In plugin %s asm incorrectly parsed %s with @Export(\"%s\")", "In plugin %s asm incorrectly parsed %s with @Export(\"%s\")",
pluginName, clazz.getName(), def.annotationValue)); pluginName, clazz.getName(), def.annotationValue));
@@ -192,7 +192,7 @@ class AutoRegisterModules {
if (listen != null) { if (listen != null) {
listen(clazz, clazz); listen(clazz, clazz);
} else { } else {
PluginLoader.log.warn( log.warn(
String.format( String.format(
"In plugin %s asm incorrectly parsed %s with @Listen", pluginName, clazz.getName())); "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.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class CleanupHandle { class CleanupHandle {
private static final Logger log = LoggerFactory.getLogger(CleanupHandle.class);
private final Path tmp; private final Path tmp;
private final JarFile jarFile; private final JarFile jarFile;
@@ -32,13 +36,13 @@ class CleanupHandle {
try { try {
jarFile.close(); jarFile.close();
} catch (IOException err) { } catch (IOException err) {
PluginLoader.log.error("Cannot close " + jarFile.getName(), err); log.error("Cannot close " + jarFile.getName(), err);
} }
try { try {
Files.deleteIfExists(tmp); Files.deleteIfExists(tmp);
PluginLoader.log.info("Cleaned plugin " + tmp.getFileName()); log.info("Cleaned plugin " + tmp.getFileName());
} catch (IOException e) { } catch (IOException e) {
PluginLoader.log.warn( log.warn(
"Cannot delete " "Cannot delete "
+ tmp.toAbsolutePath() + tmp.toAbsolutePath()
+ ", retrying to delete it on termination of the virtual machine", + ", 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.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JarScanner implements PluginContentScanner, AutoCloseable { public class JarScanner implements PluginContentScanner, AutoCloseable {
private static final Logger log = LoggerFactory.getLogger(JarScanner.class);
private static final int SKIP_ALL = private static final int SKIP_ALL =
ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES; ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES;
private final JarFile jarFile; private final JarFile jarFile;
@@ -88,7 +91,7 @@ public class JarScanner implements PluginContentScanner, AutoCloseable {
} catch (IOException err) { } catch (IOException err) {
throw new InvalidPluginException("Cannot auto-register", err); throw new InvalidPluginException("Cannot auto-register", err);
} catch (RuntimeException err) { } catch (RuntimeException err) {
PluginLoader.log.warn( log.warn(
String.format( String.format(
"Plugin %s has invalid class file %s inside of %s", "Plugin %s has invalid class file %s inside of %s",
pluginName, entry.getName(), jarFile.getName()), pluginName, entry.getName(), jarFile.getName()),
@@ -100,7 +103,7 @@ public class JarScanner implements PluginContentScanner, AutoCloseable {
if (def.isConcrete()) { if (def.isConcrete()) {
rawMap.put(def.annotationName, def); rawMap.put(def.annotationName, def);
} else { } else {
PluginLoader.log.warn( log.warn(
String.format( String.format(
"Plugin %s tries to @%s(\"%s\") abstract class %s", "Plugin %s tries to @%s(\"%s\") abstract class %s",
pluginName, def.annotationName, def.annotationValue, def.className)); pluginName, def.annotationName, def.annotationValue, def.className));
@@ -148,7 +151,7 @@ public class JarScanner implements PluginContentScanner, AutoCloseable {
try { try {
new ClassReader(read(jarFile, entry)).accept(def, SKIP_ALL); new ClassReader(read(jarFile, entry)).accept(def, SKIP_ALL);
} catch (RuntimeException err) { } catch (RuntimeException err) {
PluginLoader.log.warn( log.warn(
String.format("Jar %s has invalid class file %s", jarFile.getName(), entry.getName()), String.format("Jar %s has invalid class file %s", jarFile.getName(), entry.getName()),
err); err);
continue; continue;

View File

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

View File

@@ -71,7 +71,7 @@ import org.slf4j.LoggerFactory;
@Singleton @Singleton
public class PluginLoader implements LifecycleListener { 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) { public String getPluginName(Path srcPath) {
return MoreObjects.firstNonNull(getGerritPluginName(srcPath), nameOf(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.Attributes;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import org.eclipse.jgit.internal.storage.file.FileSnapshot; import org.eclipse.jgit.internal.storage.file.FileSnapshot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ServerPlugin extends Plugin { public class ServerPlugin extends Plugin {
private static final Logger log = LoggerFactory.getLogger(ServerPlugin.class);
private final Manifest manifest; private final Manifest manifest;
private final PluginContentScanner scanner; private final PluginContentScanner scanner;
private final Path dataDir; private final Path dataDir;
@@ -174,7 +178,7 @@ public class ServerPlugin extends Plugin {
} else if ("restart".equalsIgnoreCase(v)) { } else if ("restart".equalsIgnoreCase(v)) {
return false; return false;
} else { } else {
PluginLoader.log.warn( log.warn(
String.format( String.format(
"Plugin %s has invalid Gerrit-ReloadMode %s; assuming restart", getName(), v)); "Plugin %s has invalid Gerrit-ReloadMode %s; assuming restart", getName(), v));
return false; return false;