use of org.apache.tools.ant.types.Path in project ant by apache.
the class DefaultCompilerAdapter method getCompileClasspath.
/**
* Builds the compilation classpath.
* @return the compilation class path
*/
protected Path getCompileClasspath() {
final Path classpath = new Path(project);
if (destDir != null && getJavac().isIncludeDestClasses()) {
classpath.setLocation(destDir);
}
// Combine the build classpath with the system classpath, in an
// order determined by the value of build.sysclasspath
Path cp = compileClasspath;
if (cp == null) {
cp = new Path(project);
}
if (includeAntRuntime) {
classpath.addExisting(cp.concatSystemClasspath("last"));
} else {
classpath.addExisting(cp.concatSystemClasspath("ignore"));
}
if (includeJavaRuntime) {
classpath.addJavaRuntime();
}
return classpath;
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class DefaultCompilerAdapter method setJavac.
// CheckStyle:VisibilityModifier ON
/**
* Set the Javac instance which contains the configured compilation
* attributes.
*
* @param attributes a configured Javac task.
*/
@Override
public void setJavac(final Javac attributes) {
this.attributes = attributes;
src = attributes.getSrcdir();
destDir = attributes.getDestdir();
encoding = attributes.getEncoding();
debug = attributes.getDebug();
optimize = attributes.getOptimize();
deprecation = attributes.getDeprecation();
depend = attributes.getDepend();
verbose = attributes.getVerbose();
target = attributes.getTarget();
release = attributes.getRelease();
bootclasspath = attributes.getBootclasspath();
extdirs = attributes.getExtdirs();
compileList = attributes.getFileList();
compileClasspath = attributes.getClasspath();
modulepath = attributes.getModulepath();
upgrademodulepath = attributes.getUpgrademodulepath();
compileSourcepath = attributes.getSourcepath();
moduleSourcepath = attributes.getModulesourcepath();
project = attributes.getProject();
location = attributes.getLocation();
includeAntRuntime = attributes.getIncludeantruntime();
includeJavaRuntime = attributes.getIncludejavaruntime();
memoryInitialSize = attributes.getMemoryInitialSize();
memoryMaximumSize = attributes.getMemoryMaximumSize();
if (moduleSourcepath != null && src == null && compileSourcepath == null) {
// Compatibility to prevent NPE from Jikes, Jvc, Kjc
compileSourcepath = new Path(getProject());
}
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class Gcj method setupGCJCommand.
/**
* Set up the gcj commandline.
* @return the command line
*/
protected Commandline setupGCJCommand() {
Commandline cmd = new Commandline();
Path classpath = new Path(project);
// gcj doesn't support bootclasspath dir (-bootclasspath)
// so we'll emulate it for compatibility and convenience.
Path p = getBootClassPath();
if (!p.isEmpty()) {
classpath.append(p);
}
// so we'll emulate it for compatibility and convenience.
if (extdirs != null || includeJavaRuntime) {
classpath.addExtdirs(extdirs);
}
classpath.append(getCompileClasspath());
// will add it to classpath.
if (compileSourcepath != null) {
classpath.append(compileSourcepath);
} else {
classpath.append(src);
}
String exec = getJavac().getExecutable();
cmd.setExecutable(exec == null ? "gcj" : exec);
if (destDir != null) {
cmd.createArgument().setValue("-d");
cmd.createArgument().setFile(destDir);
if (!destDir.exists() && !(destDir.mkdirs() || destDir.isDirectory())) {
throw new BuildException("Can't make output directories. Maybe permission is wrong.");
}
}
cmd.createArgument().setValue("-classpath");
cmd.createArgument().setPath(classpath);
if (encoding != null) {
cmd.createArgument().setValue("--encoding=" + encoding);
}
if (debug) {
cmd.createArgument().setValue("-g1");
}
if (optimize) {
cmd.createArgument().setValue("-O");
}
/**
* gcj should be set for generate class.
* ... if no 'compile to native' argument is passed
*/
if (!isNativeBuild()) {
cmd.createArgument().setValue("-C");
}
if (attributes.getSource() != null) {
String source = attributes.getSource();
cmd.createArgument().setValue("-fsource=" + source);
}
if (attributes.getTarget() != null) {
String target = attributes.getTarget();
cmd.createArgument().setValue("-ftarget=" + target);
}
addCurrentCompilerArgs(cmd);
return cmd;
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class JUnitTask method checkIncludeAntRuntime.
/**
* Adding ant runtime.
* @param cmd command to run
*/
private void checkIncludeAntRuntime(final CommandlineJava cmd) {
if (includeAntRuntime) {
final Map<String, String> env = Execute.getEnvironmentVariables();
final String cp = env.get(CLASSPATH);
if (cp != null) {
cmd.createClasspath(getProject()).createPath().append(new Path(getProject(), cp));
}
log("Implicitly adding " + antRuntimeClasses + " to CLASSPATH", Project.MSG_VERBOSE);
cmd.createClasspath(getProject()).createPath().append(antRuntimeClasses);
}
}
use of org.apache.tools.ant.types.Path in project ant by apache.
the class WeblogicDeploymentTool method buildWeblogicJar.
/**
* Helper method invoked by execute() for each WebLogic jar to be built.
* Encapsulates the logic of constructing a java task for calling
* weblogic.ejbc and executing it.
*
* @param sourceJar java.io.File representing the source (EJB1.1) jarfile.
* @param destJar java.io.File representing the destination, WebLogic
* jarfile.
*/
private void buildWeblogicJar(File sourceJar, File destJar, String publicId) {
if (noEJBC) {
try {
FILE_UTILS.copyFile(sourceJar, destJar);
if (!keepgenerated) {
sourceJar.delete();
}
return;
} catch (IOException e) {
throw new BuildException("Unable to write EJB jar", e);
}
}
String ejbcClassName = ejbcClass;
try {
Java javaTask = new Java(getTask());
javaTask.setTaskName("ejbc");
javaTask.createJvmarg().setLine(additionalJvmArgs);
sysprops.forEach(javaTask::addSysproperty);
if (getJvmDebugLevel() != null) {
javaTask.createJvmarg().setLine(" -Dweblogic.StdoutSeverityLevel=" + jvmDebugLevel);
}
if (ejbcClassName == null) {
// try to determine it from publicId
if (PUBLICID_EJB11.equals(publicId)) {
ejbcClassName = COMPILER_EJB11;
} else if (PUBLICID_EJB20.equals(publicId)) {
ejbcClassName = COMPILER_EJB20;
} else {
log("Unrecognized publicId " + publicId + " - using EJB 1.1 compiler", Project.MSG_WARN);
ejbcClassName = COMPILER_EJB11;
}
}
javaTask.setClassname(ejbcClassName);
javaTask.createArg().setLine(additionalArgs);
if (keepgenerated) {
javaTask.createArg().setValue("-keepgenerated");
}
if (compiler == null) {
// try to use the compiler specified by build.compiler.
// Right now we are just going to allow Jikes
String buildCompiler = getTask().getProject().getProperty("build.compiler");
if ("jikes".equals(buildCompiler)) {
javaTask.createArg().setValue("-compiler");
javaTask.createArg().setValue("jikes");
}
} else if (!DEFAULT_COMPILER.equals(compiler)) {
javaTask.createArg().setValue("-compiler");
javaTask.createArg().setLine(compiler);
}
Path combinedClasspath = getCombinedClasspath();
if (wlClasspath != null && combinedClasspath != null && !combinedClasspath.toString().trim().isEmpty()) {
javaTask.createArg().setValue("-classpath");
javaTask.createArg().setPath(combinedClasspath);
}
javaTask.createArg().setValue(sourceJar.getPath());
if (outputDir == null) {
javaTask.createArg().setValue(destJar.getPath());
} else {
javaTask.createArg().setValue(outputDir.getPath());
}
Path classpath = wlClasspath;
if (classpath == null) {
classpath = getCombinedClasspath();
}
javaTask.setFork(true);
if (classpath != null) {
javaTask.setClasspath(classpath);
}
log("Calling " + ejbcClassName + " for " + sourceJar.toString(), Project.MSG_VERBOSE);
if (javaTask.executeJava() != 0) {
throw new BuildException("Ejbc reported an error");
}
} catch (Exception e) {
// Have to catch this because of the semantics of calling main()
throw new BuildException("Exception while calling " + ejbcClassName + ". Details: " + e.toString(), e);
}
}
Aggregations