1 18 19 package org.apache.tools.ant.taskdefs.compilers; 20 21 import java.io.IOException ; 22 import java.io.File ; 23 24 import org.apache.tools.ant.BuildException; 25 import org.apache.tools.ant.Project; 26 import org.apache.tools.ant.types.Commandline; 27 import org.apache.tools.ant.taskdefs.condition.Os; 28 import org.apache.tools.ant.util.JavaEnvUtils; 29 import org.apache.tools.ant.util.FileUtils; 30 31 36 public class JavacExternal extends DefaultCompilerAdapter { 37 38 43 public boolean execute() throws BuildException { 44 attributes.log("Using external javac compiler", Project.MSG_VERBOSE); 45 46 Commandline cmd = new Commandline(); 47 cmd.setExecutable(getJavac().getJavacExecutable()); 48 if (!assumeJava11() && !assumeJava12()) { 49 setupModernJavacCommandlineSwitches(cmd); 50 } else { 51 setupJavacCommandlineSwitches(cmd, true); 52 } 53 int firstFileName = assumeJava11() ? -1 : cmd.size(); 54 logAndAddFilesToCompile(cmd); 55 if (Os.isFamily("openvms")) { 59 return execOnVMS(cmd, firstFileName); 60 } 61 return 62 executeExternalCompile(cmd.getCommandline(), firstFileName, 63 true) 64 == 0; 65 } 66 67 73 private boolean execOnVMS(Commandline cmd, int firstFileName) { 74 File vmsFile = null; 75 try { 76 vmsFile = JavaEnvUtils.createVmsJavaOptionFile(cmd.getArguments()); 77 String [] commandLine = {cmd.getExecutable(), 78 "-V", 79 vmsFile.getPath()}; 80 return 0 == executeExternalCompile(commandLine, 81 firstFileName, 82 true); 83 84 } catch (IOException e) { 85 throw new BuildException("Failed to create a temporary file for \"-V\" switch"); 86 } finally { 87 FileUtils.delete(vmsFile); 88 } 89 } 90 91 } 92 93 | Popular Tags |