1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # html-gen.sh
|
---|
4 | # Copyright (C) 2013 Red Hat
|
---|
5 | #
|
---|
6 | # This file is part of IcedTea.
|
---|
7 | #
|
---|
8 | # IcedTea is free software; you can redistribute it and/or modify
|
---|
9 | # it under the terms of the GNU General Public License as published by
|
---|
10 | # the Free Software Foundation; either version 2, or (at your option)
|
---|
11 | # any later version.
|
---|
12 | #
|
---|
13 | # IcedTea is distributed in the hope that it will be useful, but
|
---|
14 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | # General Public License for more details.
|
---|
17 | #
|
---|
18 | # You should have received a copy of the GNU General Public License
|
---|
19 | # along with IcedTea; see the file COPYING. If not, write to the
|
---|
20 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
21 | # 02110-1301 USA.
|
---|
22 | #
|
---|
23 | # Linking this library statically or dynamically with other modules is
|
---|
24 | # making a combined work based on this library. Thus, the terms and
|
---|
25 | # conditions of the GNU General Public License cover the whole
|
---|
26 | # combination.
|
---|
27 | #
|
---|
28 | # As a special exception, the copyright holders of this library give you
|
---|
29 | # permission to link this library with independent modules to produce an
|
---|
30 | # executable, regardless of the license terms of these independent
|
---|
31 | # modules, and to copy and distribute the resulting executable under
|
---|
32 | # terms of your choice, provided that you also meet, for each linked
|
---|
33 | # independent module, the terms and conditions of the license of that
|
---|
34 | # module. An independent module is a module which is not derived from
|
---|
35 | # or based on this library. If you modify this library, you may extend
|
---|
36 | # this exception to your version of the library, but you are not
|
---|
37 | # obligated to do so. If you do not wish to do so, delete this
|
---|
38 | # exception statement from your version.
|
---|
39 |
|
---|
40 | ################################################################################
|
---|
41 |
|
---|
42 | # This script is used by the stamps/html-gen target in Makefile.am. Its purpose
|
---|
43 | # is to produce HTML-escaped and formatted documents from a set of plaintext
|
---|
44 | # documents, namely AUTHORS, NEWS, ChangeLog, and COPYING, located in the
|
---|
45 | # same directory as this script. These generated HTML documents are then used
|
---|
46 | # in the netx About Dialog, which can be invoked with "javaws -about".
|
---|
47 |
|
---|
48 | # The only configuration option is the number of Changesets, and the files processed
|
---|
49 | # are hardcoded. To run the script manually, create a directory "html-gen" in the
|
---|
50 | # same directory as this script, containing files named AUTHORS, NEWS, ChangeLog,
|
---|
51 | # and COPYING. Note that these files WILL be modified in-place during the HTML
|
---|
52 | # "conversion" process. Setting the environment variable "HTML_GEN_DEBUG" to "true"
|
---|
53 | # will enable some output from the script, which may be useful if you encounter
|
---|
54 | # issues with this script's processing of an input file.
|
---|
55 | # The number of Changesets to process into the ChangeLog can be set by setting the
|
---|
56 | # environment variable HTML_GEN_CHANGESETS, or by passing an integer argument to
|
---|
57 | # the script. The parameter will take priority over the environment variable.
|
---|
58 |
|
---|
59 | print_debug() {
|
---|
60 | if [ "$HTML_GEN_DEBUG" ]; then echo "$1"; fi
|
---|
61 | }
|
---|
62 |
|
---|
63 | CHANGESETS="$1"
|
---|
64 |
|
---|
65 | if [ -z "$CHANGESETS" ]; then CHANGESETS="$HTML_GEN_CHANGESETS"; fi
|
---|
66 |
|
---|
67 | if [ -z "$CHANGESETS" ] || [ "$CHANGESETS" -lt 0 ]; then CHANGESETS=10; fi
|
---|
68 |
|
---|
69 | NEWS_ITEMS=2
|
---|
70 | REPO_URL="$(hg paths default | sed -r 's/.*icedtea.classpath.org\/(.*)/\1/')"
|
---|
71 |
|
---|
72 | start_time="$(date +%s.%N)"
|
---|
73 |
|
---|
74 | cd html-gen
|
---|
75 |
|
---|
76 | print_debug "Generating HTML content for javaws -about for $REPO_URL. $CHANGESETS changesets, $NEWS_ITEMS news items"
|
---|
77 | print_debug "Starting sed substitutions"
|
---|
78 | for FILE in NEWS AUTHORS COPYING ChangeLog
|
---|
79 | do
|
---|
80 | print_debug "Processing $FILE..."
|
---|
81 | sed -i -r 's/\t/ /g' "./$FILE" # Convert tabs into four spaces
|
---|
82 | sed -i -r 's/\&/\&/g' "./$FILE" # "&" -> "&"
|
---|
83 | sed -i -r 's/ /\ \ /g' "./$FILE" # Double-spaces into HTML whitespace for format preservation
|
---|
84 | sed -i -r 's/</\</g' "./$FILE" # "<" -> "<"
|
---|
85 | sed -i -r 's/>/\>/g' "./$FILE" # ">" -> ">"
|
---|
86 | sed -i -r 's_(\<)?(https?://[^ ]*)(\>| |$)_\1<a href="\2">\2</a>\3_i' "./$FILE" # Create hyperlinks from http(s) URLs
|
---|
87 | sed -i -r 's/\<(.*@.*)\>/\<<a href="mailto:\1\?subject=IcedTea-Web">\1<\/a>\>/i' "./$FILE" # Create mailto links from email addresses formatted as <email@example.com>
|
---|
88 | sed -i -r 's/$/<br>/' "./$FILE" # "\n" -> "<br>"
|
---|
89 |
|
---|
90 | mv "$FILE" "$FILE.html"
|
---|
91 | print_debug "$FILE.html finished."
|
---|
92 | done
|
---|
93 |
|
---|
94 | print_debug "Done sed subs. Starting in-place additions"
|
---|
95 |
|
---|
96 | # Centre the column of author names in the Authors file
|
---|
97 | sed -i '4i <center>' AUTHORS.html
|
---|
98 | # Insert jamIcon above author names
|
---|
99 | sed -i '5i <br><img src="jamIcon.jpg" alt="Jam Icon" width="87" height="84"><br><br>' AUTHORS.html
|
---|
100 | echo "</center>" >> AUTHORS.html
|
---|
101 |
|
---|
102 | REVS=(`hg log -l"$CHANGESETS" | grep 'changeset:' | cut -d: -f3 | tr '\n' ' '`)
|
---|
103 |
|
---|
104 | print_debug "Done. Starting formatting (bolding, mailto and hyperlink creation)"
|
---|
105 |
|
---|
106 | for FILE in NEWS.html ChangeLog.html
|
---|
107 | do
|
---|
108 | print_debug "Processing $FILE..."
|
---|
109 | mv "$FILE" "$FILE.old"
|
---|
110 | COUNTER=0
|
---|
111 | while read LINE
|
---|
112 | do
|
---|
113 | BOLD=1
|
---|
114 | if [ "$FILE" = "NEWS.html" ]
|
---|
115 | then
|
---|
116 | if [[ "$LINE" =~ New\ in\ release* ]]
|
---|
117 | then
|
---|
118 | BOLD=0
|
---|
119 | COUNTER="$(( COUNTER + 1 ))"
|
---|
120 | fi
|
---|
121 | if [ "$COUNTER" -gt "$NEWS_ITEMS" ] # Cut to two releases
|
---|
122 | then
|
---|
123 | break
|
---|
124 | fi
|
---|
125 | else
|
---|
126 | email_regex=".*\<.*\@.*\>"
|
---|
127 | if [[ "$LINE" =~ $email_regex ]] # Matches eg <aazores@redhat.com>, after HTML-escaping
|
---|
128 | then
|
---|
129 | BOLD=0
|
---|
130 | fi
|
---|
131 | date_regex=[0-9]{4}-[0-9]{2}-[0-9]{2}
|
---|
132 | if [[ "$LINE" =~ $date_regex* ]] # Matches line starting with eg 2013-07-01
|
---|
133 | then
|
---|
134 | html_space="\ \ "
|
---|
135 | REV="${REVS["$COUNTER"]}"
|
---|
136 | # Turn the date into a hyperlink for the revision this changelog entry describes
|
---|
137 | LINE=$(echo "$LINE" | sed -r "s|($date_regex)($html_space.*$html_space.*)|<a href=http://icedtea.classpath.org/$REPO_URL/rev/$REV>\1</a>\2|")
|
---|
138 | COUNTER="$(( COUNTER + 1 ))"
|
---|
139 | fi
|
---|
140 | if [ "$COUNTER" -gt "$CHANGESETS" ] # Cut to ten changesets
|
---|
141 | then
|
---|
142 | break
|
---|
143 | fi
|
---|
144 | fi
|
---|
145 | if [ "$BOLD" -eq 0 ] # Highlight "New In Release" in News, and author name lines in ChangeLog
|
---|
146 | then
|
---|
147 | LINE="<b>$LINE</b>"
|
---|
148 | fi
|
---|
149 | echo "$LINE" >> "$FILE"
|
---|
150 | done < "$FILE.old"
|
---|
151 | rm "$FILE.old"
|
---|
152 | print_debug "$FILE finished"
|
---|
153 | done
|
---|
154 |
|
---|
155 | sed -i -r 's|(\*\ .*):|<u>\1</u>:|' ChangeLog.html # Underline changed files in ChangeLog, eg "* Makefile.am:"
|
---|
156 |
|
---|
157 | end_time="$(date +%s.%N)"
|
---|
158 |
|
---|
159 | print_debug "HTML generation complete"
|
---|
160 | print_debug "Total elapsed time: $(echo "$end_time - $start_time" | bc )"
|
---|