diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2017-06-08 20:03:06 +0200 |
---|---|---|
committer | Evgeny Mandrikov <Godin@users.noreply.github.com> | 2017-06-08 20:03:06 +0200 |
commit | 2a2f161920d7608630ba1163d45a858803cfef2e (patch) | |
tree | c7ab3642fa6bad331376003cf75321a2d2fea794 | |
parent | 817d0ae185106486dac2ba6dd229c1af5c42d03f (diff) | |
download | jacoco-2a2f161920d7608630ba1163d45a858803cfef2e.tar.gz |
Use dest argument as folder in any case (#543)
The instrument goal accepts folders as well as files as input. In case
of files the instrumented copy should be written to the folder given as
the dest option.
-rw-r--r-- | org.jacoco.cli.test/src/org/jacoco/cli/internal/commands/InstrumentTest.java | 21 | ||||
-rw-r--r-- | org.jacoco.cli/src/org/jacoco/cli/internal/commands/Instrument.java | 9 |
2 files changed, 27 insertions, 3 deletions
diff --git a/org.jacoco.cli.test/src/org/jacoco/cli/internal/commands/InstrumentTest.java b/org.jacoco.cli.test/src/org/jacoco/cli/internal/commands/InstrumentTest.java index 5d70b48c..59594a76 100644 --- a/org.jacoco.cli.test/src/org/jacoco/cli/internal/commands/InstrumentTest.java +++ b/org.jacoco.cli.test/src/org/jacoco/cli/internal/commands/InstrumentTest.java @@ -54,7 +54,7 @@ public class InstrumentTest extends CommandTestBase { } @Test - public void should_instrument_class_files_and_copy_resources() + public void should_instrument_class_files_and_copy_resources_when_folder_is_given() throws Exception { File destdir = tmp.getRoot(); @@ -73,6 +73,25 @@ public class InstrumentTest extends CommandTestBase { } @Test + public void should_instrument_class_files_to_dest_folder_when_class_files_are_given() + throws Exception { + File destdir = tmp.getRoot(); + + File src = new File(getClassPath(), + "org/jacoco/cli/internal/commands/InstrumentTest.class"); + + execute("instrument", "--dest", destdir.getAbsolutePath(), + src.getAbsolutePath()); + + assertOk(); + assertContains( + "[INFO] 1 classes instrumented to " + destdir.getAbsolutePath(), + out); + + assertInstrumented(new File(destdir, "InstrumentTest.class")); + } + + @Test public void should_not_instrument_anything_when_no_source_is_given() throws Exception { File destdir = tmp.getRoot(); diff --git a/org.jacoco.cli/src/org/jacoco/cli/internal/commands/Instrument.java b/org.jacoco.cli/src/org/jacoco/cli/internal/commands/Instrument.java index c52c0722..bb3a8ff6 100644 --- a/org.jacoco.cli/src/org/jacoco/cli/internal/commands/Instrument.java +++ b/org.jacoco.cli/src/org/jacoco/cli/internal/commands/Instrument.java @@ -49,14 +49,19 @@ public class Instrument extends Command { @Override public int execute(final PrintWriter out, final PrintWriter err) throws IOException { + final File absoluteDest = dest.getAbsoluteFile(); instrumenter = new Instrumenter( new OfflineInstrumentationAccessGenerator()); int total = 0; for (final File s : source) { - total += instrumentRecursive(s, dest); + if (s.isFile()) { + total += instrument(s, new File(absoluteDest, s.getName())); + } else { + total += instrumentRecursive(s, absoluteDest); + } } out.printf("[INFO] %s classes instrumented to %s.%n", - Integer.valueOf(total), dest.getAbsolutePath()); + Integer.valueOf(total), absoluteDest); return 0; } |