📄 java.java
字号:
public void setOutput(File out) { this.output = out; incompatibleWithSpawn = true; } /** * Set the input to use for the task. * * @param input name of the input file. */ public void setInput(File input) { if (inputString != null) { throw new BuildException("The \"input\" and \"inputstring\" " + "attributes cannot both be specified"); } this.input = input; incompatibleWithSpawn = true; } /** * Set the string to use as input. * * @param inputString the string which is used as the input source. */ public void setInputString(String inputString) { if (input != null) { throw new BuildException("The \"input\" and \"inputstring\" " + "attributes cannot both be specified"); } this.inputString = inputString; incompatibleWithSpawn = true; } /** * Set whether error output of exec is logged. This is only useful * when output is being redirected and error output is desired in the * Ant log. * * @param logError get in the ant log the messages coming from stderr * in the case that fork = true. */ public void setLogError(boolean logError) { redirector.setLogError(logError); incompatibleWithSpawn |= logError; } /** * Set the File to which the error stream of the process is redirected. * * @param error file getting the error stream. * * @since Ant 1.6 */ public void setError(File error) { this.error = error; incompatibleWithSpawn = true; } /** * Set the property name whose value should be set to the output of * the process. * * @param outputProp property name. * */ public void setOutputproperty(String outputProp) { redirector.setOutputProperty(outputProp); incompatibleWithSpawn = true; } /** * Set the property name whose value should be set to the error of * the process. * * @param errorProperty property name. * * @since Ant 1.6 */ public void setErrorProperty(String errorProperty) { redirector.setErrorProperty(errorProperty); incompatibleWithSpawn = true; } /** * Corresponds to -mx or -Xmx depending on VM version. * * @param max max memory parameter. */ public void setMaxmemory(String max) { getCommandLine().setMaxmemory(max); } /** * Set the JVM version. * @param value JVM version. */ public void setJVMVersion(String value) { getCommandLine().setVmversion(value); } /** * Add an environment variable. * * <p>Will be ignored if we are not forking a new VM. * * @param var new environment variable. * * @since Ant 1.5 */ public void addEnv(Environment.Variable var) { env.addVariable(var); } /** * If true, use a completely new environment. * * <p>Will be ignored if we are not forking a new VM. * * @param newenv if true, use a completely new environment. * * @since Ant 1.5 */ public void setNewenvironment(boolean newenv) { newEnvironment = newenv; } /** * If true, append output to existing file. * * @param append if true, append output to existing file. * * @since Ant 1.5 */ public void setAppend(boolean append) { redirector.setAppend(append); incompatibleWithSpawn = true; } /** * Set the timeout in milliseconds after which the process will be killed. * * @param value timeout in milliseconds. * * @since Ant 1.5 */ public void setTimeout(Long value) { timeout = value; incompatibleWithSpawn |= timeout != null; } /** * Add assertions to enable in this program (if fork=true). * @param asserts assertion set. * @since Ant 1.6 */ public void addAssertions(Assertions asserts) { if (getCommandLine().getAssertions() != null) { throw new BuildException("Only one assertion declaration is allowed"); } getCommandLine().setAssertions(asserts); } /** * Add a <code>RedirectorElement</code> to this task. * @param redirectorElement <code>RedirectorElement</code>. */ public void addConfiguredRedirector(RedirectorElement redirectorElement) { if (this.redirectorElement != null) { throw new BuildException("cannot have > 1 nested redirectors"); } this.redirectorElement = redirectorElement; incompatibleWithSpawn = true; } /** * Pass output sent to System.out to specified output file. * * @param output a string of output on its way to the handlers. * * @since Ant 1.5 */ protected void handleOutput(String output) { if (redirector.getOutputStream() != null) { redirector.handleOutput(output); } else { super.handleOutput(output); } } /** * Handle an input request by this task. * * @param buffer the buffer into which data is to be read. * @param offset the offset into the buffer at which data is stored. * @param length the amount of data to read. * * @return the number of bytes read. * * @exception IOException if the data cannot be read. * @since Ant 1.6 */ public int handleInput(byte[] buffer, int offset, int length) throws IOException { // Should work whether or not redirector.inputStream == null: return redirector.handleInput(buffer, offset, length); } /** * Pass output sent to System.out to specified output file. * * @param output string of output on its way to its handlers. * * @since Ant 1.5.2 */ protected void handleFlush(String output) { if (redirector.getOutputStream() != null) { redirector.handleFlush(output); } else { super.handleFlush(output); } } /** * Handle output sent to System.err. * * @param output string of stderr. * * @since Ant 1.5 */ protected void handleErrorOutput(String output) { if (redirector.getErrorStream() != null) { redirector.handleErrorOutput(output); } else { super.handleErrorOutput(output); } } /** * Handle output sent to System.err and flush the stream. * * @param output string of stderr. * * @since Ant 1.5.2 */ protected void handleErrorFlush(String output) { if (redirector.getErrorStream() != null) { redirector.handleErrorFlush(output); } else { super.handleErrorOutput(output); } } /** * Set up properties on the redirector that we needed to store locally. */ protected void setupRedirector() { redirector.setInput(input); redirector.setInputString(inputString); redirector.setOutput(output); redirector.setError(error); if (redirectorElement != null) { redirectorElement.configure(redirector); } if (!spawn && input == null && inputString == null) { // #24918: send standard input to the process by default. redirector.setInputStream( new KeepAliveInputStream(getProject().getDefaultInputStream())); } } /** * Executes the given classname with the given arguments as it * were a command line application. * @param command CommandlineJava. */ private void run(CommandlineJava command) throws BuildException { try { ExecuteJava exe = new ExecuteJava(); exe.setJavaCommand(command.getJavaCommand()); exe.setClasspath(command.getClasspath()); exe.setSystemProperties(command.getSystemProperties()); exe.setPermissions(perm); exe.setTimeout(timeout); redirector.createStreams(); exe.execute(getProject()); redirector.complete(); if (exe.killedProcess()) { throw new BuildException("Timeout: killed the sub-process"); } } catch (IOException e) { throw new BuildException(e); } } /** * Executes the given classname with the given arguments in a separate VM. * @param command String[] of command-line arguments. */ private int fork(String[] command) throws BuildException { Execute exe = new Execute(redirector.createHandler(), createWatchdog()); setupExecutable(exe, command); try { int rc = exe.execute(); redirector.complete(); if (exe.killedProcess()) { throw new BuildException("Timeout: killed the sub-process"); } return rc; } catch (IOException e) { throw new BuildException(e, getLocation()); } } /** * Executes the given classname with the given arguments in a separate VM. * @param command String[] of command-line arguments. */ private void spawn(String[] command) throws BuildException { Execute exe = new Execute(); setupExecutable(exe, command); try { exe.spawn(); } catch (IOException e) { throw new BuildException(e, getLocation()); } } /** * Do all configuration for an executable that * is common across the {@link #fork(String[])} and * {@link #spawn(String[])} methods. * @param exe executable. * @param command command to execute. */ private void setupExecutable(Execute exe, String[] command) { exe.setAntRun(getProject()); setupWorkingDir(exe); setupEnvironment(exe); setupCommandLine(exe, command); } /** * Set up our environment variables. * @param exe executable. */ private void setupEnvironment(Execute exe) { String[] environment = env.getVariables(); if (environment != null) { for (int i = 0; i < environment.length; i++) { log("Setting environment variable: " + environment[i], Project.MSG_VERBOSE); } } exe.setNewenvironment(newEnvironment); exe.setEnvironment(environment); } /** * Set the working dir of the new process. * @param exe executable. * @throws BuildException if the dir doesn't exist. */ private void setupWorkingDir(Execute exe) { if (dir == null) { dir = getProject().getBaseDir(); } else if (!dir.exists() || !dir.isDirectory()) { throw new BuildException(dir.getAbsolutePath() + " is not a valid directory", getLocation()); } exe.setWorkingDirectory(dir); } /** * Set the command line for the exe. * On VMS, hands off to {@link #setupCommandLineForVMS(Execute, String[])}. * @param exe executable. * @param command command to execute. */ private void setupCommandLine(Execute exe, String[] command) { //On VMS platform, we need to create a special java options file //containing the arguments and classpath for the java command. //The special file is supported by the "-V" switch on the VMS JVM. if (Os.isFamily("openvms")) { setupCommandLineForVMS(exe, command); } else { exe.setCommandline(command); } } /** * On VMS platform, we need to create a special java options file * containing the arguments and classpath for the java command. * The special file is supported by the "-V" switch on the VMS JVM. * * @param exe executable. * @param command command to execute. */ private void setupCommandLineForVMS(Execute exe, String[] command) { ExecuteJava.setupCommandLineForVMS(exe, command); } /** * Executes the given classname with the given arguments as if it * were a command line application. * * @param classname the name of the class to run. * @param args arguments for the class. * @throws BuildException in case of IOException in the execution. */ protected void run(String classname, Vector args) throws BuildException { CommandlineJava cmdj = new CommandlineJava(); cmdj.setClassname(classname); for (int i = 0; i < args.size(); i++) { cmdj.createArgument().setValue((String) args.elementAt(i)); } run(cmdj); } /** * Clear out the arguments to this java task. */ public void clearArgs() { getCommandLine().clearJavaArgs(); } /** * Create the Watchdog to kill a runaway process. * * @return new watchdog. * * @throws BuildException under unknown circumstances. * * @since Ant 1.5 */ protected ExecuteWatchdog createWatchdog() throws BuildException { if (timeout == null) { return null; } return new ExecuteWatchdog(timeout.longValue()); } /** * Log the specified Throwable. * @param t the Throwable to log. * @since 1.6.2 */ private void log(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter w = new PrintWriter(sw); t.printStackTrace(w); w.close(); log(sw.toString(), Project.MSG_ERR); } /** * Accessor to the command line. * * @return the current command line. * @since 1.6.3 */ public CommandlineJava getCommandLine() { return cmdl; } /** * Get the system properties of the command line. * * @return the current properties of this java invocation. * @since 1.6.3 */ public CommandlineJava.SysProperties getSysProperties() { return getCommandLine().getSystemProperties(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -