Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8684051c245924703d571b47c988d75142121bdc (plain) (blame)
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
#!/bin/sh
# ====================================================================
# Copyright (c) 2014 Obeo
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#    Obeo - initial API and implementation
# ====================================================================

# The path to the p2-admin executable
export P2_ADMIN_PATH="/jobs/genie.modeling.emfcompare/p2-admin/lastStable/archive/org.eclipselabs.equinox.p2.admin.product/target/products/org.eclipse.equinox.p2.admin.rcp.product/linux/gtk/x86_64/p2-admin"

# The root folder for all EMF Compare udpate sites
export EMF_COMPARE_UPDATES_ROOT="/home/data/httpd/download.eclipse.org/modeling/emf/compare/updates"

# The base URL for all EMF Compare update sites
export EMF_COMPARE_UPDATES_BASE_URL="http://download.eclipse.org/modeling/emf/compare/updates"

NIGHTLY="nightly"
NIGHTLY_PREFIX="N"
INTEGRATION="integration"
INTEGRATION_PREFIX="I"
RELEASE="release"
RELEASE_PREFIX="R"
PREFIXES="$NIGHTLY_PREFIX$INTEGRATION_PREFIX$RELEASE_PREFIX"
VERSION_PATTERN="([0-9]+)\.([0-9]+)\.([0-9]+)-?([$PREFIXES])?([0-9]{8}-[0-9]{6})?"

# To avoid error find: paths must precede expression
# It takes apart the argument list to find and concatenates the arguments back into another 
# argument list but inserts -regextype posix-awk in front of any -iregex or -regex arguments it finds.
# see http://superuser.com/a/666634
findGnuRegex () {
    args=
    for arg in $*
    do
        case $arg in
            -ireges|-regex)
                args="$args -regextype posix-extended $arg"
                ;;
            *)
                args="$args $arg"
                ;;
        esac
    done
    set -f
    command find $args
    set +f
}

# define alias depending on the underlying OS 
# e.g., regex on BSD-like and GNU-like OS are not handled through the same options for
# find and sed.
if [[ "$OSTYPE" == "linux"* ]]; then
	alias sed-regex="sed -r"
	alias find-regex="findGnuRegex"
elif [[ "$OSTYPE" == "cygwin" ]]; then
    alias sed-regex="sed -r"
    alias find-regex="findGnuRegex"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
	alias sed-regex="sed -E"
	alias find-regex="find -E"
elif [[ "$OSTYPE" == "darwin"* ]]; then
	alias sed-regex="sed -E"
	alias find-regex="find -E"
else
	echo "Unknown 'OSTYPE'=$OSTYPE."
	exit -1
fi

chmod u+x $P2_ADMIN_PATH
alias p2-admin="${JAVA_HOME}/bin/java -jar $P2_ADMIN_PATH/plugins/org.eclipse.equinox.launcher_*.jar"
alias composite-repository="p2-admin -application org.eclipselabs.equinox.p2.composite.repository -compressed"

# Create a p2 index file for composite repositories
createP2Index() {
	    cat > "$1/p2.index" <<EOF
version = 1
metadata.repository.factory.order = compositeContent.xml,\!
artifact.repository.factory.order = compositeArtifacts.xml,\!
EOF
}

# Remove any previous file from the $1 path and create a composite repository with a single
# child ($2). The composite will be name $3.
createRedirect() {
	local from="$1"
	local to="$2"
	local name="$3"
	
	mkdir -p "$from"
	rm -f "$from/compositeArtifacts."*
	rm -f "$from/compositeContent."*
	composite-repository -location "$from" -add "$to" -repositoryName "$name"
	createP2Index $from
}

