Skip to content

Commit dcd8be1

Browse files
zilmTTmnencia
authored andcommitted
Add a basic filter for FileUtil.copy
As i encountered some copy issues, e.g was not able to copy blank build/ dir, i implemented a basic filter for the FileUtil.copy function. This matches on any XML-File and on includes specified on ManualIncludes list from scm-sync-configuration.
1 parent aabe49b commit dcd8be1

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/main/java/hudson/plugins/scm_sync_configuration/ScmSyncConfigurationBusiness.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class ScmSyncConfigurationBusiness {
3939
private SCMManipulator scmManipulator;
4040
private File checkoutScmDirectory = null;
4141
private ScmSyncConfigurationStatusManager scmSyncConfigurationStatusManager = null;
42+
private List<String> manualSynchronizationIncludes = new ArrayList<String>();
4243

4344
/**
4445
* Use of a size 1 thread pool frees us from worrying about accidental thread death and
@@ -187,8 +188,17 @@ private void processCommitsQueue() {
187188
String firstNonExistingParentScmPath = pathRelativeToJenkinsRoot.getFirstNonExistingParentScmPath();
188189

189190
try {
190-
FileUtils.copyDirectory(JenkinsFilesHelper.buildFileFromPathRelativeToHudsonRoot(pathRelativeToJenkinsRoot.getPath()),
191-
fileTranslatedInScm);
191+
File buildFileFromPathRelativeToHudsonRoot = JenkinsFilesHelper.buildFileFromPathRelativeToHudsonRoot(pathRelativeToJenkinsRoot.getPath());
192+
FileUtils.copyDirectory(buildFileFromPathRelativeToHudsonRoot, fileTranslatedInScm, new FileFilter() {
193+
@Override
194+
public boolean accept(File pathname) {
195+
if(pathname.getPath().endsWith(".xml")
196+
|| getManualSynchronizationIncludes().contains(pathname)){
197+
return true;
198+
}
199+
return false;
200+
}
201+
});
192202
} catch (IOException e) {
193203
throw new LoggableException("Error while copying file hierarchy to SCM directory", FileUtils.class, "copyDirectory", e);
194204
}
@@ -212,7 +222,8 @@ private void processCommitsQueue() {
212222
}
213223
for(Path path : commit.getChangeset().getPathsToDelete()){
214224
List<File> deletedFiles = deleteHierarchy(commit.getScmContext(), path);
215-
updatedFiles.addAll(deletedFiles);
225+
if(deletedFiles != null)
226+
updatedFiles.addAll(deletedFiles);
216227
}
217228

218229
if(updatedFiles.isEmpty()){
@@ -245,6 +256,15 @@ private void processCommitsQueue() {
245256
}
246257
}
247258

259+
public List<String> getManualSynchronizationIncludes() {
260+
return manualSynchronizationIncludes;
261+
}
262+
263+
public void setManualSynchronizationIncludes(
264+
List<String> manualSynchronizationIncludes) {
265+
this.manualSynchronizationIncludes = manualSynchronizationIncludes;
266+
}
267+
248268
private boolean writeScmContentOnlyIfItDiffers(Path pathRelativeToJenkinsRoot, byte[] content, File fileTranslatedInScm)
249269
throws LoggableException {
250270
boolean scmContentUpdated = false;

src/main/java/hudson/plugins/scm_sync_configuration/ScmSyncConfigurationPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public void loadData(ScmSyncConfigurationPOJO pojo){
164164
this.displayStatus = pojo.isDisplayStatus();
165165
this.commitMessagePattern = pojo.getCommitMessagePattern();
166166
this.manualSynchronizationIncludes = pojo.getManualSynchronizationIncludes();
167+
this.business.setManualSynchronizationIncludes(manualSynchronizationIncludes);
167168
}
168169

169170
protected void initialInit() throws Exception {
@@ -228,6 +229,8 @@ public void configure(StaplerRequest req, JSONObject formData)
228229
this.manualSynchronizationIncludes = new ArrayList<String>();
229230
}
230231

232+
this.business.setManualSynchronizationIncludes(manualSynchronizationIncludes);
233+
231234
// Repo initialization should be made _before_ plugin save, in order to let scm-sync-configuration.xml
232235
// file synchronizable
233236
if(repoInitializationRequired){

0 commit comments

Comments
 (0)