Andrew Overholt 579969
#!/bin/bash
Andrew Overholt 579969
Andrew Overholt 1fcf3f
# args:  [-f <feature>] [-d <dependencies (outside="" sdk)="">] [-a <additional build="" args="">] [-j <jvm args="">] [-v] [-D] [-o <orbit dependencies="">]
Andrew Overholt 579969
Andrew Overholt 579969
function usage {
Andrew Overholt 579969
cat << _EOF_
Andrew Overholt 579969
usage: $0 [<options>]
Andrew Overholt 579969
Andrew Overholt 579969
Use PDE Build to build Eclipse features
Andrew Overholt 579969
Andrew Overholt 579969
Optional arguments:
Andrew Overholt 579969
   -h      Show this help message
Andrew Overholt 579969
   -f      Feature ID to build
Andrew Overholt 579969
   -d      Plugin dependencies in addition to Eclipse SDK
Andrew Overholt 579969
           (space-separated, names on which to glob features and plugins)
Andrew Overholt 579969
   -a      Additional build arguments (ex. -DjavacSource=1.5)
Andrew Overholt 579969
   -j      VM arguments (ex. -DJ2SE-1.5=%{_jvmdir}/java/jre/lib/rt.jar)
Andrew Overholt 579969
   -v      Be verbose
Andrew Overholt 579969
   -D      Debug platform itself (passes -consolelog -debug to Eclipse)
Andrew Overholt 1fcf3f
   -o      Orbit dependencies
Andrew Overholt 579969
_EOF_
Andrew Overholt 579969
}
Andrew Overholt 579969
Andrew Overholt 579969
function copyPlatform {
Andrew Overholt 579969
    # This seems silly but I was running into issues with empty strings
Andrew Overholt 579969
    # counting as arguments to copy-platform -- overholt, 2008-03
Andrew Overholt 1fcf3f
    if [ -z "$dependencies" ]; then
Andrew Overholt 579969
        if [ $verbose -eq 1 ]; then
Andrew Overholt 579969
            echo "/bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse"
Andrew Overholt 579969
            /bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse
Andrew Overholt 579969
        else
Andrew Overholt 579969
            echo "/bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse"
Andrew Overholt 579969
            /bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse
Andrew Overholt 579969
        fi
Andrew Overholt 579969
    else
Andrew Overholt 579969
        if [ $verbose -eq 1 ]; then
Andrew Overholt 579969
            echo "/bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies"
Andrew Overholt 579969
            /bin/sh -x $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies
Andrew Overholt 579969
        else
Andrew Overholt 579969
            echo "/bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies"
Andrew Overholt 579969
            /bin/sh $datadir/eclipse/buildscripts/copy-platform $SDK $datadir/eclipse $dependencies
Andrew Overholt 579969
        fi
Andrew Overholt 579969
    fi
Andrew Overholt 579969
}
Andrew Overholt 579969
Andrew Overholt 579969
function findFeatureId {
Andrew Overholt 579969
    # We can determine the feature ID if we have only one
Andrew Overholt 579969
    numFeatures=$(find $sourceDir -name feature.xml | wc -l)
Andrew Overholt 579969
    if [ $numFeatures -ne 1 ]; then
Andrew Overholt 579969
        #echo "# features found = $numFeatures"
Andrew Overholt 579969
        echo "Cannot determine feature ID.  Please specify with -f."
Andrew Overholt 579969
        usage
Andrew Overholt 579969
        exit 1
Andrew Overholt 579969
    fi
Andrew Overholt 579969
    
Andrew Overholt 579969
    featureXml=$(find $sourceDir -name feature.xml)
Andrew Overholt 579969
    
Andrew Overholt 579969
    # Taken from Ben Konrath's package-build
Andrew Overholt 579969
    # make an ant build files to extract the id from the feature.xml
Andrew Overholt 579969
    buildFile=$buildDir/findFeatureForRPM-tmp-build.xml
Andrew Overholt 579969
    
Andrew Overholt 579969
    echo "<project default="\"main\"">
Andrew Overholt 579969
    	<target name="\"main\"">
Andrew Overholt 579969
                   	<xmlproperty file="\"$featureXml\"" collapseattributes="\"true\"/">
Andrew Overholt 579969
    		<fail unless="\"feature.id\"" message="\"feature.id" not="" set\"=""/>
Andrew Overholt 579969
                   	<echo message="\"\${feature.id}\""/>
Andrew Overholt 579969
            </target>
Andrew Overholt 579969
    </project>" > $buildFile
Andrew Overholt 579969
    
Andrew Overholt 579969
    featureId=$(ant -Dbasedir=$sourceDir -f $buildFile 2>&1 | grep echo | cut --delimiter=' ' -f 7)
Andrew Overholt 579969
    rm $buildFile
Andrew Overholt 579969
}
Andrew Overholt 579969
Andrew Overholt 8fa0c0
function findFeatureNameAndVersion {
Andrew Overholt 8fa0c0
    featureXml=$(find $sourceDir -name feature.xml | while read f; do grep -l id=\"$featureId\" $f; done)
Andrew Overholt 8fa0c0
    
Andrew Overholt 8fa0c0
    buildFile=$buildDir/findFeatureForRPM-tmp-build.xml
Andrew Overholt 8fa0c0
    
Andrew Overholt 8fa0c0
    echo "<project default="\"main\"">
Andrew Overholt 8fa0c0
    	<target name="\"main\"">
Andrew Overholt 8fa0c0
                   	<xmlproperty file="\"$featureXml\"" collapseattributes="\"true\"/">
Andrew Overholt 8fa0c0
    		<fail unless="\"feature.id\"" message="\"feature.id" not="" set\"=""/>
Andrew Overholt 8fa0c0
                   	<echo message="\"\${feature.label}\""/>
Andrew Overholt 8fa0c0
            </target>
Andrew Overholt 8fa0c0
    </project>" > $buildFile
Andrew Overholt 8fa0c0
    
Andrew Overholt 8fa0c0
    featureName=$(ant -Dbasedir=$sourceDir -f $buildFile 2>&1 | grep echo | sed "s/.*\[echo\]\ //")
Andrew Overholt 8fa0c0
    rm $buildFile
Andrew Overholt 8fa0c0
Andrew Overholt 8fa0c0
    echo "<project default="\"main\"">
Andrew Overholt 8fa0c0
    	<target name="\"main\"">
Andrew Overholt 8fa0c0
                   	<xmlproperty file="\"$featureXml\"" collapseattributes="\"true\"/">
Andrew Overholt 8fa0c0
    		<fail unless="\"feature.id\"" message="\"feature.id" not="" set\"=""/>
Andrew Overholt 8fa0c0
                   	<echo message="\"\${feature.version}\""/>
Andrew Overholt 8fa0c0
            </target>
Andrew Overholt 8fa0c0
    </project>" > $buildFile
Andrew Overholt 8fa0c0
    
Andrew Overholt 8fa0c0
    featureVersion=$(ant -Dbasedir=$sourceDir -f $buildFile 2>&1 | grep echo | sed "s/.*\[echo\]\ //")
Andrew Overholt 8fa0c0
    rm $buildFile
Andrew Overholt 8fa0c0
}
Andrew Overholt 579969
sourceDir=$PWD
Andrew Overholt 579969
buildDir=$PWD/build
Andrew Overholt 579969
SDK=$buildDir/SDK
Andrew Overholt 579969
homeDir=$buildDir/home
Andrew Overholt 1fcf3f
datadir=`rpm --eval "%{_libdir}"`
Andrew Overholt df2c91
pdeBuildDir=$datadir/eclipse/dropins/sdk/plugins/org.eclipse.pde.build_@PDEBUILDVERSION@
Andrew Overholt 579969
Andrew Overholt 579969
featureId=
Andrew Overholt 579969
dependencies=
Andrew Overholt 579969
additionalArgs=
Andrew Overholt 579969
vmArgs=
Andrew Overholt 579969
verbose=0
Andrew Overholt 579969
dryRun=0
Andrew Overholt 579969
debugPlatform=0
Andrew Overholt 1fcf3f
orbitDepsDir=
Andrew Overholt 465153
p2Generate=
Andrew Overholt 465153
testing=false
Andrew Overholt 579969
Andrew Overholt 579969
# See above.  r = dry run (used for testing)
Andrew Overholt 465153
while getopts “hf:d:a:j:tvrDo:” OPTION
Andrew Overholt 579969
do
Andrew Overholt 579969
     case $OPTION in
Andrew Overholt 579969
         h)
Andrew Overholt 579969
             usage
Andrew Overholt 579969
             exit
Andrew Overholt 579969
             ;;
Andrew Overholt 579969
         f)
Andrew Overholt 579969
             featureId=$OPTARG
Andrew Overholt 579969
             ;;
Andrew Overholt 579969
         d)
Andrew Overholt 579969
             dependencies=$OPTARG
Andrew Overholt 579969
             ;;
Andrew Overholt 579969
         a)
Andrew Overholt 579969
             additionalArgs=$OPTARG
Andrew Overholt 579969
             ;;
Andrew Overholt 579969
         j)
Andrew Overholt 579969
             vmArgs=$OPTARG
Andrew Overholt 579969
             ;;
Andrew Overholt 465153
         t)
Andrew Overholt 465153
             testing=true
Andrew Overholt 465153
             ;;
Andrew Overholt 579969
         v)
Andrew Overholt 579969
             verbose=1
Andrew Overholt 579969
             ;;
Andrew Overholt 579969
         r)
Andrew Overholt 579969
             dryRun=1
Andrew Overholt 579969
             ;;
Andrew Overholt 579969
         D)
Andrew Overholt 579969
             debugPlatform=1
Andrew Overholt 579969
             ;;
Andrew Overholt 1fcf3f
         o)
Andrew Overholt 1fcf3f
             orbitDepsDir=$OPTARG
Andrew Overholt 1fcf3f
             ;;
Andrew Overholt 579969
         ?)
Andrew Overholt 579969
             usage
Andrew Overholt 579969
             exit
Andrew Overholt 579969
             ;;
Andrew Overholt 579969
     esac
Andrew Overholt 579969
done
Andrew Overholt 579969
Andrew Overholt 579969
echo "mkdir -p $buildDir"
Andrew Overholt 579969
if [ $dryRun -ne 1 ]; then
Andrew Overholt 579969
    mkdir -p $buildDir
Andrew Overholt 579969
fi
Andrew Overholt 579969
Andrew Overholt 579969
# Eclipse may try to write to the building user's home directory so we create a
Andrew Overholt 579969
# temporary one for use by the build.
Andrew Overholt 579969
echo "mkdir -p $homeDir"
Andrew Overholt 579969
if [ $dryRun -ne 1 ]; then
Andrew Overholt 579969
    mkdir -p $homeDir
Andrew Overholt 579969
fi
Andrew Overholt 579969
Andrew Overholt 579969
if [ -z $featureId ]; then
Andrew Overholt 579969
    findFeatureId
Andrew Overholt 579969
fi
Andrew Overholt 579969
Andrew Overholt 579969
if [ -z $featureId ]; then
Andrew Overholt 579969
    echo "Cannot determine feature ID.  Please specify with -f."
Andrew Overholt 579969
    usage
Andrew Overholt 579969
    exit 1
Andrew Overholt 579969
fi
Andrew Overholt 579969
Andrew Overholt 8fa0c0
findFeatureNameAndVersion
Andrew Overholt 8fa0c0
Andrew Overholt 579969
echo "Building feature = $featureId."
Andrew Overholt 579969
Andrew Overholt 579969
if [ -z "$dependencies" ]; then
Andrew Overholt 579969
    if [ $verbose -eq 1 ]; then
Andrew Overholt 579969
        echo "Assuming no dependencies except Eclipse SDK."
Andrew Overholt 579969
    fi
Andrew Overholt 579969
fi
Andrew Overholt 579969
Andrew Overholt 579969
# Symlink the SDK and dependencies for build
Andrew Overholt 579969
if [ -z "$dependencies" ]; then
Andrew Overholt 579969
    echo "Symlinking SDK into $SDK directory."
Andrew Overholt 579969
else
Andrew Overholt 579969
    echo "Symlinking SDK and \"$dependencies\" into $SDK directory."
Andrew Overholt 579969
fi
Andrew Overholt 579969
if [ $dryRun -ne 1 ]; then
Andrew Overholt 579969
    copyPlatform
Andrew Overholt 579969
fi
Andrew Overholt 579969
Andrew Overholt 579969
if [ $debugPlatform -eq 1 ]; then
Andrew Overholt 579969
    debugPlatformArgs="-debug -consolelog"
