Krzysztof Daniel 48b3c87
#!/bin/bash
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
# args:  [-f <feature>] [-d <dependencies (outside SDK)>] [-a <additional build args>] [-j <JVM args>] [-v] [-D] [-o <Orbit dependencies>]
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
function usage {
Krzysztof Daniel 48b3c87
cat << _EOF_
Krzysztof Daniel 48b3c87
usage: $0 [<options>]
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
Use PDE Build to build Eclipse features
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
Optional arguments:
Krzysztof Daniel 48b3c87
   -h      Show this help message
Krzysztof Daniel 48b3c87
   -f      Feature ID to build
Krzysztof Daniel 48b3c87
   -d      Plugin dependencies in addition to Eclipse SDK
Krzysztof Daniel 48b3c87
           (space-separated, names on which to glob features and plugins)
Krzysztof Daniel 48b3c87
   -a      Additional build arguments (ex. -DjavacSource=1.5)
Krzysztof Daniel 48b3c87
   -j      VM arguments (ex. -DJ2SE-1.5=%{_jvmdir}/java/jre/lib/rt.jar)
Krzysztof Daniel 48b3c87
   -v      Be verbose
Krzysztof Daniel 48b3c87
   -D      Debug platform itself (passes -consolelog -debug to Eclipse)
Krzysztof Daniel 48b3c87
   -o      Directory containing Orbit-style dependencies
Krzysztof Daniel 48b3c87
   -z      Comma-delimited list of dependency zips (not for use during RPM build)
Krzysztof Daniel 48b3c87
_EOF_
Krzysztof Daniel 48b3c87
}
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
function copyPlatform {
Krzysztof Daniel 48b3c87
    # This seems silly but I was running into issues with empty strings
Krzysztof Daniel 48b3c87
    # counting as arguments to copy-platform -- overholt, 2008-03
Krzysztof Daniel 48b3c87
    if [ -z "$dependencies" ]; then
Krzysztof Daniel 48b3c87
        if [ $verbose -eq 1 ]; then
Krzysztof Daniel 48b3c87
            echo "/bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse"
Krzysztof Daniel 48b3c87
            /bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse
Krzysztof Daniel 48b3c87
        else
Krzysztof Daniel 48b3c87
            echo "/bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse"
Krzysztof Daniel 48b3c87
            /bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse
Krzysztof Daniel 48b3c87
        fi
Krzysztof Daniel 48b3c87
    else
Krzysztof Daniel 48b3c87
        if [ $verbose -eq 1 ]; then
Krzysztof Daniel 48b3c87
            echo "/bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies"
Krzysztof Daniel 48b3c87
            /bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies
Krzysztof Daniel 48b3c87
        else
Krzysztof Daniel 48b3c87
            echo "/bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies"
Krzysztof Daniel 48b3c87
            /bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies
Krzysztof Daniel 48b3c87
        fi
Krzysztof Daniel 48b3c87
    fi
Krzysztof Daniel 48b3c87
}
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
function findFeatureId {
Krzysztof Daniel 48b3c87
    # We can determine the feature ID if we have only one
Krzysztof Daniel 48b3c87
    numFeatures=$(find $sourceDir -name feature.xml | wc -l)
Krzysztof Daniel 48b3c87
    if [ $numFeatures -ne 1 ]; then
Krzysztof Daniel 48b3c87
        #echo "# features found = $numFeatures"
Krzysztof Daniel 48b3c87
        echo "Cannot determine feature ID.  Please specify with -f."
Krzysztof Daniel 48b3c87
        usage
Krzysztof Daniel 48b3c87
        exit 1
Krzysztof Daniel 48b3c87
    fi
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    featureXml=$(find $sourceDir -name feature.xml)
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    # Taken from Ben Konrath's package-build
Krzysztof Daniel 48b3c87
    # make an ant build files to extract the id from the feature.xml
Krzysztof Daniel 48b3c87
    buildFile=$buildDir/findFeatureForRPM-tmp-build.xml
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    echo "<project default=\"main\">
Krzysztof Daniel 48b3c87
    	<target name=\"main\">
Krzysztof Daniel 48b3c87
                   	<xmlproperty file=\"$featureXml\" collapseAttributes=\"true\"/>
Krzysztof Daniel 48b3c87
    		<fail unless=\"feature.id\" message=\"feature.id not set\"/>
Krzysztof Daniel 48b3c87
                   	<echo message=\"\${feature.id}\" />
Krzysztof Daniel 48b3c87
            </target>
Krzysztof Daniel 48b3c87
    </project>" > $buildFile
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    featureId=$(ant -Dbasedir=$sourceDir -f $buildFile 2>&1 | grep echo | cut --delimiter=' ' -f 7)
Krzysztof Daniel 48b3c87
    rm $buildFile
Krzysztof Daniel 48b3c87
}
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
function findFeatureNameAndVersion {
Krzysztof Daniel 48b3c87
    featureXml=$(find $sourceDir -name feature.xml | while read f; do grep -l id=\"$featureId\" $f; done)
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    buildFile=$buildDir/findFeatureForRPM-tmp-build.xml
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    echo "<project default=\"main\">
Krzysztof Daniel 48b3c87
    	<target name=\"main\">
Krzysztof Daniel 48b3c87
                   	<xmlproperty file=\"$featureXml\" collapseAttributes=\"true\"/>
Krzysztof Daniel 48b3c87
    		<fail unless=\"feature.id\" message=\"feature.id not set\"/>
Krzysztof Daniel 48b3c87
                   	<echo message=\"\${feature.label}\" />
Krzysztof Daniel 48b3c87
            </target>
Krzysztof Daniel 48b3c87
    </project>" > $buildFile
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    featureName=$(ant -Dbasedir=$sourceDir -f $buildFile 2>&1 | grep echo | sed "s/.*\[echo\]\ //")
Krzysztof Daniel 48b3c87
    rm $buildFile
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
    echo "<project default=\"main\">
Krzysztof Daniel 48b3c87
    	<target name=\"main\">
Krzysztof Daniel 48b3c87
                   	<xmlproperty file=\"$featureXml\" collapseAttributes=\"true\"/>
Krzysztof Daniel 48b3c87
    		<fail unless=\"feature.id\" message=\"feature.id not set\"/>
Krzysztof Daniel 48b3c87
                   	<echo message=\"\${feature.version}\" />
Krzysztof Daniel 48b3c87
            </target>
Krzysztof Daniel 48b3c87
    </project>" > $buildFile
Krzysztof Daniel 48b3c87
    
Krzysztof Daniel 48b3c87
    featureVersion=$(ant -Dbasedir=$sourceDir -f $buildFile 2>&1 | grep echo | sed "s/.*\[echo\]\ //")
Krzysztof Daniel 48b3c87
    rm $buildFile
Krzysztof Daniel 48b3c87
}
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
function findMaxBREE {
Krzysztof Daniel 48b3c87
	manifests=$(find $sourceDir -name MANIFEST.MF)
Krzysztof Daniel 48b3c87
	maxBree=1.4
Krzysztof Daniel 48b3c87
	for i in $manifests; do
Krzysztof Daniel 48b3c87
		breeLine=$(cat $i|grep RequiredExecutionEnvironment|cut -c37-|sed 's/^ *\(.*\) *$/\1/')
Krzysztof Daniel 48b3c87
		case $breeLine in
Krzysztof Daniel 48b3c87
         "J2SE-1.5")
Krzysztof Daniel 48b3c87
         	 bree=1.5
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         "JavaSE-1.6")
Krzysztof Daniel 48b3c87
         	 bree=1.6
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
     	esac
