
org.kuali.maven.plugins.jenkins.helper.RsyncHelper Maven / Gradle / Ivy
package org.kuali.maven.plugins.jenkins.helper;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RsyncHelper {
private static final Logger logger = LoggerFactory.getLogger(RsyncHelper.class);
/**
* Recursively scan the file system starting at dir
and return a list of directories matching the
* pattern passed in
*
* @param dir
* @param pattern
* @param filter
* @return
*/
public List getMatchingDirs(File basedir, File dir, String endsWithPattern, DirectoryFileFilter filter) {
List fileList = new ArrayList();
String path = dir.getAbsolutePath();
boolean match = path.endsWith(File.separator + endsWithPattern);
if (!match) {
File[] dirs = dir.listFiles(filter);
for (File newDir : dirs) {
fileList.addAll(getMatchingDirs(basedir, newDir, endsWithPattern, filter));
}
} else {
fileList.add(dir);
}
return fileList;
}
/**
* Return a list of rsync friendly exclude patterns based on a base directory and directories underneath it that
* should be excluded.
*
* @param basedir
* @param dirs
* @param pattern
* @return
*/
public List getExcludesList(File basedir, List excludeDirs) {
String basedirPath = basedir.getAbsolutePath();
List excludes = new ArrayList();
for (File excludeDir : excludeDirs) {
String path = excludeDir.getAbsolutePath();
logger.debug("path=" + path);
if (excludeDir.equals(basedir)) {
continue;
}
logger.debug("basedirPath=" + basedirPath);
String token = path.substring(basedirPath.length() + 1);
excludes.add(token);
}
return excludes;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy