Skip to content

Commit

Permalink
[FIXED JENKINS-13108] exclude p4config file from wipe on checkout
Browse files Browse the repository at this point in the history
note: Jenkins' built-in wipe out workspace functionality is not affected, and will still wipe the entire workspace (outside the scope of the p4 plugin)
  • Loading branch information
rpetti committed Mar 17, 2012
1 parent f37dd67 commit 7c0c24c
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/main/java/hudson/plugins/perforce/PerforceSCM.java
Expand Up @@ -625,10 +625,25 @@ private static void retrieveUserInformation(Depot depot, List<Changelist> change
}
}

private static class WipeWorkspaceFilter implements FileFilter, Serializable {
private static class WipeWorkspaceExcludeFilter implements FileFilter, Serializable {

private List<String> excluded = new ArrayList<String>();

public WipeWorkspaceExcludeFilter(String... args){
for(String arg : args){
excluded.add(arg);
}
}

public void exclude(String arg){
excluded.add(arg);
}

public boolean accept(File arg0) {
if(arg0.getName().equals(".repository")){
return false;
for(String exclude : excluded){
if(arg0.getName().equals(exclude)){
return false;
}
}
return true;
}
Expand Down Expand Up @@ -703,15 +718,17 @@ public boolean checkout(AbstractBuild build, Launcher launcher,

if(wipeBeforeBuild){
log.println("Clearing workspace...");
String p4config = substituteParameters("${P4CONFIG}", build);
WipeWorkspaceExcludeFilter wipeFilter = new WipeWorkspaceExcludeFilter(".p4config",p4config);
if(wipeRepoBeforeBuild){
log.println("Clear workspace includes .repository ...");
workspace.deleteContents();
log.println("Clear workspace includes .repository ...");
} else {
log.println("Note: .repository directory in workspace (if exists) is skipped.");
List<FilePath> workspaceDirs = workspace.list(new WipeWorkspaceFilter());
for(FilePath dir : workspaceDirs){
dir.deleteRecursive();
}
wipeFilter.exclude(".repository");
}
List<FilePath> workspaceDirs = workspace.list(wipeFilter);
for(FilePath dir : workspaceDirs){
dir.deleteRecursive();
}
log.println("Cleared workspace.");
forceSync = true;
Expand Down

0 comments on commit 7c0c24c

Please sign in to comment.