File: tycho-scripts.sh

package info (click to toggle)
tycho 0.25.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 104,880 kB
  • ctags: 165,013
  • sloc: java: 994,151; ansic: 92,109; xml: 35,919; cpp: 15,327; sh: 1,100; makefile: 207
file content (222 lines) | stat: -rwxr-xr-x 6,250 bytes parent folder | download
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
##! /bin/bash
# this file was developed by Fedora packagers
# modified by Luca Vercelli 2016 for Debian
# contains utility functions that build (small) maven projects without using maven

# expected variables:
# $REPO is a writeable, temporary, maven repository

function minibuild () {
#usage: minibuild srcfolder dependencies ext_dependencies
#we expect to find there: build.properties META-INF/MANIFEST.MF pom.xml

echo "minibuild: $1======================="

basedir=$1

src=`cat "${basedir}/build.properties" | grep 'source..' | cut -d'=' -f2 | tr ' ' '\0'`
output=`cat "${basedir}/build.properties" | grep 'output..' | cut -d'=' -f2 | tr ' ' '\0'`
bName=`cat "${basedir}/META-INF/MANIFEST.MF" | grep 'Bundle-SymbolicName:' | sed 's/Bundle-SymbolicName: \([a-zA-Z0-9_.-]*\)\(;\)\?.*/\1/'`
artifactId=`cat "${basedir}/pom.xml" | sed '/<parent>/,/<\/parent>/ d' | grep "<artifactId>" | sed 's/.*<artifactId>\(.*\)<\/artifactId>.*/\1/'`
#debian: added head -n1
version=`cat "${basedir}/pom.xml" | grep "<version>" | sed 's/.*<version>\(.*\)<\/version>.*/\1/' | head -n1`

echo "loading libraries..."

# External (System) dependencies
if [ $# -eq 3 ]; then
  mkdir -p "${basedir}/target/externalDeps"
  copyBundles $3 "${basedir}/target/externalDeps"
else
  mkdir -p "${basedir}/target"
fi

mkdir -p "${basedir}/${output}"

# Compile
cp=
if [ $# -gt 1 ]; then
  cp='-classpath '$2':'"${basedir}"'/target/externalDeps/*'
fi

echo "compiling..."

javac -Xmaxerrs 10 -d "${basedir}/${output}" \
  $(for file in `find "${basedir}/${src}" -name "*.java"`; \
    do echo -n "${file} "; \
  done;) \
  ${cp}

echo "jar..."

# Package
pushd ${basedir}
pushd ${output}
classfiles=`for file in $(find . -name "*.class"); do echo -n ' -C '${output} ${file} ; done;`
popd
packagefiles="${classfiles}"
[ -e about.html ] && packagefiles="about.html $packagefiles"
[ -e plugin.properties ] && packagefiles="plugin.properties $packagefiles"
[ -e plugin.xml ] && packagefiles="plugin.xml $packagefiles"
[ -e OSGI-INF ] && packagefiles="OSGI-INF $packagefiles"
jar -cfmv "target/${bName}-${version}.jar" 'META-INF/MANIFEST.MF' ${packagefiles}
popd

echo "install..."

# Install
loc="$REPO/org/eclipse/tycho/${artifactId}/${version}"
mkdir -p ${loc}
cp "${basedir}/target/${bName}-${version}.jar" ${loc}
cp "${basedir}/pom.xml" "${loc}/${bName}-${version}.pom"

}


function copyBundles () {
#usage: copyBundles bundlesList destDir
# scls='scl1 scl2 scl3'

echo "copyBundles to $2..."

baseLocations=( '/usr/share/java' '/usr/lib/java' '/usr/lib*/eclipse' )
osgiLocations=(${baseLocations[@]} ${osgiLocations[@]} )
for scl in ${scls} ; do
  osgiLocations=( ${baseLocations[@]/#//opt/rh/${scl}/root} ${osgiLocations[@]} )
done

#debian: this won't work because we don't have /bootstrap..

if [ ${eclipse_bootstrap} -eq 1 ]; then
	prefix="$(pwd)/bootstrap"
osgiLocations=( ${osgiLocations[@]/#/${prefix}} )
osgiLocations+=( ${osgiLocations[@]/${prefix}/} )
osgiLocations=( ${prefix}/extras ${osgiLocations[@]} )
fi

wantedBundles=`echo $1 | tr ',' ' '`
destDir=$2

#debian:
#sl4j is just used by FedoraProject-p2. FIXME
cp $REPO/org/eclipse/eclipse-bootstrap/${eclipseV}/eclipse-bootstrap-${eclipseV}.jar ${destDir}
cp $REPO/org/slf4j/slf4j-api/debian/slf4j-api-debian.jar ${destDir}
return


for loc in ${osgiLocations[@]} ; do
  for jar in `find ${loc} -name "*.jar" 2>/dev/null`; do
    bsn=`readBSN ${jar}`
    if [ -n "${bsn}" ]; then
      if echo ${wantedBundles} | grep "${bsn}" ; then
        #debian: lines moved
        versionline=`unzip -p ${jar} 'META-INF/MANIFEST.MF' | grep 'Bundle-Version:'` 2>/dev/null
        vers=`echo "${versionline}" | sed 's/Bundle-Version: \([a-zA-Z0-9_.-]*\).*/\1/'`
        cp ${jar} "${destDir}/${bsn}_${vers}.jar"
        wantedBundles=`removeFromList "${wantedBundles}" "${bsn}"`
      fi
    fi
  done
done

}

function symlinkBundles () {

# Bootstrap Built Tycho provides some Eclipse bundles
# Prevent non-bootstrap build's de-bundling from symlinking to them
# SCL priority is from right to left.
# scls='scl1 scl2 scl3'
baseLocations=( '/usr/share/java/eclipse' '/usr/share/java' '/usr/lib/java' )
osgiLocations=(${baseLocations[@]} ${osgiLocations[@]} )
for scl in ${scls} ; do
  osgiLocations=( ${baseLocations[@]/#//opt/rh/${scl}/root} ${osgiLocations[@]} )
done

echo "symlinkBundles $1..."

wantedBundles=`echo $1 | tr ',' ' '`

for loc in ${osgiLocations[@]} ; do
  for jar in `find ${loc} -name "*.jar" 2>/dev/null`; do
    bsn=`readBSN ${jar}`
    if [ -n "${bsn}" ]; then
      echo ${wantedBundles} | grep -q "${bsn}"
      if [ $? -eq 0 ]; then
        ln -s ${jar} "${bsn}.jar"
        wantedBundles=`removeFromList "${wantedBundles}" "${bsn}"`
      fi
    fi
  done
done
}

function removeFromList () {
arr=( ${1} )
for (( i=0; i < ${#arr[@]}; i++ )); do
  if [ "${arr[${i}]}" = "$2" ]; then
    arr[${i}]=
  fi
done
echo ${arr[@]}
}

function isolateProject () {
#usage: isolateProject srcfolder

echo "isolateProject $1======================="

cp $1/pom.xml $1/pom.xml.bak

sed -i '/<parent>/,/<\/parent>/ d' "$1/pom.xml"
if [ $# -eq 2 ]; then
  sed -i "/<modelVersion>/ a <groupId>org.eclipse.tycho<\/groupId><version>$2<\/version>" "$1/pom.xml"
else
  sed -i "/<modelVersion>/ a <groupId>org.eclipse.tycho<\/groupId><version>${v}<\/version>" "$1/pom.xml"
fi


}

function unifyProject () {
#usage: unifyProject srcfolder

echo "unifyProject $1========================="

cp $1/pom.xml.bak $1/pom.xml
#sed -i "/<version>${osgiV}<\/version>/ d" "$1/pom.xml"

}

function readBSN () {
#read Bundle-SymbolicName from bundle's MANIFEST.MF
#usage: readBSN fullfilename.jar

bsn=
manEntryPat="^[a-zA-Z-]*:"
foundBSNLine=0

while read line; do
if [ ${foundBSNLine} -eq 1 ]; then
  echo ${line} | grep -qE ${manEntryPat}
  if [ $? -eq 0 ]; then
    break
  else
    bsn=${bsn}"`echo ${line} | sed 's/\([a-zA-Z0-9_.-]*\)\(;\)\?.*/\1/'`"
  fi
fi

echo ${line} | grep -q "Bundle-SymbolicName:"
if [ $? -eq 0 ]; then
  bsn=`echo ${line} | grep 'Bundle-SymbolicName:' | sed 's/Bundle-SymbolicName: \([a-zA-Z0-9_.-]*\)\(;\)\?.*/\1/'`
  echo ${line} | grep "Bundle-SymbolicName:" | grep -q ";"
  if [ $? -eq 0 ]; then
    break
  fi
  foundBSNLine=1
fi
done < <(unzip -p $1 'META-INF/MANIFEST.MF')

echo ${bsn}

}