You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 1999/12/14 00:11:52 UTC

cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs Ant.java defaults.properties

costin      99/12/13 15:11:52

  Modified:    ant/src/main/org/apache/tools/ant Main.java Project.java
                        ProjectHelper.java
               ant/src/main/org/apache/tools/ant/taskdefs
                        defaults.properties
  Added:       ant/src/main/org/apache/tools/ant/taskdefs Ant.java
  Log:
  - Added a new task to call Ant in a subproject.
  - -f == -buildfile ( as in make -f )
  - allow user to set basedir in command line
  ( usefull if you run ant from crontab and you want to avoid cds )
  
  Revision  Changes    Path
  1.11      +2 -1      jakarta-tools/ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Main.java	1999/12/12 22:06:01	1.10
  +++ Main.java	1999/12/13 23:11:51	1.11
  @@ -119,7 +119,7 @@
   	    } else if (arg.equals("-verbose") || arg.equals("-v") ||
   		       arg.equals("v")) {
   		msgOutputLevel = Project.MSG_VERBOSE;
  -            } else if (arg.equals("-buildfile") || arg.equals("-file")) {
  +            } else if (arg.equals("-buildfile") || arg.equals("-file") || arg.equals("-f")) {
   		try {
   		    buildFile = new File(args[i+1]);
   		    i++;
  @@ -210,6 +210,7 @@
   	} catch (BuildException be) {
   	    String msg = "BUILD CONFIG ERROR: ";
   	    System.out.println(msg + be.getMessage());
  +	    be.printStackTrace();
   	    exit(1);
   	}
   
  
  
  
  1.21      +3 -0      jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Project.java	1999/12/13 20:02:50	1.20
  +++ Project.java	1999/12/13 23:11:51	1.21
  @@ -144,6 +144,9 @@
       public void setOutputLevel(int msgOutputLevel) {
   	this.msgOutputLevel = msgOutputLevel;
       }
  +    public int getOutputLevel() {
  +	return this.msgOutputLevel;
  +    }
       
       public void log(String msg) {
   	log(msg, MSG_INFO);
  
  
  
  1.9       +18 -14    jakarta-tools/ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ProjectHelper.java	1999/12/12 02:20:33	1.8
  +++ ProjectHelper.java	1999/12/13 23:11:51	1.9
  @@ -71,7 +71,7 @@
   
   public class ProjectHelper {
   
  -    static void configureProject(Project project, File buildFile)
  +    public static void configureProject(Project project, File buildFile)
   	throws BuildException
       {
   
  @@ -105,21 +105,25 @@
   	project.setName(root.getAttribute("name"));
   	project.setDefaultTarget(root.getAttribute("default"));
   
  -	String baseDir = root.getAttribute("basedir");
  -	if (!baseDir.equals("")) {
  -	    try {
  -		project.setBaseDir(new File(new File(baseDir)
  -					    .getCanonicalPath()));
  -	    } catch (IOException ioe) {
  -		String msg = "Can't set basedir " + baseDir + " due to " +
  -		    ioe.getMessage();
  -		throw new BuildException(msg);
  +	if( project.getProperty( "basedir" ) == null) {
  +	    String baseDir = root.getAttribute("basedir");
  +	    if (!baseDir.equals("")) {
  +		try {
  +		    project.setBaseDir(new File(new File(baseDir)
  +			.getCanonicalPath()));
  +		} catch (IOException ioe) {
  +		    String msg = "Can't set basedir " + baseDir + " due to " +
  +			ioe.getMessage();
  +		    throw new BuildException(msg);
  +		}
  +	    } else {
  +		// Using clunky JDK1.1 methods here
  +		String absPath = buildFile.getAbsolutePath();
  +		String parentPath = new File(absPath).getParent();
  +		project.setBaseDir(new File(parentPath));
   	    }
   	} else {
  -            // Using clunky JDK1.1 methods here
  -            String absPath = buildFile.getAbsolutePath();
  -            String parentPath = new File(absPath).getParent();
  -	    project.setBaseDir(new File(parentPath));
  +	    project.setBaseDir( new File( project.getProperty("basedir")));
   	}
   
   	// set up any properties that may be in the config file
  
  
  
  1.13      +1 -0      jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- defaults.properties	1999/12/11 23:00:22	1.12
  +++ defaults.properties	1999/12/13 23:11:52	1.13
  @@ -19,3 +19,4 @@
   tstamp=org.apache.tools.ant.taskdefs.Tstamp
   property=org.apache.tools.ant.taskdefs.Property
   taskdef=org.apache.tools.ant.taskdefs.Taskdef
  +ant=org.apache.tools.ant.taskdefs.Ant
  
  
  
  1.1                  jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.*;
  import java.io.*;
  import java.util.*;
  
  /**
   * Call Ant in  a sub-project
   *
   * @author costin@dnt.ro
   */
  public class Ant extends Task {
  
      private String dir = null;
      private String antFile = null;
      private String target = null;
      
      /**
       * Do the execution.
       */
      public void execute() throws BuildException {
  	Project p1=new Project();
  	p1.setOutputLevel( project.getOutputLevel() );
  	
  	// set user-define properties
  	Hashtable prop1=project.getProperties();
          Enumeration e = prop1.keys();
          while (e.hasMoreElements()) {
              String arg = (String)e.nextElement();
              String value = (String)prop1.get(arg);
              p1.setUserProperty(arg, value);
          }
  	
  	p1.setBasedir( dir );
  	p1.setUserProperty( "basedir" , dir);
  	ProjectHelper.configureProject(p1, new File(antFile));
  
  	if (target == null) {
  	    target = p1.getDefaultTarget();
  	}
  
  	p1.executeTarget( target );
  	
      }
      
      public void setDir(String d) {
          this.dir = d;
      }
  
      public void setAntfile(String s) {
          this.antFile = s;
      }
  
      public void setTarget(String s) {
          this.target = s;
      }
  
  
  }