Skip to content

Commit

Permalink
[JENKINS-32765] Perhaps it makes more sense to make this a property o…
Browse files Browse the repository at this point in the history
…f the PluginManager rather than the classic strategy

- Also expose via servlet context parameter of same name to allow multiple instances of Jenkins in the same servlet container to have different directories
- As we are no longer a constant, change the system property to camelCase
  • Loading branch information
stephenc committed Feb 4, 2016
1 parent d27cff8 commit c0cbff7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 2 additions & 10 deletions core/src/main/java/hudson/ClassicPluginStrategy.java
Expand Up @@ -88,12 +88,6 @@ public boolean accept(File dir,String name) {
}
};

/**
* If set this should be the absolute file path to the the base directory for all exploded .hpi/.jpi plugins.
* If {@literal null} then plugins will be exploded into {@literal JENKINS_HOME/plugins}.
*/
private static final String WORK_DIR = System.getProperty(ClassicPluginStrategy.class.getName() + ".WORK_DIR");

private PluginManager pluginManager;

/**
Expand Down Expand Up @@ -168,10 +162,8 @@ private static Manifest loadLinkedManifest(File archive) throws IOException {
if (archive.isDirectory()) {// already expanded
expandDir = archive;
} else {
expandDir = WORK_DIR == null
? new File(archive.getParentFile(), getBaseName(archive.getName()))
: new File(WORK_DIR, getBaseName(archive.getName()));
;
File f = pluginManager.getWorkDir();
expandDir = new File(f == null ? archive.getParentFile() : f, getBaseName(archive.getName()));
explode(archive, expandDir);
}

Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -149,6 +149,12 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
*/
public final File rootDir;

/**
* If non-null, the base directory for all exploded .hpi/.jpi plugins. Controlled by the system property / servlet
* context parameter {@literal hudson.PluginManager.workDir}.
*/
private final File workDir;

/**
* @deprecated as of 1.355
* {@link PluginManager} can now live longer than {@link jenkins.model.Jenkins} instance, so
Expand Down Expand Up @@ -199,6 +205,11 @@ public PluginManager(ServletContext context, File rootDir) {
this.rootDir = rootDir;
if(!rootDir.exists())
rootDir.mkdirs();
String workDir = System.getProperty(PluginManager.class.getName()+".workDir");
if (workDir == null) {
workDir = context.getInitParameter(PluginManager.class.getName() + ".workDir");
}
this.workDir = workDir == null ? null : new File(workDir);

strategy = createPluginStrategy();

Expand All @@ -218,6 +229,14 @@ public Api getApi() {
return new Api(this);
}

/**
* If non-null, the base directory for all exploded .hpi/.jpi plugins.
* @return the base directory for all exploded .hpi/.jpi plugins or {@code null} to leave this up to the strategy.
*/
public File getWorkDir() {
return workDir;
}

/**
* Find all registered overrides (intended to allow overriding/adding views)
* @return List of extensions
Expand Down

0 comments on commit c0cbff7

Please sign in to comment.