I use this script pattern a lot so that I can store QB configurations in version control with a path and name that matches QB configuration paths. Especially having it in vcs allows searching all configs/scripts for strings like variables etc.
Thought others might use it.
- Use Export Configurations
2a) If you have this in VCS, check it out from vcs. - Unzip export.zip
- Run groovy script below
- Check into VCS.
groovy:
try
{
com.pmease.quickbuild.persistence.SessionManager.openSession();
def dir = new File(configuration.workspaceDir, "<directoryWhereUnzip of expert>");
new File(dir, 'export.properties').delete();
def fileList = dir.listFiles();
// rename # files with build cfg name.
fileList.each { file ->
if (file.name.endsWith(".xml")) {
logger.info("Found xml file: " + file.name);
def tmp = file.name.substring(0, file.name.indexOf('.'));
logger.info("Found id: " + tmp);
def cfg = system.getConfigurationManager().load(Long.valueOf(tmp));
if (cfg) {
tmp = cfg.getPathName().replace("root/", "").replace(cfg.getName(), "");
def tmpDir = new File(file.getParentFile(), tmp);
tmpDir.mkdirs();
def tmpFile = new File(tmpDir, cfg.getName() + ".xml");
logger.info("Rename to: " + tmpFile.absolutePath);
file.renameTo(tmpFile);
} else {
logger.info("Config Not found for id: " + tmp + " - deleting file");
file.delete();
}
}
}
// this section is to handle when source is in vcs and configurations are moved by looking up id number and matching and checking path.
dir = new File(dir, "root/Deploy".replace("root/", ""));
logger.info('Checking dir:' + dir.absolutePath);
if (dir.exists()) {
dir.eachFileRecurse(groovy.io.FileType.FILES) { file ->
def tmp = file.text;
def idx = tmp.indexOf('<id>');
def idx2 = tmp.indexOf('</id>');
if (idx != -1 && idx2 != -1) {
def idTmp = tmp.substring(idx+4, idx2);
logger.info('File:' + file.absolutePath + ' = ID: ' + idTmp);
def cfg = system.getConfigurationManager().get(Long.valueOf(idTmp));
if (!cfg) {
logger.info('File:' + file.absolutePath + ' with id: ' + idTmp + ' does not have a build cfg, deleting');
file.delete();
} else {
logger.info('File:' + file.absolutePath + ' with id: ' + idTmp + ' found cfg at:' + cfg.getPathName());
def tp = cfg.getPathName().replace("root/", "");
if (!file.absolutePath.endsWith(tp + ".xml")) {
logger.info('File:' + file.absolutePath + ' with id: ' + idTmp + ' moved, deleting:');
file.delete();
}
}
}
}
}
}
finally
{
com.pmease.quickbuild.persistence.SessionManager.closeSession();
}