<commit_before>#!/bin/bash -e

# Copyright 2015 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Heron self-extractable installer for api package
function usage() {
  echo "Usage: $progname [options]" >&2
  echo "Options are:" >&2
  echo "  --prefix=/some/path set the prefix path (default=/usr/local)." >&2
  echo "  --user configure for user install, expands to" >&2
  echo '           `--prefix=$HOME/.heronapi`.' >&2
  echo "  --maven install jars to maven local repo" >&2
  exit 1
}

function test_write() {
  local file="$1"
  while [ "$file" != "/" ] && [ -n "${file}" ] && [ ! -e "$file" ]; do
    file="$(dirname "${file}")"
  done
  [ -w "${file}" ] || {
    echo >&2
    echo "The Heron installer must have write access to $1!" >&2
    echo >&2
    usage
  }
}

# Test for unzip dependencies
function check_unzip() {
  if ! which unzip >/dev/null; then
    echo >&2
    echo "unzip not found, please install the corresponding package." >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

# Test for tar dependencies
function check_tar() {
  if ! which tar >/dev/null; then
    echo >&2
    echo "tar not found, please install the corresponding package." >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

# Test for maven dependencies
function check_maven() {
  if ! which mvn >/dev/null; then
     echo >&2
     echo "maven not found, please install the corresponding package." >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

# Test for java dependencies
function check_java() {
  if [ -z "${JAVA_HOME-}" ]; then
    case "$(uname -s | tr 'A-Z' 'a-z')" in
      linux)
        JAVA_HOME="$(readlink -f $(which javac) 2>/dev/null | sed 's_/bin/javac__')" || true
        BASHRC="~/.bashrc"
        ;;
      freebsd)
        JAVA_HOME="/usr/local/openjdk8"
        BASHRC="~/.bashrc"
        ;;
      darwin)
        JAVA_HOME="$(/usr/libexec/java_home -v ${JAVA_VERSION}+ 2> /dev/null)" || true
        BASHRC="~/.bash_profile"
        ;;
    esac
  fi
  if [ ! -x "${JAVA_HOME}/bin/javac" ]; then
    echo >&2
    echo "Java not found, please install the corresponding package" >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

function install_to_local() {
  # Test for write access
  test_write "${base}"

  # Do the actual installation
  echo -n "Uncompressing."

  # Cleaning-up, with some guards.
  if [ -d "${base}" -a -x "${base}/lib/heron-api.jar" ]; then
    rm -fr "${base}"
  fi

  mkdir -p ${base}
  echo -n .

  unzip -q -o "${BASH_SOURCE[0]}" -d "${base}"
  tar xfz "${base}/heron-api.tar.gz" -C "${base}"
  echo -n .
  chmod -R og-w "${base}"
  chmod -R og+rX "${base}"
  chmod -R u+rwX "${base}"
  echo -n .

  rm "${base}/heron-api.tar.gz"
}

function install_to_maven() {
  echo "Installing jars to local maven repo." >&2

  # Uncompress from zip
  tmp="./tmp"
  mkdir "$tmp"
  unzip -q -o "${BASH_SOURCE[0]}" -d "${tmp}"
  tar xfz "tmp/heron-api.tar.gz" -C "${tmp}"

  # Install into maven local
  mvn install:install-file -q -Dfile="${tmp}/heron-api.jar" -DgroupId="com.twitter.heron" \
    -DartifactId="heron-api" -Dversion="SNAPSHOT" -Dpackaging="jar"

  mvn install:install-file -q -Dfile="${tmp}/heron-storm.jar" -DgroupId="com.twitter.heron" \
    -DartifactId="heron-storm" -Dversion="SNAPSHOT" -Dpackaging="jar"

  # clean tmp files
  rm -rf tmp
}

# Installation and etc prefix can be overriden from command line
install_prefix=${1:-"/usr/local/heronapi"}

progname="$0"

echo "Heron API installer"
echo "---------------------"
echo
cat <<EOF
%release_info%
EOF

prefix="/usr/local"
base="%prefix%/heronapi"
use_maven=false

for opt in "${@}"; do
  case $opt in
    --prefix=*)<commit_msg>use mktemp to create temp dir<commit_after>#!/bin/bash -e

