You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FetchReleaseNotesAuthors.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.buildhelpers;
  17. import java.io.BufferedReader;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.io.InputStreamReader;
  21. import java.util.ArrayList;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import java.util.Properties;
  25. public class FetchReleaseNotesAuthors {
  26. private static final String template = "<li class=\"author\">@author@</li>";
  27. public static void main(String[] args) throws IOException,
  28. InterruptedException {
  29. Properties authorMap = new Properties();
  30. String authorsFilename = FetchReleaseNotesAuthors.class.getPackage()
  31. .getName().replace(".", "/")
  32. + "/authormap.properties";
  33. InputStream s = FetchReleaseNotesAuthors.class.getClassLoader()
  34. .getResourceAsStream(authorsFilename);
  35. if (s == null) {
  36. System.err.println("Author mapping file " + authorsFilename
  37. + " not found!");
  38. }
  39. authorMap.load(s);
  40. String version = System.getProperty("vaadin.version");
  41. String previousVersion = getPreviousVersion(version);
  42. // System.out.println("Using previous version: " + previousVersion);
  43. // List all commits which are in this version but not in
  44. // "previousVersion"
  45. String cmd = "git log --pretty=%an HEAD ^origin/" + previousVersion;
  46. Process p = Runtime.getRuntime().exec(cmd);
  47. p.waitFor();
  48. if (p.exitValue() != 0) {
  49. System.err.println("Exit code: " + p.exitValue());
  50. }
  51. BufferedReader b = new BufferedReader(new InputStreamReader(
  52. p.getInputStream()));
  53. String line = "";
  54. List<String> authors = new ArrayList<String>();
  55. while ((line = b.readLine()) != null) {
  56. String author = line;
  57. if (authorMap.containsKey(author)) {
  58. author = authorMap.getProperty(author);
  59. }
  60. if (author != null && !author.equals("")
  61. && !authors.contains(author)) {
  62. authors.add(author);
  63. }
  64. }
  65. Collections.sort(authors);
  66. for (String author : authors) {
  67. System.out.println(template.replace("@author@", author));
  68. }
  69. }
  70. private static String getPreviousVersion(String version) {
  71. String[] versionNumbers = version.split("\\.");
  72. if (versionNumbers.length > 4 || versionNumbers.length < 3) {
  73. throw new IllegalArgumentException("Cannot parse version: "
  74. + version);
  75. }
  76. int major = Integer.parseInt(versionNumbers[0]);
  77. int minor = Integer.parseInt(versionNumbers[1]);
  78. int maintenance = Integer.parseInt(versionNumbers[2]);
  79. // String qualifier = versionNumbers[3];
  80. if (minor == 0) {
  81. // Major release, can't know what the previous minor was
  82. throw new IllegalArgumentException(
  83. "Can't know what previous minor version was");
  84. }
  85. if (maintenance == 0) {
  86. // Minor release, use last minor
  87. return major + "." + (minor - 1);
  88. } else {
  89. // Maintenance, use last maintenance
  90. return major + "." + minor + "." + (maintenance - 1);
  91. }
  92. }
  93. }