o Committing changes submitted by Trygve Laugst��l to accomodate the new form

of specifying a parent model to use which is of the form:

<parent>
  <groupId/>
  <artifactId/>
  <version/>
</parent>

This allows us to work consistently from the local repository or the unified
source root where missing models are downloaded now that we have the required
information within the <parent/> element.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162656 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2004-04-12 14:40:35 +00:00
parent a6bc88eff0
commit a771832d41
4 changed files with 157 additions and 31 deletions

View File

@ -163,13 +163,24 @@ buildMavenProject()
# $1 == directory where project lives
# $2 == jar name
# $3 == flag to install
# $4 == flag to leave mboot files
# $4 == flag to install pom
# $5 == flag to leave mboot files
(
home=`pwd`
cd $1
# If the user only want to install the POM skip the rest
if [ "$3" == "0" ] && [ "$4" == "1" ]
then
installPom
return
fi
# Look for source directory in project.xml
sourceDirectory=`grep sourceDirectory project.xml | sed -e 's/^*//;s/<sourceDirectory>//;s/<\/sourceDirectory>//;s/\${basedir}\///'`
@ -196,7 +207,7 @@ buildMavenProject()
runJava ${MBOOT_HOME}/classes Bootstrapper ${home}
isCommandSuccessful $? "Failed running project parser!"
bootstrapClasspath=`cat bootstrap.classpath`
if $cygwin = true; then
@ -249,7 +260,7 @@ buildMavenProject()
else
jarName=$2
fi
echo "Building jars (${jarName}) in `pwd`/target"
buildJar $buildDest target/${jarName}
@ -259,17 +270,19 @@ buildMavenProject()
findAndSetMavenRepoLocal
groupId=`cat project.xml | tr '\n' ' ' | sed 's#<dependencies>.*</dependencies>##' | grep '<groupId>' | sed -e 's#^.*<groupId>##;s#</groupId>.*$##'`
groupId=`getGroupId`
echo "Installing ${jarName} in ${repoLocal}/${groupId}/jars"
mkdir -p ${repoLocal}/${groupId}/jars > /dev/null 2>&1
cp target/${jarName} ${repoLocal}/${groupId}/jars
installPom
fi
if [ "$4" = "0" ]
if [ "$5" = "0" ]
then
rm -f bootstrap.classpath > /dev/null 2>&1
rm -f bootstrap.libs > /dev/null 2>&1
@ -284,6 +297,23 @@ buildMavenProject()
)
}
installPom()
{
findAndSetMavenRepoLocal
groupId=`getGroupId`
pomName=`getPomName project.xml`
dir=${repoLocal}/${groupId}/poms
echo "Installing POM in ${dir}/${pomName}"
mkdir -p ${dir}
cp project.xml ${dir}/${pomName}
}
getJarName()
{
# $1 == project.xml
@ -307,6 +337,35 @@ getJarName()
echo $jarName
}
# returns the name under which the pom should be installed
getPomName()
{
version=`cat $1 | tr '\n' ' ' | sed 's#<versions>.*</versions>##' | sed 's#<dependencies>.*</dependencies>##' | grep '<version>' | sed -e 's#^.*<version>##;s#</version>.*$##'`
if [ -z $version ]
then
version=`grep currentVersion $1 | sed -e 's/^ *//;s/<currentVersion>//;s/<\/currentVersion>//'`
fi
artifactId=`cat $1 | tr '\n' ' ' | sed 's#<dependencies>.*</dependencies>##' | grep '<artifactId>' | sed -e 's#^.*<artifactId>##;s#</artifactId>.*$##'`
if [ -z $artifactId ]
then
artifactId=`cat $1 | tr '\n' ' ' | sed 's#<versions>.*</versions>##' | sed 's#<developers>.*</developers>##' | sed 's#<dependencies>.*</dependencies>##' | grep '<id>' | sed -e 's#^.*<id>##;s#</id>.*$##'`
fi
pomName="${artifactId}-${version}.pom"
echo $pomName
}
getGroupId()
{
groupId=`cat project.xml | tr '\n' ' ' | sed 's#<dependencies>.*</dependencies>##' | grep '<groupId>' | sed -e 's#^.*<groupId>##;s#</groupId>.*$##'`
echo $groupId
}
copyResources()
{
# $1 == resourcesfile

View File

@ -4,7 +4,7 @@ VERSION=1.0
usage ()
{
echo "usage: `basename $0` [--dir=<directory>] [--jar=<name>] [--leave-boot-files] [--version] [--help]" >&2
echo "usage: `basename $0` [--dir=<directory>] [--jar=<name>] [--install] [--pom-install] [-v] [--leave-boot-files] [--version] [--help]" >&2
echo "" >&2
echo " (ex: `basename $0` --dir=../builds/plexus --jar=plexus.jar)" >&2
exit 1
@ -14,6 +14,7 @@ dir="."
jar="default"
leaveBootFiles="0"
install="0"
pomInstall="0"
while [ $# -gt 0 ]; do
case $1 in
@ -49,6 +50,9 @@ while [ $# -gt 0 ]; do
--install)
install=1;
;;
--pom-install)
pomInstall=1;
;;
esac
shift
@ -62,4 +66,4 @@ export MBOOT_HOME=`dirname $0`
[ ! -f $dir/project.xml ] && echo "No project.xml in specified directory!" && exit
buildMavenProject $dir $jar $install $leaveBootFiles
buildMavenProject $dir $jar $install $pomInstall $leaveBootFiles

View File

@ -35,14 +35,14 @@ while [ $# -gt 0 ]; do
shift
fi
;;
--model-version*)
if echo $1 | grep -q '=' ; then
model_version=`echo $1 | sed 's/^--model-version=//'`
else
model_version=$2
shift
fi
;;
# --model-version*)
# if echo $1 | grep -q '=' ; then
# model_version=`echo $1 | sed 's/^--model-version=//'`
# else
# model_version=$2
# shift
# fi
# ;;
--model*)
if echo $1 | grep -q '=' ; then
model=`echo $1 | sed 's/^--model=//'`
@ -80,4 +80,5 @@ if $cygwin; then
CP=`cygpath -pw "$CP"`
fi
java -classpath "$CP" org.codehaus.modello.Modello $model $mode "$dir" $model_version
java -classpath "$CP" org.codehaus.modello.Modello $model $mode "$dir"
# $model_version

View File

@ -1,11 +1,4 @@
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
@ -19,12 +12,23 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class Bootstrapper
{
private ArtifactDownloader downloader;
private BootstrapPomParser bootstrapPomParser;
private int pomVersion;
private List dependencies;
private UnitTests unitTests;
@ -48,7 +52,11 @@ public class Bootstrapper
bootstrapPomParser = new BootstrapPomParser();
bootstrapPomParser.parse( new File( "project.xml" ) );
if( ! bootstrapPomParser.parse( new File( "project.xml" ) ) )
{
System.err.println( "Could not parse project.xml" );
System.exit( 1 );
}
dependencies = bootstrapPomParser.getDependencies();
@ -377,6 +385,12 @@ public class Bootstrapper
class BootstrapPomParser
extends DefaultHandler
{
private String parentGroupId;
private String parentArtifactId;
private String parentVersion;
private List dependencies = new ArrayList();
private UnitTests unitTests;
@ -389,6 +403,8 @@ public class Bootstrapper
private SAXParserFactory saxFactory;
private boolean insideParent = false;
private boolean insideDependency = false;
private boolean insideUnitTest = false;
@ -414,7 +430,7 @@ public class Bootstrapper
return resources;
}
public void parse( File file )
public boolean parse( File file )
{
this.file = file;
@ -427,16 +443,24 @@ public class Bootstrapper
InputSource is = new InputSource( new FileInputStream( file ) );
parser.parse( is, this );
return true;
}
catch ( Exception e )
{
e.printStackTrace();
return false;
}
}
public void startElement( String uri, String localName, String rawName, Attributes attributes )
{
if ( rawName.equals( "unitTest" ) )
if ( rawName.equals( "parent" ) )
{
insideParent = true;
}
else if ( rawName.equals( "unitTest" ) )
{
unitTests = new UnitTests();
@ -467,22 +491,45 @@ public class Bootstrapper
}
public void endElement( String uri, String localName, String rawName )
throws SAXException
{
if ( rawName.equals( "extend" ) )
if ( rawName.equals( "parent" ) )
{
String extend = interpolate( getBodyText(), properties );
File f;
File f = new File( file.getParentFile(), extend );
// support both v3 <extend> and v4 <parent>
if( getBodyText() == null )
{
String extend = interpolate( getBodyText(), properties );
f = new File( file.getParentFile(), extend );
}
else
{
if ( parentArtifactId == null || parentArtifactId.trim().length() == 0 )
throw new SAXException( "Missing required element in <parent>: artifactId." );
if ( parentGroupId == null || parentGroupId.trim().length() == 0 )
throw new SAXException( "Missing required element in <parent>: groupId." );
if ( parentVersion == null || parentVersion.trim().length() == 0 )
throw new SAXException( "Missing required element in <parent>: version." );
f = new File( downloader.getMavenRepoLocal(), parentGroupId + "/poms/" + parentArtifactId + "-" + parentVersion + ".pom" );
}
BootstrapPomParser p = new BootstrapPomParser();
p.parse( f );
if ( ! p.parse( f ) )
throw new SAXException( "Could not parse parent project.xml" );
dependencies.addAll( p.getDependencies() );
unitTests = p.getUnitTests();
resources.addAll( p.getResources() );
insideParent = false;
}
else if ( rawName.equals( "unitTest" ) )
{
@ -507,6 +554,21 @@ public class Bootstrapper
insideResource = false;
}
else if ( insideParent )
{
if ( rawName.equals( "groupId" ) )
{
parentGroupId = getBodyText();
}
else if ( rawName.equals( "artifactId" ) )
{
parentArtifactId = getBodyText();
}
else if ( rawName.equals( "version" ) )
{
parentVersion = getBodyText();
}
}
else if ( insideDependency )
{
if ( rawName.equals( "id" ) )