-
Notifications
You must be signed in to change notification settings - Fork 23
/
GitHubCrawl.java
58 lines (39 loc) · 1.45 KB
/
GitHubCrawl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package dev.nipafx.lab.loom.crawl;
import dev.nipafx.lab.loom.crawl.crawler.PageTreeFactory;
import dev.nipafx.lab.loom.crawl.operations.Pretty;
import dev.nipafx.lab.loom.crawl.operations.Statistician;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
public class GitHubCrawl {
/**
* @param args 0: path to GitHub issue or PR page
* 1: depth of tree that will be built
*/
public static void main(String[] args) throws Exception {
var config = Configuration.parse(args);
System.out.println("For maximum effect, run this command while the app is resolving a bunch of links:");
System.out.printf("jcmd %s Thread.dump_to_file -format=json threads.json%n", ProcessHandle.current().pid());
var client = HttpClient.newHttpClient();
var factory = new PageTreeFactory(client);
var rootPage = factory.createPage(config.seedUrl(), config.depth());
System.out.println(STR."""
---
\{Statistician.evaluate(rootPage)}
---
\{Pretty.printPageList(rootPage)}
---
\{Pretty.printPageTree(rootPage)}
---
""");
}
private record Configuration(URI seedUrl, int depth) {
static Configuration parse(String[] args) throws URISyntaxException {
if (args.length < 2)
throw new IllegalArgumentException("Please specify the seed URL and depth.");
var seedUrl = new URI(args[0]);
var depth = Integer.parseInt(args[1]);
return new Configuration(seedUrl, depth);
}
}
}