Blame SOURCES/tycho-scripts.sh

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