diff options
-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; } |