ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/helper ProjectHelper2.java
Date Tue, 24 Dec 2002 17:40:35 GMT
costin      2002/12/24 09:40:35

  Modified:    src/main/org/apache/tools/ant/helper ProjectHelper2.java
  Log:
  Make the basedir of each project available.
  
  I added both ant.file.NAME and basedir.NAME, and cleaned up a bit
  the code.
  
  Revision  Changes    Path
  1.4       +41 -29    jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  
  Index: ProjectHelper2.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProjectHelper2.java	17 Dec 2002 05:47:16 -0000	1.3
  +++ ProjectHelper2.java	24 Dec 2002 17:40:34 -0000	1.4
  @@ -119,7 +119,7 @@
       public void parse(Project project, Object source, RootHandler handler)
               throws BuildException
       {
  -        
  +        long t1=System.currentTimeMillis();
           AntXmlContext context=handler.context;
   
           if(source instanceof File) {
  @@ -158,6 +158,11 @@
               context.parser.setErrorHandler(hb);
               context.parser.setDTDHandler(hb);
               context.parser.parse(inputSource);
  +
  +            long t2=System.currentTimeMillis();
  +            //project.log("parsing buildfile " + context.buildFile +
  +            //        " with URI = " + uri + " in " + ( t2-t1 ) , Project.MSG_INFO);
  +
           } catch(SAXParseException exc) {
               Location location =
                   new Location(exc.getSystemId(), exc.getLineNumber(), exc.getColumnNumber());
  @@ -569,11 +574,12 @@
               for (int i = 0; i < attrs.getLength(); i++) {
                   String key = attrs.getQName(i);
                   String value = attrs.getValue(i);
  -                
  +
                   if (key.equals("default")) {
                       if ( value != null && !value.equals("")) {
  -                        if( !context.ignoreProjectTag )
  +                        if( !context.ignoreProjectTag ) {
                               project.setDefaultTarget(value);
  +                        }
                       }
                   } else if (key.equals("name")) {
                       if (value != null) {
  @@ -582,7 +588,7 @@
                           if( !context.ignoreProjectTag ) {
                               project.setName(value);
                               project.addReference(value, project);
  -                        } 
  +                        }
                       }
                   } else if (key.equals("id")) {
                       if (value != null) {
  @@ -592,38 +598,45 @@
                           }
                       }
                   } else if (key.equals("basedir")) {
  -                    if( !context.ignoreProjectTag )
  -                        baseDir = value;
  +                    baseDir = value;
                   } else {
                       // XXX ignore attributes in a different NS ( maybe store them ? )
  -                    throw new SAXParseException("Unexpected attribute \"" + attrs.getQName(i)
+ "\"", context.locator);
  +                    throw new SAXParseException("Unexpected attribute \"" +
  +                            attrs.getQName(i) + "\"", context.locator);
                   }
               }
   
  -            if( context.ignoreProjectTag ) {
  -                // no further processing
  -                return;
  -            }
  -            // set explicitely before starting ?
  -            if (project.getProperty("basedir") != null) {
  -                project.setBasedir(project.getProperty("basedir"));
  +            // make the location available ( for imported files and top level )
  +            project.setUserProperty("ant.file."+context.currentProjectName,
  +                    context.buildFile.toString());
  +
  +            if (baseDir == null) {
  +                baseDir=context.buildFile.getAbsolutePath();
               } else {
  -                // Default for baseDir is the location of the build file.
  -                if (baseDir == null) {
  -                    project.setBasedir(context.buildFileParent.getAbsolutePath());
  -                } else {
  -                    // check whether the user has specified an absolute path
  -                    if ((new File(baseDir)).isAbsolute()) {
  -                        project.setBasedir(baseDir);
  -                    } else {
  -                        project.setBaseDir(project.resolveFile(baseDir,
  -                                                               context.buildFileParent));
  -                    }
  +                // check whether the user has specified an absolute path
  +                if (! (new File(baseDir)).isAbsolute()) {
  +                    baseDir=project.resolveFile(baseDir,
  +                            context.buildFileParent).toString();
                   }
               }
  -            
  -            project.addTarget("", context.implicitTarget);
  -            context.currentTarget=context.implicitTarget;
  +            // set basedir.NAME for all projects
  +            project.setUserProperty("basedir." + context.currentProjectName,
  +                        baseDir);
  +
  +            // setBasedir - only for top level project
  +            if( ! context.ignoreProjectTag ) {
  +               if (project.getProperty("basedir") != null) {
  +                    project.setBasedir(project.getProperty("basedir"));
  +               } else {
  +                    project.setBasedir(baseDir);
  +               }
  +            }
  +
  +            // Create an implicit target - only top level project
  +            if( ! context.ignoreProjectTag ) {
  +                project.addTarget("", context.implicitTarget);
  +                context.currentTarget=context.implicitTarget;
  +            }
           }
   
           /**
  @@ -834,7 +847,6 @@
                  delayed eval */
               UnknownElement task= new UnknownElement(qname);
               task.setProject(context.getProject());
  -            //XXX task.setTaskType(qname);
   
               task.setTaskName(qname);
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message