Search in sources :

Example 1 with RmicAdapter

use of org.apache.tools.ant.taskdefs.rmic.RmicAdapter in project ant by apache.

the class Rmic method execute.

/**
 * execute by creating an instance of an implementation
 * class and getting to do the work
 * @throws BuildException
 * if there's a problem with baseDir or RMIC
 */
@Override
public void execute() throws BuildException {
    try {
        compileList.clear();
        File outputDir = getOutputDir();
        if (outputDir == null) {
            throw new BuildException(ERROR_BASE_NOT_SET, getLocation());
        }
        if (!outputDir.exists()) {
            throw new BuildException(ERROR_NO_BASE_EXISTS + outputDir, getLocation());
        }
        if (!outputDir.isDirectory()) {
            throw new BuildException(ERROR_NOT_A_DIR + outputDir, getLocation());
        }
        if (verify) {
            log("Verify has been turned on.", Project.MSG_VERBOSE);
        }
        RmicAdapter adapter = nestedAdapter != null ? nestedAdapter : RmicAdapterFactory.getRmic(getCompiler(), this, createCompilerClasspath());
        // now we need to populate the compiler adapter
        adapter.setRmic(this);
        Path classpath = adapter.getClasspath();
        loader = getProject().createClassLoader(classpath);
        // 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 " + outputDir, Project.MSG_INFO);
            if (listFiles) {
                compileList.forEach(this::log);
            }
            // 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 && !outputDir.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 {
                compileList.forEach(f -> moveGeneratedFile(outputDir, sourceBase, f, adapter));
            }
        }
    } finally {
        cleanup();
    }
}
Also used : Path(org.apache.tools.ant.types.Path) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) RmicAdapter(org.apache.tools.ant.taskdefs.rmic.RmicAdapter) File(java.io.File)

Aggregations

File (java.io.File)1 BuildException (org.apache.tools.ant.BuildException)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 RmicAdapter (org.apache.tools.ant.taskdefs.rmic.RmicAdapter)1 Path (org.apache.tools.ant.types.Path)1