Created
April 9, 2018 08:43
-
-
Save beilly/be27dbbd490a86758824c93c7d24a646 to your computer and use it in GitHub Desktop.
打包配置自增插件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: HJPackPlugin | |
class HJPackPlugin implements Plugin<Project> { | |
@Override | |
void apply(Project project) { | |
def file = project.rootProject.file("packageHJ.properties") | |
project.extensions.create("hjConf", InnerStorage, file) | |
} | |
} | |
class InnerStorage { | |
Properties hjProp | |
File packageHJ; | |
InnerStorage(File file) { | |
packageHJ = file; | |
loadProperty() | |
} | |
private loadProperty() { | |
hjProp = new Properties() | |
if (!packageHJ.exists()) { | |
packageHJ.createNewFile() | |
} else { | |
packageHJ.withInputStream { | |
ins -> hjProp.load(ins) | |
} | |
} | |
println("loadProperty from $packageHJ --> $hjProp") | |
} | |
def propertyMissing(String name, value) { | |
hjProp.setProperty(name, String.valueOf(value)) | |
save() | |
} | |
def propertyMissing(String name) { | |
def v = hjProp.getProperty(name) | |
null == v ? "": v.integer ? v.toInteger() : v.toString() | |
} | |
private save() { | |
if (!packageHJ.exists()) { | |
packageHJ.createNewFile() | |
} | |
packageHJ.withOutputStream { | |
os -> hjProp.store(os, null) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考 https://gist.github.com/8enet/4af5c10e7a3137ba07c7c7008323a819