# Copyright 2015 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Heron self-extractable installer for api package
function usage() {
  echo "Usage: $progname [options]" >&2
  echo "Options are:" >&2
  echo "  --prefix=/some/path set the prefix path (default=/usr/local)." >&2
  echo "  --user configure for user install, expands to" >&2
  echo '           `--prefix=$HOME/.heronapi`.' >&2
  echo "  --maven install jars to maven local repo" >&2
  exit 1
}

function test_write() {
  local file="$1"
  while [ "$file" != "/" ] && [ -n "${file}" ] && [ ! -e "$file" ]; do
    file="$(dirname "${file}")"
  done
  [ -w "${file}" ] || {
    echo >&2
    echo "The Heron installer must have write access to $1!" >&2
    echo >&2
    usage
  }
}

# Test for unzip dependencies
function check_unzip() {
  if ! which unzip >/dev/null; then
    echo >&2
    echo "unzip not found, please install the corresponding package." >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

# Test for tar dependencies
function check_tar() {
  if ! which tar >/dev/null; then
    echo >&2
    echo "tar not found, please install the corresponding package." >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

# Test for maven dependencies
function check_maven() {
  if ! which mvn >/dev/null; then
     echo >&2
     echo "maven not found, please install the corresponding package." >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

# Test for java dependencies
function check_java() {
  if [ -z "${JAVA_HOME-}" ]; then
    case "$(uname -s | tr 'A-Z' 'a-z')" in
      linux)
        JAVA_HOME="$(readlink -f $(which javac) 2>/dev/null | sed 's_/bin/javac__')" || true
        BASHRC="~/.bashrc"
        ;;
      freebsd)
        JAVA_HOME="/usr/local/openjdk8"
        BASHRC="~/.bashrc"
        ;;
      darwin)
        JAVA_HOME="$(/usr/libexec/java_home -v ${JAVA_VERSION}+ 2> /dev/null)" || true
        BASHRC="~/.bash_profile"
        ;;
    esac
  fi
  if [ ! -x "${JAVA_HOME}/bin/javac" ]; then
    echo >&2
    echo "Java not found, please install the corresponding package" >&2
    echo "See http://heron.github.io/docs/install.html for more information on" >&2
    echo "dependencies of Heron." >&2
    exit 1
  fi
}

function install_to_local() {
  # Test for write access
  test_write "${base}"

  # Do the actual installation
  echo -n "Uncompressing."

  # Cleaning-up, with some guards.
  if [ -d "${base}" -a -x "${base}/lib/heron-api.jar" ]; then
    rm -fr "${base}"
  fi

  mkdir -p ${base}
  echo -n .

  unzip -q -o "${BASH_SOURCE[0]}" -d "${base}"
  tar xfz "${base}/heron-api.tar.gz" -C "${base}"
  echo -n .
  chmod -R og-w "${base}"
  chmod -R og+rX "${base}"
  chmod -R u+rwX "${base}"
  echo -n .

  rm "${base}/heron-api.tar.gz"
}

function install_to_maven() {
  echo "Installing jars to local maven repo." >&2

  # Uncompress from zip
  tmp_dir=`mktemp -d -t heron`
  unzip -q -o "${BASH_SOURCE[0]}" -d "${tmp_dir}"
  tar xfz "${tmp_dir}/heron-api.tar.gz" -C "${tmp_dir}"

  # Install into maven local
  mvn install:install-file -q -Dfile="${tmp_dir}/heron-api.jar" -DgroupId="com.twitter.heron" \
    -DartifactId="heron-api" -Dversion="SNAPSHOT" -Dpackaging="jar"

  mvn install:install-file -q -Dfile="${tmp_dir}/heron-storm.jar" -DgroupId="com.twitter.heron" \
    -DartifactId="heron-storm" -Dversion="SNAPSHOT" -Dpackaging="jar"

  # clean tmp files
  rm -rf "${tmp_dir}"
}

# Installation and etc prefix can be overriden from command line
install_prefix=${1:-"/usr/local/heronapi"}

progname="$0"

echo "Heron API installer"
echo "---------------------"
echo
cat <<EOF
%release_info%
EOF

prefix="/usr/local"
base="%prefix%/heronapi"
use_maven=false

for opt in "${@}"; do
  case $opt in
    --prefix=*)
{'fraction_non_alphanumeric': 0.15755521539470807, 'fraction_numerical': 0.010496391865296304, 'mean_word_length': 2.9341935483870967, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '654196', 'n_tokens_mistral': 3289, 'n_tokens_neox': 3142, 'n_words': 1019}