forked from cytoscape/cytoscape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cy.sh
executable file
·300 lines (248 loc) · 6.61 KB
/
cy.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
#
# @(#) cy version 3.0.0 11/14/2016
#
# USAGE:
# init
#
# DESCRIPTION:
# Cytoscape 3 repository management utility.
# This script is only for core developers.
#
# Requirments:
# - git
#
# By Keiichiro Ono (kono at ucsd edu)
#
###############################################################################
# Command Name
CMDNAME=$(basename $0)
# Error Message
ERROR_MESSAGE="Usage: $CMDNAME [-h] [action]"
# Help
HELP='Cytoscape build helper script'
# Git base URL
BASE_URL='[email protected]:cytoscape/cytoscape-'
# Core Apps URL
APP_URL='[email protected]:cytoscape/'
# Cytoscape repository names
REPOSITORIES=(. parent api impl support gui-distribution app-developer)
# List of Core Apps
CORE_APPS=(biopax command-dialog core-apps-meta cyREST datasource-biogrid \
json idmapper network-analyzer network-merge opencl-cycl opencl-layout \
psi-mi sbml welcome webservice-psicquic-client webservice-biomart-client)
#######################################
# Handling command-line arguments #
#######################################
while getopts 'hd:' OPT
do
case $OPT in
h) FLG_H=1
echo "$HELP: $ERROR_MESSAGE"
exit 0
;;
?) echo $ERROR_MESSAGE 1>&2
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
COMMAND=$1
TARGET_DIR=$2
if [[ -z $COMMAND ]]; then
echo "COMMAND is required. $ERROR_MESSAGE" 1>&2
exit 1
fi
###############################################################################
# Functrions
###############################################################################
function reset {
echo "This command resets all of your local changes!"
confirm
for REPO in "${REPOSITORIES[@]}"; do
echo "\n - Resetting local changes: $REPO"
pushd $REPO
git clean -f -d
git reset --hard
popd ..
done
}
function pull {
for REPO in "${REPOSITORIES[@]}"; do
pushd $REPO
echo "Downloading changes from upstream: $REPO"
git pull
popd
done
}
function push {
echo "- Sending all local commits to upstream..."
for REPO in "${REPOSITORIES[@]}"; do
pushd $REPO
git push -u origin
popd
done
}
function status {
for REPO in "${REPOSITORIES[@]}"; do
pushd $REPO || { echo Could not find subproject; exit 1; }
echo "\n- $REPO:"
git status
popd
done
}
function switch {
TARGET="${TARGET_DIR}"
if [[ -z $TARGET ]]; then
echo "Branch name is required: cy switch BRANCH_NAME" 1>&2
exit 1
fi
for REPO in "${REPOSITORIES[@]}"; do
echo "\n - Switching to ${TARGET}: $REPO"
pushd $REPO || { echo Could not find subproject; exit 1; }
# Switch
git checkout $TARGET || { echo Could not checkout branch $TARGET; }
popd
done
}
# Not finished yet.
function resetAll {
git checkout master
git reset --hard $(git BRANCH -av | grep "remotes/origin/master" | awk '{ print $2 }')
git clean -d -f
git checkout develop
git reset --hard $(git BRANCH -av | grep "remotes/origin/develop" | awk '{ print $2 }')
git clean -d -f
git checkout $BRANCH
git reset --hard $(git BRANCH -av | grep "remotes/origin/$BRANCH" | awk '{ print $2 }')
git clean -d -f
git BRANCH -avv
}
function confirm {
printf 'Do you really want to continue? Type [yes] to proceed: '
read answer
if [[ $answer != 'yes' || -z $answer ]]; then
echo "Abort\n"
exit 0
fi
}
#################################################################################
#
# Project initializer.
#
# This function clones top-level pom.xml and then clones all sub-projects
# into the top-level Cytoscape directory.
#
# Use -d option to specify directory. Otherwise, it will create new project
# in the current directory.
#
#################################################################################
function init {
# By default, clone everything in current directory.
echo "Target directory = $TARGET_DIR"
if [[ -z "$TARGET_DIR" ]]; then
TARGET_DIR=$(pwd)
elif ! [ -e "$TARGET_DIR" ]; then
echo "No such dir: $TARGET_DIR"
exit 1
fi
echo "Cytoscape project will be cloned to: ${TARGET_DIR}"
cd $TARGET_DIR || { echo Could not find target directory: $TARGET_DIR; exit 1; }
# Clone cy
let LENGTH=${#BASE_URL}-1
CY3REPO_URL=$(echo $BASE_URL | cut -c 1-$LENGTH)
git clone "${CY3REPO_URL}.git" || { echo Could not clone remote repository: $TARGET_DIR; exit 1; }
cd cytoscape
for REPO in "${REPOSITORIES[@]}"; do
if [ ${REPO} != . ]
then
REPO_URL="$BASE_URL$REPO.git"
echo "Cloning: $REPO (URI = $REPO_URL)"
git clone $REPO_URL $REPO || { echo Could not clone remote repository: $TARGET_DIR; exit 1; }
pushd $REPO
# git checkout master
# git flow init -d
git checkout develop
popd
fi
done
echo "\n\n - Finished: here is the current status:\n"
status
}
# Utility command to clone all Core Apps as independent repositories.
function apps {
mkdir ./apps
cd apps
for app in "${CORE_APPS[@]}"; do
echo "\n - Cloning $app"
REPO_URL="$APP_URL$app.git"
git clone $REPO_URL || { echo Could not clone remote repository: $REPO_URL; exit 1; }
done
cd ..
}
function update-apps {
cd apps
for app in "${CORE_APPS[@]}"; do
cd $app
echo "- Pulling changes for $app"
git pull || { echo Could not pull changes: $REPO_URL; exit 1; }
cd ..
done
cd ..
}
function build-apps {
cd apps
echo "Core apps: $CORE_APPS"
for app in "${CORE_APPS[@]}"; do
cd $app
echo "- Building $app"
mvn clean install || { echo Could not pull changes: $REPO_URL; exit 1; }
cd ..
done
cd ..
}
function switch-apps {
TARGET="${TARGET_DIR}"
if [[ -z $TARGET ]]; then
echo "Branch name is required: cy switch-apps BRANCH_NAME" 1>&2
exit 1
fi
cd apps
for app in "${CORE_APPS[@]}"; do
cd $app
echo "- Switching to ${TARGET}: $app"
git checkout $TARGET || { echo Could not checkout branch $TARGET; }
cd ..
done
cd ..
}
function init-all {
cur_dir=`pwd`
init
cd ./cytoscape
mvn clean install || { echo Failed to build Cytoscape; }
cd ${cur_dir}
apps
cd ./apps
build-apps
cd -
}
###############################################################################
# Main workflow
###############################################################################
# Save current directory location
START_DIR=$(pwd)
case $COMMAND in
init ) init ;;
init-all ) init-all ;;
reset ) reset ;;
push ) push ;;
pull ) pull ;;
switch ) switch ;;
status ) status ;;
apps ) apps ;;
pull-apps ) update-apps ;;
build-apps ) build-apps ;;
switch-apps ) switch-apps ;;
* ) echo "Invalid command $COMMAND: $ERROR_MESSAGE"
exit 1;;
esac