createCategoryXml.groovy 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import groovy.xml.*
  2. def cli = new CliBuilder(usage:'createUpdateSite.groovy')
  3. cli.r(longOpt:'repo', args:1, argName:'data', 'features and plugins repository')
  4. cli.s(longOpt:'categoryXml', args:1, argName:'data', 'result category.xml')
  5. def options = cli.parse(args)
  6. def repoPath = options.repo;
  7. if (!new File(repoPath).exists())
  8. {
  9. println("repository dir is incorrectly specified");
  10. return;
  11. }
  12. def categoryXml = options.categoryXml;
  13. new File(categoryXml).getParentFile().mkdirs();
  14. println("repoPath = ${repoPath}, categoryXml=${categoryXml}");
  15. def featureRefs = [];
  16. new File(repoPath + File.separator + 'features').eachFile{file ->
  17. if(file.isFile() && file.name.matches("(.+)_(.+)[.]jar")){
  18. featureRefs.add(file.getParentFile().name + File.separator + file.name);
  19. }
  20. }
  21. def xmlFeatures = [];
  22. Set xmlCategories = [];
  23. def categoryXds = "com.excelsior.xds";
  24. def categoryXdsJre = "com.excelsior.xds.jre";
  25. def categoryEclipse = "org.eclipse";
  26. def categoryOther = "other";
  27. Map<String, CategoryDesc> categoryName2Desc = [:];
  28. categoryName2Desc[categoryXds] = new CategoryDesc(categoryXds, "XDS Modula IDE components", "XDS Modula IDE components description");
  29. categoryName2Desc[categoryXdsJre] = new CategoryDesc(categoryXds, "Oracle JRE", "Oracle JRE description");
  30. categoryName2Desc[categoryEclipse] = new CategoryDesc(categoryEclipse, "Eclipse components", "Eclipse components description");
  31. categoryName2Desc[categoryOther] = new CategoryDesc(categoryOther, "Other", "Other description");
  32. def closure = {
  33. site {
  34. featureRefs.each { ref ->
  35. def regex = /.+[\\](.+)_(\d+[.]\d+[.]\d+).*[.]jar/;
  36. def matcher = ref =~ regex;
  37. if (matcher.matches())
  38. {
  39. def versionVal = matcher.group(2);
  40. def idVal = matcher.group(1);
  41. feature(id : idVal, version : versionVal + '.qualifier', url : ref)
  42. {
  43. if (idVal.startsWith(categoryXdsJre))
  44. {
  45. xmlCategories.add(categoryXdsJre);
  46. category(name : categoryXdsJre) {}
  47. }
  48. else if (idVal.startsWith(categoryXds))
  49. {
  50. xmlCategories.add(categoryXds);
  51. category(name : categoryXds) {}
  52. }
  53. else if (idVal.startsWith("org.eclipse"))
  54. {
  55. xmlCategories.add(categoryEclipse);
  56. category(name : categoryEclipse) {}
  57. }
  58. else {
  59. xmlCategories.add(categoryOther);
  60. category(name : categoryOther) {}
  61. }
  62. }
  63. }
  64. }
  65. xmlCategories.each { categoryName ->
  66. CategoryDesc categoryDesc = categoryName2Desc[categoryName];
  67. 'category-def' (name : categoryName, label : categoryDesc.label)
  68. {
  69. description(categoryDesc.description);
  70. }
  71. }
  72. }
  73. }
  74. writeFile(categoryXml, closure);
  75. class CategoryDesc
  76. {
  77. String name;
  78. String label;
  79. String description;
  80. public CategoryDesc(String name, String label, String description) {
  81. this.name = name;
  82. this.label = label;
  83. this.description = description;
  84. }
  85. }
  86. def writeFile(fileName, closure) {
  87. def xmlFile = new File(fileName)
  88. def writer = xmlFile.newWriter()
  89. def builder = new StreamingMarkupBuilder()
  90. def Writable writable = builder.bind closure
  91. writable.writeTo(writer)
  92. }