Krzysztof Daniel 48b3c87
     	if [ "$bree" \> "$maxBree" ]; then
Krzysztof Daniel 48b3c87
     		maxBree=$bree
Krzysztof Daniel 48b3c87
     	fi
Krzysztof Daniel 48b3c87
    done
Krzysztof Daniel 48b3c87
}
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
sourceDir=$PWD
Krzysztof Daniel 48b3c87
buildDir=$PWD/build
Krzysztof Daniel 48b3c87
SDK=$buildDir/SDK
Krzysztof Daniel 48b3c87
homeDir=$buildDir/home
Krzysztof Daniel 48b3c87
workspaceDir=$homeDir/workspace
Krzysztof Daniel 48b3c87
datadir=`rpm --eval "%{_libdir}"`
Krzysztof Daniel 48b3c87
pdeBuildDir=$datadir/eclipse/dropins/sdk/plugins/org.eclipse.pde.build_@PDEBUILDVERSION@
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
featureId=
Krzysztof Daniel 48b3c87
dependencies=
Krzysztof Daniel 48b3c87
additionalArgs=
Krzysztof Daniel 48b3c87
vmArgs=
Krzysztof Daniel 48b3c87
verbose=0
Krzysztof Daniel 48b3c87
dryRun=0
Krzysztof Daniel 48b3c87
debugPlatform=0
Krzysztof Daniel 48b3c87
orbitDepsDir=
Krzysztof Daniel 48b3c87
p2Generate=
Krzysztof Daniel 48b3c87
testing=false
Krzysztof Daniel 48b3c87
zipDeps=
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
# See above.  r = dry run (used for testing)
Krzysztof Daniel 48b3c87
while getopts “hf:d:z:a:j:tvrDo:” OPTION
Krzysztof Daniel 48b3c87
do
Krzysztof Daniel 48b3c87
     case $OPTION in
