加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
genbuildinfo.gradle 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
Fei Wang 提交于 2017-03-22 14:44 . multiple key accelerators for tool item
def runShellCommand(cmd, theargs) {
def os = new ByteArrayOutputStream()
exec {
executable cmd
args theargs
standardOutput = os
}
return os.toString().replace("\n", "");
}
import java.text.SimpleDateFormat
def buildTime(){
def df = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}
def genBuildInfo(String czName, String pkgName, String baseDir) {
String header = "// " + czName + ".java generated by build script"
def commit = runShellCommand('git', ['rev-parse', 'HEAD'])
def branch = runShellCommand('git', ['rev-parse', '--abbrev-ref', 'HEAD'])
def tag = runShellCommand('git', ['name-rev', '--tags', '--name-only', commit])
def commitinfo = runShellCommand('git', ['show-branch', 'HEAD'])
def server = InetAddress.getLocalHost().getHostName()
def builder = System.getProperty('user.name')
def buildos = System.getProperty('os.name')
def buildtime = buildTime()
String modif = " public static final String "
String fname = baseDir + pkgName.replace(".", "/") + "/" + czName + ".java"
println "Generating build information to " + fname
new File(fname).withWriter { out ->
out.writeLine(header)
out.writeLine("package " + pkgName + ";")
out.writeLine("public final class " + czName + " {")
out.writeLine(modif + "VERSION = \"$version\";");
out.writeLine(modif + "BRANCH = \"$branch\";");
out.writeLine(modif + "TAG = \"$tag\";");
out.writeLine(modif + "COMMIT = \"$commit\";");
out.writeLine(modif + "COMMIT_INFO = \"$commitinfo\";");
out.writeLine(modif + "BUILD_SERVER = \"$server\";");
out.writeLine(modif + "BUILD_OS = \"$buildos\";");
out.writeLine(modif + "BUILD_USER = \"$builder\";");
out.writeLine(modif + "BUILD_TIME = \"$buildtime\";");
out.writeLine("}")
}
/*
exec {
executable 'cat'
args fname
}
*/
}
task genBuildInfo << {
String pkgName = 'feiw'
String gendir = '/generated-sources/'
new File(project.buildDir.toString() + gendir + pkgName.replace(".", "/")).mkdirs();
genBuildInfo('BuildInfo', pkgName, project.buildDir.toString() + gendir)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化