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

📄 pathconvert.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  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.taskdefs;import java.io.File;import java.util.List;import java.util.Vector;import java.util.ArrayList;import java.util.StringTokenizer;import org.apache.tools.ant.Task;import org.apache.tools.ant.Project;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.taskdefs.condition.Os;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.types.Mapper;import org.apache.tools.ant.types.Reference;import org.apache.tools.ant.types.ResourceCollection;import org.apache.tools.ant.types.EnumeratedAttribute;import org.apache.tools.ant.types.resources.Union;import org.apache.tools.ant.util.FileNameMapper;/** * Converts path and classpath information to a specific target OS * format. The resulting formatted path is placed into the specified property. * * @since Ant 1.4 * @ant.task category="utility" */public class PathConvert extends Task {    /**     * Set if we're running on windows     */    private static boolean onWindows = Os.isFamily("dos");    // Members    /**     * Path to be converted     */    private Union path = null;    /**     * Reference to path/fileset to convert     */    private Reference refid = null;    /**     * The target OS type     */    private String targetOS = null;    /**     * Set when targetOS is set to windows     */    private boolean targetWindows = false;    /**     * Set if we should create a new property even if the result is empty     */    private boolean setonempty = true;    /**     * The property to receive the conversion     */    private String property = null;    /**     * Path prefix map     */    private Vector prefixMap = new Vector();    /**     * User override on path sep char     */    private String pathSep = null;    /**     * User override on directory sep char     */    private String dirSep = null;    /** Filename mapper */    private Mapper mapper = null;    /**     * Construct a new instance of the PathConvert task.     */    public PathConvert() {    }    /**     * Helper class, holds the nested <map> values. Elements will look like     * this: <map from="d:" to="/foo"/>     *     * When running on windows, the prefix comparison will be case     * insensitive.     */    public class MapEntry {        // Members        private String from = null;        private String to = null;        /**         * Set the "from" attribute of the map entry.         * @param from the prefix string to search for; required.         * Note that this value is case-insensitive when the build is         * running on a Windows platform and case-sensitive when running on         * a Unix platform.         */        public void setFrom(String from) {            this.from = from;        }        /**         * Set the replacement text to use when from is matched; required.         * @param to new prefix.         */        public void setTo(String to) {            this.to = to;        }        /**         * Apply this map entry to a given path element.         *         * @param elem Path element to process.         * @return String Updated path element after mapping.         */        public String apply(String elem) {            if (from == null || to == null) {                throw new BuildException("Both 'from' and 'to' must be set "                     + "in a map entry");            }            // If we're on windows, then do the comparison ignoring case            // and treat the two directory characters the same            String cmpElem =                onWindows ? elem.toLowerCase().replace('\\', '/') : elem;            String cmpFrom =                onWindows ? from.toLowerCase().replace('\\', '/') : from;            // If the element starts with the configured prefix, then            // convert the prefix to the configured 'to' value.            return cmpElem.startsWith(cmpFrom)                ? to + elem.substring(from.length()) : elem;        }    }    /**     * An enumeration of supported targets:     * "windows", "unix", "netware", and "os/2".     */    public static class TargetOs extends EnumeratedAttribute {        /**         * @return the list of values for this enumerated attribute.         */        public String[] getValues() {            return new String[]{"windows", "unix", "netware", "os/2", "tandem"};        }    }    /**     * Create a nested path element.     * @return a Path to be used by Ant reflection.     */    public Path createPath() {        if (isReference()) {            throw noChildrenAllowed();        }        Path result = new Path(getProject());        add(result);        return result;    }    /**     * Add an arbitrary ResourceCollection.     * @param rc the ResourceCollection to add.     * @since Ant 1.7     */    public void add(ResourceCollection rc) {        if (isReference()) {            throw noChildrenAllowed();        }        getPath().add(rc);    }    private synchronized Union getPath() {        if (path == null) {            path = new Union();            path.setProject(getProject());        }        return path;    }    /**     * Create a nested MAP element.     * @return a Map to configure.     */    public MapEntry createMap() {        MapEntry entry = new MapEntry();        prefixMap.addElement(entry);        return entry;    }    /**     * Set targetos to a platform to one of     * "windows", "unix", "netware", or "os/2";     * current platform settings are used by default.     * @param target the target os.     * @deprecated since 1.5.x.     *             Use the method taking a TargetOs argument instead.     * @see #setTargetos(PathConvert.TargetOs)     */    public void setTargetos(String target) {        TargetOs to = new TargetOs();        to.setValue(target);        setTargetos(to);    }    /**     * Set targetos to a platform to one of     * "windows", "unix", "netware", or "os/2";     * current platform settings are used by default.     * @param target the target os     *     * @since Ant 1.5     */    public void setTargetos(TargetOs target) {        targetOS = target.getValue();        // Currently, we deal with only two path formats: Unix and Windows        // And Unix is everything that is not Windows        // for NetWare and OS/2, piggy-back on Windows, since in the        // validateSetup code, the same assumptions can be made as        // with windows - that ; is the path separator

⌨️ 快捷键说明

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