blob: b29ec3b0e7a0603ae556b6fdc284a07f57713f90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.darylteo.gradle:javassist-plugin:0.4.1'
}
}
import com.darylteo.gradle.javassist.tasks.TransformationTask
import com.darylteo.gradle.javassist.transformers.ClassTransformer
import javassist.CtClass
import javassist.CtConstructor
class StaticBlockRemover extends ClassTransformer {
private static final SOURCE = "com.mapbox.mapboxsdk.style.sources.Source";
private static final LAYER = "com.mapbox.mapboxsdk.style.layers.Layer";
private static
final NATIVE_CONNECTIVITY_LISTENER = "com.mapbox.mapboxsdk.net.NativeConnectivityListener";
private static final OFFLINE_MANAGER = "com.mapbox.mapboxsdk.offline.OfflineManager";
private static final OFFLINE_REGION = "com.mapbox.mapboxsdk.offline.OfflineRegion";
private static final List<String> excludes = new ArrayList<>();
static {
excludes.add(SOURCE)
excludes.add(LAYER)
excludes.add(NATIVE_CONNECTIVITY_LISTENER)
excludes.add(OFFLINE_MANAGER)
excludes.add(OFFLINE_REGION)
}
public void applyTransformations(CtClass clazz) throws Exception {
if (shouldFilter(clazz)) {
CtConstructor constructor = clazz.getClassInitializer()
if (constructor != null) {
clazz.removeConstructor(constructor)
}
}
}
public boolean shouldFilter(CtClass clazz) {
return hasAStaticBlock(clazz);
}
private boolean hasAStaticBlock(CtClass clazz) {
String name = clazz.getName();
return excludes.contains(name);
}
}
task removeStatic(type: TransformationTask) {
// TODO Find a better way to get output classes path
String fromToDirPath = buildDir.getAbsolutePath() + "/intermediates/classes/debug"
from fromToDirPath
transformation = new StaticBlockRemover()
into fromToDirPath
}
afterEvaluate {
compileDebugUnitTestJavaWithJavac.doLast {
tasks.removeStatic.execute()
}
}
|