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

📄 rmic.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void setIncludeantruntime(boolean include) {        includeAntRuntime = include;    }    /**     * Gets whether or not the ant classpath is to be included in the     * task's classpath.     * @return true if ant's classpath is to be included     */    public boolean getIncludeantruntime() {        return includeAntRuntime;    }    /**     * task's classpath.     * Enables or disables including the default run-time     * libraries from the executing VM; optional,     * defaults to false     * @param include if true include default run-time libraries     */    public void setIncludejavaruntime(boolean include) {        includeJavaRuntime = include;    }    /**     * Gets whether or not the java runtime should be included in this     * task's classpath.     * @return true if default run-time libraries are included     */    public boolean getIncludejavaruntime() {        return includeJavaRuntime;    }    /**     * Sets the extension directories that will be used during the     * compilation; optional.     * @param extDirs the extension directories to be used     */    public void setExtdirs(Path extDirs) {        if (this.extDirs == null) {            this.extDirs = extDirs;        } else {            this.extDirs.append(extDirs);        }    }    /**     * Maybe creates a nested extdirs element.     * @return path object to be configured with the extension directories     */    public Path createExtdirs() {        if (extDirs == null) {            extDirs = new Path(getProject());        }        return extDirs.createPath();    }    /**     * Gets the extension directories that will be used during the     * compilation.     * @return the extension directories to be used     */    public Path getExtdirs() {        return extDirs;    }    /**     * @return the compile list.     */    public Vector getCompileList() {        return compileList;    }    /**     * Sets the compiler implementation to use; optional,     * defaults to the value of the <code>build.rmic</code> property,     * or failing that, default compiler for the current VM     * @param compiler the compiler implemention to use     * @since Ant 1.5     */    public void setCompiler(String compiler) {        if (compiler.length() > 0) {            facade.setImplementation(compiler);        }    }    /**     * get the name of the current compiler     * @return the name of the compiler     * @since Ant 1.5     */    public String getCompiler() {        facade.setMagicValue(getProject().getProperty("build.rmic"));        return facade.getImplementation();    }    /**     * Adds an implementation specific command line argument.     * @return an object to be configured with a command line argument     * @since Ant 1.5     */    public ImplementationSpecificArgument createCompilerArg() {        ImplementationSpecificArgument arg =            new ImplementationSpecificArgument();        facade.addImplementationArgument(arg);        return arg;    }    /**     * Get the additional implementation specific command line arguments.     * @return array of command line arguments, guaranteed to be non-null.     * @since Ant 1.5     */    public String[] getCurrentCompilerArgs() {        getCompiler();        return facade.getArgs();    }    /**     * execute by creating an instance of an implementation     * class and getting to do the work     * @throws org.apache.tools.ant.BuildException     * if there's a problem with baseDir or RMIC     */    public void execute() throws BuildException {        if (baseDir == null) {            throw new BuildException(ERROR_BASE_NOT_SET, getLocation());        }        if (!baseDir.exists()) {            throw new BuildException(ERROR_NO_BASE_EXISTS + baseDir, getLocation());        }        if (!baseDir.isDirectory()) {            throw new BuildException(ERROR_NOT_A_DIR + baseDir, getLocation());        }        if (verify) {            log("Verify has been turned on.", Project.MSG_VERBOSE);        }        RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this);        // now we need to populate the compiler adapter        adapter.setRmic(this);        Path classpath = adapter.getClasspath();        loader = getProject().createClassLoader(classpath);        try {            // scan base dirs to build up compile lists only if a            // specific classname is not given            if (classname == null) {                DirectoryScanner ds = this.getDirectoryScanner(baseDir);                String[] files = ds.getIncludedFiles();                scanDir(baseDir, files, adapter.getMapper());            } else {                // otherwise perform a timestamp comparison - at least                String path = classname.replace('.', File.separatorChar) + ".class";                File f = new File(baseDir, path);                if (f.isFile()) {                    scanDir(baseDir, new String[] {path}, adapter.getMapper());                } else {                    // Does not exist, so checking whether it is up to date makes no sense.                    // Compilation will fail later anyway, but tests expect a certain output.                    compileList.add(classname);                }            }            int fileCount = compileList.size();            if (fileCount > 0) {                log("RMI Compiling " + fileCount                    + " class" + (fileCount > 1 ? "es" : "") + " to " + baseDir,                    Project.MSG_INFO);                // finally, lets execute the compiler!!                if (!adapter.execute()) {                    throw new BuildException(ERROR_RMIC_FAILED, getLocation());                }            }            /*             * Move the generated source file to the base directory.  If             * base directory and sourcebase are the same, the generated             * sources are already in place.             */            if (null != sourceBase && !baseDir.equals(sourceBase)                && fileCount > 0) {                if (idl) {                    log("Cannot determine sourcefiles in idl mode, ",                        Project.MSG_WARN);                    log("sourcebase attribute will be ignored.",                        Project.MSG_WARN);                } else {                    for (int j = 0; j < fileCount; j++) {                        moveGeneratedFile(baseDir, sourceBase,                                          (String) compileList.elementAt(j),                                          adapter);                    }                }            }        } finally {            compileList.removeAllElements();        }    }    /**     * Move the generated source file(s) to the base directory     *     * @throws org.apache.tools.ant.BuildException When error     * copying/removing files.     */    private void moveGeneratedFile (File baseDir, File sourceBaseFile,                                    String classname,                                    RmicAdapter adapter)        throws BuildException {        String classFileName =            classname.replace('.', File.separatorChar) + ".class";        String[] generatedFiles =            adapter.getMapper().mapFileName(classFileName);        for (int i = 0; i < generatedFiles.length; i++) {            final String generatedFile = generatedFiles[i];            if (!generatedFile.endsWith(".class")) {                // don't know how to handle that - a IDL file doesn't                // have a corresponding Java source for example.                continue;            }            final int pos = generatedFile.length() - ".class".length();            String sourceFileName =                generatedFile.substring(0, pos) + ".java";            File oldFile = new File(baseDir, sourceFileName);            if (!oldFile.exists()) {                // no source file generated, nothing to move                continue;            }            File newFile = new File(sourceBaseFile, sourceFileName);            try {                if (filtering) {                    FILE_UTILS.copyFile(oldFile, newFile,                        new FilterSetCollection(getProject()                                                .getGlobalFilterSet()));                } else {                    FILE_UTILS.copyFile(oldFile, newFile);                }                oldFile.delete();            } catch (IOException ioe) {                String msg = "Failed to copy " + oldFile + " to "                    + newFile + " due to " + ioe.getMessage();                throw new BuildException(msg, ioe, getLocation());            }        }    }    /**     * Scans the directory looking for class files to be compiled.     * The result is returned in the class variable compileList.     * @param baseDir the base direction     * @param files   the list of files to scan     * @param mapper  the mapper of files to target files     */    protected void scanDir(File baseDir, String[] files,                           FileNameMapper mapper) {        String[] newFiles = files;        if (idl) {            log("will leave uptodate test to rmic implementation in idl mode.",                Project.MSG_VERBOSE);        } else if (iiop                   && iiopOpts != null && iiopOpts.indexOf("-always") > -1) {            log("no uptodate test as -always option has been specified",                Project.MSG_VERBOSE);        } else {            SourceFileScanner sfs = new SourceFileScanner(this);            newFiles = sfs.restrict(files, baseDir, baseDir, mapper);        }        for (int i = 0; i < newFiles.length; i++) {            String name = newFiles[i].replace(File.separatorChar, '.');            name = name.substring(0, name.lastIndexOf(".class"));            compileList.addElement(name);        }    }    /**     * Load named class and test whether it can be rmic'ed     * @param classname the name of the class to be tested     * @return true if the class can be rmic'ed     */    public boolean isValidRmiRemote(String classname) {        try {            Class testClass = loader.loadClass(classname);            // One cannot RMIC an interface for "classic" RMI (JRMP)            if (testClass.isInterface() && !iiop && !idl) {                return false;            }            return isValidRmiRemote(testClass);        } catch (ClassNotFoundException e) {            log(ERROR_UNABLE_TO_VERIFY_CLASS + classname                + ERROR_NOT_FOUND, Project.MSG_WARN);        } catch (NoClassDefFoundError e) {            log(ERROR_UNABLE_TO_VERIFY_CLASS + classname                + ERROR_NOT_DEFINED, Project.MSG_WARN);        } catch (Throwable t) {            log(ERROR_UNABLE_TO_VERIFY_CLASS + classname                + ERROR_LOADING_CAUSED_EXCEPTION                + t.getMessage(), Project.MSG_WARN);        }        // we only get here if an exception has been thrown        return false;    }    /**     * Returns the topmost interface that extends Remote for a given     * class - if one exists.     * @param testClass the class to be tested     * @return the topmost interface that extends Remote, or null if there     *         is none.     */    public Class getRemoteInterface(Class testClass) {        if (Remote.class.isAssignableFrom(testClass)) {            Class [] interfaces = testClass.getInterfaces();            if (interfaces != null) {                for (int i = 0; i < interfaces.length; i++) {                    if (Remote.class.isAssignableFrom(interfaces[i])) {                        return interfaces[i];                    }                }            }        }        return null;    }    /**     * Check to see if the class or (super)interfaces implement     * java.rmi.Remote.     */    private boolean isValidRmiRemote (Class testClass) {        return getRemoteInterface(testClass) != null;    }    /**     * Classloader for the user-specified classpath.     * @return the classloader     */    public ClassLoader getLoader() {        return loader;    }    /**     * Adds an "compiler" attribute to Commandline$Attribute used to     * filter command line attributes based on the current     * implementation.     */    public class ImplementationSpecificArgument extends        org.apache.tools.ant.util.facade.ImplementationSpecificArgument {        /**         * Only pass the specified argument if the         * chosen compiler implementation matches the         * value of this attribute. Legal values are         * the same as those in the above list of         * valid compilers.)         * @param impl the compiler to be used.         */        public void setCompiler(String impl) {            super.setImplementation(impl);        }    }}

⌨️ 快捷键说明

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