Search in sources :

Example 11 with Java

use of org.apache.tools.ant.taskdefs.Java in project ant by apache.

the class BorlandGenerateClient method executeJava.

/**
 * launch the generate client using java api.
 * @throws BuildException if there is an error.
 */
protected void executeJava() throws BuildException {
    try {
        if (version == BorlandDeploymentTool.BES) {
            throw new BuildException("java mode is supported only for previous version <= %d", BorlandDeploymentTool.BAS);
        }
        log("mode : java");
        Java execTask = new Java(this);
        execTask.setDir(new File("."));
        execTask.setClassname("com.inprise.server.commandline.EJBUtilities");
        // classpath
        // add at the end of the classpath
        // the system classpath in order to find the tools.jar file
        execTask.setClasspath(classpath.concatSystemClasspath());
        execTask.setFork(true);
        execTask.createArg().setValue("generateclient");
        if (debug) {
            execTask.createArg().setValue("-trace");
        }
        execTask.createArg().setValue("-short");
        execTask.createArg().setValue("-jarfile");
        // ejb jar file
        execTask.createArg().setValue(ejbjarfile.getAbsolutePath());
        // client jar file
        execTask.createArg().setValue("-single");
        execTask.createArg().setValue("-clientjarfile");
        execTask.createArg().setValue(clientjarfile.getAbsolutePath());
        log("Calling EJBUtilities", Project.MSG_VERBOSE);
        execTask.execute();
    } catch (Exception e) {
        // Have to catch this because of the semantics of calling main()
        throw new BuildException("Exception while calling generateclient", e);
    }
}
Also used : Java(org.apache.tools.ant.taskdefs.Java) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Example 12 with Java

use of org.apache.tools.ant.taskdefs.Java in project ant by apache.

the class JonasDeploymentTool method addGenICGeneratedFiles.

/**
 * Add to the given hashtable all the file generated by GenIC.
 *
 * @param genericJarFile jar file.
 * @param ejbFiles the hashtable.
 */
