Blame SOURCES/tycho-scripts.sh

35a07c
#! /bin/bash
35a07c
35a07c
function minibuild () {
35a07c
35a07c
basedir=$1
35a07c
35a07c
src=$(cat "${basedir}/build.properties" | grep 'source..' | cut -d'=' -f2 | sed -e 's/ //g')
35a07c
output=$(cat "${basedir}/build.properties" | grep 'output..' | cut -d'=' -f2 | sed -e 's/ //g')
35a07c
bName=$(cat "${basedir}/META-INF/MANIFEST.MF" | grep 'Bundle-SymbolicName:' | sed 's/Bundle-SymbolicName: \([a-zA-Z0-9_.-]*\)\(;\)\?.*/\1/')
35a07c
artifactId=$(cat "${basedir}/pom.xml" | sed '/<parent>/,/<\/parent>/ d' | grep "<artifactId>" | sed 's/.*<artifactId>\(.*\)<\/artifactId>.*/\1/')
35a07c
version=$(cat "${basedir}/pom.xml" | grep "<version>" | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
35a07c
35a07c
# External (System) dependencies
35a07c
if [ $# -eq 3 ]; then
35a07c
  mkdir -p "${basedir}/target/externalDeps"
35a07c
  copyBundles $3 "${basedir}/target/externalDeps"
35a07c
else
35a07c
  mkdir -p "${basedir}/target"
35a07c
fi
35a07c
35a07c
mkdir -p "${basedir}/${output}"
35a07c
35a07c
# Compile
35a07c
cp=
35a07c
if [ $# -gt 1 ]; then
35a07c
  cp='-classpath '$2':'"${basedir}"'/target/externalDeps/*'
35a07c
fi
35a07c
35a07c
javac -d "${basedir}/${output}" -encoding utf8 \
35a07c
  $(for file in `find "${basedir}/${src}" -name "*.java"`; \
35a07c
    do echo -n "${file} "; \
35a07c
  done;) \
35a07c
  ${cp}
35a07c
35a07c
# Package
35a07c
pushd ${basedir}
35a07c
pushd ${output}
35a07c
classfiles=`for file in $(find . -name "*.class"); do echo -n ' -C '${output} ${file} ; done;`
35a07c
popd
35a07c
packagefiles="${classfiles}"
35a07c
[ -e about.html ] && packagefiles="about.html $packagefiles"
35a07c
[ -e plugin.properties ] && packagefiles="plugin.properties $packagefiles"
35a07c
[ -e plugin.xml ] && packagefiles="plugin.xml $packagefiles"
35a07c
[ -e OSGI-INF ] && packagefiles="OSGI-INF $packagefiles"
35a07c
jar -cfmv "target/${bName}-${version}.jar" 'META-INF/MANIFEST.MF' ${packagefiles}
35a07c
popd
35a07c
35a07c
# Install
35a07c
loc=".m2/org/eclipse/tycho/${artifactId}/${version}"
35a07c
mkdir -p ${loc}
35a07c
cp "${basedir}/target/${bName}-${version}.jar" ${loc}
35a07c
cp "${basedir}/pom.xml" "${loc}/${bName}-${version}.pom"
35a07c
35a07c
}
35a07c
35a07c
35a07c
function copyBundles () {
35a07c
35a07c
# X_SCLS expands to list of currently enabled SCLs, in the order they were enabled, if any
35a07c
scls="$X_SCLS"
35a07c
baseLocations=( '/usr/share/java' '/usr/lib/java' '/usr/lib/eclipse' )
35a07c
osgiLocations=(${baseLocations[@]} ${osgiLocations[@]} )
35a07c
for scl in ${scls} ; do
35a07c
  osgiLocations=( ${baseLocations[@]/#//opt/rh/${scl}/root} ${osgiLocations[@]} )
35a07c
done
35a07c
35a07c
prefix="$(pwd)/bootstrap"
35a07c
osgiLocations=( ${osgiLocations[@]/#/${prefix}} )
35a07c
osgiLocations+=( ${osgiLocations[@]/${prefix}/} )
35a07c
osgiLocations=( ${prefix}/extras ${osgiLocations[@]} )
35a07c
35a07c
wantedBundles=`echo $1 | tr ',' ' '`
35a07c
destDir=$2
35a07c
35a07c
for loc in ${osgiLocations[@]} ; do
35a07c
  for jar in `find ${loc} -name "*.jar" 2>/dev/null`; do
35a07c
    bsn=`readBSN ${jar}`
35a07c
    if [ -n "${bsn}" ]; then
35a07c
      versionline=`unzip -p ${jar} 'META-INF/MANIFEST.MF' | grep 'Bundle-Version:'`
35a07c
      vers=`echo "${versionline}" | sed 's/Bundle-Version: \([a-zA-Z0-9_.-]*\).*/\1/'`
35a07c
      if echo ${wantedBundles} | grep "${bsn}" ; then
35a07c
        cp ${jar} "${destDir}/${bsn}_${vers}.jar"
35a07c
        wantedBundles=`removeFromList "${wantedBundles}" "${bsn}"`
35a07c
      fi
35a07c
    fi
35a07c
  done
35a07c
done
35a07c
35a07c
}
35a07c
35a07c
function symlinkBundles () {
35a07c
35a07c
# Bootstrap Built Tycho provides some Eclipse bundles
35a07c
# Prevent non-bootstrap build's de-bundling from symlinking to them
35a07c
# SCL priority is from right to left.
35a07c
# X_SCLS expands to list of currently enabled SCLs, in the order they were enabled, if any
35a07c
scls="$X_SCLS"
35a07c
baseLocations=( '/usr/share/java/eclipse' '/usr/share/java' '/usr/lib/java' )
35a07c
osgiLocations=(${baseLocations[@]} ${osgiLocations[@]} )
35a07c
for scl in ${scls} ; do
35a07c
  osgiLocations=( ${baseLocations[@]/#//opt/rh/${scl}/root} ${osgiLocations[@]} )
35a07c
done
35a07c
35a07c
35a07c
wantedBundles=`echo $1 | tr ',' ' '`
35a07c
35a07c
for loc in ${osgiLocations[@]} ; do
35a07c
  for jar in `find ${loc} -name "*.jar" 2>/dev/null`; do
35a07c
    bsn=`readBSN ${jar}`
35a07c
    if [ -n "${bsn}" ]; then
35a07c
      echo ${wantedBundles} | grep -q "${bsn}"
35a07c
      if [ $? -eq 0 ]; then
35a07c
        ln -s ${jar} "${bsn}.jar"
35a07c
        wantedBundles=`removeFromList "${wantedBundles}" "${bsn}"`
35a07c
      fi
35a07c
    fi
35a07c
  done
35a07c
done
35a07c
}
35a07c
35a07c
function removeFromList () {
35a07c
arr=( ${1} )
35a07c
for (( i=0; i < ${#arr[@]}; i++ )); do
35a07c
  if [ "${arr[${i}]}" = "$2" ]; then
35a07c
    arr[${i}]=
35a07c
  fi
35a07c
done
35a07c
echo ${arr[@]}
35a07c
}
35a07c
35a07c
function isolateProject () {
35a07c
  cp $1/pom.xml $1/pom.xml.boot
35a07c
35a07c
  sed -i -e "/<artifactId>org.eclipse.osgi</ a <version>${osgiV}</version>" \
35a07c
         -e "/<artifactId>org.eclipse.osgi.compatibility.state</ a <version>${osgiCompatV}</version>" \
35a07c
         -e '/<parent>/,/<\/parent>/ d' "$1/pom.xml"
35a07c
  if ! grep -q generate-metadata "$1/pom.xml" ; then
35a07c
    sed -i -e "/<artifactId>plexus-component-metadata</ a <version>1.5.5</version><executions><execution><goals><goal>generate-metadata</goal></goals></execution></executions>" "$1/pom.xml"
35a07c
  fi
35a07c
35a07c
  if [ $# -eq 2 ]; then
35a07c
    sed -i "/<modelVersion>/ a <groupId>org.eclipse.tycho<\/groupId><version>$2<\/version>" "$1/pom.xml"
35a07c
  else
35a07c
    sed -i "/<modelVersion>/ a <groupId>org.eclipse.tycho<\/groupId><version>${v}<\/version>" "$1/pom.xml"
35a07c
  fi
35a07c
}
35a07c
35a07c
function unifyProject () {
35a07c
  cp $1/pom.xml.boot $1/pom.xml
35a07c
}
35a07c
35a07c
function readBSN () {
35a07c
35a07c
bsn=
35a07c
manEntryPat="^[a-zA-Z-]*:"
35a07c
foundBSNLine=0
35a07c
35a07c
while read line; do
35a07c
if [ ${foundBSNLine} -eq 1 ]; then
35a07c
  echo ${line} | grep -qE ${manEntryPat}
35a07c
  if [ $? -eq 0 ]; then
35a07c
    break
35a07c
  else
35a07c
    bsn=${bsn}"`echo ${line} | sed 's/\([a-zA-Z0-9_.-]*\)\(;\)\?.*/\1/'`"
35a07c
  fi
35a07c
fi
35a07c
35a07c
echo ${line} | grep -q "Bundle-SymbolicName:"
35a07c
if [ $? -eq 0 ]; then
35a07c
  bsn=`echo ${line} | grep 'Bundle-SymbolicName:' | sed 's/Bundle-SymbolicName: \([a-zA-Z0-9_.-]*\)\(;\)\?.*/\1/'`
35a07c
  echo ${line} | grep "Bundle-SymbolicName:" | grep -q ";"
35a07c
  if [ $? -eq 0 ]; then
35a07c
    break
35a07c
  fi
35a07c
  foundBSNLine=1
35a07c
fi
35a07c
done < <(unzip -p $1 'META-INF/MANIFEST.MF')
35a07c
35a07c
echo ${bsn}
35a07c
35a07c
}