提交 0c9a22f0 编写于 作者: L lacostej

indentation

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24653 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c8094046
...@@ -53,8 +53,8 @@ import org.apache.tools.ant.taskdefs.Expand; ...@@ -53,8 +53,8 @@ import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;
public class ClassicPluginStrategy implements PluginStrategy { public class ClassicPluginStrategy implements PluginStrategy {
private static final Logger LOGGER = Logger.getLogger(ClassicPluginStrategy.class.getName()); private static final Logger LOGGER = Logger.getLogger(ClassicPluginStrategy.class.getName());
/** /**
* Filter for jar files. * Filter for jar files.
...@@ -66,39 +66,39 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -66,39 +66,39 @@ public class ClassicPluginStrategy implements PluginStrategy {
}; };
private PluginManager pluginManager; private PluginManager pluginManager;
public ClassicPluginStrategy(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
public PluginWrapper createPluginWrapper(File archive) throws IOException { public ClassicPluginStrategy(PluginManager pluginManager) {
final Manifest manifest; this.pluginManager = pluginManager;
URL baseResourceURL; }
public PluginWrapper createPluginWrapper(File archive) throws IOException {
final Manifest manifest;
URL baseResourceURL;
File expandDir = null; File expandDir = null;
// if .hpi, this is the directory where war is expanded // if .hpi, this is the directory where war is expanded
boolean isLinked = archive.getName().endsWith(".hpl"); boolean isLinked = archive.getName().endsWith(".hpl");
if (isLinked) { if (isLinked) {
// resolve the .hpl file to the location of the manifest file // resolve the .hpl file to the location of the manifest file
String firstLine = new BufferedReader(new FileReader(archive)) String firstLine = new BufferedReader(new FileReader(archive))
.readLine(); .readLine();
if (firstLine.startsWith("Manifest-Version:")) { if (firstLine.startsWith("Manifest-Version:")) {
// this is the manifest already // this is the manifest already
} else { } else {
// indirection // indirection
archive = resolve(archive, firstLine); archive = resolve(archive, firstLine);
} }
// then parse manifest // then parse manifest
FileInputStream in = new FileInputStream(archive); FileInputStream in = new FileInputStream(archive);
try { try {
manifest = new Manifest(in); manifest = new Manifest(in);
} catch (IOException e) { } catch (IOException e) {
throw new IOException2("Failed to load " + archive, e); throw new IOException2("Failed to load " + archive, e);
} finally { } finally {
in.close(); in.close();
} }
} else { } else {
if (archive.isDirectory()) {// already expanded if (archive.isDirectory()) {// already expanded
expandDir = archive; expandDir = archive;
} else { } else {
...@@ -118,49 +118,49 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -118,49 +118,49 @@ public class ClassicPluginStrategy implements PluginStrategy {
} finally { } finally {
fin.close(); fin.close();
} }
} }
final Attributes atts = manifest.getMainAttributes(); final Attributes atts = manifest.getMainAttributes();
// TODO: define a mechanism to hide classes // TODO: define a mechanism to hide classes
// String export = manifest.getMainAttributes().getValue("Export"); // String export = manifest.getMainAttributes().getValue("Export");
List<File> paths = new ArrayList<File>(); List<File> paths = new ArrayList<File>();
if (isLinked) { if (isLinked) {
parseClassPath(manifest, archive, paths, "Libraries", ","); parseClassPath(manifest, archive, paths, "Libraries", ",");
parseClassPath(manifest, archive, paths, "Class-Path", " +"); // backward compatibility parseClassPath(manifest, archive, paths, "Class-Path", " +"); // backward compatibility
baseResourceURL = resolve(archive,atts.getValue("Resource-Path")).toURI().toURL(); baseResourceURL = resolve(archive,atts.getValue("Resource-Path")).toURI().toURL();
} else { } else {
File classes = new File(expandDir, "WEB-INF/classes"); File classes = new File(expandDir, "WEB-INF/classes");
if (classes.exists()) if (classes.exists())
paths.add(classes); paths.add(classes);
File lib = new File(expandDir, "WEB-INF/lib"); File lib = new File(expandDir, "WEB-INF/lib");
File[] libs = lib.listFiles(JAR_FILTER); File[] libs = lib.listFiles(JAR_FILTER);
if (libs != null) if (libs != null)
paths.addAll(Arrays.asList(libs)); paths.addAll(Arrays.asList(libs));
baseResourceURL = expandDir.toURI().toURL(); baseResourceURL = expandDir.toURI().toURL();
} }
File disableFile = new File(archive.getPath() + ".disabled"); File disableFile = new File(archive.getPath() + ".disabled");
if (disableFile.exists()) { if (disableFile.exists()) {
LOGGER.info("Plugin " + archive.getName() + " is disabled"); LOGGER.info("Plugin " + archive.getName() + " is disabled");
} }
// compute dependencies // compute dependencies
List<PluginWrapper.Dependency> dependencies = new ArrayList<PluginWrapper.Dependency>(); List<PluginWrapper.Dependency> dependencies = new ArrayList<PluginWrapper.Dependency>();
List<PluginWrapper.Dependency> optionalDependencies = new ArrayList<PluginWrapper.Dependency>(); List<PluginWrapper.Dependency> optionalDependencies = new ArrayList<PluginWrapper.Dependency>();
String v = atts.getValue("Plugin-Dependencies"); String v = atts.getValue("Plugin-Dependencies");
if (v != null) { if (v != null) {
for (String s : v.split(",")) { for (String s : v.split(",")) {
PluginWrapper.Dependency d = new PluginWrapper.Dependency(s); PluginWrapper.Dependency d = new PluginWrapper.Dependency(s);
if (d.optional) { if (d.optional) {
optionalDependencies.add(d); optionalDependencies.add(d);
} else { } else {
dependencies.add(d); dependencies.add(d);
} }
} }
} }
for (DetachedPlugin detached : DETACHED_LIST) for (DetachedPlugin detached : DETACHED_LIST)
detached.fix(atts,optionalDependencies); detached.fix(atts,optionalDependencies);
...@@ -181,9 +181,9 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -181,9 +181,9 @@ public class ClassicPluginStrategy implements PluginStrategy {
cl = new URLClassLoader(urls.toArray(new URL[urls.size()]),dependencyLoader); cl = new URLClassLoader(urls.toArray(new URL[urls.size()]),dependencyLoader);
} }
return new PluginWrapper(archive, manifest, baseResourceURL, return new PluginWrapper(archive, manifest, baseResourceURL,
cl, disableFile, dependencies, optionalDependencies); cl, disableFile, dependencies, optionalDependencies);
} }
/** /**
* Information about plugins that were originally in the core. * Information about plugins that were originally in the core.
...@@ -231,14 +231,14 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -231,14 +231,14 @@ public class ClassicPluginStrategy implements PluginStrategy {
} }
public void initializeComponents(PluginWrapper plugin) { public void initializeComponents(PluginWrapper plugin) {
} }
public void load(PluginWrapper wrapper) throws IOException { public void load(PluginWrapper wrapper) throws IOException {
loadPluginDependencies(wrapper.getDependencies(), loadPluginDependencies(wrapper.getDependencies(),
wrapper.getOptionalDependencies()); wrapper.getOptionalDependencies());
if (!wrapper.isActive()) if (!wrapper.isActive())
return; return;
// override the context classloader so that XStream activity in plugin.start() // override the context classloader so that XStream activity in plugin.start()
// will be able to resolve classes in this plugin // will be able to resolve classes in this plugin
...@@ -270,7 +270,7 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -270,7 +270,7 @@ public class ClassicPluginStrategy implements PluginStrategy {
// initialize plugin // initialize plugin
try { try {
Plugin plugin = wrapper.getPlugin(); Plugin plugin = wrapper.getPlugin();
plugin.setServletContext(pluginManager.context); plugin.setServletContext(pluginManager.context);
startPlugin(wrapper); startPlugin(wrapper);
} catch(Throwable t) { } catch(Throwable t) {
...@@ -280,11 +280,11 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -280,11 +280,11 @@ public class ClassicPluginStrategy implements PluginStrategy {
} finally { } finally {
Thread.currentThread().setContextClassLoader(old); Thread.currentThread().setContextClassLoader(old);
} }
} }
public void startPlugin(PluginWrapper plugin) throws Exception { public void startPlugin(PluginWrapper plugin) throws Exception {
plugin.getPlugin().start(); plugin.getPlugin().start();
} }
private static File resolve(File base, String relative) { private static File resolve(File base, String relative) {
File rel = new File(relative); File rel = new File(relative);
...@@ -351,41 +351,41 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -351,41 +351,41 @@ public class ClassicPluginStrategy implements PluginStrategy {
} }
} }
/** /**
* Loads the dependencies to other plugins. * Loads the dependencies to other plugins.
* *
* @throws IOException * @throws IOException
* thrown if one or several mandatory dependencies doesnt * thrown if one or several mandatory dependencies doesnt
* exists. * exists.
*/ */
private void loadPluginDependencies(List<Dependency> dependencies, private void loadPluginDependencies(List<Dependency> dependencies,
List<Dependency> optionalDependencies) throws IOException { List<Dependency> optionalDependencies) throws IOException {
List<String> missingDependencies = new ArrayList<String>(); List<String> missingDependencies = new ArrayList<String>();
// make sure dependencies exist // make sure dependencies exist
for (Dependency d : dependencies) { for (Dependency d : dependencies) {
if (pluginManager.getPlugin(d.shortName) == null) if (pluginManager.getPlugin(d.shortName) == null)
missingDependencies.add(d.toString()); missingDependencies.add(d.toString());
} }
if (!missingDependencies.isEmpty()) { if (!missingDependencies.isEmpty()) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("Dependency "); builder.append("Dependency ");
builder.append(Util.join(missingDependencies, ", ")); builder.append(Util.join(missingDependencies, ", "));
builder.append(" doesn't exist"); builder.append(" doesn't exist");
throw new IOException(builder.toString()); throw new IOException(builder.toString());
} }
// add the optional dependencies that exists // add the optional dependencies that exists
for (Dependency d : optionalDependencies) { for (Dependency d : optionalDependencies) {
if (pluginManager.getPlugin(d.shortName) != null) if (pluginManager.getPlugin(d.shortName) != null)
dependencies.add(d); dependencies.add(d);
} }
} }
/** /**
* Used to load classes from dependency plugins. * Used to load classes from dependency plugins.
*/ */
final class DependencyClassLoader extends ClassLoader { final class DependencyClassLoader extends ClassLoader {
private List<Dependency> dependencies; private List<Dependency> dependencies;
public DependencyClassLoader(ClassLoader parent, List<Dependency> dependencies) { public DependencyClassLoader(ClassLoader parent, List<Dependency> dependencies) {
super(parent); super(parent);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册