private void addGenICGeneratedFiles(File genericJarFile, Hashtable<String, File> ejbFiles) {
    if (nogenic) {
        return;
    }
    // GenIC task
    Java genicTask = new Java(getTask());
    genicTask.setTaskName("genic");
    genicTask.setFork(true);
    // jonasroot
    genicTask.createJvmarg().setValue("-Dinstall.root=" + jonasroot);
    // java policy file
    String jonasConfigDir = jonasroot + File.separator + "config";
    File javaPolicyFile = new File(jonasConfigDir, "java.policy");
    if (javaPolicyFile.exists()) {
        genicTask.createJvmarg().setValue("-Djava.security.policy=" + javaPolicyFile.toString());
    }
    // outputdir
    try {
        outputdir = createTempDir();
    } catch (IOException aIOException) {
        String msg = "Cannot create temp dir: " + aIOException.getMessage();
        throw new BuildException(msg, aIOException);
    }
    log("Using temporary output directory: " + outputdir, Project.MSG_VERBOSE);
    genicTask.createArg().setValue("-d");
    genicTask.createArg().setFile(outputdir);
    for (String key : ejbFiles.keySet()) {
        File f = new File(outputdir + File.separator + key);
        f.getParentFile().mkdirs();
    }
    log("Worked around a bug of GenIC 2.5.", Project.MSG_VERBOSE);
    // classpath
    Path classpath = getCombinedClasspath();
    if (classpath == null) {
        classpath = new Path(getTask().getProject());
    }
    classpath.append(new Path(classpath.getProject(), jonasConfigDir));
    classpath.append(new Path(classpath.getProject(), outputdir.toString()));
    // try to create the classpath for the correct ORB
    if (orb != null) {
        String orbJar = jonasroot + File.separator + "lib" + File.separator + orb + "_jonas.jar";
        classpath.append(new Path(classpath.getProject(), orbJar));
    }
    log("Using classpath: " + classpath.toString(), Project.MSG_VERBOSE);
    genicTask.setClasspath(classpath);
    // GenIC class (3 are supported for various
    String genicClass;
    // versions
    // work around a bug of GenIC 2.5
    // class name (search in the classpath provided for the ejbjar element)
    genicClass = getGenicClassName(classpath);
    if (genicClass == null) {
        log("Cannot find GenIC class in classpath.", Project.MSG_ERR);
        throw new BuildException("GenIC class not found, please check the classpath.");
    }
    log("Using '" + genicClass + "' GenIC class.", Project.MSG_VERBOSE);
    genicTask.setClassname(genicClass);
    // keepgenerated
    if (keepgenerated) {
        genicTask.createArg().setValue("-keepgenerated");
    }
    // nocompil
    if (nocompil) {
        genicTask.createArg().setValue("-nocompil");
    }
    // novalidation
    if (novalidation) {
        genicTask.createArg().setValue("-novalidation");
    }
    // javac
    if (javac != null) {
        genicTask.createArg().setValue("-javac");
        genicTask.createArg().setLine(javac);
    }
    // javacopts
    if (javacopts != null && !javacopts.isEmpty()) {
        genicTask.createArg().setValue("-javacopts");
        genicTask.createArg().setLine(javacopts);
    }
    // rmicopts
    if (rmicopts != null && !rmicopts.isEmpty()) {
        genicTask.createArg().setValue("-rmicopts");
        genicTask.createArg().setLine(rmicopts);
    }
    // secpropag
    if (secpropag) {
        genicTask.createArg().setValue("-secpropag");
    }
    // verbose
    if (verbose) {
        genicTask.createArg().setValue("-verbose");
    }
    // additionalargs
    if (additionalargs != null) {
        genicTask.createArg().setValue(additionalargs);
    }
    // the generated classes must not be added in the generic JAR!
    // is that buggy on old JOnAS (2.4) ??
    genicTask.createArg().setValue("-noaddinjar");
    // input file to process by GenIC
    genicTask.createArg().setValue(genericJarFile.getPath());
    // calling GenIC task
    log("Calling " + genicClass + " for " + getConfig().descriptorDir + File.separator + descriptorName + ".", Project.MSG_VERBOSE);
    if (genicTask.executeJava() != 0) {
        // the method deleteOnExit() do not work because the directory is not empty
        log("Deleting temp output directory '" + outputdir + "'.", Project.MSG_VERBOSE);
        deleteAllFiles(outputdir);
        if (!keepgeneric) {
            log("Deleting generic JAR " + genericJarFile.toString(), Project.MSG_VERBOSE);
            genericJarFile.delete();
        }
        throw new BuildException("GenIC reported an error.");
    }
    // add the generated files to the ejbFiles
    addAllFiles(outputdir, "", ejbFiles);
}
Also used : Path(org.apache.tools.ant.types.Path) Java(org.apache.tools.ant.taskdefs.Java) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 13 with Java

use of org.apache.tools.ant.taskdefs.Java in project ant by apache.

the class WebsphereDeploymentTool method buildWebsphereJar.

/**
 * Helper method invoked by execute() for each websphere jar to be built.
 * Encapsulates the logic of constructing a java task for calling
 * websphere.ejbdeploy and executing it.
 *
 * @param sourceJar java.io.File representing the source (EJB1.1) jarfile.
 * @param destJar java.io.File representing the destination, websphere
 *      jarfile.
 */
