/** * There are two things we need to check * * <ul> * <li>files created or modified since last build time, we only need to check the source folder * <li>file deleted since last build time, we have to compare source and destination folder * </ul> */ @Override public boolean pollChanges( AbstractProject project, Launcher launcher, FilePath workspace, TaskListener listener) throws IOException, InterruptedException { long start = System.currentTimeMillis(); PrintStream log = launcher.getListener().getLogger(); log.println("FSSCM.pollChange: " + path); AllowDeleteList allowDeleteList = new AllowDeleteList(project.getRootDir()); // we will only delete a file if it is listed in the allowDeleteList // ie. we will only delete a file if it is copied by us if (allowDeleteList.fileExists()) { allowDeleteList.load(); } else { // watch list save file doesn't exist // we will assuem all existing files are under watch // ie. everything can be deleted Set<String> existingFiles = workspace.act(new RemoteListDir()); allowDeleteList.setList(existingFiles); } RemoteFolderDiff.PollChange callable = new RemoteFolderDiff.PollChange(); setupRemoteFolderDiff(callable, project, allowDeleteList.getList()); boolean changed = workspace.act(callable); String str = callable.getLog(); if (str.length() > 0) log.println(str); log.println("FSSCM.pollChange return " + changed); log.println( "FSSCM.poolChange completed in " + formatDurration(System.currentTimeMillis() - start)); return changed; }
@Override public boolean checkout( AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changelogFile) throws IOException, InterruptedException { long start = System.currentTimeMillis(); PrintStream log = launcher.getListener().getLogger(); log.println("FSSCM.checkout " + path + " to " + workspace); Boolean b = Boolean.TRUE; AllowDeleteList allowDeleteList = new AllowDeleteList(build.getProject().getRootDir()); if (clearWorkspace) { log.println("FSSCM.clearWorkspace..."); workspace.deleteRecursive(); } // we will only delete a file if it is listed in the allowDeleteList // ie. we will only delete a file if it is copied by us if (allowDeleteList.fileExists()) { allowDeleteList.load(); } else { // watch list save file doesn't exist // we will assuem all existing files are under watch // ie. everything can be deleted Set<String> existingFiles = workspace.act(new RemoteListDir()); allowDeleteList.setList(existingFiles); } RemoteFolderDiff.CheckOut callable = new RemoteFolderDiff.CheckOut(); setupRemoteFolderDiff(callable, build.getProject(), allowDeleteList.getList()); List<FolderDiff.Entry> list = workspace.act(callable); // maintain the watch list for (FolderDiff.Entry entry : list) { if (FolderDiff.Entry.Type.DELETED.equals(entry.getType())) { allowDeleteList.remove(entry.getFilename()); } else { // added or modified allowDeleteList.add(entry.getFilename()); } } allowDeleteList.save(); // raw log String str = callable.getLog(); if (str.length() > 0) log.println(str); ChangelogSet.XMLSerializer handler = new ChangelogSet.XMLSerializer(); ChangelogSet changeLogSet = new ChangelogSet(build, list); handler.save(changeLogSet, changelogFile); log.println("FSSCM.check completed in " + formatDurration(System.currentTimeMillis() - start)); return b; }