Krzysztof Daniel 48b3c87
         h)
Krzysztof Daniel 48b3c87
             usage
Krzysztof Daniel 48b3c87
             exit
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         f)
Krzysztof Daniel 48b3c87
             featureId=$OPTARG
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         d)
Krzysztof Daniel 48b3c87
             dependencies=$OPTARG
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         a)
Krzysztof Daniel 48b3c87
             additionalArgs=$OPTARG
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         j)
Krzysztof Daniel 48b3c87
             vmArgs=$OPTARG
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         t)
Krzysztof Daniel 48b3c87
             testing=true
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         v)
Krzysztof Daniel 48b3c87
             verbose=1
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         r)
Krzysztof Daniel 48b3c87
             dryRun=1
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         D)
Krzysztof Daniel 48b3c87
             debugPlatform=1
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         o)
Krzysztof Daniel 48b3c87
             orbitDepsDir=$OPTARG
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         z)
Krzysztof Daniel 48b3c87
             zipDeps=$OPTARG
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
         ?)
Krzysztof Daniel 48b3c87
             usage
Krzysztof Daniel 48b3c87
             exit 1
Krzysztof Daniel 48b3c87
             ;;
Krzysztof Daniel 48b3c87
     esac
Krzysztof Daniel 48b3c87
done
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
echo "mkdir -p $buildDir"
Krzysztof Daniel 48b3c87
if [ $dryRun -ne 1 ]; then
Krzysztof Daniel 48b3c87
    mkdir -p $buildDir
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
# Eclipse may try to write to the building user's home directory so we create a
Krzysztof Daniel 48b3c87
# temporary one for use by the build.
Krzysztof Daniel 48b3c87
echo "mkdir -p $homeDir"
Krzysztof Daniel 48b3c87
if [ $dryRun -ne 1 ]; then
Krzysztof Daniel 48b3c87
    mkdir -p $homeDir
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
echo "mkdir -p $workspaceDir"
Krzysztof Daniel 48b3c87
if [ $dryRun -ne 1 ]; then
Krzysztof Daniel 48b3c87
    mkdir -p $workspaceDir
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
if [ -z $featureId ]; then
Krzysztof Daniel 48b3c87
    findFeatureId
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
if [ -z $featureId ]; then
Krzysztof Daniel 48b3c87
    echo "Cannot determine feature ID.  Please specify with -f."
Krzysztof Daniel 48b3c87
    usage
Krzysztof Daniel 48b3c87
    exit 1
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
findFeatureNameAndVersion
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
echo "Building feature = $featureId."
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
if [ -z "$dependencies" ]; then
Krzysztof Daniel 48b3c87
    if [ $verbose -eq 1 ]; then
Krzysztof Daniel 48b3c87
        echo "Assuming no dependencies except Eclipse SDK."
Krzysztof Daniel 48b3c87
    fi
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
# Symlink the SDK and dependencies for build
Krzysztof Daniel 48b3c87
if [ -z "$dependencies" ]; then
Krzysztof Daniel 48b3c87
    echo "Symlinking SDK into $SDK directory."
Krzysztof Daniel 48b3c87
else
Krzysztof Daniel 48b3c87
    echo "Symlinking SDK and \"$dependencies\" into $SDK directory."
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
if [ $dryRun -ne 1 ]; then
Krzysztof Daniel 48b3c87
    copyPlatform
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
if [ $debugPlatform -eq 1 ]; then
Krzysztof Daniel 48b3c87
    debugPlatformArgs="-debug -consolelog"
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
if [ "x$orbitDepsDir" != "x" ]; then
Krzysztof Daniel 48b3c87
    orbitDeps="-DorbitDepsDir=$orbitDepsDir"
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
if [ "x$zipDeps" != "x" ]; then
Krzysztof Daniel 48b3c87
    OLD_IFS="$IFS"
Krzysztof Daniel 48b3c87
    IFS=","
Krzysztof Daniel 48b3c87
    zipDepsArray=($zipDeps)
Krzysztof Daniel 48b3c87
    IFS="$OLD_IFS"
Krzysztof Daniel 48b3c87
    numZips=${#zipDepsArray[@]}
Krzysztof Daniel 48b3c87
    for (( i=0; i< $numZips; i++ )); do
Krzysztof Daniel 48b3c87
        thisZip=${zipDepsArray[$i]}
Krzysztof Daniel 48b3c87
        thisFile=$(basename $thisZip)
Krzysztof Daniel 48b3c87
        thisURL=$(echo $thisZip | sed s/$thisFile//)
Krzysztof Daniel 48b3c87
        if [ ! -e $thisFile ]; then
Krzysztof Daniel 48b3c87
            wget -q $thisZip
Krzysztof Daniel 48b3c87
        fi
Krzysztof Daniel 48b3c87
        mkdir -p tmp
Krzysztof Daniel 48b3c87
        unzip -q -o $thisFile -d tmp
Krzysztof Daniel 48b3c87
        cp -raf tmp/eclipse/features/* $SDK/features
Krzysztof Daniel 48b3c87
        cp -raf tmp/eclipse/plugins/* $SDK/plugins
Krzysztof Daniel 48b3c87
        rm -rf tmp
Krzysztof Daniel 48b3c87
        thisZip=
Krzysztof Daniel 48b3c87
        thisFile=
Krzysztof Daniel 48b3c87
        thisURL=
Krzysztof Daniel 48b3c87
    done
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
if [ -z "$additionalArgs" ]; then
Krzysztof Daniel 48b3c87
	findMaxBREE
Krzysztof Daniel 48b3c87
	additionalArgs="-DjavacSource=$maxBree -DjavacTarget=$maxBree"
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
echo "Starting build:"
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
launcherJar=$(ls $SDK/plugins | grep "org.eclipse.equinox.launcher_")
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
if [ $testing != true ]; then
Krzysztof Daniel 48b3c87
  java -cp $SDK/plugins/${launcherJar} \
Krzysztof Daniel 48b3c87
    -Duser.home=$homeDir \
Krzysztof Daniel 48b3c87
    $vmArgs \
Krzysztof Daniel 48b3c87
    org.eclipse.core.launcher.Main \
Krzysztof Daniel 48b3c87
    -data $workspaceDir \
Krzysztof Daniel 48b3c87
    -application org.eclipse.ant.core.antRunner \
Krzysztof Daniel 48b3c87
    $debugPlatformArgs \
Krzysztof Daniel 48b3c87
    -Dtype=feature \
Krzysztof Daniel 48b3c87
    -Did=$featureId \
Krzysztof Daniel 48b3c87
    -DbaseLocation=$SDK \
Krzysztof Daniel 48b3c87
    -DsourceDirectory=$sourceDir \
Krzysztof Daniel 48b3c87
    -DbuildDirectory=$buildDir \
Krzysztof Daniel 48b3c87
    -Dbuilder=$datadir/eclipse/dropins/sdk/plugins/org.eclipse.pde.build_@PDEBUILDVERSION@/templates/package-build \
Krzysztof Daniel 48b3c87
    $orbitDeps \
Krzysztof Daniel 48b3c87
    -Dtesting="$testing" \
Krzysztof Daniel 48b3c87
    $additionalArgs \
Krzysztof Daniel 48b3c87
    -f $pdeBuildDir/scripts/build.xml
Krzysztof Daniel 48b3c87
else
Krzysztof Daniel 48b3c87
  echo "\
Krzysztof Daniel 48b3c87
  java -cp $SDK/plugins/${launcherJar} \
Krzysztof Daniel 48b3c87
    -Duser.home=$homeDir \
Krzysztof Daniel 48b3c87
    $vmArgs \
Krzysztof Daniel 48b3c87
    org.eclipse.core.launcher.Main \
Krzysztof Daniel 48b3c87
    -data $workspaceDir \
Krzysztof Daniel 48b3c87
    -application org.eclipse.ant.core.antRunner \
Krzysztof Daniel 48b3c87
    $debugPlatformArgs \
Krzysztof Daniel 48b3c87
    -Dtype=feature \
Krzysztof Daniel 48b3c87
    -Did=$featureId \
Krzysztof Daniel 48b3c87
    -DbaseLocation=$SDK \
Krzysztof Daniel 48b3c87
    -DsourceDirectory=$sourceDir \
Krzysztof Daniel 48b3c87
    -DbuildDirectory=$buildDir \
Krzysztof Daniel 48b3c87
    -Dbuilder=$datadir/eclipse/dropins/sdk/plugins/org.eclipse.pde.build_@PDEBUILDVERSION@/templates/package-build \
Krzysztof Daniel 48b3c87
    $orbitDeps \
Krzysztof Daniel 48b3c87
    -Dtesting=\"$testing\" \
Krzysztof Daniel 48b3c87
    $additionalArgs \
Krzysztof Daniel 48b3c87
    -f $pdeBuildDir/scripts/build.xml
Krzysztof Daniel 48b3c87
  "
Krzysztof Daniel 48b3c87
fi
Krzysztof Daniel 48b3c87
Krzysztof Daniel 48b3c87
exit $?