* Added snapshot version resolution using maven-metadata.xml

* moved generated-sources, classes locations etc to target/

* use the correct maven version when generating the pom.properties:
  'BOOTSTRAP' is an illegal version, and causes multiple plugins to
  not run because they require 2.0.2 or newer.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@462848 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kenney Westerhof 2006-10-11 16:44:55 +00:00
parent 591d7948e7
commit 05d91510ad
1 changed files with 85 additions and 25 deletions

110
build.xml
View File

@ -1,4 +1,5 @@
<project default="run-full-maven"> <project default="run-full-maven">
<description> <description>
The first time you build Maven from source, you have to build Maven without Maven. 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 This Ant script builds a minimal Maven, just enough to re-launch Maven again in this
@ -12,6 +13,7 @@
You can set the maven.repo.local property to specify a custom location for your You can set the maven.repo.local property to specify a custom location for your
local repository for the bootstrap process. local repository for the bootstrap process.
</description> </description>
<target name="isMavenHomeSet"> <target name="isMavenHomeSet">
<property environment="env"/> <property environment="env"/>
<condition property="maven.home" value="${env.M2_HOME}"> <condition property="maven.home" value="${env.M2_HOME}">
@ -20,6 +22,7 @@
<fail unless="maven.home" <fail unless="maven.home"
message="You must set the M2_HOME environment variable or specify a maven.home property to this Ant script"/> message="You must set the M2_HOME environment variable or specify a maven.home property to this Ant script"/>
</target> </target>
<target name="checkMavenHome" depends="isMavenHomeSet"> <target name="checkMavenHome" depends="isMavenHomeSet">
<basename file="${maven.home}" property="maven.home.basename"/> <basename file="${maven.home}" property="maven.home.basename"/>
<dirname file="${maven.home}" property="maven.home.dirname"/> <dirname file="${maven.home}" property="maven.home.dirname"/>
@ -33,18 +36,20 @@
</condition> </condition>
<fail if="build.failed"> <fail if="build.failed">
The Maven install destination directory must end with '${maven.home.basename.expected}'. The Maven install destination directory must end with '${maven.home.basename.expected}'.
Your maven.home was = ${maven.home} Your M2_HOME was = ${maven.home}
We recommend = ${maven.home.recommended} We recommend = ${maven.home.recommended}
</fail> </fail>
<echo message="maven.home=${maven.home}"/> <echo message="maven.home=${maven.home}"/>
</target> </target>
<target name="init" depends="checkMavenHome"> <target name="init" depends="checkMavenHome">
<property name="maven.repo.local" value="${user.home}/.m2/repository"/> <property name="maven.repo.local" value="${user.home}/.m2/repository"/>
</target> </target>
<target name="clean-bootstrap" description="cleans up generated bootstrap classes"> <target name="clean-bootstrap" description="cleans up generated bootstrap classes">
<delete dir="bootstrap/generated-sources"/> <delete dir="bootstrap/target"/>
<delete dir="bootstrap/classes"/>
</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 --> <!-- 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...? --> <!-- Then again, this *is* a very simple Ant script, so maybe there's no need to get fancy...? -->
<target name="pull" depends="init" <target name="pull" depends="init"
@ -55,18 +60,16 @@
<attribute name="name"/> <attribute name="name"/>
<attribute name="version"/> <attribute name="version"/>
<sequential> <sequential>
<get src="http://people.apache.org/repo/m2-snapshot-repository/@{orgpath}/@{version}/@{name}-@{version}.jar" <!-- call an ant task to download the artifact. The script cannot be
dest="${maven.repo.local}/@{orgpath}/@{version}/@{name}-@{version}.jar" usetimestamp="true" defined in here, because you cannot re-initialize properties.
ignoreerrors="true"/> Calling the script like this will scope the properties so they can
<get src="http://repo1.maven.org/maven2/@{orgpath}/@{version}/@{name}-@{version}.jar" be re-initialized.
dest="${maven.repo.local}/@{orgpath}/@{version}/@{name}-@{version}.jar" usetimestamp="true" -->
ignoreerrors="false"/> <antcall target="download-artifact" inheritAll="true">
<condition property="build.failed"> <param name="orgpath" value="@{orgpath}"/>
<not> <param name="name" value="@{name}"/>
<available file="${maven.repo.local}/@{orgpath}/@{version}/@{name}-@{version}.jar"/> <param name="version" value="@{version}"/>
</not> </antcall>
</condition>
<fail if="build.failed" message="Couldn't pull dependency @{orgpath}/@{name}/@{version}"/>
</sequential> </sequential>
</macrodef> </macrodef>
<pull orgpath="org/codehaus/plexus/plexus-utils" version="1.1" name="plexus-utils"/> <pull orgpath="org/codehaus/plexus/plexus-utils" version="1.1" name="plexus-utils"/>
@ -84,11 +87,14 @@
<pull orgpath="org/codehaus/modello/modello-core" version="1.0-alpha-7" name="modello-core"/> <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-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="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>
<target name="classpath-pre" depends="init,pull" <target name="classpath-pre" depends="init,pull"
description="constructs a classpath reference containing our dependencies, and verifies that all files are present"> description="constructs a classpath reference containing our dependencies, and verifies that all files are present">
<path id="pre.classpath"> <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}/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 <pathelement
location="${maven.repo.local}/org/codehaus/plexus/plexus-container-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.jar"/> 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}/commons-cli/commons-cli/1.0/commons-cli-1.0.jar"/>
@ -125,9 +131,13 @@ need different versions of modello. -->
<pathconvert property="pre.classpath.str" refid="pre.classpath" pathsep="&#xa;"/> <pathconvert property="pre.classpath.str" refid="pre.classpath" pathsep="&#xa;"/>
<pathconvert property="modello.classpath.str" refid="modello.classpath" pathsep="&#xa;"/> <pathconvert property="modello.classpath.str" refid="modello.classpath" pathsep="&#xa;"/>
</target> </target>
<target name="generate-sources" depends="classpath-pre" <target name="generate-sources" depends="classpath-pre"
description="generates Java sources from Modello mdo model files"> description="generates Java sources from Modello mdo model files"
<mkdir dir="bootstrap/generated-sources"/> >
<mkdir dir="bootstrap/target"/>
<mkdir dir="bootstrap/target/generated-sources"/>
<macrodef name="modello-single-mode"> <macrodef name="modello-single-mode">
<attribute name="file"/> <attribute name="file"/>
<attribute name="mode"/> <attribute name="mode"/>
@ -137,12 +147,13 @@ need different versions of modello. -->
<classpath refid="modello.classpath"/> <classpath refid="modello.classpath"/>
<arg file="@{file}"/> <arg file="@{file}"/>
<arg value="@{mode}"/> <arg value="@{mode}"/>
<arg file="bootstrap/generated-sources"/> <arg file="bootstrap/target/generated-sources"/>
<arg value="@{version}"/> <arg value="@{version}"/>
<arg value="false"/> <arg value="false"/>
</java> </java>
</sequential> </sequential>
</macrodef> </macrodef>
<macrodef name="modello"> <macrodef name="modello">
<attribute name="file"/> <attribute name="file"/>
<attribute name="version" default="1.0.0"/> <attribute name="version" default="1.0.0"/>
@ -153,6 +164,7 @@ need different versions of modello. -->
<modello-single-mode file="@{file}" version="@{version}" mode="xpp3-writer"/> <modello-single-mode file="@{file}" version="@{version}" mode="xpp3-writer"/>
</sequential> </sequential>
</macrodef> </macrodef>
<modello file="maven-model/maven.mdo" version="4.0.0"/> <modello file="maven-model/maven.mdo" version="4.0.0"/>
<!-- DGF TODO turn this into a big <apply> task? write a custom task? --> <!-- 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-descriptor/src/main/mdo/lifecycle.mdo"/>
@ -168,7 +180,7 @@ need different versions of modello. -->
<target name="compile-boot" depends="generate-sources" description="compiles the bootstrap sources"> <target name="compile-boot" depends="generate-sources" description="compiles the bootstrap sources">
<path id="sources"> <path id="sources">
<dirset dir="."> <dirset dir=".">
<include name="bootstrap/generated-sources"/> <include name="bootstrap/target/generated-sources"/>
<include name="*/src/main/*"/> <include name="*/src/main/*"/>
<include name="maven-reporting/maven-reporting-api/src/main/*"/> <include name="maven-reporting/maven-reporting-api/src/main/*"/>
<exclude name="maven-repository-tools/**"/> <exclude name="maven-repository-tools/**"/>
@ -176,19 +188,19 @@ need different versions of modello. -->
</dirset> </dirset>
</path> </path>
<mkdir dir="bootstrap/classes"/> <mkdir dir="bootstrap/target/classes"/>
<javac destdir="bootstrap/classes" debug="on"> <javac destdir="bootstrap/target/classes" debug="on">
<src refid="sources"/> <src refid="sources"/>
<classpath refid="pre.classpath"/> <classpath refid="pre.classpath"/>
</javac> </javac>
<!-- DGF generating a fake pom.properties so Maven thinks it has a version number --> <!-- DGF generating a fake pom.properties so Maven thinks it has a version number -->
<mkdir dir="bootstrap/classes/META-INF/maven/org.apache.maven/maven-core"/> <mkdir dir="bootstrap/target/classes/META-INF/maven/org.apache.maven/maven-core"/>
<echo message="version=BOOTSTRAP" <echo message="version=${pom.project.version}"
file="bootstrap/classes/META-INF/maven/org.apache.maven/maven-core/pom.properties"/> file="bootstrap/target/classes/META-INF/maven/org.apache.maven/maven-core/pom.properties"/>
<path id="maven.classpath"> <path id="maven.classpath">
<pathelement location="bootstrap/classes"/> <pathelement location="bootstrap/target/classes"/>
<path refid="sources"/> <path refid="sources"/>
<path refid="pre.classpath"/> <path refid="pre.classpath"/>
</path> </path>
@ -205,6 +217,7 @@ need different versions of modello. -->
<arg value="install"/> <arg value="install"/>
</java> </java>
</target> </target>
<target name="maven-assembly" depends="maven-compile" <target name="maven-assembly" depends="maven-compile"
description="generates the Maven installation assembly using the bootstrap Maven"> description="generates the Maven installation assembly using the bootstrap Maven">
<java fork="true" dir="maven-cli" classname="org.apache.maven.cli.MavenCli" failonerror="true"> <java fork="true" dir="maven-cli" classname="org.apache.maven.cli.MavenCli" failonerror="true">
@ -223,11 +236,13 @@ need different versions of modello. -->
<fail if="build.failed" <fail if="build.failed"
message="Assembly task seemed to succeed, but couldn't find assembly file: ${maven.assembly}"/> message="Assembly task seemed to succeed, but couldn't find assembly file: ${maven.assembly}"/>
</target> </target>
<target name="extract-assembly" depends="init,maven-assembly" <target name="extract-assembly" depends="init,maven-assembly"
description="extracts the maven assembly into maven.home"> description="extracts the maven assembly into maven.home">
<delete dir="${maven.home}"/> <delete dir="${maven.home}"/>
<unzip src="${maven.assembly}" dest="${maven.home.dirname}"/> <unzip src="${maven.assembly}" dest="${maven.home.dirname}"/>
</target> </target>
<target name="run-full-maven" depends="init,extract-assembly" <target name="run-full-maven" depends="init,extract-assembly"
description="runs the full extracted Maven, now with tests"> description="runs the full extracted Maven, now with tests">
<property name="maven.goals" value="clean install"/> <property name="maven.goals" value="clean install"/>
@ -245,4 +260,49 @@ need different versions of modello. -->
<arg line="${maven.goals}"/> <arg line="${maven.goals}"/>
</java> </java>
</target> </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>
<!-- 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}-${version}.jar"/>
</not>
</condition>
<fail if="build.failed" message="Couldn't pull dependency ${orgpath}/${name}/${version}"/>
</target>
</project> </project>