⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 project.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one or more *  contributor license agreements.  See the NOTICE file distributed with *  this work for additional information regarding copyright ownership. *  The ASF licenses this file to You under the Apache License, Version 2.0 *  (the "License"); you may not use this file except in compliance with *  the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, software *  distributed under the License is distributed on an "AS IS" BASIS, *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  See the License for the specific language governing permissions and *  limitations under the License. * */package org.apache.tools.ant;import java.io.File;import java.io.IOException;import java.io.EOFException;import java.io.InputStream;import java.lang.reflect.Method;import java.lang.reflect.Modifier;import java.util.Collections;import java.util.Enumeration;import java.util.Hashtable;import java.util.Iterator;import java.util.Properties;import java.util.Stack;import java.util.Vector;import java.util.Set;import java.util.HashSet;import java.util.HashMap;import java.util.Map;import java.util.WeakHashMap;import org.apache.tools.ant.input.DefaultInputHandler;import org.apache.tools.ant.input.InputHandler;import org.apache.tools.ant.helper.DefaultExecutor;import org.apache.tools.ant.types.FilterSet;import org.apache.tools.ant.types.FilterSetCollection;import org.apache.tools.ant.types.Description;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.types.Resource;import org.apache.tools.ant.types.ResourceFactory;import org.apache.tools.ant.types.resources.FileResource;import org.apache.tools.ant.util.FileUtils;import org.apache.tools.ant.util.JavaEnvUtils;import org.apache.tools.ant.util.StringUtils;/** * Central representation of an Ant project. This class defines an * Ant project with all of its targets, tasks and various other * properties. It also provides the mechanism to kick off a build using * a particular target name. * <p> * This class also encapsulates methods which allow files to be referred * to using abstract path names which are translated to native system * file paths at runtime. * */public class Project implements ResourceFactory {    private static final String LINE_SEP = System.getProperty("line.separator");    /** Message priority of &quot;error&quot;. */    public static final int MSG_ERR = 0;    /** Message priority of &quot;warning&quot;. */    public static final int MSG_WARN = 1;    /** Message priority of &quot;information&quot;. */    public static final int MSG_INFO = 2;    /** Message priority of &quot;verbose&quot;. */    public static final int MSG_VERBOSE = 3;    /** Message priority of &quot;debug&quot;. */    public static final int MSG_DEBUG = 4;    /**     * Constant for the &quot;visiting&quot; state, used when     * traversing a DFS of target dependencies.     */    private static final String VISITING = "VISITING";    /**     * Constant for the &quot;visited&quot; state, used when     * traversing a DFS of target dependencies.     */    private static final String VISITED = "VISITED";    /**     * Version constant for Java 1.0 .     *     * @deprecated since 1.5.x.     *             Use {@link JavaEnvUtils#JAVA_1_0} instead.     */    public static final String JAVA_1_0 = JavaEnvUtils.JAVA_1_0;    /**     * Version constant for Java 1.1 .     *     * @deprecated since 1.5.x.     *             Use {@link JavaEnvUtils#JAVA_1_1} instead.     */    public static final String JAVA_1_1 = JavaEnvUtils.JAVA_1_1;    /**     * Version constant for Java 1.2 .     *     * @deprecated since 1.5.x.     *             Use {@link JavaEnvUtils#JAVA_1_2} instead.     */    public static final String JAVA_1_2 = JavaEnvUtils.JAVA_1_2;    /**     * Version constant for Java 1.3 .     *     * @deprecated since 1.5.x.     *             Use {@link JavaEnvUtils#JAVA_1_3} instead.     */    public static final String JAVA_1_3 = JavaEnvUtils.JAVA_1_3;    /**     * Version constant for Java 1.4 .     *     * @deprecated since 1.5.x.     *             Use {@link JavaEnvUtils#JAVA_1_4} instead.     */    public static final String JAVA_1_4 = JavaEnvUtils.JAVA_1_4;    /** Default filter start token. */    public static final String TOKEN_START = FilterSet.DEFAULT_TOKEN_START;    /** Default filter end token. */    public static final String TOKEN_END = FilterSet.DEFAULT_TOKEN_END;    /** Instance of a utility class to use for file operations. */    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();    /** Name of this project. */    private String name;    /** Description for this project (if any). */    private String description;    /** Map of references within the project (paths etc) (String to Object). */    private Hashtable references = new AntRefTable();    /** Map of id references - used for indicating broken build files */    private HashMap idReferences = new HashMap();    /** the parent project for old id resolution (if inheritreferences is set) */    private Project parentIdProject = null;    /** Name of the project's default target. */    private String defaultTarget;    /** Map from target names to targets (String to Target). */    private Hashtable targets = new Hashtable();    /** Set of global filters. */    private FilterSet globalFilterSet = new FilterSet();    {        // Initialize the globalFileSet's project        globalFilterSet.setProject(this);    }    /**     * Wrapper around globalFilterSet. This collection only ever     * contains one FilterSet, but the wrapper is needed in order to     * make it easier to use the FileUtils interface.     */    private FilterSetCollection globalFilters        = new FilterSetCollection(globalFilterSet);    /** Project base directory. */    private File baseDir;    /** List of listeners to notify of build events. */    private Vector listeners = new Vector();    /**     * The Ant core classloader--may be <code>null</code> if using     * parent classloader.     */    private ClassLoader coreLoader = null;    /** Records the latest task to be executed on a thread. */    private Map/*<Thread,Task>*/ threadTasks = Collections.synchronizedMap(new WeakHashMap());    /** Records the latest task to be executed on a thread group. */    private Map/*<ThreadGroup,Task>*/ threadGroupTasks        = Collections.synchronizedMap(new WeakHashMap());    /**     * Called to handle any input requests.     */    private InputHandler inputHandler = null;    /**     * The default input stream used to read any input.     */    private InputStream defaultInputStream = null;    /**     * Keep going flag.     */    private boolean keepGoingMode = false;    /**     * Flag which catches Listeners which try to use System.out or System.err .     */    private boolean loggingMessage = false;    /**     * Set the input handler.     *     * @param handler the InputHandler instance to use for gathering input.     */    public void setInputHandler(InputHandler handler) {        inputHandler = handler;    }    /**     * Set the default System input stream. Normally this stream is set to     * System.in. This inputStream is used when no task input redirection is     * being performed.     *     * @param defaultInputStream the default input stream to use when input     *        is requested.     * @since Ant 1.6     */    public void setDefaultInputStream(InputStream defaultInputStream) {        this.defaultInputStream = defaultInputStream;    }    /**     * Get this project's input stream.     *     * @return the InputStream instance in use by this Project instance to     * read input.     */    public InputStream getDefaultInputStream() {        return defaultInputStream;    }    /**     * Retrieve the current input handler.     *     * @return the InputHandler instance currently in place for the project     *         instance.     */    public InputHandler getInputHandler() {        return inputHandler;    }    /**     * Create a new Ant project.     */    public Project() {        inputHandler = new DefaultInputHandler();    }    /**     * Create and initialize a subproject. By default the subproject will be of     * the same type as its parent. If a no-arg constructor is unavailable, the     * <code>Project</code> class will be used.     * @return a Project instance configured as a subproject of this Project.     * @since Ant 1.7     */    public Project createSubProject() {        Project subProject = null;        try {            subProject = (Project) (getClass().newInstance());        } catch (Exception e) {            subProject = new Project();        }        initSubProject(subProject);        return subProject;    }    /**     * Initialize a subproject.     * @param subProject the subproject to initialize.     */    public void initSubProject(Project subProject) {        ComponentHelper.getComponentHelper(subProject)            .initSubProject(ComponentHelper.getComponentHelper(this));        subProject.setDefaultInputStream(getDefaultInputStream());        subProject.setKeepGoingMode(this.isKeepGoingMode());        subProject.setExecutor(getExecutor().getSubProjectExecutor());    }    /**     * Initialise the project.     *     * This involves setting the default task definitions and loading the     * system properties.     *     * @exception BuildException if the default task list cannot be loaded.     */    public void init() throws BuildException {        initProperties();        ComponentHelper.getComponentHelper(this).initDefaultDefinitions();    }    /**     * Initializes the properties.     * @exception BuildException if an vital property could not be set.     * @since Ant 1.7     */    public void initProperties() throws BuildException {        setJavaVersionProperty();        setSystemProperties();        setPropertyInternal(MagicNames.ANT_VERSION, Main.getAntVersion());        setAntLib();    }    /**     * Set a property to the location of ant.jar.     * Use the locator to find the location of the Project.class, and     * if this is not null, set the property {@link MagicNames#ANT_LIB}     * to the result     */    private void setAntLib() {        File antlib = org.apache.tools.ant.launch.Locator.getClassSource(            Project.class);        if (antlib != null) {            setPropertyInternal(MagicNames.ANT_LIB, antlib.getAbsolutePath());        }    }    /**     * Factory method to create a class loader for loading classes from     * a given path.     *     * @param path the path from which classes are to be loaded.     *     * @return an appropriate classloader.     */    public AntClassLoader createClassLoader(Path path) {        return new AntClassLoader(            getClass().getClassLoader(), this, path);    }    /**     * Factory method to create a class loader for loading classes from     * a given path.     *     * @param parent the parent classloader for the new loader.     * @param path the path from which classes are to be loaded.     *     * @return an appropriate classloader.     */    public AntClassLoader createClassLoader(        ClassLoader parent, Path path) {        return new AntClassLoader(parent, this, path);    }    /**     * Set the core classloader for the project. If a <code>null</code>     * classloader is specified, the parent classloader should be used.     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -