├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
└── runConfigurations.xml
├── CHANGELOG.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── leavesc
│ │ └── hello
│ │ └── dokv
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── leavesc
│ │ │ └── hello
│ │ │ └── dokv
│ │ │ ├── MainActivity.java
│ │ │ ├── MyApplication.java
│ │ │ └── model
│ │ │ ├── Book.java
│ │ │ ├── CustomKeyUser.java
│ │ │ └── User.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── leavesc
│ └── hello
│ └── dokv
│ └── ExampleUnitTest.java
├── build.gradle
├── dokv_annotation
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── leavesc
│ └── hello
│ └── dokv
│ ├── DoKV.java
│ ├── IDoKVHolder.java
│ └── annotation
│ └── DoKV.java
├── dokv_impl
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── leavesc
│ │ └── hello
│ │ └── dokv_imp
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── leavesc
│ │ │ └── hello
│ │ │ └── dokv_imp
│ │ │ └── MMKVDoKVHolder.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── leavesc
│ └── hello
│ └── dokv_imp
│ └── ExampleUnitTest.java
├── dokv_processor
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── leavesc
│ └── hello
│ └── dokv_processor
│ ├── DoKVProcessor.java
│ └── utils
│ ├── ElementUtils.java
│ └── StringUtils.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches/build_file_checksums.ser
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | .DS_Store
9 | /build
10 | /captures
11 | .externalNativeBuild
12 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | ### **更新记录**
3 | ### **Change Log**
4 |
5 |
6 |
7 | #### **Version 0.1.8**
8 |
9 | 2018/04/03
10 |
11 | - **IDoKVHolder** 新增 **clear()** 方法用于删除全局的缓存数据,**MMKVDoKVHolder** 增加对应实现
12 | - **DoKV** 注解支持自定义缓存 **Key** 。在之前的版本,**DoKV** 默认以**被注解类的类路径**作为缓存 Key,以此来保证 Key 值的唯一性,但考虑到被注解类在后续开发中可能会被移动到其它包下,从而导致丢失缓存数据,因为在此版本中为注解 DoKV 新增了 Key 属性
13 |
14 |
15 |
16 | #### **Version 0.1.6**
17 |
18 | 2018/03/16
19 |
20 | - 初始版本
21 | - 支持外部自定义**序列化与反序列化**的方案,并提供一个默认的开源实现 **MMKVDoKVHolder**
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### DoKV
2 |
3 | DoKV 是一个小巧而强大的 **Key-Value** 管理框架,其设计初衷是为了解决 Android 平台下各种**繁琐且丑陋**的配置类代码
4 |
5 | **(如果你是从我的博客:[Android APT 实例讲解](https://www.jianshu.com/p/cc8379522c5e) 跳转过来的,那需要切换到 master 分支,对应的是第二次的提交记录)**
6 |
7 |
8 |
9 | ### Download
10 |
11 | ```groovy
12 | dependencies {
13 | implementation 'leavesc.hello:dokv:0.1.8'
14 | annotationProcessor 'leavesc.hello:dokv-compiler:0.1.8'
15 | }
16 | ```
17 |
18 | 如果不想自定义序列化方案,则可以使用我的另一个开源实现
19 |
20 | ```groovy
21 | dependencies {
22 | implementation 'leavesc.hello:dokv-impl:0.1.8'
23 | }
24 | ```
25 |
26 | 更新日记:[CHANGELOG](CHANGELOG.md)
27 |
28 |
29 |
30 | ### 一、介绍
31 |
32 | 之所以说小巧,是因为 DoKV 的实现仅依赖于**一个注解、一个接口、四个类**。当然,其实现基础不仅仅如此,还需要 APT 技术的支持,需要依赖于 APT 来自动生成某些中间代码,关于 APT 的知识我在以前的一篇博客中也有所介绍,点击查看:[APT](https://www.jianshu.com/p/cc8379522c5e)
33 |
34 | 
35 |
36 | 之所以说强大,是因为通过使用 DoKV 后,你基本是可以抛弃如下类型的代码了
37 |
38 | ```java
39 | SharedPreferences sharedPreferences = getSharedPreferences("SharedPreferencesName", Context.MODE_PRIVATE);
40 | SharedPreferences.Editor editor = sharedPreferences.edit();
41 | editor.putString("IP", "192.168.0.1");
42 | editor.commit();
43 | String userName = sharedPreferences.getString("userName", "");
44 | String ip = sharedPreferences.getString("IP", "");
45 | ```
46 |
47 | 通常,我们的应用都会有很多配置项需要进行缓存,比如用户信息、设置项开关、服务器IP地址等。如果采用原生的 **SharedPreferences** 来实现的话,则很容易就写出如上所示那样丑陋的代码,不仅需要维护多个数据项的 key 值,而且每次存入和取出数据时都会有一大片重复的代码,不易维护
48 |
49 | 那 DoKV 的表现如何呢?
50 |
51 | 很简单!!!
52 |
53 | 假设你的应用包含了一个 User 类用于缓存用户信息,首先,为该类加上一个注解:**@DoKV**
54 |
55 | ```java
56 | /**
57 | * 作者:leavesC
58 | * 时间:2019/03/17 0:12
59 | * 描述:
60 | * GitHub:https://github.com/leavesC
61 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
62 | */
63 | @DoKV
64 | public class User {
65 |
66 | private String name;
67 |
68 | private int age;
69 |
70 | private String sex;
71 |
72 | private Book book;
73 |
74 | private List stringList;
75 |
76 | ···
77 |
78 | }
79 | ```
80 |
81 | **build** 下工程,DoKV 就会自动为你生成一个以 **类名+DoKV结尾** 的 Java 类(UserDoKV),之后你就可以通过以下这种形式来进行数据存取了,而你无需关心其内部是如何保存的(当然,其内部的缓存机制是可以由你来自定义的)
82 |
83 | ```java
84 | //缓存整个对象
85 | User user = new User();
86 | user.setAge(24);
87 | user.setName("leavesC");
88 | UserDoKV.get().setUser(user);
89 |
90 | //获取缓存的对象
91 | User user1 = UserDoKV.get().getUser();
92 |
93 | //更新本地已缓存的数据的某个设置项
94 | //如果之前没有缓存过,则会自动 new 一个对象并自动赋值
95 | //因为 DoKV 要求注解类必须包含一个无参构造函数,并且包含的字段有对应的 Get 和 Set 方法
96 | UserDoKV.get().setName("leavesCZY");
97 | UserDoKV.get().setAge(28);
98 |
99 | //移除缓存数据
100 | UserDoKV.get().remove();
101 |
102 | //移除所有缓存数据
103 | DoKV.clear();
104 | ```
105 |
106 | 上文说过,DoKV 是依赖于 APT 技术的,其实际原理就是开发者通过继承 AbstractProcessor 来定义目标代码的生成规则,由编译器根据此规则来生成目标代码,所以 DoKv 的执行效率就如同构造一般的 Java 类,不存在什么依靠反射使性能降低的情况
107 |
108 | UserDoKV 类的定义如下所示:
109 |
110 | ```java
111 | public class UserDoKV extends User {
112 |
113 | private static final String KEY = "leavesc.hello.dokv.model.UserDoKV";
114 |
115 | private UserDoKV() {
116 | }
117 |
118 | public static UserDoKV get() {
119 | return new UserDoKV();
120 | }
121 |
122 | private IDoKVHolder getDoKVHolder() {
123 | return DoKV.getInstance().getDoKVHolder();
124 | }
125 |
126 | private String serialize(String _KEY, User _User) {
127 | return getDoKVHolder().serialize(_KEY, _User);
128 | }
129 |
130 | private User deserialize(String _KEY) {
131 | return getDoKVHolder().deserialize(_KEY, User.class);
132 | }
133 |
134 | public User getUser() {
135 | return deserialize(KEY);
136 | }
137 |
138 | private User getUserNotNull() {
139 | User variable = deserialize(KEY);
140 | if (variable != null) {
141 | return variable;
142 | }
143 | return new User();
144 | }
145 |
146 | public String setUser(User instance) {
147 | if (instance == null) {
148 | remove();
149 | return "";
150 | }
151 | return serialize(KEY, instance);
152 | }
153 |
154 | public void remove() {
155 | getDoKVHolder().remove(KEY);
156 | }
157 |
158 | @Override
159 | public String getName() {
160 | User variable = getUser();
161 | if (variable != null) {
162 | return variable.getName();
163 | }
164 | return super.getName();
165 | }
166 |
167 | @Override
168 | public void setName(String _name) {
169 | User _user = getUserNotNull();
170 | _user.setName(_name);
171 | serialize(KEY, _user);
172 | }
173 |
174 | //省略类似的 Get/Set 方法
175 | }
176 | ```
177 |
178 |
179 |
180 | ### 二、自定义缓存 Key
181 |
182 | 在 v0.1.7 版本之前, **DoKV** 默认以**被注解类的类路径**作为缓存 Key,以此来保证 Key 值的唯一性,但考虑到被注解类在后续开发中可能会被移动到其它包下从而导致丢失缓存数据,因为在 v0.1.7 版本中为注解 DoKV 新增了 Key 属性,如果开发者向该属性赋予了值,则以该值作为缓存 Key,而且该 Key 的唯一性需要由开发者自己来保证
183 |
184 | ```java
185 | @DoKV(key = "CustomKeyUser_Key")
186 | public class CustomKeyUser {
187 |
188 | ···
189 |
190 | }
191 | ```
192 |
193 | ```java
194 | public class CustomKeyUserDoKV extends CustomKeyUser {
195 |
196 | private static final String KEY = "CustomKeyUser_Key";
197 |
198 |
199 | ```
200 |
201 | }
202 | ```
203 |
204 |
205 |
206 | ### 三、引入
207 |
208 | 为了获得更高的自由度, DoKV 默认将数据持久化的实现方案交由外部来实现,即由使用者来决定如何将对象序列化保存到本地,此时你就可以选择只依赖以下两个引用
209 |
210 | ```groovy
211 | dependencies {
212 | implementation 'leavesc.hello:dokv:xxx'
213 | annotationProcessor 'leavesc.hello:dokv-compiler:xxx'
214 | }
215 | ```
216 |
217 | 然后,外部将 IDoKVHolder 实例传给 DoKV 即可
218 |
219 | ```java
220 | DoKV.init(new IDoKVHolder() {
221 |
222 | //序列化
223 | @Override
224 | public String serialize(String key, Object src) {
225 | return null;
226 | }
227 |
228 | //反序列化
229 | @Override
230 | public T deserialize(String key, Class classOfT) {
231 | return null;
232 | }
233 |
234 | //移除指定对象
235 | @Override
236 | public void remove(String key) {
237 |
238 | }
239 |
240 | //删除全局的缓存数据
241 | @Override
242 | public void clear() {
243 |
244 | }
245 | });
246 | ```
247 |
248 | 如果你不想自己实现 IDoKVHolder ,DoKV 也提供了一个默认实现,此时你就只要多引用如下一个依赖即可,其内部是通过 **Gson + MMKV** 来实现序列化方案
249 |
250 | ```groovy
251 | dependencies {
252 | implementation 'leavesc.hello:dokv-impl:xxx'
253 | }
254 | ```
255 |
256 | 进行初始化,之后就可以自由地玩耍了
257 |
258 | ```java
259 | DoKV.init(new MMKVDoKVHolder(Context));
260 | ```
261 |
262 |
263 |
264 | ### 四、结尾
265 |
266 | 本开源库的 GitHub 主页在这里:[DoKV](https://github.com/leavesC/DoKV)
267 |
268 | APK 下载体检:[DoKV](https://www.pgyer.com/DoKV)
269 |
270 | 我的博客主页:[leavesC](https://www.jianshu.com/u/9df45b87cfdf)
271 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "leavesc.hello.dokv"
7 | minSdkVersion 22
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | lintOptions {
20 | abortOnError false
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation 'com.android.support:appcompat-v7:28.0.0'
27 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
31 | implementation project(':dokv_annotation')
32 | annotationProcessor project(':dokv_processor')
33 | implementation project(':dokv_impl')
34 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/leavesc/hello/dokv/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("leavesc.hello.dokv", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/dokv/MainActivity.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.text.TextUtils;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 | import android.widget.TextView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import leavesc.hello.dokv.model.Book;
15 | import leavesc.hello.dokv.model.CustomKeyUserDoKV;
16 | import leavesc.hello.dokv.model.User;
17 | import leavesc.hello.dokv.model.UserDoKV;
18 |
19 | /**
20 | * 作者:leavesC
21 | * 时间:2019/1/4 23:15
22 | * 描述:
23 | * GitHub:https://github.com/leavesC
24 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
25 | */
26 | public class MainActivity extends AppCompatActivity {
27 |
28 | private EditText et_userName;
29 |
30 | private EditText et_userAge;
31 |
32 | private EditText et_bookName;
33 |
34 | private EditText et_userSex;
35 |
36 | private Button btn_serializeAll;
37 |
38 | private EditText et_singleUserName;
39 |
40 | private Button btn_serializeSingle;
41 |
42 | private Button btn_remove;
43 |
44 | private Button btn_clear;
45 |
46 | private Button btn_print;
47 |
48 | private TextView tv_hint;
49 |
50 | @Override
51 | protected void onCreate(Bundle savedInstanceState) {
52 | super.onCreate(savedInstanceState);
53 | setContentView(R.layout.activity_main);
54 | initView();
55 | btn_serializeAll.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | String userName = et_userName.getText().toString();
59 | String ageStr = et_userAge.getText().toString();
60 | int age = 0;
61 | if (!TextUtils.isEmpty(ageStr)) {
62 | age = Integer.parseInt(ageStr);
63 | }
64 | User user = new User();
65 | user.setAge(age);
66 | user.setName(userName);
67 | user.setSex(et_userSex.getText().toString());
68 | List stringList = new ArrayList<>();
69 | for (int i = 0; i < 4; i++) {
70 | stringList.add(String.valueOf(i));
71 | }
72 | user.setStringList(stringList);
73 | Book book = new Book();
74 | book.setName(et_bookName.getText().toString());
75 | user.setBook(book);
76 | UserDoKV.get().setUser(user);
77 | }
78 | });
79 | btn_serializeSingle.setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View v) {
82 | String userName = et_singleUserName.getText().toString();
83 | UserDoKV.get().setName(userName);
84 | }
85 | });
86 | btn_remove.setOnClickListener(new View.OnClickListener() {
87 | @Override
88 | public void onClick(View v) {
89 | UserDoKV.get().remove();
90 | }
91 | });
92 | btn_clear.setOnClickListener(new View.OnClickListener() {
93 | @Override
94 | public void onClick(View v) {
95 | DoKV.clear();
96 | }
97 | });
98 | btn_print.setOnClickListener(new View.OnClickListener() {
99 | @Override
100 | public void onClick(View v) {
101 | StringBuilder sb = new StringBuilder();
102 | sb.append("User : ----->").append(UserDoKV.get().getUser());
103 | sb.append("\n\n");
104 | sb.append("User Name : ----->").append(UserDoKV.get().getName());
105 |
106 | sb.append("\n\n");
107 | sb.append("CustomKeyUser : ----->").append(CustomKeyUserDoKV.get().getCustomKeyUser());
108 |
109 | tv_hint.setText(sb);
110 | }
111 | });
112 |
113 | CustomKeyUserDoKV.get().setKey("这是默认赋予的值");
114 | }
115 |
116 | private void initView() {
117 | et_userName = findViewById(R.id.et_userName);
118 | et_userAge = findViewById(R.id.et_userAge);
119 | et_bookName = findViewById(R.id.et_bookName);
120 | et_userSex = findViewById(R.id.et_userSex);
121 | btn_serializeAll = findViewById(R.id.btn_serializeAll);
122 | et_singleUserName = findViewById(R.id.et_singleUserName);
123 | btn_serializeSingle = findViewById(R.id.btn_serializeSingle);
124 | btn_remove = findViewById(R.id.btn_remove);
125 | btn_clear = findViewById(R.id.btn_clear);
126 | btn_print = findViewById(R.id.btn_print);
127 | tv_hint = findViewById(R.id.tv_hint);
128 | }
129 |
130 | }
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/dokv/MyApplication.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv;
2 |
3 | import android.app.Application;
4 |
5 | import leavesc.hello.dokv_imp.MMKVDoKVHolder;
6 |
7 | /**
8 | * 作者:leavesC
9 | * 时间:2019/1/5 1:06
10 | * 描述:
11 | * GitHub:https://github.com/leavesC
12 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
13 | */
14 | public class MyApplication extends Application {
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | DoKV.init(new MMKVDoKVHolder(this));
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/dokv/model/Book.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv.model;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | /**
6 | * 作者:leavesC
7 | * 时间:2019/1/5 15:11
8 | * 描述:
9 | * GitHub:https://github.com/leavesC
10 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
11 | */
12 | public class Book {
13 |
14 | private String name;
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public void setName(String name) {
21 | this.name = name;
22 | }
23 |
24 | @NonNull
25 | @Override
26 | public String toString() {
27 | return "Book{" +
28 | "name='" + name + '\'' +
29 | '}';
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/dokv/model/CustomKeyUser.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv.model;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import leavesc.hello.dokv.annotation.DoKV;
6 |
7 | /**
8 | * 作者:leavesC
9 | * 时间:2019/4/3 13:41
10 | * 描述:
11 | */
12 | @DoKV(key = "CustomKeyUser_Key")
13 | public class CustomKeyUser {
14 |
15 | private String key;
16 |
17 | private String value;
18 |
19 | public String getKey() {
20 | return key;
21 | }
22 |
23 | public void setKey(String key) {
24 | this.key = key;
25 | }
26 |
27 | public String getValue() {
28 | return value;
29 | }
30 |
31 | public void setValue(String value) {
32 | this.value = value;
33 | }
34 |
35 | @NonNull
36 | @Override
37 | public String toString() {
38 | return "CustomKeyUser{" +
39 | "key='" + key + '\'' +
40 | ", value='" + value + '\'' +
41 | '}';
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/dokv/model/User.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv.model;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import java.util.List;
6 |
7 | import leavesc.hello.dokv.annotation.DoKV;
8 |
9 | /**
10 | * 作者:leavesC
11 | * 时间:2019/1/5 0:12
12 | * 描述:
13 | * GitHub:https://github.com/leavesC
14 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
15 | */
16 | @DoKV
17 | public class User {
18 |
19 | private String name;
20 |
21 | private int age;
22 |
23 | private String sex;
24 |
25 | private Book book;
26 |
27 | private List stringList;
28 |
29 | public String getName() {
30 | return name;
31 | }
32 |
33 | public void setName(String name) {
34 | this.name = name;
35 | }
36 |
37 | public int getAge() {
38 | return age;
39 | }
40 |
41 | public void setAge(int age) {
42 | this.age = age;
43 | }
44 |
45 | public String getSex() {
46 | return sex;
47 | }
48 |
49 | public void setSex(String sex) {
50 | this.sex = sex;
51 | }
52 |
53 | public Book getBook() {
54 | return book;
55 | }
56 |
57 | public void setBook(Book book) {
58 | this.book = book;
59 | }
60 |
61 | public List getStringList() {
62 | return stringList;
63 | }
64 |
65 | public void setStringList(List stringList) {
66 | this.stringList = stringList;
67 | }
68 |
69 | @NonNull
70 | @Override
71 | public String toString() {
72 | return "User{" +
73 | "name='" + name + '\'' +
74 | ", age=" + age +
75 | ", sex='" + sex + '\'' +
76 | ", book=" + book +
77 | ", stringList=" + stringList +
78 | '}';
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
20 |
21 |
28 |
29 |
34 |
35 |
40 |
41 |
47 |
48 |
54 |
55 |
61 |
62 |
69 |
70 |
77 |
78 |
85 |
86 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DoKV
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/leavesc/hello/dokv/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.2.1'
11 | classpath 'com.novoda:bintray-release:0.9'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | tasks.withType(Javadoc) {
24 | options.addStringOption('Xdoclint:none', '-quiet')
25 | options.addStringOption('encoding', 'UTF-8')
26 | }
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/dokv_annotation/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/dokv_annotation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | dependencies {
5 | implementation fileTree(dir: 'libs', include: ['*.jar'])
6 | }
7 |
8 | sourceCompatibility = "7"
9 | targetCompatibility = "7"
10 |
11 | publish {
12 | repoName = 'DokvRepo'
13 | userOrg = 'leavesc'
14 | groupId = 'leavesc.hello'
15 | artifactId = 'dokv'
16 | publishVersion = REPO_PUBLISH_VERSION
17 | website = 'https://github.com/leavesC/DoKV'
18 | desc = 'An small mobile key-value manage framework'
19 | }
--------------------------------------------------------------------------------
/dokv_annotation/src/main/java/leavesc/hello/dokv/DoKV.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv;
2 |
3 | /**
4 | * 作者:leavesC
5 | * 时间:2019/3/11 10:58
6 | * 描述:
7 | * GitHub:https://github.com/leavesC
8 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
9 | */
10 | public enum DoKV {
11 |
12 | INSTANCE;
13 |
14 | private IDoKVHolder doKVHolder;
15 |
16 | public static DoKV getInstance() {
17 | return INSTANCE;
18 | }
19 |
20 | public static void init(IDoKVHolder doKVHolder) {
21 | getInstance().doKVHolder = doKVHolder;
22 | }
23 |
24 | public static void clear() {
25 | getInstance().doKVHolder.clear();
26 | }
27 |
28 | public IDoKVHolder getDoKVHolder() {
29 | return doKVHolder;
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/dokv_annotation/src/main/java/leavesc/hello/dokv/IDoKVHolder.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv;
2 |
3 | /**
4 | * 作者:leavesC
5 | * 时间:2019/1/5 1:01
6 | * 描述:
7 | * GitHub:https://github.com/leavesC
8 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
9 | */
10 | public interface IDoKVHolder {
11 |
12 | //序列化
13 | String serialize(String key, Object src);
14 |
15 | //反序列化
16 | T deserialize(String key, Class classOfT);
17 |
18 | //移除指定对象
19 | void remove(String key);
20 |
21 | //删除全局的缓存数据
22 | void clear();
23 |
24 | }
--------------------------------------------------------------------------------
/dokv_annotation/src/main/java/leavesc/hello/dokv/annotation/DoKV.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 作者:leavesC
10 | * 时间:2019/3/14 22:25
11 | * 描述:
12 | * GitHub:https://github.com/leavesC
13 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
14 | */
15 | @Retention(RetentionPolicy.SOURCE)
16 | @Target(ElementType.TYPE)
17 | public @interface DoKV {
18 |
19 | String key() default "";
20 |
21 | }
--------------------------------------------------------------------------------
/dokv_impl/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/dokv_impl/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 28
6 | defaultConfig {
7 | minSdkVersion 16
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | testImplementation 'junit:junit:4.12'
25 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
26 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
27 | implementation 'com.google.code.gson:gson:2.8.5'
28 | implementation 'com.tencent:mmkv:1.0.18'
29 | implementation project(':dokv_annotation')
30 | }
31 |
32 | publish {
33 | repoName = 'DokvRepo'
34 | userOrg = 'leavesc'
35 | groupId = 'leavesc.hello'
36 | artifactId = 'dokv-impl'
37 | publishVersion = REPO_PUBLISH_VERSION
38 | website = 'https://github.com/leavesC/DoKV'
39 | desc = 'An small mobile key-value manage framework'
40 | }
--------------------------------------------------------------------------------
/dokv_impl/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/dokv_impl/src/androidTest/java/leavesc/hello/dokv_imp/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv_imp;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("leavesc.hello.dokv_imp.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/dokv_impl/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/dokv_impl/src/main/java/leavesc/hello/dokv_imp/MMKVDoKVHolder.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv_imp;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 |
6 | import com.google.gson.Gson;
7 | import com.tencent.mmkv.MMKV;
8 |
9 | import leavesc.hello.dokv.IDoKVHolder;
10 |
11 | /**
12 | * 作者:leavesC
13 | * 时间:2019/1/5 1:05
14 | * 描述:
15 | * GitHub:https://github.com/leavesC
16 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
17 | */
18 | public class MMKVDoKVHolder implements IDoKVHolder {
19 |
20 | private MMKV mmkv;
21 |
22 | private Gson gson;
23 |
24 | public MMKVDoKVHolder(Context context) {
25 | MMKV.initialize(context);
26 | mmkv = MMKV.defaultMMKV();
27 | gson = new Gson();
28 | }
29 |
30 | @Override
31 | public String serialize(String key, Object src) {
32 | String json = gson.toJson(src);
33 | mmkv.putString(key, json);
34 | return json;
35 | }
36 |
37 | @Override
38 | public T deserialize(String key, Class classOfT) {
39 | String json = mmkv.decodeString(key, "");
40 | if (!TextUtils.isEmpty(json)) {
41 | return gson.fromJson(json, classOfT);
42 | }
43 | return null;
44 | }
45 |
46 | @Override
47 | public void remove(String key) {
48 | mmkv.remove(key);
49 | }
50 |
51 | @Override
52 | public void clear() {
53 | mmkv.clear();
54 | }
55 |
56 | }
--------------------------------------------------------------------------------
/dokv_impl/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DoKV_imp
3 |
4 |
--------------------------------------------------------------------------------
/dokv_impl/src/test/java/leavesc/hello/dokv_imp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv_imp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/dokv_processor/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/dokv_processor/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | dependencies {
5 | implementation fileTree(dir: 'libs', include: ['*.jar'])
6 | implementation 'com.google.auto.service:auto-service:1.0-rc2'
7 | implementation 'com.squareup:javapoet:1.10.0'
8 | implementation project(':dokv_annotation')
9 | }
10 |
11 | sourceCompatibility = "7"
12 | targetCompatibility = "7"
13 |
14 | publish {
15 | repoName = 'DokvRepo'
16 | userOrg = 'leavesc'
17 | groupId = 'leavesc.hello'
18 | artifactId = 'dokv-compiler'
19 | publishVersion = REPO_PUBLISH_VERSION
20 | website = 'https://github.com/leavesC/DoKV'
21 | desc = 'An small mobile key-value manage framework'
22 | }
--------------------------------------------------------------------------------
/dokv_processor/src/main/java/leavesc/hello/dokv_processor/DoKVProcessor.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv_processor;
2 |
3 | import com.google.auto.service.AutoService;
4 | import com.squareup.javapoet.ClassName;
5 | import com.squareup.javapoet.CodeBlock;
6 | import com.squareup.javapoet.FieldSpec;
7 | import com.squareup.javapoet.JavaFile;
8 | import com.squareup.javapoet.MethodSpec;
9 | import com.squareup.javapoet.TypeSpec;
10 |
11 | import java.io.IOException;
12 | import java.text.MessageFormat;
13 | import java.util.ArrayList;
14 | import java.util.HashMap;
15 | import java.util.HashSet;
16 | import java.util.List;
17 | import java.util.Map;
18 | import java.util.Set;
19 |
20 | import javax.annotation.processing.AbstractProcessor;
21 | import javax.annotation.processing.ProcessingEnvironment;
22 | import javax.annotation.processing.Processor;
23 | import javax.annotation.processing.RoundEnvironment;
24 | import javax.lang.model.SourceVersion;
25 | import javax.lang.model.element.Element;
26 | import javax.lang.model.element.Modifier;
27 | import javax.lang.model.element.TypeElement;
28 | import javax.lang.model.element.VariableElement;
29 | import javax.lang.model.util.Elements;
30 |
31 | import leavesc.hello.dokv.IDoKVHolder;
32 | import leavesc.hello.dokv.annotation.DoKV;
33 | import leavesc.hello.dokv_processor.utils.ElementUtils;
34 | import leavesc.hello.dokv_processor.utils.StringUtils;
35 |
36 | /**
37 | * 作者:leavesC
38 | * 时间:2019/1/3 17:35
39 | * 描述:
40 | * GitHub:https://github.com/leavesC
41 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
42 | */
43 | @AutoService(Processor.class)
44 | public class DoKVProcessor extends AbstractProcessor {
45 |
46 | private Elements elementUtils;
47 |
48 | private static final String SUFFIX = "DoKV";
49 |
50 | private static final String INSTANCE = "INSTANCE";
51 |
52 | private static final String KEY_NAME = "KEY";
53 |
54 | private static final ClassName serializeManagerClass = ClassName.get(leavesc.hello.dokv.DoKV.class);
55 |
56 | @Override
57 | public synchronized void init(ProcessingEnvironment processingEnv) {
58 | super.init(processingEnv);
59 | elementUtils = processingEnv.getElementUtils();
60 | }
61 |
62 | @Override
63 | public Set getSupportedAnnotationTypes() {
64 | Set hashSet = new HashSet<>();
65 | hashSet.add(DoKV.class.getCanonicalName());
66 | return hashSet;
67 | }
68 |
69 | @Override
70 | public SourceVersion getSupportedSourceVersion() {
71 | return SourceVersion.latestSupported();
72 | }
73 |
74 | @Override
75 | public boolean process(Set extends TypeElement> set, RoundEnvironment roundEnvironment) {
76 | //获取所有包含 DoKV 注解的元素
77 | Set extends Element> elementSet = roundEnvironment.getElementsAnnotatedWith(DoKV.class);
78 | Map> elementListHashMap = new HashMap<>();
79 | for (Element element : elementSet) {
80 | TypeElement typeElement = (TypeElement) element;
81 | List extends Element> enclosedElements = typeElement.getEnclosedElements();
82 | if (enclosedElements != null && enclosedElements.size() > 0) {
83 | for (Element enclosedElement : enclosedElements) {
84 | if (enclosedElement instanceof VariableElement) {
85 | if (checkModifier(enclosedElement.getModifiers())) {
86 | List variableElementList = elementListHashMap.get(typeElement);
87 | if (variableElementList == null) {
88 | variableElementList = new ArrayList<>();
89 | elementListHashMap.put(typeElement, variableElementList);
90 | }
91 | variableElementList.add((VariableElement) enclosedElement);
92 | }
93 | }
94 | }
95 | }
96 | }
97 | for (TypeElement key : elementListHashMap.keySet()) {
98 | List variableElementList = elementListHashMap.get(key);
99 | String packageName = ElementUtils.getPackageName(elementUtils, key);
100 | JavaFile javaFile = JavaFile.builder(packageName, generateCodeByPoet(key, variableElementList)).build();
101 | try {
102 | javaFile.writeTo(processingEnv.getFiler());
103 | } catch (IOException e) {
104 | e.printStackTrace();
105 | }
106 | }
107 | return true;
108 | }
109 |
110 | private boolean checkModifier(Set modifiers) {
111 | for (Modifier modifier : modifiers) {
112 | switch (modifier) {
113 | case ABSTRACT:
114 | case STATIC:
115 | case FINAL: {
116 | return false;
117 | }
118 | }
119 | }
120 | return true;
121 | }
122 |
123 | /**
124 | * 生成 Java 类
125 | *
126 | * @param typeElement 注解对象上层元素对象,即 Java 对象
127 | * @param variableElementList Java 对象包含的注解对象以及注解的目标对象
128 | * @return
129 | */
130 | private TypeSpec generateCodeByPoet(TypeElement typeElement, List variableElementList) {
131 | //自动生成的文件以 Java 类名 + DoKV 进行命名
132 | TypeSpec.Builder builder = TypeSpec.classBuilder(typeElement.getSimpleName().toString() + SUFFIX)
133 | .addModifiers(Modifier.PUBLIC)
134 | .superclass(ClassName.bestGuess(typeElement.getQualifiedName().toString()))
135 | .addField(generateKeyField(typeElement))
136 | .addMethod(generateConstructorMethod())
137 | .addMethod(generateInstanceHolderMethod(typeElement))
138 | .addMethod(generateGetDoKVHolderMethod())
139 | .addMethod(generateSerializeMethod(typeElement))
140 | .addMethod(generateDeserializeMethod(typeElement))
141 | .addMethod(generateGetInstanceMethod(typeElement))
142 | .addMethod(generateGetInstanceNotNullMethod(typeElement))
143 | .addMethod(generateSetInstanceMethod(typeElement))
144 | .addMethod(generateRemoveKeyMethod());
145 | for (VariableElement variableElement : variableElementList) {
146 | builder.addMethod(generateGetFieldMethod(typeElement, variableElement));
147 | builder.addMethod(generateSetFieldMethod(typeElement, variableElement));
148 | }
149 | return builder.build();
150 | }
151 |
152 | /**
153 | * 定义该注解类在序列化时使用的 Key
154 | *
155 | * @param typeElement 注解对象上层元素对象,即 Java 对象
156 | * @return
157 | */
158 | private FieldSpec generateKeyField(TypeElement typeElement) {
159 | DoKV doKV = typeElement.getAnnotation(DoKV.class);
160 | String key = doKV.key();
161 | if (key.length() == 0) {
162 | key = typeElement.getQualifiedName().toString() + SUFFIX;
163 | }
164 | return FieldSpec.builder(String.class, KEY_NAME)
165 | .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
166 | .initializer(MessageFormat.format("\"{0}\"", key))
167 | .build();
168 | }
169 |
170 | /**
171 | * 构建内部静态类,用于持有单例对象
172 | *
173 | * @param typeElement 注解对象上层元素对象,即 Java 对象
174 | * @return
175 | */
176 | private TypeSpec generateInstanceHolderClass(TypeElement typeElement) {
177 | //包名
178 | String packageName = ElementUtils.getPackageName(elementUtils, typeElement);
179 | //自动构造的类的类名
180 | String enclosingClassName = getGenerateEnclosingClassName(typeElement);
181 | //静态内部类类名
182 | String staticClassName = ElementUtils.getStaticClassName(typeElement);
183 | ClassName className = ClassName.get(packageName, enclosingClassName);
184 | //构建实例变量
185 | FieldSpec instance = FieldSpec.builder(className, INSTANCE)
186 | .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
187 | .initializer(CodeBlock.builder().addStatement("new $L()", enclosingClassName).build())
188 | .build();
189 | return TypeSpec.classBuilder(staticClassName)
190 | .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
191 | .addField(instance)
192 | .build();
193 | }
194 |
195 | /**
196 | * 构建获取唯一实例的 Get 方法
197 | *
198 | * @param typeElement 注解对象上层元素对象,即 Java 对象
199 | * @return
200 | */
201 | private MethodSpec generateInstanceHolderMethod(TypeElement typeElement) {
202 | //包名
203 | final String packageName = ElementUtils.getPackageName(elementUtils, typeElement);
204 | //自动构造的类的类名
205 | final String enclosingClassName = getGenerateEnclosingClassName(typeElement);
206 | ClassName className = ClassName.get(packageName, enclosingClassName);
207 | MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("get")
208 | .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
209 | .returns(className)
210 | .addStatement("return new $L()", enclosingClassName);
211 | return methodBuilder.build();
212 | }
213 |
214 | private MethodSpec generateConstructorMethod() {
215 | MethodSpec.Builder methodBuilder = MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE);
216 | return methodBuilder.build();
217 | }
218 |
219 | /**
220 | * 构造用于获取 IDoKVHolder 实例的方法
221 | *
222 | * @return IDoKVHolder
223 | */
224 | private MethodSpec generateGetDoKVHolderMethod() {
225 | //方法名
226 | String methodName = "getDoKVHolder";
227 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
228 | .addModifiers(Modifier.PRIVATE)
229 | .returns(IDoKVHolder.class)
230 | .addStatement("return $T.getInstance().getDoKVHolder()", serializeManagerClass);
231 | return builder.build();
232 | }
233 |
234 | /**
235 | * 构造用于序列化的方法
236 | *
237 | * @return IDoKVHolder
238 | */
239 | private MethodSpec generateSerializeMethod(TypeElement parameter) {
240 | //方法名
241 | String methodName = "serialize";
242 | //方法参数名
243 | String keyName = "_" + KEY_NAME;
244 | String instanceName = "_" + ElementUtils.getEnclosingClassName(parameter);
245 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
246 | .addModifiers(Modifier.PRIVATE)
247 | .returns(String.class)
248 | .addParameter(String.class, keyName)
249 | .addParameter(ClassName.get(parameter.asType()), instanceName)
250 | .addStatement("return getDoKVHolder().serialize($L, $L)", keyName, instanceName);
251 | return builder.build();
252 | }
253 |
254 | /**
255 | * 构造用于反序列化的方法
256 | *
257 | * @return MethodSpec
258 | */
259 | private MethodSpec generateDeserializeMethod(TypeElement parameter) {
260 | //方法名
261 | String methodName = "deserialize";
262 | //方法参数名
263 | String keyName = "_" + KEY_NAME;
264 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
265 | .addModifiers(Modifier.PRIVATE)
266 | .returns(ClassName.get(parameter))
267 | .addParameter(String.class, keyName)
268 | .addStatement("return getDoKVHolder().deserialize($L, $L.class)", keyName, ElementUtils.getEnclosingClassName(parameter));
269 | return builder.build();
270 | }
271 |
272 | /**
273 | * 构造用于获取整个序列化对象的方法,返回值可能为 null
274 | *
275 | * @param typeElement 注解对象上层元素对象,即 Java 对象
276 | * @return
277 | */
278 | private MethodSpec generateGetInstanceMethod(TypeElement typeElement) {
279 | //顶层类类名
280 | String enclosingClassName = ElementUtils.getEnclosingClassName(typeElement);
281 | //方法名
282 | String methodName = "get" + StringUtils.toUpperCaseFirstChar(enclosingClassName);
283 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
284 | .addModifiers(Modifier.PUBLIC)
285 | .returns(ClassName.get(typeElement.asType()))
286 | .addStatement("return deserialize($L)", KEY_NAME);
287 | return builder.build();
288 | }
289 |
290 | /**
291 | * 构造用于获取整个序列化对象的方法,返回值不为 null
292 | *
293 | * @param typeElement 注解对象上层元素对象,即 Java 对象
294 | * @return
295 | */
296 | private MethodSpec generateGetInstanceNotNullMethod(TypeElement typeElement) {
297 | //顶层类类名
298 | String enclosingClassName = ElementUtils.getEnclosingClassName(typeElement);
299 | //方法名
300 | String methodName = "get" + StringUtils.toUpperCaseFirstChar(enclosingClassName) + "NotNull";
301 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
302 | .addModifiers(Modifier.PRIVATE)
303 | .returns(ClassName.get(typeElement.asType()))
304 | .addStatement("$L variable = deserialize($L)", enclosingClassName, KEY_NAME)
305 | .addStatement("if(variable != null) { return variable; } return new $L()", enclosingClassName);
306 | return builder.build();
307 | }
308 |
309 | /**
310 | * 构造用于序列化整个对象的方法
311 | *
312 | * @param typeElement 注解对象上层元素对象,即 Java 对象
313 | * @return
314 | */
315 | private MethodSpec generateSetInstanceMethod(TypeElement typeElement) {
316 | //顶层类类名
317 | String enclosingClassName = ElementUtils.getEnclosingClassName(typeElement);
318 | //方法名
319 | String methodName = "set" + StringUtils.toUpperCaseFirstChar(enclosingClassName);
320 | //方法参数名
321 | String fieldName = "instance";
322 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
323 | .addModifiers(Modifier.PUBLIC)
324 | .returns(String.class)
325 | .addParameter(ClassName.get(typeElement.asType()), fieldName)
326 | .beginControlFlow("if($L == null)", fieldName)
327 | .addStatement("remove(); return \"\"")
328 | .endControlFlow()
329 | .addStatement("return serialize($L,$L)", KEY_NAME, fieldName);
330 | return builder.build();
331 | }
332 |
333 | /**
334 | * 构造用于移除该序列化对象的方法
335 | *
336 | * @return
337 | */
338 | private MethodSpec generateRemoveKeyMethod() {
339 | //方法名
340 | String methodName = "remove";
341 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
342 | .addModifiers(Modifier.PUBLIC)
343 | .returns(void.class)
344 | .addStatement("getDoKVHolder().remove($L)", KEY_NAME);
345 | return builder.build();
346 | }
347 |
348 | /**
349 | * 重写包含 DoKV 注解的字段的 Get 方法
350 | *
351 | * @param typeElement 注解对象上层元素对象,即 Java 对象
352 | * @param variableElement 包含 DoKV 注解的字段
353 | * @return
354 | */
355 | private MethodSpec generateGetFieldMethod(TypeElement typeElement, VariableElement variableElement) {
356 | //顶层类类名
357 | String enclosingClassName = ElementUtils.getEnclosingClassName(typeElement);
358 | //字段名
359 | String fieldName = variableElement.getSimpleName().toString();
360 | //方法名
361 | String methodName = "get" + StringUtils.toUpperCaseFirstChar(fieldName);
362 | //方法名
363 | String getInstanceMethodName = "get" + StringUtils.toUpperCaseFirstChar(ElementUtils.getEnclosingClassName(typeElement)) + "()";
364 | MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
365 | .addModifiers(Modifier.PUBLIC)
366 | .returns(ClassName.get(variableElement.asType()))
367 | .addAnnotation(Override.class)
368 | .addStatement("$L variable = $L", enclosingClassName, getInstanceMethodName)
369 | .addStatement("if(variable != null) { return variable.$L(); } return super.$L() ", methodName, methodName);
370 | return builder.build();
371 | }
372 |
373 | /**
374 | * 重写包含 DoKV 注解的字段的 Set 方法
375 | *
376 | * @param variableElement 包含 DoKV 注解的字段
377 | * @return
378 | */
379 | private MethodSpec generateSetFieldMethod(TypeElement typeElement, VariableElement variableElement) {
380 | //顶层类类名
381 | String enclosingClassName = ElementUtils.getEnclosingClassName(typeElement);
382 | //字段名
383 | String fieldName = variableElement.getSimpleName().toString();
384 | String upperCaseFieldName = StringUtils.toUpperCaseFirstChar(fieldName);
385 | //set方法名
386 | String setMethodName = "set" + upperCaseFieldName;
387 | //序列化对象名
388 | String serializeObjName = "_" + StringUtils.toLowerCaseFirstChar(enclosingClassName);
389 | //方法名
390 | String methodName = "get" + StringUtils.toUpperCaseFirstChar(enclosingClassName) + "NotNull()";
391 | MethodSpec.Builder builder = MethodSpec.methodBuilder(setMethodName)
392 | .addModifiers(Modifier.PUBLIC)
393 | .returns(void.class)
394 | .addParameter(ClassName.get(variableElement.asType()), "_" + fieldName)
395 | .addAnnotation(Override.class)
396 | .addStatement("$L $L = $L", enclosingClassName, serializeObjName, methodName)
397 | .addStatement("$L.$L($L)", serializeObjName, setMethodName, "_" + fieldName)
398 | .addStatement("serialize($L,$L)", KEY_NAME, serializeObjName);
399 | return builder.build();
400 | }
401 |
402 | //获取自动构造的类的类名
403 | private static String getGenerateEnclosingClassName(TypeElement typeElement) {
404 | return ElementUtils.getEnclosingClassName(typeElement) + SUFFIX;
405 | }
406 |
407 | }
--------------------------------------------------------------------------------
/dokv_processor/src/main/java/leavesc/hello/dokv_processor/utils/ElementUtils.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv_processor.utils;
2 |
3 | import javax.lang.model.element.TypeElement;
4 | import javax.lang.model.util.Elements;
5 |
6 | /**
7 | * 作者:leavesC
8 | * 时间:2019/1/5 14:49
9 | * 描述:
10 | * GitHub:https://github.com/leavesC
11 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
12 | */
13 | public class ElementUtils {
14 |
15 | //获取包名
16 | public static String getPackageName(Elements elementUtils, TypeElement typeElement) {
17 | return elementUtils.getPackageOf(typeElement).getQualifiedName().toString();
18 | }
19 |
20 | //获取顶层类类名
21 | public static String getEnclosingClassName(TypeElement typeElement) {
22 | return typeElement.getSimpleName().toString();
23 | }
24 |
25 | //获取静态内部类类名
26 | public static String getStaticClassName(TypeElement typeElement) {
27 | return getEnclosingClassName(typeElement) + "Holder";
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/dokv_processor/src/main/java/leavesc/hello/dokv_processor/utils/StringUtils.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.dokv_processor.utils;
2 |
3 | /**
4 | * 作者:leavesC
5 | * 时间:2019/1/5 14:46
6 | * 描述:
7 | * GitHub:https://github.com/leavesC
8 | * Blog:https://www.jianshu.com/u/9df45b87cfdf
9 | */
10 | public class StringUtils {
11 |
12 | //将首字母转为小写
13 | public static String toLowerCaseFirstChar(String text) {
14 | if (text == null || text.length() == 0) {
15 | return "";
16 | }
17 | if (Character.isLowerCase(text.charAt(0))) {
18 | return text;
19 | }
20 | return String.valueOf(Character.toLowerCase(text.charAt(0))) + text.substring(1);
21 | }
22 |
23 | //将首字母转为大写
24 | public static String toUpperCaseFirstChar(String text) {
25 | if (Character.isUpperCase(text.charAt(0))) {
26 | return text;
27 | } else {
28 | return String.valueOf(Character.toUpperCase(text.charAt(0))) + text.substring(1);
29 | }
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | REPO_PUBLISH_VERSION=0.1.8
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/DoKV/bbd54587f49d91fb5f0ed4524e4e4d938f49fdf8/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':dokv_processor', ':dokv_annotation', ':dokv_impl'
2 |
--------------------------------------------------------------------------------