-
Notifications
You must be signed in to change notification settings - Fork 89
/
injector_generator_example.gradle
48 lines (46 loc) · 2.61 KB
/
injector_generator_example.gradle
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
// Use your package instead "your.package", and add file "app/src/main/java/your/package/debug/DTInjector.java" to your git ignore list.
task ensureDebugBottleInjectFile << {
def file = new File(rootDir, 'app/src/main/java/your/package/debug/DTInjector.java')
if (!file.exists()) {
print("creating DTInjector.java...")
file.withWriter('utf-8') { writer ->
writer.writeLine 'package your.package.debug;'
writer.writeLine ''
writer.writeLine 'import android.content.Intent;'
writer.writeLine 'import android.widget.Toast;'
writer.writeLine 'import com.exyui.android.debugbottle.components.injector.Injector;'
writer.writeLine 'import your.package.MainActivity;'
writer.writeLine ''
writer.writeLine '/**'
writer.writeLine " * Created by Machine on ${new Date().format('MM/dd/yy')}."
writer.writeLine ''
writer.writeLine ' * This file has been added in "git ignore" list.'
writer.writeLine ' * The file shows an example to write the fake Runnable & Activity entries'
writer.writeLine ' * You can edit this file at any time if you wish to change the defaults.'
writer.writeLine ' * If you like to revert just delete the file.'
writer.writeLine ' */'
writer.writeLine '@SuppressWarnings("unused")'
writer.writeLine 'public class DTInjector extends Injector {'
writer.writeLine ' @Override'
writer.writeLine ' public void inject() {'
writer.writeLine ' put(new Runnable() {'
writer.writeLine ' @Override'
writer.writeLine ' public void run() {'
writer.writeLine ' // Do clean cache file here.'
writer.writeLine ' Toast.makeText(getActivity(), "Cache cleaned", Toast.LENGTH_SHORT).show();'
writer.writeLine ' }'
writer.writeLine ' }, "Clean cache file example");'
writer.writeLine ''
writer.writeLine ' put(new Intent(getActivity(), MainActivity.class), "Intent Activity example");'
writer.writeLine ' }'
writer.writeLine '}'
}
print("DTInjector.java created.")
def ignoreFile = new File(rootDir, '.gitignore')
if (ignoreFile.exists()) {
def SEPARATOR = System.getProperty("line.separator")
ignoreFile.append("${SEPARATOR}app/src/main/java/your/package/debug/DTInjector.java")
}
}
}
preBuild.dependsOn ensureDebugBottleInjectFile