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

📄 main.java

📁 java ant的源码!非常值得看的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    listeners.addElement(args[i + 1]);                    i++;                } catch (ArrayIndexOutOfBoundsException aioobe) {                    String msg = "You must specify a classname when "                        + "using the -listener argument";                    throw new BuildException(msg);                }            } else if (arg.startsWith("-D")) {                /* 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 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 (i < args.length - 1) {                    value = args[++i];                } else {                    throw new BuildException("Missing value for property "                                             + name);                }                definedProps.put(name, value);            } else if (arg.equals("-logger")) {                if (loggerClassname != null) {                    throw new BuildException("Only one logger class may "                        + " be specified.");                }                try {                    loggerClassname = args[++i];                } catch (ArrayIndexOutOfBoundsException aioobe) {                    throw new BuildException("You must specify a classname when"                                             + " using the -logger argument");                }            } else if (arg.equals("-inputhandler")) {                if (inputHandlerClassname != null) {                    throw new BuildException("Only one input handler class may "                                             + "be specified.");                }                try {                    inputHandlerClassname = args[++i];                } catch (ArrayIndexOutOfBoundsException aioobe) {                    throw new BuildException("You must specify a classname when"                                             + " using the -inputhandler"                                             + " argument");                }            } else if (arg.equals("-emacs") || arg.equals("-e")) {                emacsMode = true;            } else if (arg.equals("-projecthelp") || arg.equals("-p")) {                // set the flag to display the targets and quit                projectHelp = true;            } else if (arg.equals("-find") || arg.equals("-s")) {                // eat up next arg if present, default to build.xml                if (i < args.length - 1) {                    searchForThis = args[++i];                } else {                    searchForThis = DEFAULT_BUILD_FILENAME;                }            } else if (arg.startsWith("-propertyfile")) {                try {                    propertyFiles.addElement(args[i + 1]);                    i++;                } catch (ArrayIndexOutOfBoundsException aioobe) {                    String msg = "You must specify a property filename when "                        + "using the -propertyfile argument";                    throw new BuildException(msg);                }            } else if (arg.equals("-k") || arg.equals("-keep-going")) {                keepGoingMode = true;            } else if (arg.equals("-nice")) {                try {                    threadPriority = Integer.decode(args[i + 1]);                } 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[i + 1]);                }                i++;                if (threadPriority.intValue() < Thread.MIN_PRIORITY                    || threadPriority.intValue() > Thread.MAX_PRIORITY) {                    throw new BuildException(                            "Niceness value is out of the range 1-10");                }            } else if (launchCommands.get(arg) != null) {                //catch script/ant mismatch with a meaningful message                //we could ignore it, but there are likely to be other                //version problems, so we stamp down on the configuration now                String msg = "Ant's Main method is being handed "                        + "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 = false;            } 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        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));                }            }        }        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;    }    /**     * 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());                    }                }

⌨️ 快捷键说明

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