replaceBuildProperties.groovy 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import java.io.File;
  2. class Globals {
  3. static String svnBase;
  4. }
  5. def productDir = properties["productDir"];
  6. Globals.svnBase = properties["svnBase"];
  7. def svnBase2 = Globals.svnBase;
  8. println("productDir = ${productDir}, svnBase=${svnBase2}");
  9. List<File> pluginDirs = getPluginDirectories(productDir);
  10. pluginDirs.each {
  11. pluginDir -> processPluginDirectory(pluginDir)
  12. }
  13. def processPluginDirectory(File pluginDir)
  14. {
  15. String svnRevision = getPluginDirSvnRevision(pluginDir);
  16. setBuildPropertiesQualifier(pluginDir, svnRevision)
  17. }
  18. def setBuildPropertiesQualifier(File pluginDir, String svnRevision)
  19. {
  20. def buildPropsPath = pluginDir.getAbsolutePath() + java.io.File.separator + "build.properties";
  21. if (new File(buildPropsPath).exists())
  22. {
  23. String buildPropsText = new File(buildPropsPath).getText();
  24. def regex = /(?m)^\s*qualifier\s+=\s+none\s*$/;
  25. String newBuildPropsText = buildPropsText.replaceAll(regex,'qualifier = ' + svnRevision);
  26. new File(buildPropsPath).setText(newBuildPropsText);
  27. }
  28. }
  29. def getPluginDirSvnRevision(File pluginDir)
  30. {
  31. def command = 'svn info ' + Globals.svnBase + pluginDir.getName();
  32. def proc = command.execute() // Call *execute* on the string
  33. def svnRevision = null;
  34. proc.in.eachLine { line -> def tmp = fetchSvnRevision(line); if (tmp != null) svnRevision = tmp; }
  35. svnRevision;
  36. }
  37. def getPluginDirectories(String productDir)
  38. {
  39. def pluginDirs = [];
  40. new File(productDir).eachFile{file ->
  41. if(file.isDirectory() && file.name.startsWith("com.excelsior" )){
  42. pluginDirs.add(file);
  43. }
  44. }
  45. pluginDirs;
  46. }
  47. def fetchSvnRevision(String line)
  48. {
  49. def matcher = line =~ /^Last Changed Rev: (\d+)\s*$/;
  50. if (matcher.matches())
  51. {
  52. return matcher.group(1);
  53. }
  54. return null;
  55. }