windows环境下载android源码批量下载 java版本

转载自 http://blog.csdn.net/hlf48641715/article/details/7188450 

非常感谢博主的文章,博主用的python写的批量下载源码,现在提供一个java版本的批量下载源码

package com.pactera.android.download;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class DownLoadSrc {

	/**
	 * @param args
	 */
	// 源码存放路径
	private static String downloadDir;
	// xml路径
	private static String defaultXMLFile;
	private static List<Project> projects = new ArrayList<DownLoadSrc.Project>();

	public static void main(String[] args) {

		downloadDir = "E:/android_src";
		defaultXMLFile = "F:/source/manifest/default.xml";

		File downLoadFile = new File(downloadDir);
		if (!downLoadFile.exists())
			downLoadFile.mkdirs();
		getProjects(defaultXMLFile);
		downLoadSrc();
		System.out.println("恭喜你,下载完成!!!!!");
	}

	private static void downLoadSrc() {
		// git program path
		String git = "E:/Program Files/Git/bin/git.exe";
		String prefix = git + " clone https://android.googlesource.com/";
		String suffix = ".git";
		for (Project project : projects) {
			String path = project.getPath();
			String pathsp[] = path.split("/");
			if (pathsp.length > 0) {
				path = pathsp[0];
			}
			String childrenPath = downloadDir + "/" + path;
			File childrenFile = new File(childrenPath);
			if (!childrenFile.exists()) {
				childrenFile.mkdirs();
			}
			String command = prefix + project.getName() + suffix + " "
					+ childrenPath;
			Runtime r = Runtime.getRuntime();
			try {
				r.exec(command);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	static void getProjects(String fileName) {
		SAXReader reader = new SAXReader();
		try {
			Document doc = reader.read(new File(fileName));

			List<String> ps = doc.selectNodes("manifest/project");
			Iterator it = ps.iterator();
			while (it.hasNext()) {
				Element elm = (Element) it.next();
				String name = elm.attributeValue("name");
				String path = elm.attributeValue("path");
				// System.out.println("name:" + name + ",path:" + path);
				projects.add(new Project(name, path));
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	static private class Project {
		String name;
		String path;

		public Project(String name, String path) {
			super();
			this.name = name;
			this.path = path;
		}

		public String getName() {
			return name;
		}

		public String getPath() {
			return path;
		}

	}
}

附上源代码--->源码下载 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值