use of org.apache.tools.ant.taskdefs.Java in project liferay-ide by liferay.
the class BladeCLI method execute.
public static String[] execute(String args) throws BladeCLIException {
IPath bladeCLIPath = getBladeCLIPath();
if (FileUtil.notExists(bladeCLIPath)) {
throw new BladeCLIException("Could not get blade cli jar.");
}
Project project = new Project();
Java javaTask = new Java();
javaTask.setProject(project);
javaTask.setFork(true);
javaTask.setFailonerror(true);
javaTask.setJar(bladeCLIPath.toFile());
javaTask.setArgs(args);
DefaultLogger logger = new DefaultLogger();
project.addBuildListener(logger);
StringBufferOutputStream out = new StringBufferOutputStream();
logger.setOutputPrintStream(new PrintStream(out));
logger.setMessageOutputLevel(Project.MSG_INFO);
int returnCode = javaTask.executeJava();
List<String> lines = new ArrayList<>();
Scanner scanner = new Scanner(out.toString());
while (scanner.hasNextLine()) {
lines.add(scanner.nextLine().replaceAll(".*\\[null\\] ", ""));
}
scanner.close();
boolean hasErrors = false;
StringBuilder errors = new StringBuilder();
for (String line : lines) {
if (line.startsWith("Error")) {
hasErrors = true;
} else if (hasErrors) {
errors.append(line);
}
}
if ((returnCode != 0) || hasErrors) {
throw new BladeCLIException(errors.toString());
}
return lines.toArray(new String[0]);
}
use of org.apache.tools.ant.taskdefs.Java in project liferay-ide by liferay.
the class BladeCLI method execute.
public static String[] execute(String args) {
Project project = new Project();
Java javaTask = new Java();
javaTask.setProject(project);
javaTask.setFork(true);
javaTask.setFailonerror(true);
Properties properties = System.getProperties();
boolean needToCopy = true;
File temp = new File(properties.getProperty("user.home"), ".liferay-ide");
File bladeJar = new File(temp, "blade.jar");
ClassLoader bladeClassLoader = BladeCLI.class.getClassLoader();
URL url = bladeClassLoader.getResource("/libs/blade.jar");
try (InputStream in = bladeClassLoader.getResourceAsStream("/libs/blade.jar")) {
JarURLConnection jarUrlConnection = (JarURLConnection) url.openConnection();
JarEntry jarEntry = jarUrlConnection.getJarEntry();
Long bladeJarTimestamp = jarEntry.getTime();
if (bladeJar.exists()) {
Long destTimestamp = bladeJar.lastModified();
if (destTimestamp < bladeJarTimestamp) {
bladeJar.delete();
} else {
needToCopy = false;
}
}
if (needToCopy) {
FileUtil.writeFile(bladeJar, in);
bladeJar.setLastModified(bladeJarTimestamp);
}
} catch (IOException ioe) {
}
javaTask.setJar(bladeJar);
javaTask.setArgs(args);
DefaultLogger logger = new DefaultLogger();
project.addBuildListener(logger);
StringBufferOutputStream out = new StringBufferOutputStream();
logger.setOutputPrintStream(new PrintStream(out));
logger.setMessageOutputLevel(Project.MSG_INFO);
javaTask.executeJava();
List<String> lines = new ArrayList<>();
Scanner scanner = new Scanner(out.toString());
while (scanner.hasNextLine()) {
String nextLine = scanner.nextLine();
lines.add(nextLine.replaceAll(".*\\[null\\] ", ""));
}
scanner.close();
boolean hasErrors = false;
StringBuilder errors = new StringBuilder();
for (String line : lines) {
if (line.startsWith("Error")) {
hasErrors = true;
} else if (hasErrors) {
errors.append(line);
}
}
return lines.toArray(new String[0]);
}
use of org.apache.tools.ant.taskdefs.Java 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);
}
}
use of org.apache.tools.ant.taskdefs.Java in project ant by apache.
the class JonasHotDeploymentTool method validateAttributes.
/**
* Validates the passed in attributes.
*
* <p>The rules are:</p>
* <ol>
* <li> If action is "deploy" or "update" the "application"
* and "source" attributes must be supplied.</li>
* <li> If action is "delete" or "undeploy" the
* "application" attribute must be supplied.</li>
* </ol>
*
* @exception BuildException if something goes wrong
*/
@Override
public void validateAttributes() throws BuildException {
// super.validateAttributes(); // don't want to call this method
Java java = getJava();
String action = getTask().getAction();
if (action == null) {
throw new BuildException("The \"action\" attribute must be set");
}
if (!isActionValid()) {
throw new BuildException("Invalid action \"%s\" passed", action);
}
if (getClassName() == null) {
setClassName(JONAS_DEPLOY_CLASS_NAME);
}
if (jonasroot == null || jonasroot.isDirectory()) {
java.createJvmarg().setValue("-Dinstall.root=" + jonasroot);
java.createJvmarg().setValue("-Djava.security.policy=" + jonasroot + "/config/java.policy");
if ("DAVID".equals(orb)) {
java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBClass" + "=org.objectweb.david.libs.binding.orbs.iiop.IIOPORB");
java.createJvmarg().setValue("-Dorg.omg.CORBA.ORBSingletonClass=" + "org.objectweb.david.libs.binding.orbs.ORBSingletonClass");
java.createJvmarg().setValue("-Djavax.rmi.CORBA.StubClass=" + "org.objectweb.david.libs.stub_factories.rmi.StubDelegate");
java.createJvmarg().setValue("-Djavax.rmi.CORBA.PortableRemoteObjectClass=" + "org.objectweb.david.libs.binding.rmi.ORBPortableRemoteObjectDelegate");
java.createJvmarg().setValue("-Djavax.rmi.CORBA.UtilClass=" + "org.objectweb.david.libs.helpers.RMIUtilDelegate");
java.createJvmarg().setValue("-Ddavid.CosNaming.default_method=0");
java.createJvmarg().setValue("-Ddavid.rmi.ValueHandlerClass=" + "com.sun.corba.se.internal.io.ValueHandlerImpl");
if (davidHost != null) {
java.createJvmarg().setValue("-Ddavid.CosNaming.default_host=" + davidHost);
}
if (davidPort != 0) {
java.createJvmarg().setValue("-Ddavid.CosNaming.default_port=" + davidPort);
}
}
}
if (getServer() != null) {
java.createArg().setLine("-n " + getServer());
}
if (ACTION_DEPLOY.equals(action) || ACTION_UPDATE.equals(action) || "redeploy".equals(action)) {
java.createArg().setLine("-a " + getTask().getSource());
} else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) {
java.createArg().setLine("-r " + getTask().getSource());
} else if (action.equals(ACTION_LIST)) {
java.createArg().setValue("-l");
}
}
use of org.apache.tools.ant.taskdefs.Java in project ant by apache.
the class JasperC method execute.
/**
* Our execute method.
* @return true if successful
* @throws BuildException on error
*/
@Override
public boolean execute() throws BuildException {
getJspc().log("Using jasper compiler", Project.MSG_VERBOSE);
CommandlineJava cmd = setupJasperCommand();
try {
// Create an instance of the compiler, redirecting output to
// the project log
Java java = new Java(owner);
Path p = getClasspath();
if (getJspc().getClasspath() != null) {
getProject().log("using user supplied classpath: " + p, Project.MSG_DEBUG);
} else {
getProject().log("using system classpath: " + p, Project.MSG_DEBUG);
}
java.setClasspath(p);
java.setDir(getProject().getBaseDir());
java.setClassname("org.apache.jasper.JspC");
// this is really irritating; we need a way to set stuff
for (String arg : cmd.getJavaCommand().getArguments()) {
java.createArg().setValue(arg);
}
java.setFailonerror(getJspc().getFailonerror());
// we are forking here to be sure that if JspC calls
// System.exit() it doesn't halt the build
java.setFork(true);
java.setTaskName("jasperc");
java.execute();
return true;
} catch (Exception ex) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
}
throw new BuildException("Error running jsp compiler: ", ex, getJspc().getLocation());
} finally {
getJspc().deleteEmptyJavaFiles();
}
}
Aggregations