diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2013-09-21 20:39:55 +0200 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2013-09-21 21:13:58 +0200 |
commit | 80e4ab959ee3e39cf56f757ce53c3deb1dbc5cd5 (patch) | |
tree | 50c16ccaa9f81047f963146fd6d402cbabfc96d5 /org.jacoco.ant | |
parent | 9412b685496e840cf2f9691c2ec8e84f5f018252 (diff) | |
download | jacoco-80e4ab959ee3e39cf56f757ce53c3deb1dbc5cd5.tar.gz |
Consolidate implementation for exec file locking and parent folder
creation in ExecFileLoader.save().
Diffstat (limited to 'org.jacoco.ant')
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/DumpTask.java | 51 | ||||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/MergeTask.java | 1 |
2 files changed, 15 insertions, 37 deletions
diff --git a/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java b/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java index 9bfa937c..9fbd8011 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java @@ -14,16 +14,13 @@ package org.jacoco.ant; import static java.lang.String.format; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.net.InetAddress; import java.net.Socket; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; -import org.apache.tools.ant.util.FileUtils; -import org.jacoco.core.data.ExecutionDataWriter; +import org.jacoco.core.data.ExecFileLoader; import org.jacoco.core.runtime.AgentOptions; import org.jacoco.core.runtime.RemoteControlReader; import org.jacoco.core.runtime.RemoteControlWriter; @@ -34,13 +31,6 @@ import org.jacoco.core.runtime.RemoteControlWriter; */ public class DumpTask extends Task { - private static final OutputStream NUL = new OutputStream() { - @Override - public void write(final int b) throws IOException { - // nothing to do - } - }; - private boolean dump = true; private boolean reset = false; private File destfile = null; @@ -94,7 +84,7 @@ public class DumpTask extends Task { /** * Sets whether execution data should be downloaded from the remote host. - * Defaults to <code>false</code> + * Defaults to <code>true</code> * * @param dump * <code>true</code> to download execution data @@ -105,7 +95,7 @@ public class DumpTask extends Task { /** * Sets whether a reset command should be sent after the execution data has - * been copied. Defaults to <code>false</code> + * been dumped. Defaults to <code>false</code> * * @param reset * <code>true</code> to reset execution data @@ -126,9 +116,8 @@ public class DumpTask extends Task { getLocation()); } - OutputStream output = null; - try { + final ExecFileLoader loader = new ExecFileLoader(); // 1. Open socket connection final Socket socket = new Socket(InetAddress.getByName(address), @@ -138,36 +127,26 @@ public class DumpTask extends Task { socket.getOutputStream()); final RemoteControlReader remoteReader = new RemoteControlReader( socket.getInputStream()); + remoteReader.setSessionInfoVisitor(loader.getSessionInfoStore()); + remoteReader + .setExecutionDataVisitor(loader.getExecutionDataStore()); - // 2. Open file output - output = openOutputStream(); - final ExecutionDataWriter outputWriter = new ExecutionDataWriter( - output); - remoteReader.setSessionInfoVisitor(outputWriter); - remoteReader.setExecutionDataVisitor(outputWriter); - - // 3. Request dump + // 2. Request dump remoteWriter.visitDumpCommand(dump, reset); remoteReader.read(); + // 3. Write execution data to file + if (dump) { + log(format("Dumping execution data to %s", + destfile.getAbsolutePath())); + loader.save(destfile, append); + } + socket.close(); } catch (final IOException e) { throw new BuildException("Unable to dump coverage data", e, getLocation()); - } finally { - FileUtils.close(output); - } - } - - private OutputStream openOutputStream() throws IOException { - if (dump) { - log(format("Dumping execution data to %s", - destfile.getAbsolutePath())); - FileUtils.getFileUtils().createNewFile(destfile, true); - return new FileOutputStream(destfile, append); - } else { - return NUL; } } diff --git a/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java b/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java index 166e3181..9c2eb97f 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java @@ -96,7 +96,6 @@ public class MergeTask extends Task { log(format("Writing merged execution data to %s", destfile.getAbsolutePath())); try { - FileUtils.getFileUtils().createNewFile(destfile, true); loader.save(destfile, false); } catch (final IOException e) { throw new BuildException(format("Unable to write merged file %s", |