Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Export QB Config and rename number files to store in version control #3745

jclx ·

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.

  1. Use Export Configurations
    2a) If you have this in VCS, check it out from vcs.
  2. Unzip export.zip
  3. Run groovy script below
  4. 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();
}
  • replies 1
  • views 2169
  • stars 1
robinshen ADMIN ·

Thanks for sharing! Definitely useful to many of our customers!