This repository has been archived by the owner on Mar 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.sh
executable file
·131 lines (98 loc) · 3.24 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
OUTPUT_DIR="."
PROJECT_FQDN_NAME=
PROJECT_NAME=
PACKAGE_NAME=
GRADLE_WRAPPER_BASE="https://raw.githubusercontent.com/pellepelster/mango/master"
BOOTSTRAP_GROUP_NAME="io.pelle.mango"
BOOTSTRAP_NAME="mango-bootstrap"
PROJECT_NAME_REGEX='(([a-z][a-z0-9]*\.)*)([A-Z]([A-Z]|[a-z]|[a-z0-9])*)'
OUTPUT_DIR=$(pwd)
TEMP=`getopt -o p: --long project-name: -n 'bootstrap.sh' -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-p|--project-name)
case "$2" in
"") shift 2 ;;
*) PROJECT_FQDN_NAME=$2 ; shift 2 ;;
esac ;;
--) shift ; break ;;
*) echo "internal error!" ; exit 1 ;;
esac
done
if [[ $PROJECT_FQDN_NAME =~ $PROJECT_NAME_REGEX ]]; then
PROJECT_NAME=${BASH_REMATCH[3]}
PACKAGE_NAME=${BASH_REMATCH[1]}
else
if [[ $1 =~ $PROJECT_NAME_REGEX ]]; then
PROJECT_NAME=${BASH_REMATCH[3]}
PACKAGE_NAME=${BASH_REMATCH[1]}
else
echo "please provide a project name in the format 'org.example.Project1'"
exit 1;
fi
fi
PACKAGE_NAME=${PACKAGE_NAME%?}
TEMP_DIR=$(mktemp -d);
echo "downloading gradle wrapper to '${TEMP_DIR}'"
GRADLE_WRAPPER_FILES=(gradlew gradle/wrapper/gradle-wrapper.jar gradle/wrapper/gradle-wrapper.properties)
for FILE in "${GRADLE_WRAPPER_FILES[@]}"
do
DIRECTORY="${TEMP_DIR}/$(dirname $FILE)"
if [ -d "${DIRECTORY}" ]; then
mkdir -p "${DIRECTORY}"
fi
wget "${GRADLE_WRAPPER_BASE}/${FILE}" -qP ${DIRECTORY}
done
GRADLE_WRAPPER="${TEMP_DIR}/gradlew"
chmod +x $GRADLE_WRAPPER
TEMP_GRADLE_FILE=$(mktemp -p ${TEMP_DIR} --suffix .gradle);
echo "writing temporary gradle bootstrap file to '${TEMP_GRADLE_FILE}'"
cat > ${TEMP_GRADLE_FILE} <<EOF
repositories {
ivy {
name "releaseBuildRepository"
url System.getenv("WORKSPACE") + "/mango-build/build/repository"
layout "maven"
}
ivy {
name "localDevelopmentRepository"
url System.properties['user.home'] + "/.gradle/mango_development"
layout "maven"
}
ivy {
name "mangoCiRepository"
url "http://zoidberg.pelle.io/~mango-ci/repository/"
layout "maven"
}
mavenCentral()
}
configurations {
bootstrap
}
dependencies {
bootstrap group: '${BOOTSTRAP_GROUP_NAME}', name: '${BOOTSTRAP_NAME}', version: '+', transitive: false
}
task extractBootstrapGradle(type: Copy) {
configurations.bootstrap.asFileTree.each {
println "extracting \${it} to \${bootstrapTempDir}"
from(zipTree(it))
}
into bootstrapTempDir
println "###${bootstrapTempDir}/bootstrap.gradle###"
}
EOF
echo "executing temporary gradle bootstrap file '${TEMP_GRADLE_FILE}'"
GRADLE_OUTPUT=$($GRADLE_WRAPPER --build-file ${TEMP_GRADLE_FILE} extractBootstrapGradle -PbootstrapTempDir=$TEMP_DIR)
if [[ $GRADLE_OUTPUT =~ (###(.*)###) ]]; then
echo $GRADLE_OUTPUT
GRADLE_BOOTSTRAP_FILE=${BASH_REMATCH[2]}
echo "temporary bootstrap returned bootstrap gradle file at '${TEMP_DIR}/${GRADLE_BOOTSTRAP_FILE}'"
else
echo "could not parse gradle output, was:"
echo $GRADLE_OUTPUT
exit 1;
fi
echo "starting bootstrap with: package name '$PACKAGE_NAME', project name '$PROJECT_NAME', output dir '$OUTPUT_DIR'"
$GRADLE_WRAPPER --refresh-dependencies --rerun-tasks --build-file ${TEMP_DIR}/${GRADLE_BOOTSTRAP_FILE} bootstrapProjectTemplate -PpackageName=$PACKAGE_NAME -PprojectName=$PROJECT_NAME -PoutputDir=$OUTPUT_DIR