/** * @param isJUnit5 tell if the given tests are JUnit5 or not * @param classesDirectory the path to the directory that contains the .class file of sources * @param testClassesDirectory the path to the directory that contains the .class file of test sources * @param blackList the names of the test methods to NOT be run. */ public JacocoRunner(boolean isJUnit5, String classesDirectory, String testClassesDirectory, List<String> blackList) { this.isJUnit5 = isJUnit5; try { this.instrumentedClassLoader = new MemoryClassLoader( new URL[]{ new File(classesDirectory).toURI().toURL(), new File(testClassesDirectory).toURI().toURL() } ); } catch (MalformedURLException e) { throw new RuntimeException(e); } this.blackList = blackList; this.runtime = new LoggerRuntime(); this.instrumenter = new Instrumenter(this.runtime); // instrument source code instrumentAll(classesDirectory); }
public InputStream openStream() { try { final IRuntime runtime = ArquillianRuntime.getInstance(); final Instrumenter instrumenter = new Instrumenter(runtime); final byte[] instrumented = instrumenter.instrument(asset.openStream(), EX_STRING); return new ByteArrayInputStream(instrumented); } catch (Exception e) { throw new RuntimeException("Could not instrument Asset " + asset, e); } } }
public InputStream openStream() { try { final IRuntime runtime = ArquillianRuntime.getInstance(); final Instrumenter instrumenter = new Instrumenter(runtime); final byte[] instrumented = instrumenter.instrument(asset.openStream(), EX_STRING); return new ByteArrayInputStream(instrumented); } catch (Exception e) { throw new RuntimeException("Could not instrument Asset " + asset, e); } } }
@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) { 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), absoluteDest); return 0; }
@Override public void transform(@NonNull TransformInvocation invocation) throws IOException, TransformException, InterruptedException { checkNotNull(invocation.getOutputProvider(), "Missing output object for transform " + getName()); File outputDir = invocation.getOutputProvider().getContentLocation( "main", getOutputTypes(), getScopes(), Format.DIRECTORY); FileUtils.mkdirs(outputDir); TransformInput input = Iterables.getOnlyElement(invocation.getInputs()); // we don't want jar inputs. Preconditions.checkState(input.getJarInputs().isEmpty()); DirectoryInput directoryInput = Iterables.getOnlyElement(input.getDirectoryInputs()); File inputDir = directoryInput.getFile(); Instrumenter instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator()); if (invocation.isIncremental()) { instrumentFilesIncremental(instrumenter, inputDir, outputDir, directoryInput.getChangedFiles()); } else { instrumentFilesFullRun(instrumenter, inputDir, outputDir); } }