<commit_before>#!/usr/bin/env bash

#
# Prepare Jenkins
#

jenkinsHome="./jenkins_home"
jenkinsWar="./jenkins.war"
jenkinsWarDownloadLink="http://mirrors.jenkins-ci.org/war/1.645/jenkins.war"

if [ ! -f ${jenkinsWar} ]; then
    echo "### File ${jenkinsWar} was not found. I will download it..."
    wget ${jenkinsWarDownloadLink} -O ${jenkinsWar}
fi

#
# Prepare plugins
#

pluginsDir="${jenkinsHome}/plugins"

mkdir -p ${pluginsDir}

greenBallsPluginHpi="${pluginsDir}/greenballs.hpi"
if [ ! -f ${greenBallsPluginHpi} ]; then
    echo "### File ${greenBallsPluginHpi} was not found. I will download it..."
    wget "http://updates.jenkins-ci.org/download/plugins/greenballs/1.15/greenballs.hpi" -O ${greenBallsPluginHpi}
fi

jobDslPluginHpi="${pluginsDir}/job-dsl.hpi"
if [ ! -f ${jobDslPluginHpi} ]; then
    echo "### File ${jobDslPluginHpi} was not found. I will download it..."
    wget "http://updates.jenkins-ci.org/download/plugins/job-dsl/1.42/job-dsl.hpi" -O ${jobDslPluginHpi}
fi

scmApiPluginHpi="${pluginsDir}/scm-api.hpi"
if [ ! -f ${scmApiPluginHpi} ]; then
    echo "### File ${scmApiPluginHpi} was not found. I will download it..."
    wget "http://updates.jenkins-ci.org/download/plugins/scm-api/1.0/scm-api.hpi" -O ${scmApiPluginHpi}
fi

gitClientPluginHpi="${pluginsDir}/git-client.hpi"
if [ ! -f ${gitClientPluginHpi} ]; then
    echo "### File ${gitClientPluginHpi} was not found. I will download it..."
    wget "http://updates.jenkins-ci.org/download/plugins/git-client/1.19.0/git-client.hpi" -O ${gitClientPluginHpi}
fi

gitPluginHpi="${pluginsDir}/git.hpi"
if [ ! -f ${gitPluginHpi} ]; then
    echo "### File ${gitPluginHpi} was not found. I will download it..."
    wget "http://updates.jenkins-ci.org/download/plugins/git/2.4.1/git.hpi" -O ${gitPluginHpi}
fi

slackPluginHpi="${pluginsDir}/slack.hpi"
if [ ! -f ${slackPluginHpi} ]; then
    echo "### File ${slackPluginHpi} was not found. I will download it..."
    wget "http://updates.jenkins-ci.org/download/plugins/slack/1.8.1/slack.hpi" -O ${slackPluginHpi}
fi

#
# Run Jenkins
#

echo "### Starting Jenkins on http://localhost:8080/ with home directory set to ${jenkinsHome} ..."
export JENKINS_HOME="${jenkinsHome}"
java -jar ${jenkinsWar}<commit_msg>runJenkins.sh rewritten<commit_after>#!/usr/bin/env bash

# abort this script if any command fail
set -e
# pipe sequence will result with exit code of last *failed* subcommand
set -o pipefail

# print every command
#set -x

script_name="$0"

function log {
	echo -e "[$script_name] $1"
}

function downloadIfMissing {
    sourceUrl="$1"
    targetFile="$2"
    if [ ! -f $targetFile ]; then
        log "Downloading $sourceUrl ..."
        wget "$sourceUrl" -O "$targetFile"
    fi
}

jenkinsWar="./jenkins.war"
jenkinsHome="./jenkins_home"
pluginsDir="${jenkinsHome}/plugins"
mkdir -p ${pluginsDir}

function downloadJenkins {
    jenkinsVersion="$1"
    jenkinsDownloadUrl="http://mirrors.jenkins-ci.org/war/${jenkinsVersion}/jenkins.war"
    downloadIfMissing ${jenkinsDownloadUrl} ${jenkinsWar}
}

function downloadPlugin {
    pluginName="$1"
    pluginVersion="$2"
    pluginDownloadUrl="http://updates.jenkins-ci.org/download/plugins/${pluginName}/${pluginVersion}/${pluginName}.hpi"
    pluginHpi="${pluginsDir}/${pluginName}.hpi"
    downloadIfMissing ${pluginDownloadUrl} ${pluginHpi}
}

downloadJenkins 1.645

downloadPlugin greenballs 1.15
downloadPlugin job-dsl 1.42
downloadPlugin scm-api 1.0
downloadPlugin git-client 1.19.0
downloadPlugin git 2.4.1
downloadPlugin slack 1.8.1

log "Starting Jenkins on http://localhost:8080/ with home directory set to $jenkinsHome ..."
export JENKINS_HOME="$jenkinsHome"
java -jar ${jenkinsWar}
{'fraction_non_alphanumeric': 0.1610537751222162, 'fraction_numerical': 0.016023900054318304, 'mean_word_length': 4.194640338504937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 33, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1621902', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1303, 'n_words': 281}