📄 defaultcompileradapter.java
字号:
// support for -source 1.1 and -source 1.2 has been // added with JDK 1.4.2 - and isn't present in 1.5.0 // or 1.6.0 either cmd.createArgument().setValue("1.3"); } else { cmd.createArgument().setValue(source); } } else if ((assumeJava15() || assumeJava16()) && attributes.getTarget() != null) { String t = attributes.getTarget(); if (t.equals("1.1") || t.equals("1.2") || t.equals("1.3") || t.equals("1.4")) { String s = t; if (t.equals("1.1")) { // 1.5.0 doesn't support -source 1.1 s = "1.2"; } attributes.log("", Project.MSG_WARN); attributes.log(" WARNING", Project.MSG_WARN); attributes.log("", Project.MSG_WARN); attributes.log("The -source switch defaults to 1.5 in JDK 1.5 and 1.6.", Project.MSG_WARN); attributes.log("If you specify -target " + t + " you now must also specify -source " + s + ".", Project.MSG_WARN); attributes.log("Ant will implicitly add -source " + s + " for you. Please change your build file.", Project.MSG_WARN); cmd.createArgument().setValue("-source"); cmd.createArgument().setValue(s); } } return cmd; } /** * Does the command line argument processing for modern and adds * the files to compile as well. * @return the command line */ protected Commandline setupModernJavacCommand() { Commandline cmd = new Commandline(); setupModernJavacCommandlineSwitches(cmd); logAndAddFilesToCompile(cmd); return cmd; } /** * Set up the command line. * @return the command line */ protected Commandline setupJavacCommand() { return setupJavacCommand(false); } /** * Does the command line argument processing for classic and adds * the files to compile as well. * @param debugLevelCheck if true set the debug level with the -g switch * @return the command line */ protected Commandline setupJavacCommand(boolean debugLevelCheck) { Commandline cmd = new Commandline(); setupJavacCommandlineSwitches(cmd, debugLevelCheck); logAndAddFilesToCompile(cmd); return cmd; } /** * Logs the compilation parameters, adds the files to compile and logs the * "niceSourceList" * @param cmd the command line */ protected void logAndAddFilesToCompile(Commandline cmd) { attributes.log("Compilation " + cmd.describeArguments(), Project.MSG_VERBOSE); StringBuffer niceSourceList = new StringBuffer("File"); if (compileList.length != 1) { niceSourceList.append("s"); } niceSourceList.append(" to be compiled:"); niceSourceList.append(StringUtils.LINE_SEP); for (int i = 0; i < compileList.length; i++) { String arg = compileList[i].getAbsolutePath(); cmd.createArgument().setValue(arg); niceSourceList.append(" "); niceSourceList.append(arg); niceSourceList.append(StringUtils.LINE_SEP); } attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE); } /** * Do the compile with the specified arguments. * @param args - arguments to pass to process on command line * @param firstFileName - index of the first source file in args, * if the index is negative, no temporary file will ever be * created, but this may hit the command line length limit on your * system. * @return the exit code of the compilation */ protected int executeExternalCompile(String[] args, int firstFileName) { return executeExternalCompile(args, firstFileName, true); } /** * Do the compile with the specified arguments. * @param args - arguments to pass to process on command line * @param firstFileName - index of the first source file in args, * if the index is negative, no temporary file will ever be * created, but this may hit the command line length limit on your * system. * @param quoteFiles - if set to true, filenames containing * spaces will be quoted when they appear in the external file. * This is necessary when running JDK 1.4's javac and probably * others. * @return the exit code of the compilation * * @since Ant 1.6 */ protected int executeExternalCompile(String[] args, int firstFileName, boolean quoteFiles) { String[] commandArray = null; File tmpFile = null; try { /* * Many system have been reported to get into trouble with * long command lines - no, not only Windows ;-). * * POSIX seems to define a lower limit of 4k, so use a temporary * file if the total length of the command line exceeds this limit. */ if (Commandline.toString(args).length() > COMMAND_LINE_LIMIT && firstFileName >= 0) { PrintWriter out = null; try { tmpFile = FILE_UTILS.createTempFile( "files", "", getJavac().getTempdir(), true, true); out = new PrintWriter(new FileWriter(tmpFile)); for (int i = firstFileName; i < args.length; i++) { if (quoteFiles && args[i].indexOf(" ") > -1) { args[i] = args[i].replace(File.separatorChar, '/'); out.println("\"" + args[i] + "\""); } else { out.println(args[i]); } } out.flush(); commandArray = new String[firstFileName + 1]; System.arraycopy(args, 0, commandArray, 0, firstFileName); commandArray[firstFileName] = "@" + tmpFile; } catch (IOException e) { throw new BuildException("Error creating temporary file", e, location); } finally { FileUtils.close(out); } } else { commandArray = args; } try { Execute exe = new Execute( new LogStreamHandler(attributes, Project.MSG_INFO, Project.MSG_WARN)); if (Os.isFamily("openvms")) { //Use the VM launcher instead of shell launcher on VMS //for java exe.setVMLauncher(true); } exe.setAntRun(project); exe.setWorkingDirectory(project.getBaseDir()); exe.setCommandline(commandArray); exe.execute(); return exe.getExitValue(); } catch (IOException e) { throw new BuildException("Error running " + args[0] + " compiler", e, location); } } finally { if (tmpFile != null) { tmpFile.delete(); } } } /** * Add extdirs to classpath * @param classpath the classpath to use * @deprecated since 1.5.x. * Use org.apache.tools.ant.types.Path#addExtdirs instead. */ protected void addExtdirsToClasspath(Path classpath) { classpath.addExtdirs(extdirs); } /** * Adds the command line arguments specific to the current implementation. * @param cmd the command line to use */ protected void addCurrentCompilerArgs(Commandline cmd) { cmd.addArguments(getJavac().getCurrentCompilerArgs()); } /** * Shall we assume JDK 1.1 command line switches? * @return true if jdk 1.1 * @since Ant 1.5 */ protected boolean assumeJava11() { return "javac1.1".equals(attributes.getCompilerVersion()); } /** * Shall we assume JDK 1.2 command line switches? * @return true if jdk 1.2 * @since Ant 1.5 */ protected boolean assumeJava12() { return "javac1.2".equals(attributes.getCompilerVersion()) || ("classic".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) || ("extJavac".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)); } /** * Shall we assume JDK 1.3 command line switches? * @return true if jdk 1.3 * @since Ant 1.5 */ protected boolean assumeJava13() { return "javac1.3".equals(attributes.getCompilerVersion()) || ("classic".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) || ("modern".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) || ("extJavac".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)); } /** * Shall we assume JDK 1.4 command line switches? * @return true if jdk 1.4 * @since Ant 1.6.3 */ protected boolean assumeJava14() { return "javac1.4".equals(attributes.getCompilerVersion()) || ("classic".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) || ("modern".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) || ("extJavac".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)); } /** * Shall we assume JDK 1.5 command line switches? * @return true if JDK 1.5 * @since Ant 1.6.3 */ protected boolean assumeJava15() { return "javac1.5".equals(attributes.getCompilerVersion()) || ("classic".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) || ("modern".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) || ("extJavac".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)); } /** * Shall we assume JDK 1.6 command line switches? * @return true if JDK 1.6 * @since Ant 1.7 */ protected boolean assumeJava16() { return "javac1.6".equals(attributes.getCompilerVersion()) || ("classic".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)) || ("modern".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)) || ("extJavac".equals(attributes.getCompilerVersion()) && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)); } /** * Combines a user specified bootclasspath with the system * bootclasspath taking build.sysclasspath into account. * * @return a non-null Path instance that combines the user * specified and the system bootclasspath. */ protected Path getBootClassPath() { Path bp = new Path(project); if (bootclasspath != null) { bp.append(bootclasspath); } return bp.concatSystemBootClasspath("ignore"); } /** * The argument the compiler wants to see if the debug attribute * has been set to false. * * <p>A return value of <code>null</code> means no argument at all.</p> * * @return "-g:none" unless we expect to invoke a JDK 1.1 compiler. * * @since Ant 1.6.3 */ protected String getNoDebugArgument() { return assumeJava11() ? null : "-g:none"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -