Example usage for org.apache.commons.lang3.reflect FieldUtils writeStaticField

List of usage examples for org.apache.commons.lang3.reflect FieldUtils writeStaticField

Introduction

In this page you can find the example usage for org.apache.commons.lang3.reflect FieldUtils writeStaticField.

Prototype

public static void writeStaticField(final Class<?> cls, final String fieldName, final Object value,
        final boolean forceAccess) throws IllegalAccessException 

Source Link

Document

Writes a named static Field .

Usage

From source file:com.taobao.android.builder.tasks.transform.ClassInjectTransform.java

private ClassPool initClassPool(List<JarInput> jarInputs, List<DirectoryInput> directoryInputs) {

    if (((VariantScopeImpl) this.appVariantContext.getScope()).getVariantData().getName().toLowerCase()
            .contains("debug")) {
        try {/*from w  ww  . ja va 2  s. com*/
            FieldUtils.writeStaticField(ClassPool.class, "defaultPool", null, true);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    } else {
        //logger.warn(">>> ?daemon <<<<");
    }

    final ClassPool pool = ClassPool.getDefault();

    try {
        File verifyFile = PathUtil.getJarFile(com.taobao.verify.Verifier.class);
        pool.insertClassPath(verifyFile.getAbsolutePath());
        for (File file : appVariantContext.getScope().getJavaClasspath()) {
            if (file.isFile()) {
                pool.insertClassPath(file.getAbsolutePath());
            } else {
                pool.appendClassPath(file.getAbsolutePath());
            }
        }
        String path = Joiner.on(File.pathSeparator)
                .join(scope.getGlobalScope().getAndroidBuilder().getBootClasspathAsStrings(false));
        pool.appendPathList(path);
        for (JarInput jarInput : jarInputs) {
            pool.insertClassPath(jarInput.getFile().getAbsolutePath());
        }
        for (DirectoryInput directoryInput : directoryInputs) {
            pool.appendClassPath(directoryInput.getFile().getAbsolutePath());
        }
    } catch (NotFoundException e) {
        throw new StopExecutionException(e.getMessage());
    }
    return pool;
}