代码拉取完成,页面将自动刷新
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.alibaba:fastjson:latest.integration'
}
}
class StreamGobbler extends Thread {
InputStream is;
StreamGobbler(InputStream is) {
this.is = is;
}
public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
println(line);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
class Utils {
static void copyFile(String src, String des) {
if (new File(des).exists())
return
println("copyFile from:" + src + " to:" + des)
FileInputStream fis = new FileInputStream(src);
FileOutputStream fos = new FileOutputStream(des);
int len = 0;
byte[] buf = new byte[1024];
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fis.close();
fos.close();
}
static void exec(String cmd) {
println("start " + cmd)
Process p = Runtime.runtime.exec(cmd)
StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream())
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream())
errorGobbler.start()
outputGobbler.start()
p.waitFor()
println("end " + cmd)
}
}
interface IDoClone {
List<Runnable> doClone(String path)
}
class Repository {
public String repository;
public String branch;
public List<Runnable> doClone(String path, Runnable after) {
List<Runnable> ret = new ArrayList<>();
Runnable r = new Runnable() {
@Override
void run() {
if (new File(path).exists()) {
String cmd = "git -C " + path + " fetch"
Utils.exec(cmd)
cmd = "git -C " + path + " checkout " + branch
Utils.exec(cmd)
cmd = "git -C " + path + " pull"
Utils.exec(cmd)
} else {
String cmd = "git clone " + repository + " -b " + branch + " " + path
Utils.exec(cmd)
}
if (after != null)
after.run()
}
}
ret.add(r)
return ret
}
}
class CC implements IDoClone {
public String directory;
public List<Repository> repositories;
@Override
public List<Runnable> doClone(String path) {
List<Runnable> ret = new ArrayList<>();
for (Repository r : repositories) {
String name = r.repository.substring(r.repository.lastIndexOf("/"))
String fullPath = path + File.separator + directory + File.separator + name
ret.addAll(r.doClone(fullPath, new Runnable() {
@Override
void run() {
Utils.copyFile(".cc/commit-msg", fullPath + File.separator + ".git/hooks/commit-msg")
}
}))
}
return ret
}
}
class CCIni implements IDoClone {
private static final String PROJECT_PATH = "project/"
private static final String CC_PATH = "cc/"
public Repository project;
public List<CC> cc;
@Override
public List<Runnable> doClone(String path) {
String project_path = path + File.separator + PROJECT_PATH
String cc_path = path + File.separator + CC_PATH
List<Runnable> ret = new ArrayList<>();
if (project != null) {
ret.addAll(project.doClone(project_path, new Runnable() {
@Override
void run() {
Utils.copyFile(".cc/project.gradle", project_path + "project.gradle")
Utils.copyFile(".cc/commit-msg", project_path + ".git/hooks/commit-msg")
}
}))
}
if (cc != null) {
for (CC c : cc)
ret.addAll(c.doClone(cc_path))
}
return ret
}
}
CCIni readINI() {
String ini = ""
File file = new File("cc.ini")
if (file.exists()) {
InputStreamReader read = new InputStreamReader(new FileInputStream(file))
BufferedReader bufferedReader = new BufferedReader(read)
String lineTxt = null
while ((lineTxt = bufferedReader.readLine()) != null) {
ini += lineTxt
}
read.close();
}
return com.alibaba.fastjson.JSONObject.parseObject(ini, CCIni.class);
}
task ccinit << {
println('ccinit!!! ' + gradle.ext.rootPath)
CCIni ini = readINI()
List<Runnable> rs = ini.doClone(".")
List<Thread> threads = new ArrayList<>()
for (Runnable r : rs) {
Thread t = new Thread(r)
threads.add(t)
t.start()
}
for (Thread thread : threads)
thread.join()
println('ccinit done!!!')
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。