Andrew Overholt 579969
fi
Andrew Overholt 579969
Andrew Overholt 465153
if [ $testing != true ]; then
fe1b86
  p2Generate="-Dp2.root.name=\"$featureName\"" \
fe1b86
" -Dp2.root.version=\"$featureVersion\"" \
fe1b86
" -Dgenerate.p2.metadata=true" \
fe1b86
" -Dp2.metadata.repo=file:$buildDir/repo" \
fe1b86
" -Dp2.artifact.repo=file:$buildDir/repo" \
fe1b86
" -Dp2.flavor=tooling" \
fe1b86
" -Dp2.publish.artifacts=true"
Andrew Overholt 465153
fi
Andrew Overholt 465153
Andrew Overholt 579969
echo
Andrew Overholt 579969
echo "Starting build:"
Andrew Overholt 579969
Andrew Overholt 579969
echo "
Andrew Overholt 579969
java -cp $SDK/startup.jar \
Andrew Overholt 579969
org.eclipse.core.launcher.Main \
Andrew Overholt 579969
-application org.eclipse.ant.core.antRunner \
Andrew Overholt 579969
$debugPlatformArgs \
Andrew Overholt 579969
-Dtype=feature \
Andrew Overholt 579969
-Did=$featureId \
Andrew Overholt 579969
-DbaseLocation=$SDK \
Andrew Overholt 579969
-DsourceDirectory=$sourceDir \
Andrew Overholt 579969
-DbuildDirectory=$buildDir \
Andrew Overholt df2c91
-Dbuilder=$datadir/eclipse/dropins/sdk/plugins/org.eclipse.pde.build_@PDEBUILDVERSION@/templates/package-build \
Andrew Overholt 1fcf3f
-DorbitDepsDir="$orbitDepsDir" \
Andrew Overholt 465153
-Dtesting="$testing" \
Andrew Overholt 465153
$p2Generate \
Andrew Overholt 579969
$additionalArgs \
Andrew Overholt 579969
-f $pdeBuildDir/scripts/build.xml \
Andrew Overholt 579969
-vmargs \
Andrew Overholt 579969
-Duser.home=$homeDir \
Andrew Overholt 579969
$vmArgs
Andrew Overholt 579969
"
Andrew Overholt 579969
Andrew Overholt 579969
if [ $dryRun -ne 1 ]; then
Andrew Overholt 579969
    java -cp $SDK/startup.jar \
Andrew Overholt 579969
    org.eclipse.core.launcher.Main \
Andrew Overholt 579969
    -application org.eclipse.ant.core.antRunner \
Andrew Overholt 579969
    $debugPlatformArgs \
Andrew Overholt 579969
    -Dtype=feature \
Andrew Overholt 579969
    -Did=$featureId \
Andrew Overholt 579969
    -DbaseLocation=$SDK \
Andrew Overholt 579969
    -DsourceDirectory=$sourceDir \
Andrew Overholt 579969
    -DbuildDirectory=$buildDir \
Andrew Overholt df2c91
    -Dbuilder=$datadir/eclipse/dropins/sdk/plugins/org.eclipse.pde.build_@PDEBUILDVERSION@/templates/package-build \
Andrew Overholt 58053f
    -DorbitDepsDir=$orbitDepsDir \
Andrew Overholt 465153
    -Dtesting="$testing" \
Andrew Overholt 465153
    $p2Generate \
Andrew Overholt 579969
    $additionalArgs \
Andrew Overholt 579969
    -f $pdeBuildDir/scripts/build.xml \
Andrew Overholt 579969
    -vmargs \
Andrew Overholt 579969
    -Duser.home=$homeDir \
Andrew Overholt 579969
    $vmArgs
Andrew Overholt 579969
fi
Andrew Overholt 8fa0c0
Andrew Overholt 465153
if [ $testing != true ]; then
Andrew Overholt 465153
  # Add content.xml into zip
Andrew Overholt 465153
  pushd $buildDir/rpmBuild
Andrew Overholt 465153
  unzip $featureId.zip
Andrew Overholt 465153
  rm $featureId.zip
Andrew Overholt 465153
  cp -p ../repo/content.xml eclipse
Andrew Overholt 465153
  zip -r $featureId.zip eclipse
Andrew Overholt 465153
  rm -rf eclipse
Andrew Overholt 465153
  popd
fe1b86
fi