source: trunk/icedtea-web/html-gen.sh@ 443

Last change on this file since 443 was 429, checked in by dmik, 11 years ago

icedtea-web: Merge version 1.5.1 from vendor to trunk.

  • Property svn:executable set to *
File size: 6.6 KB
Line 
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
59print_debug() {
60 if [ "$HTML_GEN_DEBUG" ]; then echo "$1"; fi
61}
62
63CHANGESETS="$1"
64
65if [ -z "$CHANGESETS" ]; then CHANGESETS="$HTML_GEN_CHANGESETS"; fi
66
67if [ -z "$CHANGESETS" ] || [ "$CHANGESETS" -lt 0 ]; then CHANGESETS=10; fi
68
69NEWS_ITEMS=2
70REPO_URL="$(hg paths default | sed -r 's/.*icedtea.classpath.org\/(.*)/\1/')"
71
72start_time="$(date +%s.%N)"
73
74cd html-gen
75
76print_debug "Generating HTML content for javaws -about for $REPO_URL. $CHANGESETS changesets, $NEWS_ITEMS news items"
77print_debug "Starting sed substitutions"
78for FILE in NEWS AUTHORS COPYING ChangeLog
79do
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/</\&lt;/g' "./$FILE" # "<" -> "&lt;"
85 sed -i -r 's/>/\&gt;/g' "./$FILE" # ">" -> "&gt;"
86 sed -i -r 's_(\&lt;)?(https?://[^ ]*)(\&gt;| |$)_\1<a href="\2">\2</a>\3_i' "./$FILE" # Create hyperlinks from http(s) URLs
87 sed -i -r 's/\&lt;(.*@.*)\&gt;/\&lt;<a href="mailto:\1\?subject=IcedTea-Web">\1<\/a>\&gt;/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."
92done
93
94print_debug "Done sed subs. Starting in-place additions"
95
96# Centre the column of author names in the Authors file
97sed -i '4i <center>' AUTHORS.html
98# Insert jamIcon above author names
99sed -i '5i <br><img src="jamIcon.jpg" alt="Jam Icon" width="87" height="84"><br><br>' AUTHORS.html
100echo "</center>" >> AUTHORS.html
101
102REVS=(`hg log -l"$CHANGESETS" | grep 'changeset:' | cut -d: -f3 | tr '\n' ' '`)
103
104print_debug "Done. Starting formatting (bolding, mailto and hyperlink creation)"
105
106for FILE in NEWS.html ChangeLog.html
107do
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=".*\&lt;.*\@.*\&gt;"
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="\&ensp;\&ensp;"
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"
153done
154
155sed -i -r 's|(\*\ .*):|<u>\1</u>:|' ChangeLog.html # Underline changed files in ChangeLog, eg "* Makefile.am:"
156
157end_time="$(date +%s.%N)"
158
159print_debug "HTML generation complete"
160print_debug "Total elapsed time: $(echo "$end_time - $start_time" | bc )"
Note: See TracBrowser for help on using the repository browser.