• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -u
2#
3#####################################################################
4### © 2020 and later: Unicode, Inc. and others.                   ###
5### License & terms of use: http://www.unicode.org/copyright.html ###
6#####################################################################
7#
8# This script will attempt to build and install the necessary CLDR JAR files
9# from a given CLDR installation root directory. The JAR files are installed
10# according to the manual instructions given in README.txt and lib/README.txt.
11#
12# The user must have installed both 'ant' and 'maven' in accordance with the
13# instructions in README.txt before attempting to run this script.
14#
15# Usage (from the directory of this script):
16#
17# ./install-cldr-jars.sh <CLDR-root-directory>
18#
19# Note to maintainers: This script cannot be assumed to run on a Unix/Linux
20# based system, and while a Posix compliant bash shell is required, any
21# assumptions about auxiliary Unix tools should be minimized (e.g. things
22# like "dirname" or "tempfile" may not exist). Where bash-only alternatives
23# have to be used, they should be clearly documented.
24
25# Exit with a message for fatal errors.
26function die() {
27  echo "$1"
28  echo "Exiting..."
29  exit 1
30} >&2
31
32# Runs a given command and captures output to the global log file.
33# If a command errors, the user can then view the log file.
34function run_with_logging() {
35  echo >> "${LOG_FILE}"
36  echo "Running: ${@}" >> "${LOG_FILE}"
37  echo -- "----------------------------------------------------------------" >> "${LOG_FILE}"
38  "${@}" >> "${LOG_FILE}" 2>&1
39  if (( $? != 0 )) ; then
40    echo -- "---- Previous command failed ----" >> "${LOG_FILE}"
41    echo "Error running: ${@}"
42    read -p "Show log file? " -n 1 -r
43    echo
44    if [[ "${REPLY}" =~ ^[Yy]$ ]] ; then
45      less -X "${LOG_FILE}"
46    fi
47    echo "Log file: ${LOG_FILE}"
48    exit 1
49  fi
50  echo -- "---- Previous command succeeded ----" >> "${LOG_FILE}"
51}
52
53# First require that we are run from the same directory as the script.
54# Can't assume users have "dirname" available so hack it a bit with shell
55# substitution (if no directory path was prepended, SCRIPT_DIR==$0).
56SCRIPT_DIR=${0%/*}
57if [[ "$SCRIPT_DIR" != "$0" ]] ; then
58  cd $SCRIPT_DIR
59fi
60
61# Check for some expected environmental things early.
62which ant > /dev/null || die "Cannot find Ant executable 'ant' in the current path."
63which mvn > /dev/null || die "Cannot find Maven executable 'mvn' in the current path."
64
65# Check there's one argument that points at a directory (or a symbolic link to a directory).
66(( $# == 1 )) && [[ -d "$1" ]] || die "Usage: ./install-cldr-jars.sh <CLDR-root-directory>"
67
68# Set up a log file (and be nice about tidying it up).
69# Cannot assume "tempfile" exists so use a timestamp (we expect "date" to exist though).
70LOG_FILE="${TMPDIR:-/tmp}/cldr2icu_log_$(date '+%m%d_%H%M%S').txt"
71touch $LOG_FILE || die "Cannot create temporary file: ${LOG_FILE}"
72echo -- "---- LOG FILE ---- $(date '+%F %T') ----" >> "${LOG_FILE}"
73
74# Build the cldr-code.jar in the cldr-code/target subdirectory of the CLDR tools directory.
75CLDR_TOOLS_DIR="$1/tools"
76pushd "${CLDR_TOOLS_DIR}" > /dev/null || die "Cannot change directory to: ${CLDR_TOOLS_DIR}"
77
78echo "Building CLDR JAR file..."
79run_with_logging mvn package -DskipTests=true
80[[ -f "cldr-code/target/cldr-code.jar" ]] || die "Error creating cldr-code.jar file"
81
82popd > /dev/null
83
84# The -B flag is "batch" mode and won't mess about with escape codes in the log file.
85echo "Installing CLDR JAR file..."
86run_with_logging mvn -B install:install-file \
87  -Dproject.parent.relativePath="" \
88  -DgroupId=org.unicode.cldr \
89  -DartifactId=cldr-api \
90  -Dversion=0.1-SNAPSHOT \
91  -Dpackaging=jar \
92  -DgeneratePom=true \
93  -DlocalRepositoryPath=. \
94  -Dfile="${CLDR_TOOLS_DIR}/cldr-code/target/cldr-code.jar"
95
96echo "Syncing local Maven repository..."
97run_with_logging mvn -B dependency:purge-local-repository \
98  -Dproject.parent.relativePath="" \
99  -DmanualIncludes=org.unicode.cldr:cldr-api:jar
100
101echo "All done!"
102echo "Log file: ${LOG_FILE}"
103