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.

FetchReleaseNotesTickets.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.IOException;
  18. import java.io.InputStream;
  19. import java.net.MalformedURLException;
  20. import java.net.URL;
  21. import java.net.URLConnection;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import org.apache.commons.io.IOUtils;
  25. public class FetchReleaseNotesTickets {
  26. private static final String queryURL = "https://dev.vaadin.com/query?status=pending-release&status=released&@milestone@&resolution=fixed&col=id&col=summary&col=owner&col=type&col=priority&col=component&col=version&col=bfptime&col=fv&format=tab&order=id";
  27. private static final String ticketTemplate = "<tr>" + "@badge@" //
  28. + "<td class=\"ticket\"><a href=\"https://dev.vaadin.com/ticket/@ticket@\">#@ticket@</a></td>" //
  29. + "<td>@description@</td>" //
  30. + "</tr>"; //
  31. public static void main(String[] args) throws IOException {
  32. String versionsProperty = System.getProperty("vaadin.version");
  33. if (versionsProperty == null || versionsProperty.equals("")) {
  34. usage();
  35. }
  36. String milestone = "";
  37. List<String> versions = new ArrayList<String>();
  38. for (String version : versionsProperty.split(" ")) {
  39. if (version.endsWith(".0") || version.matches(".*\\.rc\\d+")) {
  40. // Find all prerelease versions for final or rc
  41. // Strip potential rc prefix
  42. version = version.replaceAll("\\.rc\\d+$", "");
  43. versions.addAll(findPrereleaseVersions(version));
  44. } else {
  45. versions.add(version);
  46. }
  47. }
  48. for (String version : versions) {
  49. if (!milestone.equals("")) {
  50. milestone += "&amp;";
  51. }
  52. milestone += "milestone=Vaadin+" + version;
  53. }
  54. printMilestone(milestone);
  55. }
  56. private static List<String> findPrereleaseVersions(String baseVersion) {
  57. List<String> versions = new ArrayList<String>();
  58. for (int i = 0; i < 50; i++) {
  59. versions.add(baseVersion + ".alpha" + i);
  60. }
  61. for (int i = 0; i < 10; i++) {
  62. versions.add(baseVersion + ".beta" + i);
  63. }
  64. for (int i = 0; i < 10; i++) {
  65. versions.add(baseVersion + ".rc" + i);
  66. }
  67. return versions;
  68. }
  69. private static void printMilestone(String milestone)
  70. throws MalformedURLException, IOException {
  71. URL url = new URL(queryURL.replace("@milestone@", milestone));
  72. URLConnection connection = url.openConnection();
  73. InputStream urlStream = connection.getInputStream();
  74. List<String> tickets = IOUtils.readLines(urlStream);
  75. for (String ticket : tickets) {
  76. // Omit BOM
  77. if (!ticket.isEmpty() && ticket.charAt(0) == 65279) {
  78. ticket = ticket.substring(1);
  79. }
  80. String[] fields = ticket.split("\t");
  81. if ("id".equals(fields[0])) {
  82. // This is the header
  83. continue;
  84. }
  85. String summary = fields[1];
  86. summary = modifySummaryString(summary);
  87. String badge = "<td></td>";
  88. if (fields.length >= 8 && !fields[7].equals("")) {
  89. badge = "<td class=\"bfp\"><span class=\"bfp\">Priority</span></td>";
  90. } else if (fields.length >= 9
  91. && fields[8].equalsIgnoreCase("true")) {
  92. badge = "<td class=\"fv\"><span class=\"fv\">Vote</span></td>";
  93. }
  94. System.out.println(ticketTemplate.replace("@ticket@", fields[0])
  95. .replace("@description@", summary)
  96. .replace("@badge@", badge));
  97. }
  98. urlStream.close();
  99. }
  100. private static String modifySummaryString(String summary) {
  101. if (summary.startsWith("\"") && summary.endsWith("\"")) {
  102. // If a summary starts with " and ends with " then all quotes in
  103. // the summary are encoded as double quotes
  104. summary = summary.substring(1, summary.length() - 1);
  105. summary = summary.replace("\"\"", "\"");
  106. }
  107. // this is needed for escaping html
  108. summary = escapeHtml(summary);
  109. return summary;
  110. }
  111. /**
  112. * @since 7.4
  113. * @param string
  114. * the string to be html-escaped
  115. * @return string in html-escape format
  116. */
  117. private static String escapeHtml(String string) {
  118. StringBuffer buf = new StringBuffer(string.length() * 2);
  119. // we check the string character by character and escape only special
  120. // characters
  121. for (int i = 0; i < string.length(); ++i) {
  122. char ch = string.charAt(i);
  123. String charString = ch + "";
  124. if ((charString).matches("[a-zA-Z0-9., ]")) {
  125. // character is letter, digit, dot, comma or whitespace
  126. buf.append(ch);
  127. } else {
  128. int charInt = ch;
  129. buf.append("&");
  130. buf.append("#");
  131. buf.append(charInt);
  132. buf.append(";");
  133. }
  134. }
  135. return buf.toString();
  136. }
  137. private static void usage() {
  138. System.err.println(
  139. "Usage: " + FetchReleaseNotesTickets.class.getSimpleName()
  140. + " -Dvaadin.version=<version>");
  141. System.exit(1);
  142. }
  143. }