-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathJenkinsFilesHelper.java
More file actions
23 lines (17 loc) · 940 Bytes
/
JenkinsFilesHelper.java
File metadata and controls
23 lines (17 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package hudson.plugins.scm_sync_configuration;
import jenkins.model.Jenkins;
import java.io.File;
public class JenkinsFilesHelper {
public static String buildPathRelativeToHudsonRoot(File file){
File hudsonRoot = Jenkins.getInstance().getRootDir();
if(!file.getAbsolutePath().startsWith(hudsonRoot.getAbsolutePath())){
throw new IllegalArgumentException("Err ! File ["+file.getAbsolutePath()+"] seems not to reside in ["+hudsonRoot.getAbsolutePath()+"] !");
}
String truncatedPath = file.getAbsolutePath().substring(hudsonRoot.getAbsolutePath().length()+1); // "+1" because we don't need ending file separator
return truncatedPath.replaceAll("\\\\", "/");
}
public static File buildFileFromPathRelativeToHudsonRoot(String pathRelativeToHudsonRoot){
File hudsonRoot = Jenkins.getInstance().getRootDir();
return new File(hudsonRoot.getAbsolutePath()+File.separator+pathRelativeToHudsonRoot);
}
}