strcmp() {
  local diff
  for ((i=0; i<=${#1}; ++i)); do
    if ((diff=$(printf %d \""${1:i:1}") - $(printf %d \""${2:i:1}") ));
      then echo $diff; return
    fi
  done
  echo 0
}

# Echo a negative integer, zero, or a positive integer if $1 version is less than, equal to,
# or greater than the specified $2 version.
compareOSGIVersions() {
    local this="$1"
	local that="$2"

	thisMajor=$(echo "$this" | sed-regex -e 's/'"$VERSION_PATTERN"'/\1/')
	thisMinor=$(echo "$this" | sed-regex -e 's/'"$VERSION_PATTERN"'/\2/')
	thisMicro=$(echo "$this" | sed-regex -e 's/'"$VERSION_PATTERN"'/\3/')
	thisQualifier=$(echo "$this" | sed-regex -e 's/'"$VERSION_PATTERN"'/\4\5/')
	
	thatMajor=$(echo "$that" | sed-regex -e 's/'"$VERSION_PATTERN"'/\1/')
	thatMinor=$(echo "$that" | sed-regex -e 's/'"$VERSION_PATTERN"'/\2/')
	thatMicro=$(echo "$that" | sed-regex -e 's/'"$VERSION_PATTERN"'/\3/')
	thatQualifier=$(echo "$that" | sed-regex -e 's/'"$VERSION_PATTERN"'/\4\5/')
	
	echo "'"$thisMajor"' => '"$thatMajor"'" 1>&2
	echo "'"$that"'" 1>&2
	if [ "$thisMajor" -ne "$thatMajor" ]; then
		echo $(($thisMajor-$thatMajor))  1>&2
	elif [ "$thisMinor" -ne "$thatMinor" ]; then
		echo $(($thisMinor-$thatMinor))	 1>&2
	elif [ "$thisMicro" -ne "$thatMicro" ]; then
		echo $(($thisMicro-$thatMicro))  1>&2
	elif [[ "$thisQualifier" != "$thatQualifier" ]]; then
		echo strcmp $thisQualifier $thatQualifier 1>&2
	else
		echo 0  1>&2
	fi
	echo 0
}

# print all major versions (sorted) in the $1 path on the standard output
# the output will be a list of integer
allMajors() {
	local path="$1"
	find-regex "$path" -regex '^'"$path"'/?'"$VERSION_PATTERN"'$' -type d \
		| sed-regex -e 's#^'"$path"'/?([0-9]+)\.([0-9]+)\.([0-9]+)-(['"$PREFIXES"'])([0-9]{8})-([0-9]{6})$#\1#' \
		| sort -un
}

# print all minor versions (sorted) for the given $2 major version in the $1 path on the standard output
# $2 must be an integer
# the output will be a list of the form X.Y
allMinors() {
	local path="$1"
	local major="$2"
	find-regex "$path" -regex '^'"$path"'/?'"$major"'\.[0-9]+\.[0-9]+-['"$PREFIXES"'][0-9]{8}-[0-9]{6}$' -type d \
		| sed-regex -e 's#^'"$path"'/?([0-9]+)\.([0-9]+)\.([0-9]+)-(['"$PREFIXES"'])([0-9]{8})-([0-9]{6})$#\2#' \
		| sort -un
}

# print all micro versions (sorted) for the given $2 minor version in the $1 path on the standard output
# $2 must be of the form x.y where x and y are integer
# the output will be a list of the form X.Y.Z
allMicros() {
	local path="$1"
	local major="$2"
	local minor="$3"
	find-regex "$path" -regex '^'"$path"'/?'"$major"'\.'"$minor"'\.[0-9]+-['"$PREFIXES"'][0-9]{8}-[0-9]{6}$' -type d \
		| sed-regex -e 's#^'"$path"'/?([0-9]+)\.([0-9]+)\.([0-9]+)-(['"$PREFIXES"'])([0-9]{8})-([0-9]{6})$#\3#' \
		| sort -un
}

# print all builds (sorted) for the given $2 micro version in the $1 path on the standard output
# $2 must be of the form x.y.z where x, y and z are integer
# the output will be a list of the form X.Y.Z-NYYYYMMDD-HHMMSS
allBuilds() {
	local path="$1"
	local major="$2"
	local minor="$3"
	local micro="$4"
	find-regex "$path" -regex '^'"$path"'/?'"$major"'\.'"$minor"'\.'"$micro"'-['"$PREFIXES"'][0-9]{8}-[0-9]{6}$' -type d \
		| sed-regex -e 's#'"$path"'/?##' \
		| sort -u
}

# visit all the builds in $1 path and call the $2 callback for each.
# $3 should the version of interest for this call. It is not used by this function but
# is given to the $2 callback.
#
# The callback must accept 10 parameters:
#  1/ the path (equals to $1)
#  2/ the version of interrest (equals to $3)
#  3/ the currently visited major version (an integer)
#  4/ the currently visited minor version (an integer)
#  5/ the currently visited micro version (an integer)
#  6/ the currently visited build (format x.y.z-TYYYYMMDD-HHMM, where x, y and z 
#     are integer, T is N for nightly, I for integration or R for release and YYYYMMDD-HHMM is a timestamp)
#  7/ the most recent major version in the given $1 path (an integer)
#  8/ the most recent minor version in the currently visited major version (an integer)
#  9/ the most recent micro version in the currently visited minor version (an integer)
#  10/ the most recent build version in the currently visited micro version (format x.y.z-TYYYYMMDD-HHMM, where x, y and z 
#     are integer, T is N for nightly, I for integration or R for release and YYYYMMDD-HHMM is a timestamp)
visitVersions() {
	local path="$1"
	local callback="$2"
	local version="$3"

	allMajors=$(allMajors "$path")
	latestMajor=$(echo "$allMajors" | tail -1)
	for major in $allMajors
	do
		allMinors=$(allMinors "$path" "$major")
		latestMinor=$(echo "$allMinors" | tail -1)
		for minor in $allMinors
		do
			allMicros=$(allMicros "$path" "$major" "$minor")
			latestMicro=$(echo "$allMicros" | tail -1)
			for micro in $allMicros
			do
				allBuilds=$(allBuilds "$path" "$major" "$minor" "$micro")
				latestBuild=$(echo "$allBuilds" | tail -1)

				for build in $allBuilds
				do
					$callback "$path" "$version" "$major" "$minor" "$micro" "$build" "$latestMajor" "$latestMinor" "$latestMicro" "$latestBuild" 
				done
			done
		done
	done
}

# Get the name of the minor stream from the $1 full version X.Y.Z.
# Example: majorStream 2.3.2 => 2.3.x
minorStream() {
	local version="$1"
	echo "$version" | sed-regex -e 's/^([0-9]+\.[0-9]+\.).*$/\1x/'
}

# Get the name of the major stream from the $1 full version X.Y.Z.
# Example: majorStream 2.3.2 => 2.x
majorStream() {
	local version="$1"
	echo "$version" | sed-regex -e 's/^([0-9]+\.).*$/\1x/'
}

# Converts the Hudson build id $1 (e.g. 2013-10-15_07-07-07) into the
# syntax we want for our update-sites (e.g. 20131015-070707)
buildTimestamp() {
	local buildId="$1"
	echo "$buildId" | sed -e 's/-//g' -e 's/_/-/'
}

Back to the top