use of org.apache.tools.ant.types.Path 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();
}
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class ExecTask method resolveExecutable.
/**
* The method attempts to figure out where the executable is so that we can feed
* the full path. We first try basedir, then the exec dir, and then
* fallback to the straight executable name (i.e. on the path).
*
* @param exec the name of the executable.
* @param mustSearchPath if true, the executable will be looked up in
* the PATH environment and the absolute path is returned.
*
* @return the executable as a full path if it can be determined.
*
* @since Ant 1.6
*/
protected String resolveExecutable(String exec, boolean mustSearchPath) {
if (!resolveExecutable) {
return exec;
}
// try to find the executable
File executableFile = getProject().resolveFile(exec);
if (executableFile.exists()) {
return executableFile.getAbsolutePath();
}
// now try to resolve against the dir if given
if (dir != null) {
executableFile = FILE_UTILS.resolveFile(dir, exec);
if (executableFile.exists()) {
return executableFile.getAbsolutePath();
}
}
// couldn't find it - must be on path
if (mustSearchPath) {
Path p = null;
String[] environment = env.getVariables();
if (environment != null) {
for (String variable : environment) {
if (isPath(variable)) {
p = new Path(getProject(), getPath(variable));
break;
}
}
}
if (p == null) {
String path = getPath(Execute.getEnvironmentVariables());
if (path != null) {
p = new Path(getProject(), path);
}
}
if (p != null) {
for (String pathname : p.list()) {
executableFile = FILE_UTILS.resolveFile(new File(pathname), exec);
if (executableFile.exists()) {
return executableFile.getAbsolutePath();
}
}
}
}
// fingers crossed.
return exec;
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class PathConvert method createPath.
/**
* 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;
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class MakeUrl method pathsToURL.
/**
* convert all paths to URLs
*
* @return the paths as a separated list of URLs
*/
private String pathsToURL() {
if (paths.isEmpty()) {
return "";
}
int count = 0;
StringBuilder urls = new StringBuilder();
for (Path path : paths) {
for (String element : path.list()) {
File f = new File(element);
validateFile(f);
String asUrl = toURL(f);
urls.append(asUrl);
log(asUrl, Project.MSG_DEBUG);
urls.append(separator);
count++;
}
}
// at this point there is one trailing space to remove, if the list is not empty.
return stripTrailingSeparator(urls, count);
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class SunJavah method setupJavahCommand.
static Commandline setupJavahCommand(Javah javah) {
Commandline cmd = new Commandline();
if (javah.getDestdir() != null) {
cmd.createArgument().setValue("-d");
cmd.createArgument().setFile(javah.getDestdir());
}
if (javah.getOutputfile() != null) {
cmd.createArgument().setValue("-o");
cmd.createArgument().setFile(javah.getOutputfile());
}
if (javah.getClasspath() != null) {
cmd.createArgument().setValue("-classpath");
cmd.createArgument().setPath(javah.getClasspath());
}
if (javah.getVerbose()) {
cmd.createArgument().setValue("-verbose");
}
if (javah.getOld()) {
cmd.createArgument().setValue("-old");
}
if (javah.getForce()) {
cmd.createArgument().setValue("-force");
}
if (javah.getStubs() && !javah.getOld()) {
throw new BuildException("stubs only available in old mode.", javah.getLocation());
}
if (javah.getStubs()) {
cmd.createArgument().setValue("-stubs");
}
Path bcp = new Path(javah.getProject());
if (javah.getBootclasspath() != null) {
bcp.append(javah.getBootclasspath());
}
bcp = bcp.concatSystemBootClasspath("ignore");
if (bcp.size() > 0) {
cmd.createArgument().setValue("-bootclasspath");
cmd.createArgument().setPath(bcp);
}
cmd.addArguments(javah.getCurrentArgs());
javah.logAndAddFiles(cmd);
return cmd;
}
Aggregations