diff options
Diffstat (limited to 'src/main/java/net/sf/antcontrib/cpptasks/compiler')
4 files changed, 179 insertions, 92 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java index d0cd77b..045f1ff 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java @@ -123,6 +123,13 @@ public abstract class AbstractProcessor implements Processor, Cloneable { String osName = getOSName(); return "Mac OS X".equals(osName); } +// BEGINFREEHEP + protected boolean isWindows() { + String osName = getOSName(); + return (osName != null) && osName.startsWith("Windows"); + } +// ENDFREEHEP + public final String toString() { return getIdentifier(); } diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CaptureStreamHandler.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CaptureStreamHandler.java index 83c59f7..24a0193 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CaptureStreamHandler.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CaptureStreamHandler.java @@ -14,7 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +// BEGINFREEHEP, fully replaced with a runner with threads package net.sf.antcontrib.cpptasks.compiler; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -31,92 +33,135 @@ import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; * @author Curt Arnold */ public class CaptureStreamHandler implements ExecuteStreamHandler { - /** - * Runs an executable and captures the output in a String array - * - * @param cmdline - * command line arguments - * @return output of process - */ - public static String[] run(String[] cmdline) { - CaptureStreamHandler handler = new CaptureStreamHandler(); - Execute exec = new Execute(handler); - exec.setCommandline(cmdline); - try { - int status = exec.execute(); - } catch (IOException ex) { - } - return handler.getOutput(); - } - private InputStream errorStream; - private InputStream fromProcess; - public CaptureStreamHandler() { - } - public String[] getOutput() { - String[] output; - if (fromProcess != null) { - Vector lines = new Vector(10); - try { - BufferedReader reader = new BufferedReader( - new InputStreamReader(errorStream)); - for (int i = 0; i < 2; i++) { - for (int j = 0; j < 100; j++) { - String line = reader.readLine(); - if (line == null) { - reader = new BufferedReader(new InputStreamReader( - fromProcess)); - break; - } - lines.addElement(line); - } - } - } catch (IOException ex) { - } - output = new String[lines.size()]; - lines.copyInto(output); - return output; - } - output = new String[0]; - return output; - } - /** - * Install a handler for the error stream of the subprocess. - * - * @param is - * input stream to read from the error stream from the - * subprocess - */ - public void setProcessErrorStream(InputStream is) throws IOException { - errorStream = is; - } - /** - * Install a handler for the input stream of the subprocess. - * - * @param os - * output stream to write to the standard input stream of the - * subprocess - */ - public void setProcessInputStream(OutputStream os) throws IOException { - os.close(); - } - /** - * Install a handler for the output stream of the subprocess. - * - * @param is - * input stream to read from the error stream from the - * subprocess - */ - public void setProcessOutputStream(InputStream is) throws IOException { - fromProcess = is; - } - /** - * Start handling of the streams. - */ - public void start() throws IOException { - } - /** - * Stop handling of the streams - will not be restarted. - */ - public void stop() { - } + + String[] output; + + /** + * Runs an executable and captures the output in a String array + * + * @param cmdline + * command line arguments + * @return output of process + */ + public static String[] run(String[] cmdline) { + CaptureStreamHandler handler = new CaptureStreamHandler(); + Execute exec = new Execute(handler); + exec.setCommandline(cmdline); + try { + int status = exec.execute(); + } catch (IOException ex) { + } + return handler.getOutput() != null ? handler.getOutput() : new String[0]; + } + + private InputStream processErrorStream; + + private InputStream processOutputStream; + + public CaptureStreamHandler() { + } + + public String[] getOutput() { + return output; + } + + static class Copier extends Thread { + InputStream is; + + Vector lines; + + Copier(InputStream is) { + this.is = is; + lines = new Vector(10); + } + + public void run() { + try { + BufferedReader reader = new BufferedReader( new InputStreamReader(is) ); + while ( true ) { + String line = reader.readLine(); + if ( line == null ) + break; + lines.addElement( line ); + } + } catch (IOException e) { + // Ignore + } + } + + public Vector getLines() { + return lines; + } + } + + /** + * Reads concurrently both the process standard output and standard error. + * The standard error - if not empty - is copied to the output string array field. Otherwise + * the standard output is copied to the output field. The output field is set to an empty array + * in case of any error. + */ + public void gatherOutput() { + try { + Copier errorCopier = new Copier(processErrorStream); + Copier outputCopier = new Copier(processOutputStream); + errorCopier.start(); + outputCopier.start(); + errorCopier.join(); + outputCopier.join(); + if (errorCopier.getLines().size() > 0) { + output = new String[errorCopier.getLines().size()]; + errorCopier.getLines().copyInto(output); + } else { + output = new String[outputCopier.getLines().size()]; + outputCopier.getLines().copyInto(output); + } + } catch (Exception e) { + output = new String[0]; + } + } + + /** + * Install a handler for the error stream of the subprocess. + * + * @param is + * input stream to read from the error stream from the subprocess + */ + public void setProcessErrorStream(InputStream is) throws IOException { + processErrorStream = is; + } + + /** + * Install a handler for the input stream of the subprocess. + * + * @param os + * output stream to write to the standard input stream of the + * subprocess + */ + public void setProcessInputStream(OutputStream os) throws IOException { + os.close(); + } + + /** + * Install a handler for the output stream of the subprocess. + * + * @param is + * input stream to read from the error stream from the subprocess + */ + public void setProcessOutputStream(InputStream is) throws IOException { + processOutputStream = is; + } + + /** + * Start handling of the streams. + */ + public void start() throws IOException { + gatherOutput(); + } + + /** + * Stop handling of the streams - will not be restarted. + */ + public void stop() { + } +// ENDFREEHEP } diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java index 86594fa..93c3e1e 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java @@ -145,9 +145,10 @@ public abstract class CommandLineLinker extends AbstractLinker String[] libnames = null; LibrarySet[] libsets = specificDef.getActiveLibrarySets(defaultProviders,1); - if (libsets.length > 0) { +// FREEHEP call at all times +// if (libsets.length > 0) { libnames = addLibrarySets(task, libsets, preargs, midargs, endargs); - } +// } StringBuffer buf = new StringBuffer(getIdentifier()); for (int i = 0; i < 3; i++) { @@ -336,7 +337,10 @@ public abstract class CommandLineLinker extends AbstractLinker String outputDir, String sourceFile) { String relativePath = CUtil.getRelativePath(outputDir, new File(sourceFile)); - return quoteFilename(buf,relativePath); +// FREEHEP, return the shortest +// return quoteFilename(buf, sourceFile.length() > relativePath.length() ? relativePath : sourceFile); +// FREEHEP trying with always absolute paths, as Windows relPaths have a tighter restriction on length than absPaths... + return quoteFilename(buf, sourceFile); } /** diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java index 70ee93f..67d7e6b 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkType.java @@ -27,6 +27,12 @@ public class LinkType { private OutputTypeEnum outputType = new OutputTypeEnum(); private boolean staticRuntime = false; private SubsystemEnum subsystem = new SubsystemEnum(); + +// BEGINFREEHEP + private boolean linkCPP = true; + private boolean linkFortran = false; +// ENDFREEHEP + /** * Constructor * @@ -44,6 +50,11 @@ public class LinkType { String value = outputType.getValue(); return value.equals("executable"); } + + public boolean isJNIModule() { + String value = outputType.getValue(); + return value.equals("jni"); + } /** * Gets whether the link should produce a plugin module. * @@ -60,7 +71,8 @@ public class LinkType { */ public boolean isSharedLibrary() { String value = outputType.getValue(); - return value.equals("shared") || value.equals("plugin"); +// FREEHEP + return value.equals("shared") || value.equals("plugin") || value.equals("jni"); } /** * Gets whether the link should produce a static library. @@ -147,4 +159,23 @@ public class LinkType { public String getSubsystem() { return subsystem.getValue(); } + +// BEGINFREEHEP + public void setLinkCPP(boolean linkCPP) { + this.linkCPP = linkCPP; + } + + public boolean linkCPP() { + return linkCPP; + } + + public void setLinkFortran(boolean linkFortran) { + this.linkFortran = linkFortran; + } + + public boolean linkFortran() { + return linkFortran; + } +// ENDFREEHEP + } |