private void buildWebsphereJar(File sourceJar, File destJar) {
    try {
        if (ejbdeploy) {
            Java javaTask = new Java(getTask());
            // Set the JvmArgs
            javaTask.createJvmarg().setValue("-Xms64m");
            javaTask.createJvmarg().setValue("-Xmx128m");
            // Set the Environment variable
            Environment.Variable var = new Environment.Variable();
            var.setKey("websphere.lib.dir");
            File libdir = new File(websphereHome, "lib");
            var.setValue(libdir.getAbsolutePath());
            javaTask.addSysproperty(var);
            // Set the working directory
            javaTask.setDir(websphereHome);
            // Set the Java class name
            javaTask.setTaskName("ejbdeploy");
            javaTask.setClassname("com.ibm.etools.ejbdeploy.EJBDeploy");
            javaTask.createArg().setValue(sourceJar.getPath());
            javaTask.createArg().setValue(tempdir);
            javaTask.createArg().setValue(destJar.getPath());
            javaTask.createArg().setLine(getOptions());
            if (getCombinedClasspath() != null && getCombinedClasspath().toString().length() > 0) {
                javaTask.createArg().setValue("-cp");
                javaTask.createArg().setValue(getCombinedClasspath().toString());
            }
            Path classpath = wasClasspath;
            if (classpath == null) {
                classpath = getCombinedClasspath();
            }
            javaTask.setFork(true);
            if (classpath != null) {
                javaTask.setClasspath(classpath);
            }
            log("Calling websphere.ejbdeploy for " + sourceJar.toString(), Project.MSG_VERBOSE);
            javaTask.execute();
        }
    } catch (Exception e) {
        // Have to catch this because of the semantics of calling main()
        throw new BuildException("Exception while calling ejbdeploy. Details: " + e.toString(), e);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Java(org.apache.tools.ant.taskdefs.Java) Environment(org.apache.tools.ant.types.Environment) BuildException(org.apache.tools.ant.BuildException) JarFile(java.util.jar.JarFile) File(java.io.File) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 14 with Java

use of org.apache.tools.ant.taskdefs.Java in project randomizedtesting by randomizedtesting.

the class AntBuildFileTestBase method executeForkedTarget.

protected final void executeForkedTarget(String target, long timeout) {
    Path antPath = new Path(getProject());
    antPath.createPathElement().setLocation(sourceOf(Project.class));
    antPath.createPathElement().setLocation(sourceOf(Launcher.class));
    Java java = new Java();
    java.setTaskName("forked");
    java.setProject(getProject());
    java.setClassname("org.apache.tools.ant.launch.Launcher");
    java.createClasspath().add(antPath);
    java.setFork(true);
    java.setSpawn(false);
    java.setTimeout(timeout);
    java.setFailonerror(false);
    java.setOutputproperty("stdout");
    java.setErrorProperty("stderr");
    java.createArg().setValue("-f");
    java.createArg().setValue(getProject().getUserProperty(MagicNames.ANT_FILE));
    java.createArg().setValue(target);
    java.execute();
    getProject().log("Forked stdout:\n" + getProject().getProperty("stdout"));
    getProject().log("Forked stderr:\n" + getProject().getProperty("stderr"));
}
Also used : Path(org.apache.tools.ant.types.Path) Project(org.apache.tools.ant.Project) Java(org.apache.tools.ant.taskdefs.Java) Launcher(org.apache.tools.ant.launch.Launcher)

Example 15 with Java

use of org.apache.tools.ant.taskdefs.Java in project elephant-bird by twitter.

the class TestTypedProtobufWritable method testStableHashcodeAcrossJVMs.

@Test
public void testStableHashcodeAcrossJVMs() throws IOException {
    int expectedHashCode = referenceAbWritable.hashCode();
    Java otherJvm = new Java();
    otherJvm.setNewenvironment(true);
    otherJvm.setFork(true);
    otherJvm.setProject(new Project());
    otherJvm.setClassname(OtherJvmClass.class.getName());
    for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
        Environment.Variable var = new Environment.Variable();
        var.setKey(entry.getKey());
        var.setValue(entry.getValue());
        otherJvm.addEnv(var);
    }
    for (String prop : System.getProperties().stringPropertyNames()) {
        String propValue = System.getProperty(prop);
        Environment.Variable var = new Environment.Variable();
        var.setKey(prop);
        var.setValue(propValue);
        otherJvm.addSysproperty(var);
    }
    otherJvm.setDir(new File(System.getProperty("java.io.tmpdir")));
    File tmpOut = File.createTempFile("otherJvm", "txt");
    otherJvm.setArgs(tmpOut.getAbsolutePath());
    otherJvm.init();
    otherJvm.executeJava();
    DataInputStream is = new DataInputStream(new FileInputStream(tmpOut));
    assertEquals(expectedHashCode, is.readInt());
    is.close();
}
Also used : Java(org.apache.tools.ant.taskdefs.Java) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) Project(org.apache.tools.ant.Project) Environment(org.apache.tools.ant.types.Environment) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Aggregations

Java (org.apache.tools.ant.taskdefs.Java)16 BuildException (org.apache.tools.ant.BuildException)9 File (java.io.File)7 Path (org.apache.tools.ant.types.Path)7 IOException (java.io.IOException)5 Project (org.apache.tools.ant.Project)5 Environment (org.apache.tools.ant.types.Environment)3 DataInputStream (java.io.DataInputStream)2 FileInputStream (java.io.FileInputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Scanner (java.util.Scanner)2 DefaultLogger (org.apache.tools.ant.DefaultLogger)2 Test (org.junit.Test)2 StringBufferOutputStream (com.liferay.ide.core.StringBufferOutputStream)1 InputStream (java.io.InputStream)1 JarURLConnection (java.net.JarURLConnection)1 URL (java.net.URL)1 Properties (java.util.Properties)1