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

📄 main.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        + "an option " + arg + " that is only for the launcher class."                        + "\nThis can be caused by a version mismatch between "                        + "the ant script/.bat file and Ant itself.";                throw new BuildException(msg);            } else if (arg.equals("-autoproxy")) {                proxy = true;            } else if (arg.startsWith("-")) {                // we don't have any more args to recognize!                String msg = "Unknown argument: " + arg;                System.err.println(msg);                printUsage();                throw new BuildException("");            } else {                // if it's no other arg, it may be the target                targets.addElement(arg);            }        }        // if buildFile was not specified on the command line,        if (buildFile == null) {            // but -find then search for it            if (searchForThis != null) {                buildFile = findBuildFile(System.getProperty("user.dir"),                                          searchForThis);            } else {                buildFile = new File(DEFAULT_BUILD_FILENAME);            }        }        // make sure buildfile exists        if (!buildFile.exists()) {            System.out.println("Buildfile: " + buildFile + " does not exist!");            throw new BuildException("Build failed");        }        // make sure it's not a directory (this falls into the ultra        // paranoid lets check everything category        if (buildFile.isDirectory()) {            System.out.println("What? Buildfile: " + buildFile + " is a dir!");            throw new BuildException("Build failed");        }        // Load the property files specified by -propertyfile        loadPropertyFiles();        if (msgOutputLevel >= Project.MSG_INFO) {            System.out.println("Buildfile: " + buildFile);        }        if (logTo != null) {            out = logTo;            err = logTo;            System.setOut(out);            System.setErr(err);        }        readyToRun = true;    }    // --------------------------------------------------------    //    Methods for handling the command line arguments    // --------------------------------------------------------    /** Handle the -buildfile, -file, -f argument */    private int handleArgBuildFile(String[] args, int pos) {        try {            buildFile = new File(                args[++pos].replace('/', File.separatorChar));        } catch (ArrayIndexOutOfBoundsException aioobe) {            throw new BuildException(                "You must specify a buildfile when using the -buildfile argument");        }        return pos;    }    /** Handle -listener argument */    private int handleArgListener(String[] args, int pos) {        try {            listeners.addElement(args[pos + 1]);            pos++;        } catch (ArrayIndexOutOfBoundsException aioobe) {            String msg = "You must specify a classname when "                + "using the -listener argument";            throw new BuildException(msg);        }        return pos;    }    /** Handler -D argument */    private int handleArgDefine(String[] args, int argPos) {        /* Interestingly enough, we get to here when a user         * uses -Dname=value. However, in some cases, the OS         * goes ahead and parses this out to args         *   {"-Dname", "value"}         * so instead of parsing on "=", we just make the "-D"         * characters go away and skip one argument forward.         *         * I don't know how to predict when the JDK is going         * to help or not, so we simply look for the equals sign.         */        String arg = args[argPos];        String name = arg.substring(2, arg.length());        String value = null;        int posEq = name.indexOf("=");        if (posEq > 0) {            value = name.substring(posEq + 1);            name = name.substring(0, posEq);        } else if (argPos < args.length - 1) {            value = args[++argPos];        } else {            throw new BuildException("Missing value for property "                                     + name);        }        definedProps.put(name, value);        return argPos;    }    /** Handle the -logger argument. */    private int handleArgLogger(String[] args, int pos) {        if (loggerClassname != null) {            throw new BuildException(                "Only one logger class may be specified.");        }        try {            loggerClassname = args[++pos];        } catch (ArrayIndexOutOfBoundsException aioobe) {            throw new BuildException(                "You must specify a classname when using the -logger argument");        }        return pos;    }    /** Handle the -inputhandler argument. */    private int handleArgInputHandler(String[] args, int pos) {        if (inputHandlerClassname != null) {            throw new BuildException("Only one input handler class may "                                     + "be specified.");        }        try {            inputHandlerClassname = args[++pos];        } catch (ArrayIndexOutOfBoundsException aioobe) {            throw new BuildException("You must specify a classname when"                                     + " using the -inputhandler"                                     + " argument");        }        return pos;    }    /** Handle the -propertyfile argument. */    private int handleArgPropertyFile(String[] args, int pos) {        try {            propertyFiles.addElement(args[++pos]);        } catch (ArrayIndexOutOfBoundsException aioobe) {            String msg = "You must specify a property filename when "                + "using the -propertyfile argument";            throw new BuildException(msg);        }        return pos;    }    /** Handle the -nice argument. */    private int handleArgNice(String[] args, int pos) {        try {            threadPriority = Integer.decode(args[++pos]);        } catch (ArrayIndexOutOfBoundsException aioobe) {            throw new BuildException(                "You must supply a niceness value (1-10)"                + " after the -nice option");        } catch (NumberFormatException e) {            throw new BuildException("Unrecognized niceness value: "                                     + args[pos]);        }        if (threadPriority.intValue() < Thread.MIN_PRIORITY            || threadPriority.intValue() > Thread.MAX_PRIORITY) {            throw new BuildException(                "Niceness value is out of the range 1-10");        }        return pos;    }    // --------------------------------------------------------    //    other methods    // --------------------------------------------------------    /** Load the property files specified by -propertyfile */    private void loadPropertyFiles() {        for (int propertyFileIndex = 0;             propertyFileIndex < propertyFiles.size();             propertyFileIndex++) {            String filename                = (String) propertyFiles.elementAt(propertyFileIndex);            Properties props = new Properties();            FileInputStream fis = null;            try {                fis = new FileInputStream(filename);                props.load(fis);            } catch (IOException e) {                System.out.println("Could not load property file "                                   + filename + ": " + e.getMessage());            } finally {                FileUtils.close(fis);            }            // ensure that -D properties take precedence            Enumeration propertyNames = props.propertyNames();            while (propertyNames.hasMoreElements()) {                String name = (String) propertyNames.nextElement();                if (definedProps.getProperty(name) == null) {                    definedProps.put(name, props.getProperty(name));                }            }        }    }    /**     * Helper to get the parent file for a given file.     * <p>     * Added to simulate File.getParentFile() from JDK 1.2.     * @deprecated since 1.6.x     *     * @param file   File to find parent of. Must not be <code>null</code>.     * @return       Parent file or null if none     */    private File getParentFile(File file) {        File parent = file.getParentFile();        if (parent != null && msgOutputLevel >= Project.MSG_VERBOSE) {            System.out.println("Searching in " + parent.getAbsolutePath());        }        return parent;    }    /**     * Search parent directories for the build file.     * <p>     * Takes the given target as a suffix to append to each     * parent directory in search of a build file.  Once the     * root of the file-system has been reached an exception     * is thrown.     *     * @param start  Leaf directory of search.     *               Must not be <code>null</code>.     * @param suffix  Suffix filename to look for in parents.     *                Must not be <code>null</code>.     *     * @return A handle to the build file if one is found     *     * @exception BuildException if no build file is found     */    private File findBuildFile(String start, String suffix)         throws BuildException {        if (msgOutputLevel >= Project.MSG_INFO) {            System.out.println("Searching for " + suffix + " ...");        }        File parent = new File(new File(start).getAbsolutePath());        File file = new File(parent, suffix);        // check if the target file exists in the current directory        while (!file.exists()) {            // change to parent directory            parent = getParentFile(parent);            // if parent is null, then we are at the root of the fs,            // complain that we can't find the build file.            if (parent == null) {                throw new BuildException("Could not locate a build file!");            }            // refresh our file handle            file = new File(parent, suffix);        }        return file;    }    /**     * Executes the build. If the constructor for this instance failed     * (e.g. returned after issuing a warning), this method returns     * immediately.     *     * @param coreLoader The classloader to use to find core classes.     *                   May be <code>null</code>, in which case the     *                   system classloader is used.     *     * @exception BuildException if the build fails     */    private void runBuild(ClassLoader coreLoader) throws BuildException {        if (!readyToRun) {            return;        }        final Project project = new Project();        project.setCoreLoader(coreLoader);        Throwable error = null;        try {            addBuildListeners(project);            addInputHandler(project);            PrintStream savedErr = System.err;            PrintStream savedOut = System.out;            InputStream savedIn = System.in;            // use a system manager that prevents from System.exit()            SecurityManager oldsm = null;            oldsm = System.getSecurityManager();                //SecurityManager can not be installed here for backwards                //compatibility reasons (PD). Needs to be loaded prior to                //ant class if we are going to implement it.                //System.setSecurityManager(new NoExitSecurityManager());            try {                if (allowInput) {                    project.setDefaultInputStream(System.in);                }                System.setIn(new DemuxInputStream(project));                System.setOut(new PrintStream(new DemuxOutputStream(project, false)));                System.setErr(new PrintStream(new DemuxOutputStream(project, true)));                if (!projectHelp) {                    project.fireBuildStarted();                }                // set the thread priorities                if (threadPriority != null) {                    try {                        project.log("Setting Ant's thread priority to "                                + threadPriority, Project.MSG_VERBOSE);                        Thread.currentThread().setPriority(threadPriority.intValue());                    } catch (SecurityException swallowed) {                        //we cannot set the priority here.                        project.log("A security manager refused to set the -nice value");                    }                }                project.init();                // set user-define properties                Enumeration e = definedProps.keys();                while (e.hasMoreElements()) {                    String arg = (String) e.nextElement();                    String value = (String) definedProps.get(arg);                    project.setUserProperty(arg, value);                }                project.setUserProperty(MagicNames.ANT_FILE,                                        buildFile.getAbsolutePath());                project.setKeepGoingMode(keepGoingMode);                if (proxy) {                    //proxy setup if enabled                    ProxySetup proxySetup = new ProxySetup(project);                    proxySetup.enableProxies();                }                ProjectHelper.configureProject(project, buildFile);                if (projectHelp) {                    printDescription(project);                    printTargets(project, msgOutputLevel > Project.MSG_INFO);                    return;                }                // make sure that we have a target to execute                if (targets.size() == 0) {                    if (project.getDefaultTarget() != null) {                        targets.addElement(project.getDefaultTarget());                    }                }                project.executeTargets(targets);

⌨️ 快捷键说明

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