blob: c344c7fd0cd9195f6d02729b3ad1fee4566b1584 [file] [log] [blame]
<!--
******************************************************************************
* Copyright (c) 2016 Oracle
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Konstantin Komissarchik - initial implementation and ongoing maintenance
******************************************************************************
-->
<project name="corundum.macro.pde-build">
<macrodef name="pde-build">
<attribute name="source"/>
<attribute name="target"/>
<attribute name="feature"/>
<attribute name="build.id"/>
<attribute name="warnings" default="false"/>
<element name="java-args" optional="true" implicit="true"/>
<sequential>
<clean-pde-build source="@{source}"/>
<find-eclipse-bundle property=".pdeBuildDir" eclipse="${builder}" bundle="org.eclipse.pde.build"/>
<delete dir="${build.dir}/pde" quiet="true"/>
<delete dir="${build.dir}/compilelogs" quiet="true"/>
<mkdir dir="${build.dir}/pde"/>
<copy
file="${.pdeBuildDir}/templates/headless-build/build.properties"
todir="${build.dir}/pde/builder"
overwrite="true"/>
<copy
file="${.pdeBuildDir}/templates/headless-build/customTargets.xml"
todir="${build.dir}/pde/builder"
overwrite="true"/>
<var name=".pde.build.args" value="${pde.build.system.properties}"/>
<if>
<or>
<isfalse value="@{warnings}"/>
<isfalse value="${warnings}"/>
</or>
<then>
<append property=".pde.build.args" value="-DcompilerArg=-nowarn" separator=" "/>
</then>
</if>
<append property=".pde.build.args" value="-DjavacFailOnError=true" separator=" "/>
<append property=".pde.build.args" value="-DjavacDebugInfo=true" separator=" "/>
<append property=".pde.build.args" value="-DjavacVerbose=false" separator=" "/>
<!-- Provide the build with the required JDKs based on what's required by the target and what's specified in the plugin manifests -->
<var name=".jdk.versions" unset="true"/>
<with-configuration name="@{target}">
<if>
<isset property=".java.version"/>
<then>
<init-jdk version="${.java.version}"/>
<property name=".jdk.versions" value="#${.java.version}#"/>
</then>
</if>
</with-configuration>
<for param="manifest">
<fileset dir="@{source}/plugins" includes="*/META-INF/MANIFEST.MF"/>
<sequential>
<var name=".plugin" unset="true"/>
<var name=".manifest" unset="true"/>
<var name=".env" unset="true"/>
<var name=".version" unset="true"/>
<propertyregex property=".plugin" input="@{manifest}" regexp=".*[/\\]([^/\\]+)[/\\]META-INF[/\\]MANIFEST.MF" select="\1"/>
<loadfile property=".manifest" srcFile="@{manifest}"/>
<propertyregex property=".env" input="${.manifest}" regexp="Bundle-RequiredExecutionEnvironment: ([a-zA-Z0-9\.\-]+)" select="\1"/>
<var name=".manifest" unset="true"/>
<if>
<isset property=".env"/>
<then>
<propertyregex property=".version" input="${.env}" regexp="JavaSE-1.([0-9]+)" select="\1"/>
<if>
<not><isset property=".version"/></not>
<then>
<propertyregex property=".version" input="${.env}" regexp="J2SE-1.([0-9])" select="\1"/>
</then>
</if>
<if>
<not><isset property=".version"/></not>
<then>
<fail message="Could not recognize execution environment ${.env} of ${.plugin} plugin"/>
</then>
</if>
<var name=".env" unset="true"/>
</then>
<else>
<echo message="Plugin ${.plugin} does not specify Bundle-RequiredExecutionEnvironment"/>
<var name=".version" value="8"/>
</else>
</if>
<if>
<not><contains string="${.jdk.versions}" substring="#${.version}#"/></not>
<then>
<init-jdk version="${.version}"/>
<append property=".jdk.versions" value="#${.version}#" separator=","/>
</then>
</if>
<var name=".version" unset="true"/>
<var name=".plugin" unset="true"/>
</sequential>
</for>
<for list="${.jdk.versions}" param="version" delimiter=",">
<sequential>
<propertyregex property=".version" override="true" input="@{version}" regexp="#([0-9]+)#" select="\1"/>
<if>
<or>
<equals arg1="${.version}" arg2="5"/>
<equals arg1="${.version}" arg2="4"/>
<equals arg1="${.version}" arg2="3"/>
<equals arg1="${.version}" arg2="2"/>
</or>
<then>
<var name=".env" value="J2SE-1.${.version}"/>
</then>
<else>
<var name=".env" value="JavaSE-1.${.version}"/>
</else>
</if>
<propertycopy name=".java.system.classpath" from="java.${.version}.system.classpath" override="true"/>
<append property=".pde.build.args" value="-D${.env}=${.java.system.classpath}" separator=" "/>
<var name=".java.system.classpath" unset="true"/>
<var name=".env" unset="true"/>
<var name=".version" unset="true"/>
</sequential>
</for>
<var name=".jdk.versions" unset="true"/>
<!-- Copy bundles from the target as PDE Build tends to pick up wrong versions of bundles when the
target uses a shared bundle pool -->
<with-target name="@{target}">
<for-each-eclipse-bundle eclipse="${.target}">
<if>
<available file="${.bundle.location}" type="dir"/>
<then>
<copy todir="${build.dir}/pde/target/plugins/${.bundle.file.name}">
<fileset dir="${.bundle.location}"/>
</copy>
</then>
<else>
<copy file="${.bundle.location}" tofile="${build.dir}/pde/target/plugins/${.bundle.file.name}"/>
</else>
</if>
</for-each-eclipse-bundle>
</with-target>
<eclipse location="${builder}" application="org.eclipse.ant.core.antRunner">
<arg line="-clean"/>
<arg line="-data ${build.dir}/pde/workspace"/>
<arg line="-buildfile ${.pdeBuildDir}/scripts/build.xml"/>
<arg value="-DtopLevelElementId=@{feature}"/>
<arg value="-DarchivePrefix=eclipse"/>
<arg value="-DbaseLocation=${build.dir}/pde/target"/>
<arg value="-DbuildDirectory=@{source}"/>
<arg value="-Dbuilder=${build.dir}/pde/builder"/>
<arg value="-DcollectingFolder=collecting"/>
<arg value="-DbuildId=@{build.id}"/>
<arg value="-DbuildType=I"/>
<arg value="-DbuildLabel=build"/>
<arg value="-DforceContextQualifier=@{build.id}"/>
<arg value="-DgenerateFeatureVersionSuffix=false"/>
<arg value="-DindividualSourceBundles=true"/>
<arg value="-DallowBinaryCycles=true" />
<arg line="${.pde.build.args}"/>
<java-args/>
</eclipse>
<var name=".pde.build.args" unset="true"/>
<var name=".pdeBuildDir" unset="true"/>
<delete dir="${build.dir}/pde" quiet="true"/>
<delete dir="${build.dir}/compilelogs" quiet="true"/>
<clean-pde-build source="@{source}"/>
</sequential>
</macrodef>
</project>