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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2000-2016 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)
  28. throws IOException, InterruptedException {
  29. Properties authorMap = new Properties();
  30. String authorsFilename = FetchReleaseNotesAuthors.class.getPackage()
  31. .getName().replace(".", "/") + "/authormap.properties";
  32. InputStream s = FetchReleaseNotesAuthors.class.getClassLoader()
  33. .getResourceAsStream(authorsFilename);
  34. if (s == null) {
  35. System.err.println(
  36. "Author mapping file " + authorsFilename + " not found!");
  37. }
  38. authorMap.load(s);
  39. String version = System.getProperty("vaadin.version");
  40. String previousVersion = getPreviousVersion(version);
  41. // System.out.println("Using previous version: " + previousVersion);
  42. // List all commits which are in this version but not in
  43. // "previousVersion"
  44. String cmd = "git log --pretty=%an HEAD ^origin/" + previousVersion;
  45. Process p = Runtime.getRuntime().exec(cmd);
  46. p.waitFor();
  47. if (p.exitValue() != 0) {
  48. System.err.println("Exit code: " + p.exitValue());
  49. }
  50. BufferedReader b = new BufferedReader(
  51. new InputStreamReader(p.getInputStream()));
  52. String line = "";
  53. List<String> authors = new ArrayList<String>();
  54. while ((line = b.readLine()) != null) {
  55. String author = line;
  56. if (authorMap.containsKey(author)) {
  57. author = authorMap.getProperty(author);
  58. }
  59. if (author != null && !author.equals("")
  60. && !authors.contains(author)) {
  61. authors.add(author);
  62. }
  63. }
  64. Collections.sort(authors);
  65. for (String author : authors) {
  66. System.out.println(template.replace("@author@", author));
  67. }
  68. }
  69. private static String getPreviousVersion(String version) {
  70. String[] versionNumbers = version.split("\\.");
  71. if (versionNumbers.length > 4 || versionNumbers.length < 3) {
  72. throw new IllegalArgumentException(
  73. "Cannot parse version: " + version);
  74. }
  75. int major = Integer.parseInt(versionNumbers[0]);
  76. int minor = Integer.parseInt(versionNumbers[1]);
  77. int maintenance = Integer.parseInt(versionNumbers[2]);
  78. // String qualifier = versionNumbers[3];
  79. if (minor == 0) {
  80. // Major release, can't know what the previous minor was
  81. throw new IllegalArgumentException(
  82. "Can't know what previous minor version was");
  83. }
  84. if (maintenance == 0) {
  85. // Minor release, use last minor
  86. return major + "." + (minor - 1);
  87. } else {
  88. // Maintenance, use last maintenance
  89. return major + "." + minor + "." + (maintenance - 1);
  90. }
  91. }
  92. }