Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
131 lines (112 sloc) 4.29 KB
#!/bin/bash
# This variant of the lein script is meant for downstream packagers.
# It has all the cross-platform stuff stripped out as well as the
# logic for running from checkouts and self-upgrading.
LEIN_VERSION="1.6.2"
export LEIN_VERSION
if [ `whoami` = "root" ] && [ "$LEIN_ROOT" = "" ]; then
echo "WARNING: You're currently running as root; probably by accident."
echo "Press control-C to abort or Enter to continue as root."
echo "Set LEIN_ROOT to disable this warning."
read _
fi
# cd to the project root, if applicable
NOT_FOUND=1
ORIGINAL_PWD="$PWD"
while [ ! -r "$PWD/project.clj" ] && [ "$PWD" != "/" ] && [ $NOT_FOUND -ne 0 ]; do
cd ..
if [ "$(dirname "$PWD")" = "/" ]; then
NOT_FOUND=0
cd "$ORIGINAL_PWD"
fi
done
# Support $JAVA_OPTS for backwards-compatibility.
JVM_OPTS=${JVM_OPTS:-"$JAVA_OPTS"}
JAVA_CMD=${JAVA_CMD:-"java"}
if [ "$LEIN_HOME" = "" ]; then
if [ -d "$PWD/.lein" ] && [ "$PWD" != "$HOME" ]; then
echo "Leiningen is running in bundled mode."
LEIN_HOME="$PWD/.lein"
else
LEIN_HOME="$HOME/.lein"
fi
fi
DEV_PLUGINS="$(ls -1 lib/dev/*jar 2> /dev/null)"
USER_PLUGINS="$(ls -1 "$LEIN_HOME"/plugins/*jar 2> /dev/null)"
artifact_name () {
echo "$1" | sed -e "s/.*\/\(.*\)/\1/" | \
rev | sed -e "s/raj[-[:digit:].]*-\(.*\)/\1/" | rev
}
unique_user_plugins () {
saveIFS="$IFS"
IFS="$(printf '\n\t')"
plugins="$(echo "$DEV_PLUGINS"; echo "$USER_PLUGINS")"
artifacts="$(for i in $plugins; do echo "$(artifact_name "$i")"; done)"
duplicates="$(echo "$artifacts" | sort | uniq -d)"
if [ -z "$duplicates" ]; then
echo "$USER_PLUGINS"
else
for i in $USER_PLUGINS; do
artifact="$(artifact_name "$i")"
if ! echo "$duplicates" | grep -xq "$artifact"; then
echo "$i"
fi
done
fi
IFS="$saveIFS"
}
LEIN_PLUGIN_PATH="$(echo "$DEV_PLUGINS" | tr \\n :)"
LEIN_USER_PLUGIN_PATH="$(echo "$(unique_user_plugins)" | tr \\n :)"
CLASSPATH="$CLASSPATH:$LEIN_PLUGIN_PATH:$LEIN_USER_PLUGIN_PATH:test/:src/:resources/"
CLOJURE_JAR="/usr/share/java/clojure-1.2.jar:/usr/share/java/asm3.jar:/usr/share/java/asm3-commons.jar"
NULL_DEVICE=/dev/null
# apply context specific CLASSPATH entries
if [ -f .lein-classpath ]; then
CLASSPATH="`cat .lein-classpath`:$CLASSPATH"
fi
SHARE_JARS="ant ant-launcher classworlds clojure-1.2 clojure-contrib \
lucene-memory maven-ant-tasks maven-artifact maven-artifact-manager \
maven-error-diagnostics maven-model maven-settings maven-project maven-profile \
maven-repository-metadata plexus-container-default-alpha plexus-interpolation \
plexus-utils wagon-file wagon-http-lightweight wagon-http-shared wagon-provider-api \
xml-apis lucene-core lucene-highlighter clucy robert-hooke lancet \
backport-util-concurrent" # NFI why that last one is necessary
for JAR in $SHARE_JARS; do
CLASSPATH="$CLASSPATH":"/usr/share/java/$JAR.jar"
done
# Do not use installed leiningen jar during self-compilation
if ! { [ "$1" = "compile" ] &&
grep -qsE 'defproject leiningen[[:space:]]+"[[:digit:].]+"' \
project.clj ;}; then
CLASSPATH="$CLASSPATH":/usr/share/java/leiningen-$LEIN_VERSION.jar
fi
if [ $DEBUG ]; then
echo $CLASSPATH
echo $CLOJURE_JAR
fi
# Use rlwrap if appropriate
if ([ "$1" = "repl" ] || [ "$1" = "interactive" ] || [ "$1" = "int" ]) &&
[ -z $INSIDE_EMACS ] && [ "$TERM" != "dumb" ]; then
which rlwrap > /dev/null
if [ $? -eq 0 ]; then
RLWRAP="rlwrap -r -m -q '\"'" # custom quote chars
fi
fi
if [ "$1" = "trampoline" ]; then
TRAMPOLINE_FILE="/tmp/lein-trampoline-$$"
$JAVA_CMD -Xbootclasspath/a:"$CLOJURE_JAR" -client $LEIN_JVM_OPTS \
-Dleiningen.original.pwd="$ORIGINAL_PWD" \
-Dleiningen.trampoline-file=$TRAMPOLINE_FILE -cp "$CLASSPATH" \
clojure.main -e "(use 'leiningen.core)(-main)" \
$NULL_DEVICE "$@"
if [ -r $TRAMPOLINE_FILE ]; then
TRAMPOLINE="$(cat $TRAMPOLINE_FILE)"
rm $TRAMPOLINE_FILE
exec sh -c "$TRAMPOLINE"
fi
else
exec $RLWRAP $JAVA_CMD -Xbootclasspath/a:"$CLOJURE_JAR" -client \
$LEIN_JVM_OPTS -Dleiningen.original.pwd="$ORIGINAL_PWD" \
-cp "$CLASSPATH" clojure.main -e "(use 'leiningen.core)(-main)" \
$NULL_DEVICE "$@"
fi
Jump to Line
Something went wrong with that request. Please try again.