1#!/bin/bash
2
3function help_and_exit() {
4    echo "Usage: $0 [-go] [-verbose] [-force]"
5    echo
6    echo "Moves minified CSS and JS to distribution directories and"
7    echo "creates a branch in SVN."
8    echo
9    echo "  -go:       Run commands instead of just echoing them."
10    echo "  -verbose:  More verbose logging."
11    echo "  -force:    Ignore sanity checks for testing."
12    echo "             Incompatible with -go."
13    echo "  -nobranch: Don't create a new release branch."
14    exit "$1"
15}
16
17# 1 for verbose logging
18export VERBOSE="0"
19# 1 if commands that have side-effects should actually be run instead of logged
20export EFFECT="0"
21
22for var in "$@"; do
23  case "$var" in
24      -verbose)
25          VERBOSE="1"
26          ;;
27      -go)
28          EFFECT="1"
29          ;;
30      -h)
31          help_and_exit 0
32          ;;
33      *)
34          echo "Unrecognized argument $var"
35          help_and_exit -1
36          ;;
37  esac
38done
39
40
41function panic() {
42    echo "PANIC: $*"
43
44    if ! (( $NO_PANIC )); then
45        exit -1
46    fi
47}
48
49function command() {
50    if (( $VERBOSE )) || ! (( $EFFECT )); then
51        echo '$' "$*"
52    fi
53    if (( $EFFECT )); then
54        "$@" || panic "command failed: $@"
55    fi
56}
57
58export VERSION_BASE="$(
59  pushd "$(dirname "$0")/../.." > /dev/null; pwd; popd > /dev/null)"
60
61if ! [ -d "$VERSION_BASE/trunk/tools" ]; then
62    panic "missing trunk/tools in $VERSION_BASE"
63fi
64
65VERSION="$(svn info | perl -ne 'print $1 if m/^Revision: (\d+)$/')"
66
67DOWNLOADS_ZIP="$VERSION_BASE/trunk/out/owasp-java-html-sanitizer.zip"
68VERSIONED_ZIP="$VERSION_BASE/trunk/out/owasp-java-html-sanitizer-r$VERSION.zip"
69
70pushd "$VERSION_BASE/trunk" > /dev/null
71command make download
72popd > /dev/null
73
74if ! [ -f "$DOWNLOADS_ZIP" ]; then
75    panic "$DOWNLOADS_ZIP is not up-to-date"
76fi
77
78command cp "$DOWNLOADS_ZIP" "$VERSIONED_ZIP"
79
80command "$VERSION_BASE/trunk/tools/googlecode_upload.py" \
81    --summary="JARs, source JAR, and documentation for version $VERSION." \
82    -p owasp-java-html-sanitizer -u mikesamuel \
83    --labels='Type-Archive,OpSys-All,Featured' \
84    "$VERSIONED_ZIP"
85
86if (( $EFFECT )); then
87    echo "Don't forget to mark any old ones deprecated at"
88    echo "https://code.google.com/p/owasp-java-html-sanitizer/downloads/list"
89else
90    echo
91    echo "Rerun with -go to actually run these commands."
92fi
93