-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Create a tmp directory when such doesn't exist. In some cases the tmp… #10002
base: master
Are you sure you want to change the base?
Conversation
… director won't exist and an Exception will be thrown when attempting to create a file in that directory. An example of such case is creating a JenkinsRule instance in some tests and executing those tests from an IDE.
Yay, your first pull request towards Jenkins core was created successfully! Thank you so much! |
core/src/main/java/hudson/Util.java
Outdated
if (!systemTmpDirectoryPath.toFile().exists()){ | ||
// In some cases the tmp directory set in the java.io.tmpdir property will not exist and hence will have to | ||
// be created here. | ||
systemTmpDirectoryPath.toFile().mkdirs(); |
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.
Using Files.createDirectory instead should avoid the SpotBugs warning.
core/src/main/java/hudson/Util.java
Outdated
@@ -436,6 +436,14 @@ public static File createTempDir() throws IOException { | |||
// https://github.com/jenkinsci/jenkins/pull/3161 ) | |||
final Path tempPath; | |||
final String tempDirNamePrefix = "jenkins"; | |||
|
|||
final Path systemTmpDirectoryPath = Path.of(System.getProperty("java.io.tmpdir")); | |||
if (!systemTmpDirectoryPath.toFile().exists()){ |
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 (!systemTmpDirectoryPath.toFile().exists()){ | |
if (!systemTmpDirectoryPath.toFile().exists()) { |
Description
While writing Jenkins plugin tests and debugging them in IntelliJ I stumbled upon an issue when trying to create an instance of JenkinsRule, which was failing to instantiate due to the following exception:
I was debugging the test from within IntelliJ and what I noticed was that IntelliJ was setting the
java.io.tmpdir
property to be atmp
directory within the project target directory, which doesn't exist my default, hence why I am creating this PR. This issue could have been resolved with extra maven hackery in my plugin's pom.xml, but I thought that this issue might occur in different scenarios as well and why not handle it here.