private void appendClasspath(String classpath) { try { ClassPool pool= ClassPool.getDefault(); pool.appendPathList(classpath); } catch (NotFoundException e) { throw new RuntimeException(e); } }
public OfflineClassTransformer(String outputDir, String classPoolClasspath) throws NotFoundException { classPool.appendPathList(classPoolClasspath); transformedClassListener = new TransformedClassWriteToDiskListener(outputDir); }
public SignatureImport(boolean useSystemClassPath, String supportingJars) { classPool = new ClassPool(); if (supportingJars != null) { try { classPool.appendPathList(supportingJars); } catch (NotFoundException e) { throw new RuntimeException(e); } } if (useSystemClassPath) { classPool.appendSystemPath(); } }
/** * Run the main method of the given class, transforming any classes found on * the given classpath as they are loaded. * * @param pool * the classpool to hold classes as they are loaded * @param tf * the transform(s) to apply * @param classpath * the classpath on which to search for classes * @param mainClass * the main class with the <code>main(String[])</code> method * @param args * the arguments to pass to the main method * @return the classloader used for loading the classes in the jar file * @throws Throwable * if an error occurs */ public static Loader run(ClassPool pool, MultiTransformClassFileTransformer tf, String classpath, String mainClass, String[] args) throws Throwable { final String[] paths = classpath.split(File.pathSeparator); final URL[] urls = new URL[paths.length]; for (int i = 0; i < paths.length; i++) urls[i] = new File(paths[i]).toURI().toURL(); final ClassLoader parent = new URLClassLoader(urls); pool.appendPathList(classpath); return run(parent, pool, tf, mainClass, args); }
/** * Run the main method of the given class, transforming any classes found on * the given classpath as they are loaded. * * @param pool * the classpool to hold classes as they are loaded * @param tf * the transform(s) to apply * @param classpath * the classpath on which to search for classes * @param mainClass * the main class with the <code>main(String[])</code> method * @param args * the arguments to pass to the main method * @return the classloader used for loading the classes in the jar file * @throws Throwable * if an error occurs */ public static Loader run(ClassPool pool, MultiTransformClassFileTransformer tf, String classpath, String mainClass, String[] args) throws Throwable { final String[] paths = classpath.split(File.pathSeparator); final URL[] urls = new URL[paths.length]; for (int i = 0; i < paths.length; i++) urls[i] = new File(paths[i]).toURI().toURL(); final ClassLoader parent = new URLClassLoader(urls); pool.appendPathList(classpath); return run(parent, pool, tf, mainClass, args); }
private void init(String configFileName, File in, File out, List classpath) { if ((in == null) || (!in.exists())) { throw new Error("Input jar or folder expected"); } if (in.isFile() && (!in.getName().endsWith(".jar"))) { throw new Error("Input file should be .jar"); } log.debug("input " + in.getAbsolutePath()); log.debug("output " + out.getAbsolutePath()); this.input = in; this.output = out; this.config = new Config(configFileName); this.classPool = new ClassPool(); try { this.classPool.appendClassPath(this.input.getAbsolutePath()); if (classpath != null) { for (Iterator i = classpath.iterator(); i.hasNext();) { String path = (String) i.next(); log.debug("classPath " + path); this.classPool.appendPathList(path); } } } catch (NotFoundException e) { log.error("Can't setup class path", e); throw new ConfigException("Can't setup class path", e); } }
pool.appendPathList(classPathParam);
classPool.appendPathList(classpath); if (supportingJars != null) { classPool.appendPathList(supportingJars);
public static void rewriteAccess(String classpath, File classFile) throws Exception { ClassPool classPool = new ClassPool(); classPool.appendSystemPath(); classPool.appendPathList(classpath);
public static void rewriteAccess(String classpath, File classFile) throws Exception { ClassPool classPool = new ClassPool(); classPool.appendSystemPath(); classPool.appendPathList(classpath);
classPool.appendPathList(input.getAbsolutePath()); if (this.supportingJars != null) { classPool.appendPathList(this.supportingJars);
public static void generateAccessors(String classpath, File classFile) throws Exception { ClassPool classPool = new ClassPool(); classPool.appendSystemPath(); classPool.appendPathList(classpath);
public static void generateAccessors(String classpath, File classFile) throws Exception { ClassPool classPool = new ClassPool(); classPool.appendSystemPath(); classPool.appendPathList(classpath);
/** * Instruments the given directory, reading each .class file, processing it, * and writing it back to the filesystem * * @param configurer * an {@link InstrumenterConfigurer} that will setup the actual * {@link Instrumenter} that will be used to process the directory * @param processDirectory * the directory with .class files to process * @param extraPath * a string containing a list of additional paths to add to the * classpath used on instrumentation. This string is * system-dependent, using the platform separator and directory * separator * @throws Exception * @see File#pathSeparator * @see File#separator */ public static void runInstrumentation(@NonNull InstrumenterConfigurer configurer, @NonNull Directory processDirectory, @NonNull String extraPath) throws Exception { ClassPool classPool = new ClassPool(true); classPool.appendPathList(extraPath); classPool.appendClassPath(processDirectory.getAbsolutePath()); InstrumenterImpl instrumenter = new InstrumenterImpl(classPool); configurer.configureInstrumenter(instrumenter); instrumenter.ensureConfigured(); new InstrumentationContext(instrumenter, processDirectory, classPool).doInstrument(); }