@Override protected ClassLoader createRobolectricClassLoader(Setup setup, SdkConfig sdkConfig) { URL[] urls = getJarResolver().getLocalArtifactUrls(sdkConfig.getSdkClasspathDependencies()); return new AsmInstrumentingClassLoader(setup, urls) { @Override protected byte[] getByteCode(String className) throws ClassNotFoundException { if (className.startsWith("com.github.stephanenicolas.injectview")) { try { CtClass dummyClass = ClassPool.getDefault().get(className); if (processor.shouldTransform(dummyClass)) { log.debug("Intercepting via InjectView " + className); processor.applyTransformations(dummyClass); byte[] bytes = dummyClass.toBytecode(); System.out.println("Size of weaved byte code :" + bytes.length); FileOutputStream fileOutputStream = new FileOutputStream("/tmp/" + className + ".class"); fileOutputStream.write(bytes); fileOutputStream.close(); return bytes; } } catch (Exception e) { throw new RuntimeException("Impossible to transform class " + className, e); } } return super.getByteCode(className); } }; }
@Override protected SdkConfig pickSdkVersion( AndroidManifest appManifest, Config config) { // current Robolectric supports not the latest android SDK version // so we must downgrade to simulate the latest supported version. config = overwriteConfig(config, "emulateSdk", "18"); return super.pickSdkVersion(appManifest, config); }
@Override protected ClassLoader createRobolectricClassLoader(Setup setup, SdkConfig sdkConfig) { URL[] urls = getJarResolver().getLocalArtifactUrls(sdkConfig.getSdkClasspathDependencies()); return new AsmInstrumentingClassLoader(setup, urls) { @Override protected byte[] getByteCode(String className) throws ClassNotFoundException { if (className.startsWith("com.github.stephanenicolas.lxglifecycle")) { try { CtClass dummyClass = ClassPool.getDefault().get(className); if (processor.shouldTransform(dummyClass)) { log.debug("Intercepting via InjectExtra " + className); processor.applyTransformations(dummyClass); byte[] bytes = dummyClass.toBytecode(); System.out.println("Size of weaved byte code :" + bytes.length); FileOutputStream fileOutputStream = new FileOutputStream("/tmp/" + className + ".class"); fileOutputStream.write(bytes); fileOutputStream.close(); return bytes; } } catch (Exception e) { throw new RuntimeException("Impossible to transform class " + className, e); } } return super.getByteCode(className); } }; }
private Constructor<?> findSdkConfigConstructor(Class<?> shadowClass) { Constructor constructor = null; try { constructor = shadowClass.getConstructor(SdkConfig.class); } catch (NoSuchMethodException e) { // expected } return constructor; }
@Override protected ClassLoader createRobolectricClassLoader(Setup setup, SdkConfig sdkConfig) { URL[] urls = getJarResolver().getLocalArtifactUrls(sdkConfig.getSdkClasspathDependencies()); return new AsmInstrumentingClassLoader(setup, urls) { @Override protected byte[] getByteCode(String className) throws ClassNotFoundException { if (className.startsWith("com.github.stephanenicolas.injectresource")) { try { CtClass dummyClass = ClassPool.getDefault().get(className); if (processor.shouldTransform(dummyClass)) { log.debug("Intercepting via InjectResource " + className); processor.applyTransformations(dummyClass); byte[] bytes = dummyClass.toBytecode(); System.out.println("Size of weaved byte code :" + bytes.length); FileOutputStream fileOutputStream = new FileOutputStream("/tmp/" + className + ".class"); fileOutputStream.write(bytes); fileOutputStream.close(); return bytes; } } catch (Exception e) { throw new RuntimeException("Impossible to transform class " + className, e); } } return super.getByteCode(className); } }; }
@Override protected ClassLoader createRobolectricClassLoader(Setup setup, SdkConfig sdkConfig) { URL[] urls = getJarResolver().getLocalArtifactUrls(sdkConfig.getSdkClasspathDependencies()); return new AsmInstrumentingClassLoader(setup, urls) { @Override protected byte[] getByteCode(String className) throws ClassNotFoundException { if (className.startsWith("com.github.stephanenicolas.injectextra")) { try { CtClass dummyClass = ClassPool.getDefault().get(className); if (processor.shouldTransform(dummyClass)) { log.debug("Intercepting via InjectExtra " + className); processor.applyTransformations(dummyClass); byte[] bytes = dummyClass.toBytecode(); System.out.println("Size of weaved byte code :" + bytes.length); FileOutputStream fileOutputStream = new FileOutputStream("/tmp/" + className + ".class"); fileOutputStream.write(bytes); fileOutputStream.close(); return bytes; } } catch (Exception e) { throw new RuntimeException("Impossible to transform class " + className, e); } } return super.getByteCode(className); } }; }
@Override protected ClassLoader createRobolectricClassLoader(Setup setup, SdkConfig sdkConfig) { URL[] urls = getJarResolver().getLocalArtifactUrls(sdkConfig.getSdkClasspathDependencies()); return new AsmInstrumentingClassLoader(setup, urls) { @Override protected byte[] getByteCode(String className) throws ClassNotFoundException { if (className.startsWith("com.github.stephanenicolas.loglifecycle")) { try { CtClass dummyClass = ClassPool.getDefault().get(className); if (processor.shouldTransform(dummyClass)) { log.debug("Intercepting via InjectExtra " + className); processor.applyTransformations(dummyClass); byte[] bytes = dummyClass.toBytecode(); System.out.println("Size of weaved byte code :" + bytes.length); FileOutputStream fileOutputStream = new FileOutputStream("/tmp/" + className + ".class"); fileOutputStream.write(bytes); fileOutputStream.close(); return bytes; } } catch (Exception e) { throw new RuntimeException("Impossible to transform class " + className, e); } } return super.getByteCode(className); } }; }
public ShadowContextImpl(SdkConfig sdkConfig) { this.sdkConfig = sdkConfig; }
@Override public void setSdkConfig(SdkConfig sdkConfig) { this.sdkConfig = sdkConfig; }
public ShadowWrangler(ShadowMap shadowMap, SdkConfig sdkConfig) { this.shadowMap = shadowMap; this.sdkConfig = sdkConfig; }
@Before public void setup() throws Exception { shadowWrangler = new ShadowWrangler(ShadowMap.EMPTY, SdkConfig.getDefaultSdk()); }
void setSdkConfig(SdkConfig sdkConfig);