代码拉取完成,页面将自动刷新
def targetFile = new File("./app/src/main/java/com/smartconfig/Config.java")
def targetFile2 = new File("./app/src/main/assets/test.txt")
def targetFile3 = new File("./gradle.properties")
if (targetFile2.exists()) {
def bytes = targetFile2.getBytes()
def original = new String(bytes)
if(!original.contains("data=")||!original.contains("pageName=")||!original.contains("isUseGson=")){
throw new RuntimeException("src/main/assets/test.txt文件错失必要的参数!请仔细检查")
}
//防止json数据里面存在isUseGson=true这样的字段干扰我们的判断
def result = original.substring(0,original.indexOf("data="))
if (result.contains("isUseGson=true")) {
isUseGson = true
}
if (result.contains("isUseGson=false")) {
isUseGson = false
}
}
//该接口返回的是文件内容对应的byte[]
def bytes = targetFile.getBytes()
//与上述接口对应,还可以直接使用targetFile.bytes这个属性获取文件内容
def original = new String(bytes)
def useGson = "package com.smartconfig;\n" +
"\n" +
"import com.google.gson.Gson;\n" +
"\n" +
"public class Config {\n" +
" public Object build() {\n" +
" return new Gson();\n" +
" }\n" +
"}"
def noUseGson = "package com.smartconfig;\n" +
"\n" +
"import com.google.gson.Gson;\n" +
"\n" +
"public class Config {\n" +
" public Object build() {\n" +
" // return new Gson();\n" +
" return null;\n" +
" }\n" +
"}"
//修改Config.java类之前判断Config.java是不是最新的代码,如果不是最新的代码就要爆出异常~
if (original != useGson && original != noUseGson) {
throw new RuntimeException("Config.javay类已经被修改过,需要更新才能编译!请找梁超杰")
}
//这里获取的实际是Java中的BufferedOutputStream
targetFile.withOutputStream { osm ->
osm.write((isUseGson.toBoolean() ? useGson : noUseGson).getBytes())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。