4 Star 2 Fork 0

c0der/SkyPro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cc.gradle 4.91 KB
一键复制 编辑 原始数据 按行查看 历史
luyuxiang 提交于 2016-12-13 16:52 . 增加保护
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!!!')
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Groovy
1
https://gitee.com/c0der/SkyPro.git
git@gitee.com:c0der/SkyPro.git
c0der
SkyPro
SkyPro
master

搜索帮助