git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271198 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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> | |||
| @@ -72,6 +72,7 @@ import org.apache.ant.common.model.Target; | |||
| 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 @@ import org.apache.ant.init.InitConfig; | |||
| * @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 @@ public class ExecutionFrame { | |||
| configureServices(); | |||
| componentManager.setStandardLibraries(standardLibs); | |||
| setMagicProperties(); | |||
| } | |||
| /** | |||
| @@ -248,6 +247,17 @@ public class ExecutionFrame { | |||
| addProperties(System.getProperties()); | |||
| } | |||
| /** | |||
| * 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 | |||
| * | |||
| @@ -606,17 +616,17 @@ public class ExecutionFrame { | |||
| Target target = project.getTarget(targetName); | |||
| String ifCondition = target.getIfCondition(); | |||
| String unlessCondition = target.getUnlessCondition(); | |||
| if (ifCondition != null) { | |||
| ifCondition = dataService.replacePropertyRefs(ifCondition.trim()); | |||
| if (!isDataValueSet(ifCondition)) { | |||
| return; | |||
| } | |||
| } | |||
| if (unlessCondition != null) { | |||
| unlessCondition | |||
| = dataService.replacePropertyRefs(unlessCondition.trim()); | |||
| unlessCondition | |||
| = dataService.replacePropertyRefs(unlessCondition.trim()); | |||
| if (isDataValueSet(unlessCondition)) { | |||
| return; | |||
| } | |||
| @@ -712,8 +722,9 @@ public class ExecutionFrame { | |||
| * 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 @@ public class ExecutionFrame { | |||
| } 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(); | |||
| @@ -747,7 +758,7 @@ public class ExecutionFrame { | |||
| fileService = new ExecutionFileService(this); | |||
| componentManager | |||
| = new ComponentManager(this, config.isRemoteLibAllowed()); | |||
| dataService = new ExecutionDataService(this, | |||
| dataService = new ExecutionDataService(this, | |||
| config.isUnsetPropertiesAllowed()); | |||
| services.put(FileService.class, fileService); | |||
| @@ -56,6 +56,7 @@ import org.apache.ant.common.antlib.AntContext; | |||
| 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 class Ant1Factory extends StandardLibFactory { | |||
| */ | |||
| 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 | |||
| * | |||
| @@ -196,5 +203,16 @@ public class Ant1Factory extends StandardLibFactory { | |||
| 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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,72 @@ | |||
| /* | |||
| * 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"; | |||
| } | |||
| @@ -147,6 +147,43 @@ public class LoaderUtils { | |||
| 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 | |||