PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/release-0.1-rc2/hive/external/docs/changes/changes2html.pl

#
Perl | 282 lines | 207 code | 30 blank | 45 comment | 39 complexity | 182ed80decf796aaabd021171a0c60f4 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. #!/usr/bin/perl
  2. #
  3. # Transforms Lucene Java's CHANGES.txt into Changes.html
  4. #
  5. # Input is on STDIN, output is to STDOUT
  6. #
  7. #
  8. # Licensed to the Apache Software Foundation (ASF) under one or more
  9. # contributor license agreements. See the NOTICE file distributed with
  10. # this work for additional information regarding copyright ownership.
  11. # The ASF licenses this file to You under the Apache License, Version 2.0
  12. # (the "License"); you may not use this file except in compliance with
  13. # the License. You may obtain a copy of the License at
  14. #
  15. # http://www.apache.org/licenses/LICENSE-2.0
  16. #
  17. # Unless required by applicable law or agreed to in writing, software
  18. # distributed under the License is distributed on an "AS IS" BASIS,
  19. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. # See the License for the specific language governing permissions and
  21. # limitations under the License.
  22. #
  23. use strict;
  24. use warnings;
  25. my $jira_url_prefix = 'http://issues.apache.org/jira/browse/';
  26. my $title = undef;
  27. my $release = undef;
  28. my $sections = undef;
  29. my $items = undef;
  30. my $first_relid = undef;
  31. my $second_relid = undef;
  32. my @releases = ();
  33. my @lines = <>; # Get all input at once
  34. #
  35. # Parse input and build hierarchical release structure in @releases
  36. #
  37. for (my $line_num = 0 ; $line_num <= $#lines ; ++$line_num) {
  38. $_ = $lines[$line_num];
  39. next unless (/\S/); # Skip blank lines
  40. unless ($title) {
  41. if (/\S/) {
  42. s/^\s+//; # Trim leading whitespace
  43. s/\s+$//; # Trim trailing whitespace
  44. }
  45. $title = $_;
  46. next;
  47. }
  48. if (/^(Release)|(Trunk)/) { # Release headings
  49. $release = $_;
  50. $sections = [];
  51. push @releases, [ $release, $sections ];
  52. ($first_relid = lc($release)) =~ s/\s+/_/g if ($#releases == 0);
  53. ($second_relid = lc($release)) =~ s/\s+/_/g if ($#releases == 1);
  54. $items = undef;
  55. next;
  56. }
  57. # Section heading: 2 leading spaces, words all capitalized
  58. if (/^ ([A-Z]+)\s*/) {
  59. my $heading = $_;
  60. $items = [];
  61. push @$sections, [ $heading, $items ];
  62. next;
  63. }
  64. # Handle earlier releases without sections - create a headless section
  65. unless ($items) {
  66. $items = [];
  67. push @$sections, [ undef, $items ];
  68. }
  69. my $type;
  70. if (@$items) { # A list item has been encountered in this section before
  71. $type = $items->[0]; # 0th position of items array is list type
  72. } else {
  73. $type = get_list_type($_);
  74. push @$items, $type;
  75. }
  76. if ($type eq 'numbered') { # The modern items list style
  77. # List item boundary is another numbered item or an unindented line
  78. my $line;
  79. my $item = $_;
  80. $item =~ s/^(\s{0,2}\d+\.\s*)//; # Trim the leading item number
  81. my $leading_ws_width = length($1);
  82. $item =~ s/\s+$//; # Trim trailing whitespace
  83. $item .= "\n";
  84. while ($line_num < $#lines
  85. and ($line = $lines[++$line_num]) !~ /^(?:\s{0,2}\d+\.\s*\S|\S)/) {
  86. $line =~ s/^\s{$leading_ws_width}//; # Trim leading whitespace
  87. $line =~ s/\s+$//; # Trim trailing whitespace
  88. $item .= "$line\n";
  89. }
  90. $item =~ s/\n+\Z/\n/; # Trim trailing blank lines
  91. push @$items, $item;
  92. --$line_num unless ($line_num == $#lines);
  93. } elsif ($type eq 'paragraph') { # List item boundary is a blank line
  94. my $line;
  95. my $item = $_;
  96. $item =~ s/^(\s+)//;
  97. my $leading_ws_width = defined($1) ? length($1) : 0;
  98. $item =~ s/\s+$//; # Trim trailing whitespace
  99. $item .= "\n";
  100. while ($line_num < $#lines and ($line = $lines[++$line_num]) =~ /\S/) {
  101. $line =~ s/^\s{$leading_ws_width}//; # Trim leading whitespace
  102. $line =~ s/\s+$//; # Trim trailing whitespace
  103. $item .= "$line\n";
  104. }
  105. push @$items, $item;
  106. --$line_num unless ($line_num == $#lines);
  107. } else { # $type is one of the bulleted types
  108. # List item boundary is another bullet or a blank line
  109. my $line;
  110. my $item = $_;
  111. $item =~ s/^(\s*$type\s*)//; # Trim the leading bullet
  112. my $leading_ws_width = length($1);
  113. $item =~ s/\s+$//; # Trim trailing whitespace
  114. $item .= "\n";
  115. while ($line_num < $#lines
  116. and ($line = $lines[++$line_num]) !~ /^\s*(?:$type|\Z)/) {
  117. $line =~ s/^\s{$leading_ws_width}//; # Trim leading whitespace
  118. $line =~ s/\s+$//; # Trim trailing whitespace
  119. $item .= "$line\n";
  120. }
  121. push @$items, $item;
  122. --$line_num unless ($line_num == $#lines);
  123. }
  124. }
  125. #
  126. # Print HTML-ified version to STDOUT
  127. #
  128. print<<"__HTML_HEADER__";
  129. <!--
  130. **********************************************************
  131. ** WARNING: This file is generated from CHANGES.txt by the
  132. ** Perl script 'changes2html.pl'.
  133. ** Do *not* edit this file!
  134. **********************************************************
  135. ****************************************************************************
  136. * Licensed to the Apache Software Foundation (ASF) under one or more
  137. * contributor license agreements. See the NOTICE file distributed with
  138. * this work for additional information regarding copyright ownership.
  139. * The ASF licenses this file to You under the Apache License, Version 2.0
  140. * (the "License"); you may not use this file except in compliance with
  141. * the License. You may obtain a copy of the License at
  142. *
  143. * http://www.apache.org/licenses/LICENSE-2.0
  144. *
  145. * Unless required by applicable law or agreed to in writing, software
  146. * distributed under the License is distributed on an "AS IS" BASIS,
  147. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  148. * See the License for the specific language governing permissions and
  149. * limitations under the License.
  150. ****************************************************************************
  151. -->
  152. <html>
  153. <head>
  154. <title>$title</title>
  155. <link rel="stylesheet" href="ChangesFancyStyle.css" title="Fancy">
  156. <link rel="alternate stylesheet" href="ChangesSimpleStyle.css" title="Simple">
  157. <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  158. <SCRIPT>
  159. function toggleList(e) {
  160. element = document.getElementById(e).style;
  161. element.display == 'none' ? element.display = 'block' : element.display='none';
  162. }
  163. function collapse() {
  164. for (var i = 0; i < document.getElementsByTagName("ul").length; i++) {
  165. var list = document.getElementsByTagName("ul")[i];
  166. if (list.id != '$first_relid' && list.id != '$second_relid') {
  167. list.style.display = "none";
  168. }
  169. }
  170. for (var i = 0; i < document.getElementsByTagName("ol").length; i++) {
  171. document.getElementsByTagName("ol")[i].style.display = "none";
  172. }
  173. }
  174. window.onload = collapse;
  175. </SCRIPT>
  176. </head>
  177. <body>
  178. <a href="http://hadoop.apache.org/hive/"><img class="logoImage" alt="Hive" src="images/hive-logo.jpg" title="SQL and Data Warehousing Platform on Hadoop"></a>
  179. <h1>$title</h1>
  180. __HTML_HEADER__
  181. my $heading;
  182. my $relcnt = 0;
  183. my $header = 'h2';
  184. for my $rel (@releases) {
  185. if (++$relcnt == 3) {
  186. $header = 'h3';
  187. print "<h2><a href=\"javascript:toggleList('older')\">";
  188. print "Older Releases";
  189. print "</a></h2>\n";
  190. print "<ul id=\"older\">\n"
  191. }
  192. ($release, $sections) = @$rel;
  193. # The first section heading is undefined for the older sectionless releases
  194. my $has_release_sections = $sections->[0][0];
  195. (my $relid = lc($release)) =~ s/\s+/_/g;
  196. print "<$header><a href=\"javascript:toggleList('$relid')\">";
  197. print "$release";
  198. print "</a></$header>\n";
  199. print "<ul id=\"$relid\">\n"
  200. if ($has_release_sections);
  201. for my $section (@$sections) {
  202. ($heading, $items) = @$section;
  203. (my $sectid = lc($heading)) =~ s/\s+/_/g;
  204. my $numItemsStr = $#{$items} > 0 ? "($#{$items})" : "(none)";
  205. print " <li><a href=\"javascript:toggleList('$relid.$sectid')\">",
  206. ($heading || ''), "</a>&nbsp;&nbsp;&nbsp;$numItemsStr\n"
  207. if ($has_release_sections);
  208. my $list_type = $items->[0] || '';
  209. my $list = ($has_release_sections || $list_type eq 'numbered' ? 'ol' : 'ul');
  210. my $listid = $sectid ? "$relid.$sectid" : $relid;
  211. print " <$list id=\"$listid\">\n";
  212. for my $itemnum (1..$#{$items}) {
  213. my $item = $items->[$itemnum];
  214. $item =~ s:&:&amp;:g; # Escape HTML metachars
  215. $item =~ s:<:&lt;:g;
  216. $item =~ s:>:&gt;:g;
  217. $item =~ s:\s*(\([^)"]+?\))\s*$:<br />$1:; # Separate attribution
  218. $item =~ s:\n{2,}:\n<p/>\n:g; # Keep paragraph breaks
  219. $item =~ s{(?:${jira_url_prefix})?(HADOOP-\d+)} # Link to JIRA
  220. {<a href="${jira_url_prefix}$1">$1</a>}g;
  221. print " <li>$item</li>\n";
  222. }
  223. print " </$list>\n";
  224. print " </li>\n" if ($has_release_sections);
  225. }
  226. print "</ul>\n" if ($has_release_sections);
  227. }
  228. print "</ul>\n" if ($relcnt > 3);
  229. print "</body>\n</html>\n";
  230. #
  231. # Subroutine: get_list_type
  232. #
  233. # Takes one parameter:
  234. #
  235. # - The first line of a sub-section/point
  236. #
  237. # Returns one scalar:
  238. #
  239. # - The list type: 'numbered'; or one of the bulleted types '-', or '.' or
  240. # 'paragraph'.
  241. #
  242. sub get_list_type {
  243. my $first_list_item_line = shift;
  244. my $type = 'paragraph'; # Default to paragraph type
  245. if ($first_list_item_line =~ /^\s{0,2}\d+\.\s+\S+/) {
  246. $type = 'numbered';
  247. } elsif ($first_list_item_line =~ /^\s*([-.])\s+\S+/) {
  248. $type = $1;
  249. }
  250. return $type;
  251. }
  252. 1;