ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/proposal/mutant/src/java/init/org/apache/ant/init LoaderUtils.java
Date Thu, 07 Feb 2002 09:43:17 GMT
conor       02/02/07 01:43:17

  Modified:    proposal/mutant ant1compat.xml
               proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution
                        ExecutionFrame.java
               proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant
                        Ant1Factory.java
               proposal/mutant/src/java/init/org/apache/ant/init
                        LoaderUtils.java
  Added:       proposal/mutant/src/java/common/org/apache/ant/common/service
                        MagicProperties.java
  Log:
  Additional features for classpath management
  
  Revision  Changes    Path
  1.4       +1 -1      jakarta-ant/proposal/mutant/ant1compat.xml
  
  Index: ant1compat.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/ant1compat.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- ant1compat.xml	6 Feb 2002 10:15:04 -0000	1.3
  +++ ant1compat.xml	7 Feb 2002 09:43:17 -0000	1.4
  @@ -278,7 +278,7 @@
       <copy todir="${bin.dir}/ant1compat">
         <fileset dir="${bin.dir}/ant1src" excludes="**/*.java"/>
       </copy>
  -    <jar basedir="${bin.dir}/ant1compat" jarfile="${distlib.dir}/antlibs/ant1compat.tsk">
  +    <jar basedir="${bin.dir}/ant1compat" jarfile="${distlib.dir}/antlibs/ant1compat.jar">
         <metainf dir="${java.dir}/antlibs/ant1compat" 
                   includes="antlib.xml"/>
       </jar>
  
  
  
  1.10      +22 -11    jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java
  
  Index: ExecutionFrame.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -u -r1.9 -r1.10
  --- ExecutionFrame.java	6 Feb 2002 12:52:57 -0000	1.9
  +++ ExecutionFrame.java	7 Feb 2002 09:43:17 -0000	1.10
  @@ -72,6 +72,7 @@
   import org.apache.ant.common.service.ComponentService;
   import org.apache.ant.common.service.DataService;
   import org.apache.ant.common.service.FileService;
  +import org.apache.ant.common.service.MagicProperties;
   import org.apache.ant.common.util.AntException;
   import org.apache.ant.common.util.ConfigException;
   import org.apache.ant.common.util.ExecutionException;
  @@ -88,9 +89,6 @@
    * @created 14 January 2002
    */
   public class ExecutionFrame {
  -    /** A magic property which sets the execution base directory */
  -    public final static String BASEDIR_PROP = "basedir";
  -
       /** The Ant aspect used to identify Ant metadata */
       public final static String ANT_ASPECT = "ant";
   
  @@ -206,6 +204,7 @@
   
           configureServices();
           componentManager.setStandardLibraries(standardLibs);
  +        setMagicProperties();
       }
   
       /**
  @@ -249,6 +248,17 @@
       }
   
       /**
  +     * Set the values of various magic properties
  +     *
  +     * @exception ExecutionException if the properties cannot be set
  +     */
  +    protected void setMagicProperties() throws ExecutionException {
  +        // set up various magic properties
  +        setDataValue(MagicProperties.ANT_HOME,
  +            initConfig.getAntHome().toString(), true);
  +    }
  +
  +    /**
        * Gets the project model this frame is working with
        *
        * @return the project model
  @@ -712,8 +722,9 @@
        *      determined
        */
       private void determineBaseDirs() throws ExecutionException {
  -        if (isDataValueSet(BASEDIR_PROP)) {
  -            baseDir = new File(getDataValue(BASEDIR_PROP).toString());
  +        if (isDataValueSet(MagicProperties.BASEDIR)) {
  +            baseDir
  +                 = new File(getDataValue(MagicProperties.BASEDIR).toString());
           } else {
               URL projectURL = project.getSourceURL();
               if (projectURL.getProtocol().equals("file")) {
  @@ -729,8 +740,8 @@
               } else {
                   baseDir = new File(".");
               }
  -            setDataValue(BASEDIR_PROP, baseDir.getPath(), true);
           }
  +        setDataValue(MagicProperties.BASEDIR, baseDir.getAbsolutePath(), true);
   
           for (Iterator i = getReferencedFrames(); i.hasNext(); ) {
               ExecutionFrame refFrame = (ExecutionFrame)i.next();
  
  
  
  1.4       +18 -0     jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java
  
  Index: Ant1Factory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- Ant1Factory.java	6 Feb 2002 10:15:04 -0000	1.3
  +++ Ant1Factory.java	7 Feb 2002 09:43:17 -0000	1.4
  @@ -56,6 +56,7 @@
   import org.apache.ant.common.antlib.Converter;
   import org.apache.ant.common.antlib.StandardLibFactory;
   import org.apache.ant.common.util.ExecutionException;
  +import org.apache.ant.init.LoaderUtils;
   
   /**
    * The factory object for the Ant1 compatability Ant library
  @@ -81,10 +82,16 @@
        */
       public void init(AntContext context) throws ExecutionException {
           this.context = context;
  +        // set the system classpath. In Ant2, the system classpath will not
  +        // in general, have any useful information. For Ant1 compatability
  +        // we set it now to include the Ant1 facade classes
  +        System.setProperty("java.class.path", getAnt1Classpath());
  +
           project = new Project();
           project.init(context);
       }
   
  +
       /**
        * Create an instance of the requested type class
        *
  @@ -195,6 +202,17 @@
               ProjectComponent component = (ProjectComponent)createdElement;
               component.setProject(project);
           }
  +    }
  +
  +    /**
  +     * Get an Ant1 equivalent classpath
  +     *
  +     * @return an Ant1 suitable classpath
  +     */
  +    String getAnt1Classpath() {
  +        ClassLoader classLoader = getClass().getClassLoader();
  +        String path = LoaderUtils.getClasspath(classLoader);
  +        return path;
       }
   }
   
  
  
  
  1.1                  jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service/MagicProperties.java
  
  Index: MagicProperties.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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", "Ant", 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.ant.common.service;
  
  /**
   * Ant's magic properties
   *
   * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
   * @created 7 February 2002
   */
  public class MagicProperties {
      /**
       * This property describes the basedir which is being used for an Ant
       * run.
       */
      public final static String BASEDIR = "basedir";
  
      /** This property provides the location of Ant's home directory */
      public final static String ANT_HOME = "ant.home";
  }
  
  
  
  
  1.4       +37 -0     jakarta-ant/proposal/mutant/src/java/init/org/apache/ant/init/LoaderUtils.java
  
  Index: LoaderUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/init/org/apache/ant/init/LoaderUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- LoaderUtils.java	2 Feb 2002 14:50:34 -0000	1.3
  +++ LoaderUtils.java	7 Feb 2002 09:43:17 -0000	1.4
  @@ -147,6 +147,43 @@
           return urls;
       }
   
  +    /**
  +     * Get the classpath from a classloader. This can only extract path
  +     * components from the loaders which are instances of URLClassLoaders
  +     *
  +     * @param loader the loader whose path is required
  +     * @return the loader's configuration expressed as a classpath
  +     */
  +    public static String getClasspath(ClassLoader loader) {
  +        StringBuffer pathBuffer = null;
  +        if (loader instanceof URLClassLoader) {
  +            URLClassLoader urlLoader = (URLClassLoader)loader;
  +            URL[] urls = urlLoader.getURLs();
  +            for (int i = 0; i < urls.length; ++i) {
  +                if (!urls[i].getProtocol().equals("file")) {
  +                    continue;
  +                }
  +                String pathElement = urls[i].getFile();
  +                if (pathBuffer == null) {
  +                    pathBuffer = new StringBuffer(pathElement);
  +                } else {
  +                    pathBuffer.append(File.pathSeparatorChar);
  +                    pathBuffer.append(pathElement);
  +                }
  +            }
  +        }
  +        String path = pathBuffer == null ? "" : pathBuffer.toString();
  +        ClassLoader parentLoader = loader.getParent();
  +        if (parentLoader != null) {
  +            String parentPath = getClasspath(parentLoader);
  +            if (parentPath.length() != 0) {
  +                path = parentPath + File.pathSeparator + path;
  +            }
  +        }
  +
  +        return path;
  +    }
  +
   
       /**
        * Debug method to dump a class loader hierarchy to a PrintStream
  
  
  

--
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