-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved use of java.io.tmpdir
#838
Conversation
@@ -63,7 +63,7 @@ | |||
public class UnitTestSupportingPluginManager extends PluginManager { | |||
|
|||
public UnitTestSupportingPluginManager(File rootDir) { | |||
super((ServletContext) null, new File(rootDir, "plugins")); | |||
super((ServletContext) null, rootDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Util.deleteRecursive(INSTANCE.rootDir); |
plugins
but not the parent dir jenkinsXXX
created by super(Util.createTempDir()); |
@@ -90,7 +90,7 @@ public void setup(JenkinsRule jenkinsRule, WithPluginManager recipe) throws Exce | |||
public void decorateHome(JenkinsRule jenkinsRule, File home) throws Exception { | |||
Class<? extends PluginManager> c = recipe.value(); | |||
Constructor<? extends PluginManager> ctr = c.getDeclaredConstructor(File.class); | |||
jenkinsRule.setPluginManager(ctr.newInstance(home)); | |||
jenkinsRule.setPluginManager(ctr.newInstance(new File(home, "plugins"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To restore behavior for those tests requesting UnitTestSupportingPluginManager
.
@@ -90,7 +101,6 @@ private String getMimeType(String path) { | |||
*/ | |||
public static synchronized JavaNetReverseProxy2 getInstance() throws Exception { | |||
if (INSTANCE == null) { | |||
// TODO: think of a better location --- ideally inside the target/ dir so that clean would wipe them out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
if (home.get() != null) { | ||
try { | ||
jenkinsOptions("--webroot=" + createTempDirectory("webroot"), "--pluginroot=" + createTempDirectory("pluginroot")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Various controller packagings set these options to temp dirs, so I think it is realistic to set them here automatically. Otherwise the fallback is inside $JENKINS_HOME
which is undesirable.
try { | ||
deprovision(); | ||
tmp.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be confusing depending on whether or not you have whitespace displayed: now just deleting all temp dirs when the test completes, regardless of #610 mode. (The other code in deprovision
did not seem important since a rule instance is only expected to be used once.)
* and will honor {@code java.io.tmpdir} set by Surefire | ||
* after {@code StaticProperty.JAVA_IO_TMPDIR} has been initialized. | ||
*/ | ||
public Path createTempDirectory(String prefix) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing this utility since it can be useful from certain tests, and it is otherwise tedious to arrange for dirs to be deleted at test exit.
…rness into java.io.tmpdir
|
@@ -465,7 +481,7 @@ private static AgentArguments getAgentArguments(JenkinsRule r, String name) thro | |||
if (!launcher.getWorkDirSettings().isDisabled()) { | |||
commandLineArgs = launcher.getWorkDirSettings().toCommandLineArgs(c); | |||
} | |||
File agentJar = new File(r.jenkins.getRootDir(), "agent.jar"); | |||
File agentJar = new File(System.getProperty("java.io.tmpdir"), "agent.jar"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears to completely break some things:
e.g. -DforkCount=<number_greater_than_one>
as the file may not exist for 2 forks at the time of checking (which use the same surefire temp directory) , is completely written by one and the other and then used whilst the other is overwriting it.
Or in Windows locking exceptions for the second attempt to write the file.
- the ability to quickly switch between version using
-DJenkins.version=x
(you now need tomvn clean
as opposed to just using the incremental compilation which is faster)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah a temp file would be better for this case. I can prepare a patch for it.
Ensure that temporary files are written to
target/tmp/
(wheremvn clean
can delete them) rather than the system temporary directory, including inRealJenkinsRule
forked JVMs; note that in the test JVM it seems to be necessary to look up this system property explicitly, I think since Surefire sets the system property after startup rather than using-D
, and something reads and caches the value soon after startup. Ensure that all temporary directories are deleted when the test exits. Use temporary directories instead of$JENKINS_HOME
for anything added by the test harness rather than Jenkins itself. (Extracted from #827.)