SitePaths: Convert lib_dir to Path
This bled somewhat into the plugin loading code, but that code is far from fully migrated. Change-Id: I4c9902f13e388b1671b7a88ec50c5a9f2c84c0b9
This commit is contained in:
@@ -32,6 +32,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -85,7 +86,8 @@ public class JarPluginProvider implements ServerPluginProvider {
|
||||
String extension = getExtension(srcFile);
|
||||
try (FileInputStream in = new FileInputStream(srcFile)) {
|
||||
File tmp = asTemp(in, tempNameFor(name), extension, tmpDir);
|
||||
return loadJarPlugin(name, srcFile, snapshot, tmp, description);
|
||||
return loadJarPlugin(name, srcFile.toPath(), snapshot, tmp,
|
||||
description);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new InvalidPluginException("Cannot load Jar plugin " + srcFile, e);
|
||||
@@ -120,7 +122,7 @@ public class JarPluginProvider implements ServerPluginProvider {
|
||||
sitePaths.tmp_dir.toFile());
|
||||
}
|
||||
|
||||
private ServerPlugin loadJarPlugin(String name, File srcJar,
|
||||
private ServerPlugin loadJarPlugin(String name, Path srcJar,
|
||||
FileSnapshot snapshot, File tmp, PluginDescription description)
|
||||
throws IOException, InvalidPluginException, MalformedURLException {
|
||||
JarFile jarFile = new JarFile(tmp);
|
||||
@@ -146,10 +148,9 @@ public class JarPluginProvider implements ServerPluginProvider {
|
||||
PluginLoader.parentFor(type));
|
||||
|
||||
JarScanner jarScanner = createJarScanner(srcJar);
|
||||
ServerPlugin plugin =
|
||||
new ServerPlugin(name, description.canonicalUrl, description.user,
|
||||
srcJar, snapshot, jarScanner, description.dataDir,
|
||||
pluginLoader);
|
||||
ServerPlugin plugin = new ServerPlugin(name, description.canonicalUrl,
|
||||
description.user, srcJar.toFile(), snapshot, jarScanner,
|
||||
description.dataDir, pluginLoader);
|
||||
plugin.setCleanupHandle(new CleanupHandle(tmp, jarFile));
|
||||
keep = true;
|
||||
return plugin;
|
||||
@@ -160,7 +161,7 @@ public class JarPluginProvider implements ServerPluginProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private JarScanner createJarScanner(File srcJar)
|
||||
private JarScanner createJarScanner(Path srcJar)
|
||||
throws InvalidPluginException {
|
||||
try {
|
||||
return new JarScanner(srcJar);
|
||||
|
||||
@@ -39,10 +39,10 @@ import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -69,8 +69,8 @@ public class JarScanner implements PluginContentScanner {
|
||||
|
||||
private final JarFile jarFile;
|
||||
|
||||
public JarScanner(File srcFile) throws IOException {
|
||||
this.jarFile = new JarFile(srcFile);
|
||||
public JarScanner(Path src) throws IOException {
|
||||
this.jarFile = new JarFile(src.toFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,12 +27,12 @@ import com.google.inject.Injector;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.file.FileSnapshot;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
class JsPlugin extends Plugin {
|
||||
private Injector httpInjector;
|
||||
|
||||
JsPlugin(String name, File srcFile, PluginUser pluginUser,
|
||||
JsPlugin(String name, Path srcFile, PluginUser pluginUser,
|
||||
FileSnapshot snapshot) {
|
||||
super(name, srcFile, pluginUser, snapshot, ApiType.JS);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class JsPlugin extends Plugin {
|
||||
@Override
|
||||
@Nullable
|
||||
public String getVersion() {
|
||||
String fileName = getSrcFile().getName();
|
||||
String fileName = getSrcFile().getFileName().toString();
|
||||
int firstDash = fileName.indexOf("-");
|
||||
if (firstDash > 0) {
|
||||
return fileName.substring(firstDash + 1, fileName.lastIndexOf(".js"));
|
||||
@@ -51,7 +51,7 @@ class JsPlugin extends Plugin {
|
||||
@Override
|
||||
public void start(PluginGuiceEnvironment env) throws Exception {
|
||||
manager = new LifecycleManager();
|
||||
String fileName = getSrcFile().getName();
|
||||
String fileName = getSrcFile().getFileName().toString();
|
||||
httpInjector =
|
||||
Guice.createInjector(new StandaloneJsPluginModule(getName(), fileName));
|
||||
manager.start();
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
|
||||
stdout.format("%-30s %-10s %-8s %s\n", p.getName(),
|
||||
Strings.nullToEmpty(info.version),
|
||||
p.isDisabled() ? "DISABLED" : "ENABLED",
|
||||
p.getSrcFile().getName());
|
||||
p.getSrcFile().getFileName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.google.inject.Injector;
|
||||
import org.eclipse.jgit.internal.storage.file.FileSnapshot;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.jar.Attributes;
|
||||
@@ -67,7 +68,7 @@ public abstract class Plugin {
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final File srcFile;
|
||||
private final Path srcFile;
|
||||
private final ApiType apiType;
|
||||
private final boolean disabled;
|
||||
private final CacheKey cacheKey;
|
||||
@@ -80,17 +81,18 @@ public abstract class Plugin {
|
||||
private List<ReloadableRegistrationHandle<?>> reloadableHandles;
|
||||
|
||||
public Plugin(String name,
|
||||
File srcFile,
|
||||
Path srcFile,
|
||||
PluginUser pluginUser,
|
||||
FileSnapshot snapshot,
|
||||
ApiType apiType) {
|
||||
this.name = name;
|
||||
// TODO(dborowitz): Rename to srcPath or something.
|
||||
this.srcFile = srcFile;
|
||||
this.apiType = apiType;
|
||||
this.snapshot = snapshot;
|
||||
this.pluginUser = pluginUser;
|
||||
this.cacheKey = new Plugin.CacheKey(name);
|
||||
this.disabled = srcFile.getName().endsWith(".disabled");
|
||||
this.disabled = srcFile.getFileName().toString().endsWith(".disabled");
|
||||
}
|
||||
|
||||
public CleanupHandle getCleanupHandle() {
|
||||
@@ -105,7 +107,7 @@ public abstract class Plugin {
|
||||
return pluginUser;
|
||||
}
|
||||
|
||||
public File getSrcFile() {
|
||||
public Path getSrcFile() {
|
||||
return srcFile;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import java.io.FileFilter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -172,11 +173,11 @@ public class PluginLoader implements LifecycleListener {
|
||||
synchronized (this) {
|
||||
Plugin active = running.get(name);
|
||||
if (active != null) {
|
||||
fileName = active.getSrcFile().getName();
|
||||
fileName = active.getSrcFile().getFileName().toString();
|
||||
log.info(String.format("Replacing plugin %s", active.getName()));
|
||||
File old = new File(pluginsDir, ".last_" + fileName);
|
||||
old.delete();
|
||||
active.getSrcFile().renameTo(old);
|
||||
active.getSrcFile().toFile().renameTo(old);
|
||||
}
|
||||
|
||||
new File(pluginsDir, fileName + ".disabled").delete();
|
||||
@@ -241,7 +242,7 @@ public class PluginLoader implements LifecycleListener {
|
||||
|
||||
log.info(String.format("Disabling plugin %s", active.getName()));
|
||||
File off = new File(active.getSrcFile() + ".disabled");
|
||||
active.getSrcFile().renameTo(off);
|
||||
active.getSrcFile().toFile().renameTo(off);
|
||||
|
||||
unloadPlugin(active);
|
||||
try {
|
||||
@@ -274,12 +275,12 @@ public class PluginLoader implements LifecycleListener {
|
||||
}
|
||||
|
||||
log.info(String.format("Enabling plugin %s", name));
|
||||
String n = off.getSrcFile().getName();
|
||||
String n = off.getSrcFile().toFile().getName();
|
||||
if (n.endsWith(".disabled")) {
|
||||
n = n.substring(0, n.lastIndexOf('.'));
|
||||
}
|
||||
File on = new File(pluginsDir, n);
|
||||
off.getSrcFile().renameTo(on);
|
||||
off.getSrcFile().toFile().renameTo(on);
|
||||
|
||||
disabled.remove(name);
|
||||
runPlugin(name, on, null);
|
||||
@@ -342,7 +343,7 @@ public class PluginLoader implements LifecycleListener {
|
||||
String name = active.getName();
|
||||
try {
|
||||
log.info(String.format("Reloading plugin %s", name));
|
||||
runPlugin(name, active.getSrcFile(), active);
|
||||
runPlugin(name, active.getSrcFile().toFile(), active);
|
||||
} catch (PluginInstallException e) {
|
||||
log.warn(String.format("Cannot reload plugin %s", name), e.getCause());
|
||||
throw e;
|
||||
@@ -549,7 +550,7 @@ public class PluginLoader implements LifecycleListener {
|
||||
throws InvalidPluginException {
|
||||
String pluginName = srcPlugin.getName();
|
||||
if (isJsPlugin(pluginName)) {
|
||||
return loadJsPlugin(name, srcPlugin, snapshot);
|
||||
return loadJsPlugin(name, srcPlugin.toPath(), snapshot);
|
||||
} else if (serverPluginFactory.handles(srcPlugin)) {
|
||||
return loadServerPlugin(srcPlugin, snapshot);
|
||||
} else {
|
||||
@@ -569,7 +570,7 @@ public class PluginLoader implements LifecycleListener {
|
||||
return url;
|
||||
}
|
||||
|
||||
private Plugin loadJsPlugin(String name, File srcJar, FileSnapshot snapshot) {
|
||||
private Plugin loadJsPlugin(String name, Path srcJar, FileSnapshot snapshot) {
|
||||
return new JsPlugin(name, srcJar, pluginUserFactory.create(name), snapshot);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@ public class ServerPlugin extends Plugin {
|
||||
PluginContentScanner scanner,
|
||||
File dataDir,
|
||||
ClassLoader classLoader) throws InvalidPluginException {
|
||||
super(name, srcJar, pluginUser, snapshot, Plugin.getApiType(getPluginManifest(scanner)));
|
||||
super(name, srcJar.toPath(), pluginUser, snapshot,
|
||||
Plugin.getApiType(getPluginManifest(scanner)));
|
||||
this.pluginCanonicalWebUrl = pluginCanonicalWebUrl;
|
||||
this.scanner = scanner;
|
||||
this.dataDir = dataDir;
|
||||
@@ -128,7 +129,7 @@ public class ServerPlugin extends Plugin {
|
||||
}
|
||||
|
||||
File getSrcJar() {
|
||||
return getSrcFile();
|
||||
return getSrcFile().toFile();
|
||||
}
|
||||
|
||||
private static Manifest getPluginManifest(PluginContentScanner scanner)
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.io.File;
|
||||
* group them into a directory tree and then load the directory
|
||||
* root as a single plugin.
|
||||
*/
|
||||
// TODO(dborowitz): Convert to NIO; ensure clients can migrate.
|
||||
@ExtensionPoint
|
||||
public interface ServerPluginProvider {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user