Created
September 15, 2011 00:23
-
-
Save kevinsawicki/1218202 to your computer and use it in GitHub Desktop.
Print out Eclipse Git repositories that are not mirrored on GitHub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import java.util.Collection; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.eclipse.egit.github.core.Repository; | |
import org.eclipse.egit.github.core.service.RepositoryService; | |
/** | |
* Compare Eclipse Git repositories to current GitHub mirrors | |
*/ | |
public class EclipseMirrors { | |
/** | |
* Log message to standard out | |
* | |
* @param message | |
*/ | |
public static void log(String message) { | |
System.out.println(message); | |
} | |
/** | |
* Get Eclipse Git repositories | |
* | |
* @return map of URLs to repositories | |
* @throws IOException | |
*/ | |
public static Map<String, Repository> getEclipseRepos() throws IOException { | |
Map<String, Repository> repos = new HashMap<String, Repository>(); | |
// Read list of Eclipse Git repositories | |
BufferedReader reader = null; | |
try { | |
reader = new BufferedReader(new InputStreamReader(new URL( | |
"http://eclipse.org/projects/git-repos.php") | |
.openConnection().getInputStream())); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
String[] segments = line.trim().split("\t"); | |
if (segments.length == 3) { | |
String url = segments[0].trim(); | |
if (url.length() == 0) { | |
log("Empty URL in line: " + line); | |
continue; | |
} | |
if (!url.endsWith(".git")) | |
log("URL does not end with .git suffix: " + line); | |
String name = segments[1].trim(); | |
if (name.length() == 0) { | |
log("Empty name in line: " + line); | |
continue; | |
} | |
String description = segments[2].trim(); | |
if (description.length() == 0) { | |
log("Empty description in line: " + line); | |
continue; | |
} | |
Repository repo = new Repository(); | |
repo.setName(name); | |
repo.setDescription(description); | |
repo.setUrl(url); | |
repos.put(url, repo); | |
} else | |
log("Malformed line: " + line); | |
} | |
} finally { | |
try { | |
reader.close(); | |
} catch (IOException ignored) { | |
// Ignored | |
} | |
} | |
return repos; | |
} | |
/** | |
* Remove repository URLs that are already mirrored on GitHub | |
* | |
* @param repos | |
* @throws IOException | |
*/ | |
public static void removeMirrored(Map<String, Repository> repos) | |
throws IOException { | |
// Remove existing mirrors by URL comparison | |
RepositoryService service = new RepositoryService(); | |
for (Collection<Repository> page : service | |
.pageOrgRepositories("eclipse")) { | |
for (Repository current : page) { | |
String mirrorUrl = service.getRepository("eclipse", | |
current.getName()).getMirrorUrl(); | |
if (mirrorUrl != null) | |
repos.remove(mirrorUrl.trim()); | |
} | |
} | |
} | |
/** | |
* Print out what Eclipse Git repositories are not mirrored in GitHub | |
* | |
* @param args | |
* @throws IOException | |
*/ | |
public static void main(String... args) throws IOException { | |
Map<String, Repository> repos = getEclipseRepos(); | |
removeMirrored(repos); | |
// Print out Eclipse Git repositories that are not mirrored | |
log("Repositories not mirrored: " + repos.size()); | |
log(""); | |
for (Repository repo : repos.values()) { | |
log(repo.getName()); | |
log(repo.getDescription()); | |
log(repo.getUrl()); | |
log(""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment