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