You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2004/04/12 16:40:35 UTC

cvs commit: maven-components/maven-mboot/src/main Bootstrapper.java

jvanzyl     2004/04/12 07:40:35

  Modified:    maven-mboot/src/bash maven.functions mboot modello
               maven-mboot/src/main Bootstrapper.java
  Log:
  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.
  
  Revision  Changes    Path
  1.34      +65 -6     maven-components/maven-mboot/src/bash/maven.functions
  
  Index: maven.functions
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/src/bash/maven.functions,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- maven.functions	10 Apr 2004 04:54:01 -0000	1.33
  +++ maven.functions	12 Apr 2004 14:40:35 -0000	1.34
  @@ -163,13 +163,24 @@
       # $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 @@
         runJava ${MBOOT_HOME}/classes Bootstrapper ${home}
         
         isCommandSuccessful $? "Failed running project parser!"
  -      
  +
         bootstrapClasspath=`cat bootstrap.classpath`
   
         if $cygwin = true; then
  @@ -249,7 +260,7 @@
         else
           jarName=$2
         fi
  -      
  +
         echo "Building jars (${jarName}) in `pwd`/target"
           
         buildJar $buildDest target/${jarName}
  @@ -259,17 +270,19 @@
           
           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 @@
       )
   }
   
  +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
  @@ -305,6 +335,35 @@
     jarName="${artifactId}-${version}.jar"
     
     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.7       +6 -2      maven-components/maven-mboot/src/bash/mboot
  
  Index: mboot
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/src/bash/mboot,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- mboot	7 Feb 2004 16:55:04 -0000	1.6
  +++ mboot	12 Apr 2004 14:40:35 -0000	1.7
  @@ -4,7 +4,7 @@
   
   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 @@
   jar="default"
   leaveBootFiles="0"
   install="0"
  +pomInstall="0"
   
   while [ $# -gt 0 ]; do
       case $1 in
  @@ -49,6 +50,9 @@
   	--install)
   	    install=1;
   	    ;;
  +	--pom-install)
  +	    pomInstall=1;
  +	    ;;
       esac
   
       shift
  @@ -62,4 +66,4 @@
   
   [ ! -f $dir/project.xml ] && echo "No project.xml in specified directory!" && exit
   
  -buildMavenProject $dir $jar $install $leaveBootFiles
  +buildMavenProject $dir $jar $install $pomInstall $leaveBootFiles
  
  
  
  1.5       +10 -9     maven-components/maven-mboot/src/bash/modello
  
  Index: modello
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/src/bash/modello,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- modello	9 Mar 2004 23:55:53 -0000	1.4
  +++ modello	12 Apr 2004 14:40:35 -0000	1.5
  @@ -35,14 +35,14 @@
   		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 @@
     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
  
  
  
  1.20      +76 -14    maven-components/maven-mboot/src/main/Bootstrapper.java
  
  Index: Bootstrapper.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot/src/main/Bootstrapper.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Bootstrapper.java	23 Mar 2004 02:03:20 -0000	1.19
  +++ Bootstrapper.java	12 Apr 2004 14:40:35 -0000	1.20
  @@ -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.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 @@
   
           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 @@
       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 @@
   
           private SAXParserFactory saxFactory;
   
  +        private boolean insideParent = false;
  +
           private boolean insideDependency = false;
   
           private boolean insideUnitTest = false;
  @@ -414,7 +430,7 @@
               return resources;
           }
   
  -        public void parse( File file )
  +        public boolean parse( File file )
           {
               this.file = file;
   
  @@ -427,16 +443,24 @@
                   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 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;
  +
  +                // 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." );
   
  -                File f = new File( file.getParentFile(), extend );
  +                    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" ) )
               {
  @@ -506,6 +553,21 @@
                   }
   
                   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 )
               {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org