99import java .io .IOException ;
1010import java .io .InputStream ;
1111import java .util .UUID ;
12- import javax .annotation .Nonnull ;
13- import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
1412import hudson .EnvVars ;
1513import hudson .FilePath ;
1614import hudson .Launcher ;
@@ -72,15 +70,12 @@ default void copyFileInWorkspace(String sourceFile, String targetFile, FilePath
7270 targetFilePath .chmod (0755 );
7371 }
7472
75- @ SuppressFBWarnings (value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" ,
76- justification = "workspace is passed through perform method, which will always have NonNull FilePath" )
7773 default FilePath getFilePathForUniqueFolder (Launcher launcher , String uniqueName , FilePath workspace )
7874 throws IOException , InterruptedException {
7975 /*Use of Computer is not recommended as jenkins hygeine for pipeline support
8076 * https://javadoc.jenkins-ci.org/jenkins/tasks/SimpleBuildStep.html */
8177
82- Computer cmp = workspace .toComputer ();
83- String tmpDir = (String ) cmp .getSystemProperties ().get ("java.io.tmpdir" );
78+ String tmpDir = getNodeSpecificTmpFolderPath (workspace );
8479 if (launcher .isUnix ()) {
8580 tmpDir = tmpDir + "/" + uniqueName ;
8681 } else {
@@ -89,16 +84,16 @@ default FilePath getFilePathForUniqueFolder(Launcher launcher, String uniqueName
8984 return new FilePath (launcher .getChannel (), tmpDir );
9085 }
9186
92- @ SuppressFBWarnings (value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" ,
93- justification = "workspace is passed through perform method, which will always have NonNull FilePath" )
9487 default String getNodeSpecificTmpFolderPath (FilePath workspace ) throws IOException , InterruptedException {
9588 Computer cmp = workspace .toComputer ();
89+ if (cmp == null ) {
90+ throw new IOException (Message .getValue ("build.workspace.computer.not.found" ));
91+ }
9692 String tmpDir = (String ) cmp .getSystemProperties ().get ("java.io.tmpdir" );
9793 return tmpDir ;
9894 }
9995
10096 default String getUniqueNameForRunnerFile () {
10197 return UUID .randomUUID ().toString ();
10298 }
103-
10499}
0 commit comments