blob: 1bceb78d54c0931f6ae1f9721be9b9268fbbc0f9 [file] [log] [blame]
<!--/*******************************************************************************
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
* Ant naming conventions:
* - regardless of the actual OS platform,'/' is the directory separator
* (Ant will convert as appropriate).
* - multi-word properties use periods '.'
* - properties ending in .jar define jarfile names only (no path)
* - properties ending in .lib are fully qualified jars (path and filename)
* - properties ending in .dir are directory paths
* - properties ending in .path are path refid names (classpath fragments)
* - multi-word targets use hyphens '-'
* - targets beginning with test- are reserved for high level test targets,
* and are used in test results parsing
* - targets typically use the form <action>-<object>-<type> (ie. package-bundle-zip)
* - multi-word macros use underscores '_'
* - multi-word macro attributes are concatenated
* e.g. 'runpathref'
* - multi-word tasks (taskdef) names are concatenated
* e.g. 'validateconnection'
* - OS environment variables are in ALLCAPS and have 'env' as a prefix
* e.g. ${env.XXX}.
* - Ant properties are lower case.
*
* Contributors:
* mmeswani - initial API and implementation (checked in by tware)
* egwin - updated variables as they have changed in the rest of the system
* updated svnversion to not break build, and default if exec fails
* egwin - updated for publishing to Maven Central, add ability to override
* destination URL (to pub elsewhere override ${maven.repo.url})
* egwin - converted svn.revision to git.hash (was missed in original
* migration to Git)
* egwin - migrated to javax.persistence
#******************************************************************************/-->
<!-- Variables Needed:
* build.type - should be set to "SNAPSHOT, "M##", or "RELEASE"
* git.hash - for stamping pom, to link build with source repo
*
*********************************************************************************-->
<!-- Build Assumptions:
* running from a "view"
* Needs:
* ${mavenant.dir}/maven-ant-tasks-2.0.8.jar (assumes: ${build.deps.dir}/mavenant)
* ../eclipselink.releng/ant_customizations.jar
*
*********************************************************************************-->
<project name="Upload2Maven" basedir="." xmlns:artifact="urn:maven-artifact-ant" default="info">
<property file="${user.home}/build.properties"/>
<!-- The following properties defined so they can be overridden for testing -->
<property name="mavenant.dir" value="${build.deps.dir}/mavenant"/>
<property name="eclipselink.root.download.dir" value="home/data/httpd/download.eclipse.org/rt/eclipselink"/>
<path id="maven-ant-tasks.classpath" path="${mavenant.dir}/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant"
classpathref="maven-ant-tasks.classpath" />
<!-- Tool version definitions -->
<property name="gpg.plugin.version" value="1.4"/>
<property name="wagon.http.version" value="2.4"/>
<!-- "maven dir" defined for later use ensuring only single upload occurs -->
<property name="maven.repo.dir" value="${eclipselink.root.download.dir}/maven.repo"/>
<!-- The repository info of where maven artifacts will be uploaded -->
<!-- Override value to change defaults -->
<property name="stagingId" value="eclipselink.repository"/>
<property name="stagingURL" value="file:///${maven.repo.dir}"/>
<property name="snapshotId" value="eclipselink.repository"/>
<property name="snapshotURL" value="file:///${maven.repo.dir}"/>
<target name="init">
<dirname property="maven.build.location_temp" file="${ant.file.Upload2Maven}"/>
<pathconvert targetos="unix" property="maven.build.location">
<path>
<pathelement location="${maven.build.location_temp}"/>
</path>
</pathconvert>
<property file="${user.home}/build.properties"/>
<!-- discover path definitions -->
<property name="maven.2.target.dir" value="${maven.build.location}/target"/>
<property name="maven.2.releng.dir" value="${maven.build.location}/../eclipselink.releng"/>
<echo message="maven.build.location = ${maven.build.location}"/>
<echo message="maven.2.target.dir = ${maven.2.target.dir}"/>
<echo message="maven.2.releng.dir = ${maven.2.releng.dir}"/>
<!-- Test for Basic run requirements -->
<available file="${maven.2.releng.dir}" type="dir" property="releng.exist"/>
<fail message="Cannot find Releng repo! Exiting." unless="releng.exist"/>
<!-- Custom task definitions -->
<property name="custom.tasks.lib" value="${maven.2.releng.dir}/ant_customizations.jar"/>
<property name="custom.echo.task.class" value="org.eclipse.persistence.buildtools.ant.taskdefs.Say"/>
<property name="custom.selectbundle.task.class" value="org.eclipse.persistence.buildtools.ant.taskdefs.SelectBundle"/>
<property name="custom.stripqualifier.task.class" value="org.eclipse.persistence.buildtools.ant.taskdefs.StripQualifier"/>
<taskdef name="say" classname="${custom.echo.task.class}" classpath="${custom.tasks.lib}"/>
<taskdef name="selectbundle" classname="${custom.selectbundle.task.class}" classpath="${custom.tasks.lib}"/>
<taskdef name="stripQualifier" classname="${custom.stripqualifier.task.class}" classpath="${custom.tasks.lib}"/>
<property name="bundle.prefix" value="javax.persistence"/>
<property name="bundle.criteria" value="[2.0.100, 2.2)"/>
<property name="bundle.name" value="Javax Persistence"/>
<!-- Determine Version info from built bundle filename -->
<selectbundle basename="${bundle.prefix}" directory="${maven.2.target.dir}"
criterion="${bundle.criteria}" property="OSGi.version" versiononly="true"
/>
<say message="OSGi.version: ${OSGi.version}" if="OSGi.version"/>
<fail message="${OSGi.version} property not set! SelectBundle failure. Exiting..." unless="OSGi.version"/>
<!-- Maven standards state we should publish with a stripped down 3-part version rather -->
<!-- than the 4-part OSGi version. So we need to generate a "base.version" from the -->
<!-- discovered "OSGi.version". "base.version" will be combined with build.type to get -->
<!-- the actual "maven.version" -->
<stripQualifier input="${OSGi.version}" property="base.version"/>
<say message="base.version: ${base.version}" if="base.version"/>
<fail message="${base.version} property not set! StripQualifier failure. Exiting..." unless="base.version"/>
<say message="build.type: ${build.type}" if="build.type"/>
<fail message="Cannot upload to Maven without a build.type defined!" unless="build.type"/>
<!-- used to determine whether to publish if version exists, and could also be used if -->
<!-- pgp signing required (not currently used in eclipse maven.repo) -->
<condition property="sign">
<not> <equals arg1="${build.type}" arg2="SNAPSHOT"/> </not>
</condition>
<!-- Set maven.version appropriately depending upon ${build.type}. -->
<!-- variable should only be used for maven version element in POM. -->
<condition property="maven.version" value="${base.version}"
else="${base.version}-${build.type}">
<equals arg1="${build.type}" arg2="RELEASE"/>
</condition>
<say message="maven.version: ${maven.version}"/>
<say message="git.hash: ${git.hash}" if="git.hash"/>
<fail message="Cannot upload to Maven without 'git.hash' defined!" unless="git.hash"/>
<condition property="target.repo.message" value="Target repository ID: '${stagingId}' URL:'${stagingURL}'"
else="Target repository ID: '${snapshotId}' URL:'${snapshotURL}'">
<isset property="sign"/>
</condition>
<echo message="${target.repo.message}"/>
</target>
<target name="info" depends="init, verify-publish">
<say message="If above info is correct, and you want to pubish for real, Re-run specifying target 'upload'."/>
</target>
<target name="upload" depends="init">
<antcall target="upload-artifact">
<param name="repo.dir" value="/${maven.repo.dir}/org/eclipse/persistence/${bundle.prefix}/${maven.version}"/>
<param name="groupId" value="org.eclipse.persistence"/>
<param name="artifactId" value="${bundle.prefix}"/>
<param name="artifactVersion" value="${maven.version}"/>
<param name="artifact" value="${maven.2.target.dir}/${bundle.prefix}_${bundle.version}.jar"/>
<param name="artifactSrc" value="${maven.2.target.dir}/${bundle.prefix}.source_${bundle.version}.jar"/>
<param name="artifactJavadoc" value="${maven.2.target.dir}/${bundle.prefix}.javadoc_${bundle.version}.jar"/>
<param name="artifactName" value="${bundle.name}"/>
<param name="dependencies" value=""/>
</antcall>
</target>
<!-- Generic targets to do the Maven work -->
<target name="prepare-pom">
<!-- Copy pom.template to pom.xml filtering various properties -->
<copy file="pom.xml.template" tofile="pom.xml" overwrite="true">
<filterset>
<filter token="groupId" value="${groupId}"/>
<filter token="version" value="${artifactVersion}"/>
<filter token="git.hash" value="${git.hash}"/>
<filter token="artifactId" value="${artifactId}"/>
<filter token="artifactName" value="${artifactName}"/>
<filter token="dependencies" value="${dependencies}"/>
</filterset>
</copy>
</target>
<target name="verify-publish">
<available file="${maven.repo.dir}" property="repo.exist" type="dir" value="true"/>
<say message="Repository: '${maven.repo.dir}' inaccessible. Upload will fail." unless="repo.exist"/>
<fail message="Repository inaccessible" unless="repo.exist"/>
<available file="${repo.dir}" property="repo.version.exist" type="dir" value="true"/>
<condition property="publish.ok">
<or>
<!-- if unpublished staging -->
<and>
<isset property="sign"/>
<not><isset property="repo.version.exist"/></not>
</and>
<!-- if snapshot -->
<not><isset property="sign"/></not>
</or>
</condition>
<condition property="publish.message"
value="'${artifactName}' version '${artifactVersion}' SNAPSHOT upload ok."
else="'${artifactName}' version '${artifactVersion}' never deployed to ... upload ok.">
<equals arg1="${build.type}" arg2="SNAPSHOT"/>
</condition>
<say message="'${artifactName}' version '${artifactVersion}' already deployed to repository... skipping." unless="publish.ok"/>
<say message="${publish.message}" if="publish.ok"/>
</target>
<!-- Uploads a single artifact & source to maven repository -->
<target name="upload-artifact" if="publish.ok" depends="verify-publish, prepare-pom"> <!-- , upload-snapshot, upload-artifact-staging, upload-source-staging"> -->
<!-- only needed if publishing to two repos (staging and snapshot)
<delete file="pom.xml"/>
</target>
<target name="upload-snapshot" unless="sign"> -->
<!-- Deploy the jar to maven repository along with sources -->
<artifact:pom id="maven.project" file="pom.xml" />
<!-- Deploy Artifact to repote repo, attach source and javadoc -->
<artifact:deploy file="${artifact}">
<artifact:remoteRepository id="${snapshotId}" url="${snapshotURL}"/>
<artifact:pom id="maven.project" file="pom.xml"/>
<artifact:attach file="${artifactSrc}" type="jar" classifier="sources"/>
<!-- artifact:attach file="${artifactJavadoc}" type=zip classifier="javadoc"/ -->
</artifact:deploy>
<!-- cleanup -->
<delete file="pom.xml"/>
</target>
<!-- Staging targets -->
<target name="upload-artifact-staging" if="publish.ok" >
<!-- sign and deploy the main artifact -->
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:${gpg.plugin.version}:sign-and-deploy-file"/>
<arg value="-Durl=${stagingURL}"/>
<arg value="-DrepositoryId=${stagingId}"/>
<arg value="-DpomFile=${maven.build.location}/pom.xml"/>
<arg value="-Dfile=${artifact}"/>
<arg value="-Pgpg"/>
</artifact:mvn>
</target>
<target name="upload-source-staging" if="publish.ok" >
<!-- sign and deploy the sources artifact -->
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:${gpg.plugin.version}:sign-and-deploy-file"/>
<arg value="-Durl=${stagingURL}"/>
<arg value="-DrepositoryId=${stagingId}"/>
<arg value="-DpomFile=${maven.build.location}/pom.xml"/>
<arg value="-Dfile=${artifactSrc}"/>
<arg value="-Dclassifier=sources"/>
<arg value="-Pgpg"/>
</artifact:mvn>
</target>
<target name="upload-javadoc-staging" if="publish.ok" >
<!-- sign and deploy the javadoc artifact -->
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:${gpg.plugin.version}:sign-and-deploy-file"/>
<arg value="-Durl=${stagingURL}"/>
<arg value="-DrepositoryId=${stagingId}"/>
<arg value="-DpomFile=${maven.build.location}/pom.xml"/>
<arg value="-Dfile=${artifactJavadoc}"/>
<arg value="-Dclassifier=javadoc"/>
<arg value="-Pgpg"/>
</artifact:mvn>
</target>
</project>