/** * Creates a instrumented version of the given class if possible. * * @param reader * definition of the class as ASM reader * @return instrumented definition * */ public byte[] instrument(final ClassReader reader) { return instrument(reader.b); }
/** * Creates a instrumented version of the given class if possible. * * @param buffer * definition of the class * @param name * a name used for exception messages * @return instrumented definition * @throws IOException * if the class can't be instrumented */ public byte[] instrument(final byte[] buffer, final String name) throws IOException { try { return instrument(buffer); } catch (final RuntimeException e) { throw instrumentError(name, e); } }
instrument(detector.getInputStream(), output, name); return 1; case ContentTypeDetector.ZIPFILE:
/** * Creates a instrumented version of the given class file. The provided * {@link InputStream} and {@link OutputStream} instances are not closed by * this method. * * @param input * stream to read class definition from * @param output * stream to write the instrumented version of the class to * @param name * a name used for exception messages * @throws IOException * if reading data from the stream fails or the class can't be * instrumented */ public void instrument(final InputStream input, final OutputStream output, final String name) throws IOException { output.write(instrument(input, name)); }
/** * Creates a instrumented version of the given class if possible. The * provided {@link InputStream} is not closed by this method. * * @param input * stream to read class definition from * @param name * a name used for exception messages * @return instrumented definition * @throws IOException * if reading data from the stream fails or the class can't be * instrumented */ public byte[] instrument(final InputStream input, final String name) throws IOException { final byte[] bytes; try { bytes = InputStreams.readFully(input); } catch (final IOException e) { throw instrumentError(name, e); } return instrument(bytes, name); }
private void instrumentAll(String classesDirectory) { final Iterator<File> iterator = FileUtils.iterateFiles(new File(classesDirectory), new String[]{"class"}, true); while (iterator.hasNext()) { final File next = iterator.next(); final String fileName = next.getPath().substring(classesDirectory.length() + (classesDirectory.endsWith(ConstantsHelper.FILE_SEPARATOR) ? 0 : 1)); final String fullQualifiedName = ConstantsHelper.pathToFullQualifiedName.apply(fileName).substring(0, fileName.length() - ".class".length()); try { instrumentedClassLoader.addDefinition(fullQualifiedName, instrumenter.instrument(instrumentedClassLoader.getResourceAsStream(fileName), fullQualifiedName)); } catch (IOException e) { throw new RuntimeException(fileName + "," + new File(fileName).getAbsolutePath() + "," + fullQualifiedName, e); } } clearCache(instrumentedClassLoader); }
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); } } }
private static void instrumentFile( @NonNull Instrumenter instrumenter, @NonNull File inputFile, @NonNull File outputFile) throws IOException { InputStream inputStream = null; try { inputStream = Files.asByteSource(inputFile).openBufferedStream(); Files.createParentDirs(outputFile); byte[] instrumented = instrumenter.instrument( inputStream, inputFile.toString()); Files.write(instrumented, outputFile); } finally { Closeables.closeQuietly(inputStream); } }
final byte[] instrumented = instr.instrument(getTargetClass(targetName), ""); memoryClassLoader.addDefinition(junitName, instr.instrument(getTargetClass(junitName), "")); final Class<?> junitClass = memoryClassLoader.loadClass(junitName); JUnitCore junit = new JUnitCore();