老早前就想下载android代码学习学习了,无奈android官方文档提供的方法,经尝试后发现完全不适合我,因为一旦中途断开就要重新下载,否则什么代码都看不到。而且不知道提供的那个网址被墙了还是怎样,经常连不上。换了android.googlesource.com还是差不多,代码一样下不下来。
不过经过一番努力还是有结果的,发现github有个项目是做了android.googlesource.com中android源码的镜像的,而从github上下载代码则稳定很多,速度也很快,地址为:
https://github.com/android
我试着从上面下载了其中一部分,发现很快就下载下来了。不过上面有近一百个地址,要是让我一个一个下,然后再进行分类,移到相应的文件夹,我一定会疯的,这不是我的性格。作为一个优秀的程序员,懒惰就是最大的优点。
在这种情况下,当然是写一个脚本来下载代码了,这个脚本的关键代码就是:
git clone --depth=1 $2 $1
其中参数1是下载到本地的路径,参数2是git地址。
接下来就是要解析https://github.com/android 这个页面,得到所有git地址了。
查看源代码,发现每一个git地址都在网页源代码的一个叫“repolist-name”的CSS类中,如下所示:
<h3 class="repolist-name">
<a href="/android/platform_frameworks_base">platform_frameworks_base</a>
</h3>
一共有98个。在这个标签里面,
<a href="/android/platform_frameworks_base">platform_frameworks_base</a>
是我们要提取的内容,href属性的值前面加上“http://github.com”,后面加上“.git”就是我们要的git地址,而platform_frameworks_base中的下划线转换成斜杠“/”,就是我们在本地对应的路径。
接下来建一个java工程,解析这个网页并将这两个地址输出到文本中,以方便我们的脚本编写。
解析html用jsoup库,然后输出到文本,也懒得自己再去操作输出流什么的了,用apache中的common-io包。
这里我一共写了两个类,一个是Main.java用来解析,一个是JavaBean,即GithubUrl类,代码如下:
/*
* @(#)Main.java Project:GetAndroidSource
* Date:2013-9-1
*
* Copyright (c) 2013 CFuture09, Institute of Software,
* Guangdong Ocean University, Zhanjiang, GuangDong, China.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sinaapp.msdxblog.getandroidsource;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
* @author Geek_Soledad <a target="_blank" href=
* "http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=XTAuOSVzPDM5LzI0OR0sLHM_MjA"
* style="text-decoration:none;"><img src=
* "http://rescdn.qqmail.com/zh_CN/htmledition/images/function/qm_open/ico_mailme_01.png"
* /></a>
*/
public class Main {
private static final String GITHUB_URL = "https://github.com";
private static final String GITHUB_ANDROID_URL = "https://github.com/android";
public static void main(String[] args) {
List<GithubUrl> urls = getGithubUrl();
System.out.println("repolists: " + urls.size());
try {
FileUtils.writeLines(new File("E:\\gitclone.txt"), urls);
System.out.println("write to E:\\gitclone.txt finish");
} catch (IOException e) {
e.printStackTrace();
}
}
private static List<GithubUrl> getGithubUrl() {
Document doc = null;
try {
doc = Jsoup.connect(GITHUB_ANDROID_URL).get();
} catch (IOException e) {
e.printStackTrace();
}
if (doc == null) {
return null;
}
List<GithubUrl> urls = new ArrayList<GithubUrl>();
Elements repolists = doc.getElementsByClass("repolist-name");
for (Element repolist : repolists) {
Elements hrefs = repolist.select("a[href]");
if (hrefs.isEmpty()) {
System.out.println("it is empth");
continue;
}
if (hrefs.size() > 1) {
System.out.println(hrefs.text() + ":" + hrefs.size());
}
Element e = hrefs.first();
System.out.println(e.html() + ":" + e.text() + "---" + e.attr("href"));
urls.add(new GithubUrl(e.text().replaceAll("_", "/"), GITHUB_URL + e.attr("href")));
}
return urls;
}
}
/*
* @(#)GithubUrl.java Project:GetAndroidSource
* Date:2013-9-1
*
* Copyright (c) 2013 CFuture09, Institute of Software,
* Guangdong Ocean University, Zhanjiang, GuangDong, China.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sinaapp.msdxblog.getandroidsource;
/**
* @author Geek_Soledad <a target="_blank" href=
* "http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=XTAuOSVzPDM5LzI0OR0sLHM_MjA"
* style="text-decoration:none;"><img src=
* "http://rescdn.qqmail.com/zh_CN/htmledition/images/function/qm_open/ico_mailme_01.png"
* /></a>
*/
public class GithubUrl {
private String title;
private String href;
public GithubUrl(String title, String href) {
super();
this.title = title;
this.href = href;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
@Override
public String toString() {
return String.format("cloneit %s %s.git", title, href);
}
}
上面的GithubUrl.java中,重写了toString,是因为我在脚本了定义了一个cloneit的函数用来从指定的地址下载代码到指定的目录中,这样输出的话我到时可以直接粘贴到脚本中。不过刚才发现上面的代码要略微修改一下,虽然没什么错误。
今天就先写到这里,因为是在公司电脑里写,而脚本在我家里的电脑,所以脚本在下一篇再贴上来吧。而上面的java工程我托管到了code.google.com中,可以通过svn下载,命令如下:
svn checkout http://msdx-java-code.googlecode.com/svn/trunk/GetAndroidSource
本来想在另一篇日志附上脚本的,但觉得内容不多,就决定改一下这篇文章,把脚本附在下面了。
脚本的主要代码如下:
#!/bin/bash
#sudo dpkg-reconfigure dash
#根本目录
#$1为保存的地址,$2为下载地址
function cloneit()
{
if [ -d $1 ]; then
echo -e "\033[0;38;40m $2 has been git clone \033[0m"
echo "git pull --depth 1 $1"
cd $1
git pull --depth 1
cd -
else
echo -e "\033[0;31;40m git clone $2 $1 \033[0m"
git clone --depth=1 $2 $1
fi
echo finish $(date) $1
}
#下载路径
cloneit platform/frameworks/base https://github.com/android/platform_frameworks_
base.git
cloneit platform/build https://github.com/android/platform_build.git
其中在cloneit函数里面,先判断文件夹是否存在,如果存在就使用git pull更新代码,否则就使用git clone下载代码。
完整脚本下载地址:http://www.vdisk.cn/down/index/14777400
分享到:
相关推荐
该压缩包包含两个脚本:一个bash脚本负责从github.com/android抓取页面,并调用python脚本,解析抓取下来的每个页面,输出git clone命令。 具体过程参考:...
该脚本有助于在Github上查找Android应用,并将其与Google Play上的条目进行匹配。 来自GitHub和Google Play的信息被组合在一起,以构建一个开放源代码应用程序,其源代码和版本控制数据的连接数据集。 所有Android...
java安卓辅助源码 github_arsenal github军火库 漏洞及渗透练习平台: WebGoat漏洞练习环境 Damn Vulnerable Web Application(漏洞练习平台) 数据库注入练习平台 用node编写的漏洞练习平台,like OWASP Node Goat ...
安卓tinyalsa源码,附带makefile脚本,可在linux平台直接编译,是学习linux音频驱动开的得力工具。地址:https://github.com/ZeLianWen/tinyalsa,记得点赞,thanks。
此时此景,笔者只专注Android、Iphone等移动平台开发,看着这些源码心中有万分感慨,写此文章纪念那时那景! Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这...
通过本源码可以了解到Java如何产生单钥加密的密钥(myKey)、产生双钥的密钥对(keyPair)、如何保存公钥的字节数组、保存私钥到文件privateKey.dat、如何用Java对象序列化保存私钥,通常应对私钥加密后再保存、如何从...
建立团结GitHub行动,建立Unity项目。 适用于Ubuntu,macOS和Windows。输入项unity-path Unity可执行文件的路径。 如果未提供,则将使用UNITY_PATH env。project-path Unity项目的路径。 用于查找Unity版本。 默认${...
java写qq源码 用 Python 完成 Android apk 的编译打包 Github地址: 吐槽 其实当我写完之后,发现并没有什么卵用233 我最一开始想的是每一次在 Github 上发现好玩的 Android 应用,都要下载下来,然后 Gradle build ...
说明 本案例使用Unity2019.3.8f1与AndropidStudio3.6.3 源码git地址:...然后在节点上添加一个脚本,脚本中的代码如下: using UnityEngine; using UnityEngine.UI; public class Test : MonoBe
Android 在屏幕旋转时,会销毁视图和 Activity 并重建,此时如何保存视图状态和已加载的数据、正在进行的网络请求即是问题。 Android 对部分视图状态提供了自动保存恢复,而豆芽对于其他需要保存的状态则通过自定义...
Android SDK 内容 概述 deltaDNA SDK 允许您的 Android 游戏记录游戏内事件并上传玩家操作。 它包含事件缓存、大量辅助方法和一些有助于简化集成的自动化行为。 添加到项目 deltaDNA SDK 可用于使用最低 SDK 版本 15...
java安卓仿微信聊天软件源码 原始博客站点: 镜像1: 镜像2: 我在开源社区上的贡献(PR) sqlx 是Rust语言一款数据库工具,我参与了sqlxMySQL相关文档的修正 Fix a misspelling in MySQL types document actix/...
java安卓仿微信聊天软件源码 原始博客站点: 镜像1: 镜像2: 我在开源社区上的贡献(PR) sqlx 是Rust语言一款数据库工具,我参与了sqlxMySQL相关文档的修正 Fix a misspelling in MySQL types document actix/...
填写online / plans.json并将其上传到某个地方(或将其推送到GitHub)。 填写app / app / src / main / res / values / config.xml。 使用Android Studio或“渐变构建”来构建应用。 去做 看一下
######原始代码的来源是从这里下载之后,放在android studio里面编译通过后,上传到github上给自己做个备份。 #####包含功能:######服务器部分: 由简单的php脚本组成 ######客户端部分: 登陆 注册 添加好友 赞成...
java网站源码真棒明星 我的 GitHub 星星的精选列表! 生成者 内容 动作脚本 - VVVVVV的源代码! 集会 - 用于命令和月球模块的原始阿波罗 11 号制导计算机 (AGC) 源代码。 awk —— :speech_balloon: 使用谷歌翻译、...
我的GitHub明星精选清单! 产生者 内容 [AGS脚本](#ags脚本) [Emacs Lisp](#emacs lisp) [Jupyter笔记本](#jupyter笔记本) [Vim脚本](#vim脚本) AGS脚本 -three.js的扩展系统 Arduino的 -计数使用过的Wh...
java安卓源码 简单的艺术是复杂的谜题。 安卓jitpack版 此版本是来自原始存储库的端口。 所做的更改: 应用了 Android Maven 部署配置文件更改 有些删除了一些引发 javadoc 生成器错误的 javadoc 生成器行(遵循原始...
下载librtmp源码,在GitHub上下载: 可以用git下载: git clone https://github.com/yixia/librtmp.git 编译librtmp脚本: #!/bin/bash NDK_ROOT=/root/ndk/android-ndk-r17c CPU=arm-linux-androideabi TOOLCHAIN...