maven/build.xml

332 lines
16 KiB
XML
Raw Normal View History

<project default="run-full-maven">
<description>
The first time you build Maven from source, you have to build Maven without Maven.
This Ant script builds a minimal Maven, just enough to re-launch Maven again in this
directory and generate an installation assembly. Then we extract the assembly and
re-run the Maven build one more time, this time with the full generated Maven.
To run this script, you must set the M2_HOME environment variable or the maven.home
property to the location that should contain Maven. This directory *must* be named
after the maven version you want to install, e.g. /usr/local/maven-2.1-SNAPSHOT.
You can set the maven.repo.local property to specify a custom location for your
local repository for the bootstrap process.
</description>
<target name="isMavenHomeSet">
<property environment="env"/>
<condition property="maven.home" value="${env.M2_HOME}">
<isset property="env.M2_HOME"/>
</condition>
<fail unless="maven.home"
message="You must set the M2_HOME environment variable or specify a maven.home property to this Ant script"/>
</target>
<target name="checkMavenHome" depends="isMavenHomeSet">
<basename file="${maven.home}" property="maven.home.basename"/>
<dirname file="${maven.home}" property="maven.home.dirname"/>
<xmlproperty prefix="pom" file="pom.xml"/>
<property name="maven.home.basename.expected" value="maven-${pom.project.version}"/>
<property name="maven.home.recommended" location="${maven.home.dirname}/${maven.home.basename.expected}"/>
<condition property="build.failed">
<not>
<equals arg1="${maven.home.basename}" arg2="${maven.home.basename.expected}"/>
</not>
</condition>
<fail if="build.failed">
The Maven install destination directory must end with '${maven.home.basename.expected}'.
Your M2_HOME was = ${maven.home}
We recommend = ${maven.home.recommended}
</fail>
<echo message="maven.home=${maven.home}"/>
</target>
<target name="init" depends="checkMavenHome">
<property name="maven.repo.local" value="${user.home}/.m2/repository"/>
</target>
<target name="clean-bootstrap" description="cleans up generated bootstrap classes">
<delete dir="bootstrap/target"/>
</target>
<!-- DGF TODO Make a simple Java Ant task that pulls dependencies and adds them to a path reference, so we don't have to copy-and-paste -->
<!-- Then again, this *is* a very simple Ant script, so maybe there's no need to get fancy...? -->
<target name="pull" depends="init"
description="copies all required dependencies from the Maven remote repository into your local repository. Set the 'skip.pull' property to skip this step, but only if you're sure you already have all of the dependencies downloaded to your local repository"
unless="skip.pull">
<macrodef name="pull">
<attribute name="orgpath"/>
<attribute name="name"/>
<attribute name="version"/>
<sequential>
<!-- call an ant task to download the artifact. The script cannot be
defined in here, because you cannot re-initialize properties.
Calling the script like this will scope the properties so they can
be re-initialized.
-->
<antcall target="download-artifact" inheritAll="true">
<param name="orgpath" value="@{orgpath}"/>
<param name="name" value="@{name}"/>
<param name="version" value="@{version}"/>
</antcall>
</sequential>
</macrodef>
<pull orgpath="org/codehaus/plexus/plexus-utils" version="1.1" name="plexus-utils"/>
<pull orgpath="org/codehaus/plexus/plexus-container-default" version="1.0-alpha-9" name="plexus-container-default"/>
<pull orgpath="commons-cli/commons-cli" version="1.0" name="commons-cli"/>
<pull orgpath="org/apache/maven/wagon/wagon-provider-api" version="1.0-beta-1" name="wagon-provider-api"/>
<pull orgpath="classworlds/classworlds" version="1.1-alpha-2" name="classworlds"/>
<pull orgpath="org/codehaus/plexus/plexus-interactivity-api" version="1.0-alpha-4" name="plexus-interactivity-api"/>
<pull orgpath="org/apache/maven/wagon/wagon-file" version="1.0-alpha-7" name="wagon-file"/>
<pull orgpath="org/apache/maven/wagon/wagon-http-lightweight" version="1.0-alpha-6" name="wagon-http-lightweight"/>
<pull orgpath="org/apache/maven/wagon/wagon-provider-api" version="1.0-beta-1" name="wagon-provider-api"/>
<pull orgpath="org/apache/maven/wagon/wagon-ssh-external" version="1.0-alpha-6" name="wagon-ssh-external"/>
<pull orgpath="org/apache/maven/wagon/wagon-ssh" version="1.0-alpha-7" name="wagon-ssh"/>
<pull orgpath="org/apache/maven/doxia/doxia-sink-api" version="1.0-alpha-9-SNAPSHOT" name="doxia-sink-api"/>
<pull orgpath="org/codehaus/modello/modello-core" version="1.0-alpha-7" name="modello-core"/>
<pull orgpath="org/codehaus/modello/modello-plugin-xml" version="1.0-alpha-8" name="modello-plugin-xml"/>
<pull orgpath="org/codehaus/modello/modello-plugin-xpp3" version="1.0-alpha-8" name="modello-plugin-xpp3"/>
<pull orgpath="junit/junit" version="3.8.1" name="junit"/>
</target>
<target name="classpath-pre" depends="init,pull"
description="constructs a classpath reference containing our dependencies, and verifies that all files are present">
<path id="pre.classpath">
<pathelement location="${maven.repo.local}/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar"/>
<pathelement location="${maven.repo.local}/junit/junit/3.8.1/junit-3.8.1.jar"/>
<pathelement
location="${maven.repo.local}/org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar"/>
<pathelement location="${maven.repo.local}/commons-cli/commons-cli/1.0/commons-cli-1.0.jar"/>
<pathelement
location="${maven.repo.local}/org/apache/maven/wagon/wagon-provider-api/1.0-beta-1/wagon-provider-api-1.0-beta-1.jar"/>
<pathelement location="${maven.repo.local}/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar"/>
<pathelement
location="${maven.repo.local}/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar"/>
<pathelement
location="${maven.repo.local}/org/apache/maven/wagon/wagon-file/1.0-alpha-7/wagon-file-1.0-alpha-7.jar"/>
<pathelement
location="${maven.repo.local}/org/apache/maven/wagon/wagon-http-lightweight/1.0-alpha-6/wagon-http-lightweight-1.0-alpha-6.jar"/>
<pathelement
location="${maven.repo.local}/org/apache/maven/wagon/wagon-provider-api/1.0-beta-1/wagon-provider-api-1.0-beta-1.jar"/>
<pathelement
location="${maven.repo.local}/org/apache/maven/wagon/wagon-ssh-external/1.0-alpha-6/wagon-ssh-external-1.0-alpha-6.jar"/>
<pathelement
location="${maven.repo.local}/org/apache/maven/wagon/wagon-ssh/1.0-alpha-7/wagon-ssh-1.0-alpha-7.jar"/>
<pathelement
location="${maven.repo.local}/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-9-SNAPSHOT/doxia-sink-api-1.0-alpha-9-20060810.220042-2.jar"/>
</path>
<!-- DGF Need to keep these modello classes out of the system classpath at runtime, because different parts of the build
need different versions of modello. -->
<path id="modello.classpath">
<path refid="pre.classpath"/>
<pathelement
location="${maven.repo.local}/org/codehaus/modello/modello-core/1.0-alpha-7/modello-core-1.0-alpha-7.jar"/>
<pathelement
location="${maven.repo.local}/org/codehaus/modello/modello-plugin-xml/1.0-alpha-8/modello-plugin-xml-1.0-alpha-8.jar"/>
<pathelement
location="${maven.repo.local}/org/codehaus/modello/modello-plugin-xpp3/1.0-alpha-8/modello-plugin-xpp3-1.0-alpha-8.jar"/>
</path>
<!-- DGF pathconvert immediately so we can validate the classpath -->
<pathconvert property="pre.classpath.str" refid="pre.classpath" pathsep="&#xa;"/>
<pathconvert property="modello.classpath.str" refid="modello.classpath" pathsep="&#xa;"/>
</target>
<target name="generate-sources" depends="classpath-pre"
description="generates Java sources from Modello mdo model files"
>
<mkdir dir="bootstrap/target"/>
<mkdir dir="bootstrap/target/generated-sources"/>
<macrodef name="modello-single-mode">
<attribute name="file"/>
<attribute name="mode"/>
<attribute name="version"/>
<sequential>
<java fork="false" classname="org.codehaus.modello.ModelloCli" failonerror="true">
<classpath refid="modello.classpath"/>
<arg file="@{file}"/>
<arg value="@{mode}"/>
<arg file="bootstrap/target/generated-sources"/>
<arg value="@{version}"/>
<arg value="false"/>
</java>
</sequential>
</macrodef>
<macrodef name="modello">
<attribute name="file"/>
<attribute name="version" default="1.0.0"/>
<sequential>
<echo taskname="modello" message="Generating sources for @{file}"/>
<modello-single-mode file="@{file}" version="@{version}" mode="java"/>
<modello-single-mode file="@{file}" version="@{version}" mode="xpp3-reader"/>
<modello-single-mode file="@{file}" version="@{version}" mode="xpp3-writer"/>
</sequential>
</macrodef>
<modello file="maven-model/maven.mdo" version="4.0.0"/>
<!-- DGF TODO turn this into a big <apply> task? write a custom task? -->
<modello file="maven-plugin-descriptor/src/main/mdo/lifecycle.mdo"/>
<modello file="maven-plugin-parameter-documenter/src/main/mdo/paramdoc.mdo"/>
<modello file="maven-plugin-registry/plugin-registry.mdo"/>
<modello file="maven-plugin-tools/maven-plugin-tools-model/src/main/mdo/plugin-metadata.mdo"/>
<modello file="maven-profile/profiles.mdo"/>
<modello file="maven-repository-metadata/src/main/mdo/metadata.mdo"/>
<modello file="maven-repository-metadata/src/main/mdo/plugins.mdo"/>
<modello file="maven-settings/settings.mdo"/>
</target>
<target name="compile-boot" depends="generate-sources" description="compiles the bootstrap sources">
<path id="sources">
<dirset dir=".">
<include name="bootstrap/target/generated-sources"/>
<include name="*/src/main/*"/>
<include name="maven-reporting/maven-reporting-api/src/main/*"/>
<exclude name="maven-repository-tools/**"/>
<exclude name="maven-core-it-verifier/**"/>
</dirset>
</path>
<mkdir dir="bootstrap/target/classes"/>
<javac destdir="bootstrap/target/classes" debug="on">
<src refid="sources"/>
<classpath refid="pre.classpath"/>
</javac>
<!-- DGF generating a fake pom.properties so Maven thinks it has a version number -->
<mkdir dir="bootstrap/target/classes/META-INF/maven/org.apache.maven/maven-core"/>
<echo message="version=${pom.project.version}"
file="bootstrap/target/classes/META-INF/maven/org.apache.maven/maven-core/pom.properties"/>
<path id="maven.classpath">
<pathelement location="bootstrap/target/classes"/>
<path refid="sources"/>
<path refid="pre.classpath"/>
</path>
</target>
<target name="maven-compile" depends="compile-boot"
description="compiles Maven using the bootstrap Maven, skipping automated tests">
<java fork="true" classname="org.apache.maven.cli.MavenCli" failonerror="true">
<classpath refid="maven.classpath"/>
<sysproperty key="maven.test.skip" value="true"/>
<arg value="-e"/>
<arg value="-X"/>
<arg value="clean"/>
<arg value="install"/>
</java>
</target>
<target name="maven-assembly" depends="maven-compile"
description="generates the Maven installation assembly using the bootstrap Maven">
<java fork="true" dir="maven-cli" classname="org.apache.maven.cli.MavenCli" failonerror="true">
<classpath refid="maven.classpath"/>
<sysproperty key="maven.test.skip" value="true"/>
<arg value="-e"/>
<arg value="clean"/>
<arg value="assembly:assembly"/>
</java>
<property name="maven.assembly" location="maven-cli/target/${maven.home.basename.expected}-bin.zip"/>
<condition property="build.failed">
<not>
<available file="${maven.assembly}"/>
</not>
</condition>
<fail if="build.failed"
message="Assembly task seemed to succeed, but couldn't find assembly file: ${maven.assembly}"/>
</target>
<target name="extract-assembly" depends="init,maven-assembly"
description="extracts the maven assembly into maven.home">
<delete dir="${maven.home}"/>
<unzip src="${maven.assembly}" dest="${maven.home.dirname}"/>
<chmod perm="+x">
<fileset dir="${maven.home}/bin">
<include name="mvn"/>
<include name="m2"/>
</fileset>
</chmod>
</target>
<target name="mits"
description="Run the Maven integration tests."
depends="init">
<java fork="true"
dir="maven-core-it-new"
classname="org.apache.maven.cli.MavenCli"
failonerror="true">
<classpath refid="maven.classpath"/>
<arg value="-e"/>
<arg value="clean"/>
<arg value="test"/>
</java>
</target>
<target name="run-full-maven" depends="init,extract-assembly"
description="runs the full extracted Maven, now with tests">
<property name="maven.goals" value="clean install"/>
<java classname="org.codehaus.classworlds.Launcher" fork="true" failonerror="true">
<!--<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=NONE"/>-->
<classpath>
<fileset dir="${maven.home}/core/boot" includes="classworlds-*.jar"/>
</classpath>
<sysproperty key="classworlds.conf" value="${maven.home}/bin/m2.conf"/>
<sysproperty key="maven.home" value="${maven.home}"/>
<arg value="-e"/>
<arg line="${maven.goals}"/>
</java>
</target>
<!--
Downloads an artifact, detecting wheter it's a snapshot, and uses the maven-metadata.xml to retrieve
the correct version.
-->
<target name="download-artifact">
<!-- choose the proper repository -->
<condition property="repo" value="http://people.apache.org/repo/m2-snapshot-repository"
else="http://repo1.maven.org/maven2">
<contains string="${version}" substring="SNAPSHOT"/>
</condition>
<mkdir dir="${maven.repo.local}/${orgpath}/${version}"/>
<!-- get the metadata file -->
<get src="${repo}/${orgpath}/${version}/maven-metadata.xml"
dest="${maven.repo.local}/${orgpath}/${version}/bootstrap-maven-metadata.xml" usetimestamp="true"
ignoreerrors="true"
/>
<!-- Replace 'SNAPSHOT' with 'timestamp-buildnumber'. This is ugly but
ant doesn't allow updating of properties.
-->
<xmlproperty file="${maven.repo.local}/${orgpath}/${version}/bootstrap-maven-metadata.xml"/>
<echo file="deleteme.version.properties" message="${version}"/>
<replaceregexp file="deleteme.version.properties"
match="SNAPSHOT"
replace="${metadata.versioning.snapshot.timestamp}-${metadata.versioning.snapshot.buildNumber}"
byline="true"/>
<loadfile srcFile="deleteme.version.properties" property="fileversion"/>
<echo>Resolved version ${fileversion} (given=${version})</echo>
<!-- download the final jar -->
<get src="${repo}/${orgpath}/${version}/${name}-${fileversion}.jar"
dest="${maven.repo.local}/${orgpath}/${version}/${name}-${fileversion}.jar" usetimestamp="true"
ignoreerrors="false"
/>
<condition property="build.failed">
<not>
<available file="${maven.repo.local}/${orgpath}/${version}/${name}-${fileversion}.jar"/>
</not>
</condition>
<fail if="build.failed" message="Couldn't pull dependency ${orgpath}/${name}/${version}"/>
</target>
</project>