📄 commandlinejava.java
字号:
* @see #getJar() */ public String getClassname() { if (!executeJar) { return javaCommand.getExecutable(); } return null; } /** * Create a classpath. * @param p the project to use to create the path. * @return a path to be configured. */ public Path createClasspath(Project p) { if (classpath == null) { classpath = new Path(p); } return classpath; } /** * Create a boot classpath. * @param p the project to use to create the path. * @return a path to be configured. * @since Ant 1.6 */ public Path createBootclasspath(Project p) { if (bootclasspath == null) { bootclasspath = new Path(p); } return bootclasspath; } /** * Get the vm version. * @return the vm version. */ public String getVmversion() { return vmVersion; } /** * Get the command line to run a Java vm. * @return the list of all arguments necessary to run the vm. */ public String[] getCommandline() { //create the list List commands = new LinkedList(); final ListIterator listIterator = commands.listIterator(); //fill it addCommandsToList(listIterator); //convert to an array return (String[]) commands.toArray(new String[commands.size()]); } /** * Add all the commands to a list identified by the iterator passed in. * @param listIterator an iterator that supports the add method. * @since Ant 1.6 */ private void addCommandsToList(final ListIterator listIterator) { //create the command to run Java, including user specified options getActualVMCommand().addCommandToList(listIterator); // properties are part of the vm options... sysProperties.addDefinitionsToList(listIterator); if (isCloneVm()) { SysProperties clonedSysProperties = new SysProperties(); PropertySet ps = new PropertySet(); PropertySet.BuiltinPropertySetName sys = new PropertySet.BuiltinPropertySetName(); sys.setValue("system"); ps.appendBuiltin(sys); clonedSysProperties.addSyspropertyset(ps); clonedSysProperties.addDefinitionsToList(listIterator); } //boot classpath Path bcp = calculateBootclasspath(true); if (bcp.size() > 0) { listIterator.add("-Xbootclasspath:" + bcp.toString()); } //main classpath if (haveClasspath()) { listIterator.add("-classpath"); listIterator.add( classpath.concatSystemClasspath("ignore").toString()); } //now any assertions are added if (getAssertions() != null) { getAssertions().applyAssertions(listIterator); } // JDK usage command line says that -jar must be the first option, as there is // a bug in JDK < 1.4 that forces the jvm type to be specified as the first // option, it is appended here as specified in the docs even though there is // in fact no order. if (executeJar) { listIterator.add("-jar"); } // this is the classname to run as well as its arguments. // in case of 'executeJar', the executable is a jar file. javaCommand.addCommandToList(listIterator); } /** * Specify max memory of the JVM. * -mx or -Xmx depending on VM version. * @param max the string to pass to the jvm to specifiy the max memory. */ public void setMaxmemory(String max) { this.maxMemory = max; } /** * Get a string description. * @return the command line as a string. */ public String toString() { return Commandline.toString(getCommandline()); } /** * Return a String that describes the command and arguments suitable for * verbose output before a call to <code>Runtime.exec(String[])<code>. * @return the description string. * @since Ant 1.5 */ public String describeCommand() { return Commandline.describeCommand(getCommandline()); } /** * Return a String that describes the java command and arguments * for in-VM executions. * * <p>The class name is the executable in this context.</p> * @return the description string. * @since Ant 1.5 */ public String describeJavaCommand() { return Commandline.describeCommand(getJavaCommand()); } /** * Get the VM command parameters, including memory settings. * @return the VM command parameters. */ protected Commandline getActualVMCommand() { Commandline actualVMCommand = (Commandline) vmCommand.clone(); if (maxMemory != null) { if (vmVersion.startsWith("1.1")) { actualVMCommand.createArgument().setValue("-mx" + maxMemory); } else { actualVMCommand.createArgument().setValue("-Xmx" + maxMemory); } } return actualVMCommand; } /** * Get the size of the java command line. This is a fairly intensive * operation, as it has to evaluate the size of many components. * @return the total number of arguments in the java command line. * @see #getCommandline() * @deprecated since 1.7. * Please dont use this, it effectively creates the * entire command. */ public int size() { int size = getActualVMCommand().size() + javaCommand.size() + sysProperties.size(); // cloned system properties if (isCloneVm()) { size += System.getProperties().size(); } // classpath is "-classpath <classpath>" -> 2 args if (haveClasspath()) { size += 2; } // bootclasspath is "-Xbootclasspath:<classpath>" -> 1 arg if (calculateBootclasspath(true).size() > 0) { size++; } // jar execution requires an additional -jar option if (executeJar) { size++; } //assertions take up space too if (getAssertions() != null) { size += getAssertions().size(); } return size; } /** * Get the Java command to be used. * @return the java command--not a clone. */ public Commandline getJavaCommand() { return javaCommand; } /** * Get the VM command, including memory. * @return A deep clone of the instance's VM command, with memory settings added. */ public Commandline getVmCommand() { return getActualVMCommand(); } /** * Get the classpath for the command. * @return the classpath or null. */ public Path getClasspath() { return classpath; } /** * Get the boot classpath. * @return boot classpath or null. */ public Path getBootclasspath() { return bootclasspath; } /** * Cache current system properties and set them to those in this * Java command. * @throws BuildException if Security prevented this operation. */ public void setSystemProperties() throws BuildException { sysProperties.setSystem(); } /** * Restore the cached system properties. * @throws BuildException if Security prevented this operation, or * there was no system properties to restore */ public void restoreSystemProperties() throws BuildException { sysProperties.restoreSystem(); } /** * Get the system properties object. * @return The system properties object. */ public SysProperties getSystemProperties() { return sysProperties; } /** * Deep clone the object. * @return a CommandlineJava object. * @throws BuildException if anything went wrong. * @throws CloneNotSupportedException never. */ public Object clone() throws CloneNotSupportedException { try { CommandlineJava c = (CommandlineJava) super.clone(); c.vmCommand = (Commandline) vmCommand.clone(); c.javaCommand = (Commandline) javaCommand.clone(); c.sysProperties = (SysProperties) sysProperties.clone(); if (classpath != null) { c.classpath = (Path) classpath.clone(); } if (bootclasspath != null) { c.bootclasspath = (Path) bootclasspath.clone(); } if (assertions != null) { c.assertions = (Assertions) assertions.clone(); } return c; } catch (CloneNotSupportedException e) { throw new BuildException(e); } } /** * Clear out the java arguments. */ public void clearJavaArgs() { javaCommand.clearArgs(); } /** * Determine whether the classpath has been specified, and whether it shall * really be used or be nulled by build.sysclasspath. * @return true if the classpath is to be used. * @since Ant 1.6 */ public boolean haveClasspath() { Path fullClasspath = classpath != null ? classpath.concatSystemClasspath("ignore") : null; return fullClasspath != null && fullClasspath.toString().trim().length() > 0; } /** * Determine whether the bootclasspath has been specified, and whether it * shall really be used (build.sysclasspath could be set or the VM may not * support it). * * @param log whether to log a warning if a bootclasspath has been * specified but will be ignored. * @return true if the bootclasspath is to be used. * @since Ant 1.6 */ protected boolean haveBootclasspath(boolean log) { return calculateBootclasspath(log).size() > 0; } /** * Calculate the bootclasspath based on the bootclasspath * specified, the build.sysclasspath and ant.build.clonevm magic * properties as well as the cloneVm attribute. * @param log whether to write messages to the log. * @since Ant 1.7 */ private Path calculateBootclasspath(boolean log) { if (vmVersion.startsWith("1.1")) { if (bootclasspath != null && log) { bootclasspath.log("Ignoring bootclasspath as " + "the target VM doesn't support it."); } } else { if (bootclasspath != null) { return bootclasspath.concatSystemBootClasspath(isCloneVm() ? "last" : "ignore"); } else if (isCloneVm()) { return Path.systemBootClasspath; } } return new Path(null); } /** * Find out whether either of the cloneVm attribute or the magic property * ant.build.clonevm has been set. * @return <code>boolean</code>. * @since 1.7 */ private boolean isCloneVm() { return cloneVm || "true".equals(System.getProperty("ant.build.clonevm")); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -