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