Commit 42f883a1f209ab7c8cbbe6eece68d3efbaaacf95
1 parent
762b1b1d
Exists in
yxb_dev
and in
2 other branches
no message
Showing
8 changed files
with
59 additions
and
36 deletions
Show diff stats
.idea/modules.xml
| @@ -4,8 +4,8 @@ | @@ -4,8 +4,8 @@ | ||
| 4 | <modules> | 4 | <modules> |
| 5 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> | 5 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
| 6 | <module fileurl="file://$PROJECT_DIR$/mvpsdk/mvpsdk.iml" filepath="$PROJECT_DIR$/mvpsdk/mvpsdk.iml" /> | 6 | <module fileurl="file://$PROJECT_DIR$/mvpsdk/mvpsdk.iml" filepath="$PROJECT_DIR$/mvpsdk/mvpsdk.iml" /> |
| 7 | + <module fileurl="file://$PROJECT_DIR$/parentWorkHolper.iml" filepath="$PROJECT_DIR$/parentWorkHolper.iml" /> | ||
| 7 | <module fileurl="file://E:\parentwork\parentWorkHolper.iml" filepath="E:\parentwork\parentWorkHolper.iml" /> | 8 | <module fileurl="file://E:\parentwork\parentWorkHolper.iml" filepath="E:\parentwork\parentWorkHolper.iml" /> |
| 8 | - <module fileurl="file://$PROJECT_DIR$/parentwork.iml" filepath="$PROJECT_DIR$/parentwork.iml" /> | ||
| 9 | <module fileurl="file://F:\parentWorkHolper\parentwork.iml" filepath="F:\parentWorkHolper\parentwork.iml" /> | 9 | <module fileurl="file://F:\parentWorkHolper\parentwork.iml" filepath="F:\parentWorkHolper\parentwork.iml" /> |
| 10 | <module fileurl="file://$PROJECT_DIR$/processor/processor.iml" filepath="$PROJECT_DIR$/processor/processor.iml" /> | 10 | <module fileurl="file://$PROJECT_DIR$/processor/processor.iml" filepath="$PROJECT_DIR$/processor/processor.iml" /> |
| 11 | <module fileurl="file://$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" filepath="$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" /> | 11 | <module fileurl="file://$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" filepath="$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" /> |
app/libs/processor.jar
No preview for this file type
app/src/main/assets/migrations/2.sql
| @@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
| 1 | -ALTER table test INSERT ADD COLUMN age INTEGER |
app/src/main/assets/migrations/3.sql
| @@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
| 1 | -ALTER table test INSERT ADD COLUMN name TEXT |
app/src/main/java/com/shunzhi/parent/annotation/VersionTest.java
| @@ -2,16 +2,13 @@ package com.shunzhi.parent.annotation; | @@ -2,16 +2,13 @@ package com.shunzhi.parent.annotation; | ||
| 2 | 2 | ||
| 3 | import org.shunzhi.processorlibs.AddColumn; | 3 | import org.shunzhi.processorlibs.AddColumn; |
| 4 | 4 | ||
| 5 | -/** | ||
| 6 | - * Created by 10501 on 2018/3/28. | ||
| 7 | - */ | ||
| 8 | public class VersionTest { | 5 | public class VersionTest { |
| 9 | - @AddColumn(version = 3,tableName = "test",type = "String",isDebug = false) | 6 | + @AddColumn(version = 3, tableName = "test", type = "String", isDebug = true) |
| 10 | private String name; | 7 | private String name; |
| 11 | 8 | ||
| 12 | - @AddColumn(version = 3,tableName = "test",type = "Integer",isDebug = false) | 9 | + @AddColumn(version = 3, tableName = "test", type = "Integer", isDebug = true) |
| 13 | Integer age; | 10 | Integer age; |
| 14 | - | ||
| 15 | - String area; | 11 | + @AddColumn(version = 3, tableName = "test", type = "Boolean", isDebug = true) |
| 12 | + Boolean area; | ||
| 16 | 13 | ||
| 17 | } | 14 | } |
processor/src/main/java/org/shunzhi/processorlibs/AddColumn.java
| @@ -16,4 +16,9 @@ public @interface AddColumn { | @@ -16,4 +16,9 @@ public @interface AddColumn { | ||
| 16 | String type(); | 16 | String type(); |
| 17 | 17 | ||
| 18 | boolean isDebug() default true; | 18 | boolean isDebug() default true; |
| 19 | + | ||
| 20 | + String type_string = "string"; | ||
| 21 | + String type_boolean = "boolean"; | ||
| 22 | + String type_integer = "integer"; | ||
| 23 | + | ||
| 19 | } | 24 | } |
processor/src/main/java/org/shunzhi/processorlibs/VersionProcessor.java
| 1 | package org.shunzhi.processorlibs; | 1 | package org.shunzhi.processorlibs; |
| 2 | 2 | ||
| 3 | -import org.greenrobot.greendao.annotation.Entity; | ||
| 4 | - | ||
| 5 | import java.io.BufferedWriter; | 3 | import java.io.BufferedWriter; |
| 6 | import java.io.File; | 4 | import java.io.File; |
| 7 | -import java.io.FileOutputStream; | ||
| 8 | import java.io.FileWriter; | 5 | import java.io.FileWriter; |
| 9 | import java.io.IOException; | 6 | import java.io.IOException; |
| 10 | import java.io.OutputStreamWriter; | 7 | import java.io.OutputStreamWriter; |
| 11 | import java.io.PrintStream; | 8 | import java.io.PrintStream; |
| 12 | -import java.util.ArrayList; | ||
| 13 | import java.util.HashMap; | 9 | import java.util.HashMap; |
| 14 | -import java.util.List; | ||
| 15 | -import java.util.Map; | 10 | +import java.util.HashSet; |
| 16 | import java.util.Set; | 11 | import java.util.Set; |
| 17 | 12 | ||
| 18 | import javax.annotation.processing.AbstractProcessor; | 13 | import javax.annotation.processing.AbstractProcessor; |
| @@ -26,19 +21,27 @@ import javax.lang.model.element.TypeElement; | @@ -26,19 +21,27 @@ import javax.lang.model.element.TypeElement; | ||
| 26 | @SupportedAnnotationTypes({"org.shunzhi.processorlibs.AddColumn"}) | 21 | @SupportedAnnotationTypes({"org.shunzhi.processorlibs.AddColumn"}) |
| 27 | @SupportedSourceVersion(SourceVersion.RELEASE_7) | 22 | @SupportedSourceVersion(SourceVersion.RELEASE_7) |
| 28 | public class VersionProcessor extends AbstractProcessor { | 23 | public class VersionProcessor extends AbstractProcessor { |
| 29 | - private final String sql_insert = "ALTER table %s INSERT ADD COLUMN %s %s"; | ||
| 30 | - private final String sql_update = "UPDATE table message SET %s = '%s' WHERE %s = '%s'"; | 24 | + //private final String sql_update = "UPDATE table message SET %s = '%s' WHERE %s = '%s'"; |
| 31 | 25 | ||
| 32 | - String path = "app\src\main\assets\migrations".replace("\", File.separator); | 26 | + //String path = "app\src\main\assets\migrations".replace("\", File.separator); |
| 33 | 27 | ||
| 34 | @Override | 28 | @Override |
| 35 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | 29 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
| 36 | // File file = new File("test"); | 30 | // File file = new File("test"); |
| 37 | // if (!file.exists())file.mkdir(); | 31 | // if (!file.exists())file.mkdir(); |
| 38 | - int i = 0; | 32 | +// File countFile = new File("测试数据.txt"); |
| 33 | +// try { | ||
| 34 | +// BufferedWriter writer = new BufferedWriter(new FileWriter(countFile)); | ||
| 35 | +// writer.write(System.currentTimeMillis() + ""); | ||
| 36 | +// writer.newLine(); | ||
| 37 | +// writer.flush();writer.close(); | ||
| 38 | +// } catch (IOException e) { | ||
| 39 | +// e.printStackTrace(); | ||
| 40 | +// } | ||
| 41 | + | ||
| 39 | BufferedWriter testBw = null; | 42 | BufferedWriter testBw = null; |
| 40 | 43 | ||
| 41 | - HashMap<Integer, List<String>> map = new HashMap<>(); | 44 | + HashMap<Integer, Set<String>> map = new HashMap<>(); |
| 42 | 45 | ||
| 43 | try { | 46 | try { |
| 44 | for (Element element : roundEnv.getElementsAnnotatedWith(AddColumn.class)) { | 47 | for (Element element : roundEnv.getElementsAnnotatedWith(AddColumn.class)) { |
| @@ -49,21 +52,32 @@ public class VersionProcessor extends AbstractProcessor { | @@ -49,21 +52,32 @@ public class VersionProcessor extends AbstractProcessor { | ||
| 49 | int version = addColumn.version(); | 52 | int version = addColumn.version(); |
| 50 | String tableName = addColumn.tableName(); | 53 | String tableName = addColumn.tableName(); |
| 51 | String type = addColumn.type(); | 54 | String type = addColumn.type(); |
| 52 | - List<String> list = map.get(version); | 55 | + Set<String> set = map.get(version); |
| 53 | boolean isDebug = addColumn.isDebug(); | 56 | boolean isDebug = addColumn.isDebug(); |
| 54 | - if (list == null) list = new ArrayList<>(); | 57 | + if (set == null) set = new HashSet<>(); |
| 55 | String sql = "null"; | 58 | String sql = "null"; |
| 59 | + String sql_insert = "ALTER table %s ADD COLUMN %s %s"; | ||
| 56 | if (type.equalsIgnoreCase("String")) { | 60 | if (type.equalsIgnoreCase("String")) { |
| 57 | sql = String.format(sql_insert, tableName, element.getSimpleName().toString(), "TEXT"); | 61 | sql = String.format(sql_insert, tableName, element.getSimpleName().toString(), "TEXT"); |
| 58 | - if (!isDebug) list.add(sql); | 62 | + if (!isDebug) |
| 63 | + set.add(sql); | ||
| 59 | } else if (type.equalsIgnoreCase("Integer")) { | 64 | } else if (type.equalsIgnoreCase("Integer")) { |
| 60 | sql = String.format(sql_insert, tableName, element.getSimpleName().toString(), "INTEGER"); | 65 | sql = String.format(sql_insert, tableName, element.getSimpleName().toString(), "INTEGER"); |
| 61 | - if (!isDebug) list.add(sql); | 66 | + if (!isDebug) |
| 67 | + set.add(sql); | ||
| 68 | + } else if (type.equalsIgnoreCase("boolean")){ | ||
| 69 | + sql = String.format(sql_insert, tableName, element.getSimpleName().toString(), "INTEGER"); | ||
| 70 | + if (!isDebug) | ||
| 71 | + set.add(sql); | ||
| 72 | + } | ||
| 73 | + if (isDebug) { | ||
| 74 | + testBw.write(version + " "); | ||
| 75 | + testBw.write(sql); | ||
| 76 | + testBw.newLine(); | ||
| 77 | + testBw.flush(); | ||
| 78 | + } else { | ||
| 79 | + map.put(version, set); | ||
| 62 | } | 80 | } |
| 63 | - testBw.write(version + " "); | ||
| 64 | - testBw.write(sql); | ||
| 65 | - testBw.newLine(); | ||
| 66 | - testBw.flush(); | ||
| 67 | } | 81 | } |
| 68 | } catch (Exception e) { | 82 | } catch (Exception e) { |
| 69 | e.printStackTrace(); | 83 | e.printStackTrace(); |
| @@ -74,18 +88,27 @@ public class VersionProcessor extends AbstractProcessor { | @@ -74,18 +88,27 @@ public class VersionProcessor extends AbstractProcessor { | ||
| 74 | e.printStackTrace(); | 88 | e.printStackTrace(); |
| 75 | } | 89 | } |
| 76 | } | 90 | } |
| 77 | - | 91 | + File tmp = new File("tmp"); |
| 92 | +// File migrations = new File(tmp.getParentFile(), "app\\src\\main\\assets\\migrations\\".replace("\\", File.separator)); | ||
| 93 | +// if (migrations.exists() || migrations.mkdirs()) { | ||
| 94 | +// File[] files = migrations.listFiles(); | ||
| 95 | +// if (files != null) | ||
| 96 | +// for (File f : files) { | ||
| 97 | +// if (!f.getName().equals("1.sql") && f.getName().endsWith(".sql")) f.delete(); | ||
| 98 | +// } | ||
| 99 | +// } | ||
| 78 | for (Integer version : map.keySet()) { | 100 | for (Integer version : map.keySet()) { |
| 79 | try { | 101 | try { |
| 80 | - File tmp = new File("tmp"); | ||
| 81 | String path = "app\\src\\main\\assets\\migrations\\".replace("\\", File.separator) + version + ".sql"; | 102 | String path = "app\\src\\main\\assets\\migrations\\".replace("\\", File.separator) + version + ".sql"; |
| 82 | File file = new File(tmp.getParentFile(), path); | 103 | File file = new File(tmp.getParentFile(), path); |
| 83 | BufferedWriter bw = new BufferedWriter(new FileWriter(file)); | 104 | BufferedWriter bw = new BufferedWriter(new FileWriter(file)); |
| 105 | + StringBuilder builder = new StringBuilder(); | ||
| 84 | for (String str : map.get(version)) { | 106 | for (String str : map.get(version)) { |
| 85 | - bw.write(str); | ||
| 86 | - bw.newLine(); | ||
| 87 | - bw.flush(); | 107 | + builder.append(str); |
| 108 | + builder.append("\r\n"); | ||
| 88 | } | 109 | } |
| 110 | + bw.write(builder.toString()); | ||
| 111 | + bw.flush(); | ||
| 89 | bw.close(); | 112 | bw.close(); |
| 90 | } catch (IOException e) { | 113 | } catch (IOException e) { |
| 91 | e.printStackTrace(); | 114 | e.printStackTrace(); |
| @@ -93,4 +116,4 @@ public class VersionProcessor extends AbstractProcessor { | @@ -93,4 +116,4 @@ public class VersionProcessor extends AbstractProcessor { | ||
| 93 | } | 116 | } |
| 94 | return true; | 117 | return true; |
| 95 | } | 118 | } |
| 96 | -} | 119 | -} |
| 120 | +} | ||
| 97 | \ No newline at end of file | 121 | \ No newline at end of file |
sql.txt