Skip to content

Commit ea71161

Browse files
committed
refactor: Rename classes
Use more understandable names.
1 parent 0b86d91 commit ea71161

File tree

3 files changed

+134
-134
lines changed

3 files changed

+134
-134
lines changed

src/Blobber.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

src/Main.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
MissingBlobs b = new MissingBlobs();
4+
5+
// Add each path to search for blobs
6+
for (String arg : args) {
7+
b.addBlobDir(arg);
8+
}
9+
10+
b.updateMissingBlobs();
11+
b.showMissingBlobs();
12+
13+
System.out.println();
14+
System.out.println("Done.");
15+
}
16+
}

src/MissingBlobs.java

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,125 @@
1+
import java.io.BufferedReader;
2+
import java.io.File;
3+
import java.io.InputStreamReader;
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
18
public class MissingBlobs {
2-
public static void main(String[] args) {
3-
Blobber b = new Blobber();
49

5-
// Add each path to search for blobs
6-
for (String arg : args) {
7-
b.addBlobDir(arg);
10+
/*
11+
* Key: Name of the blob
12+
* Value: Reference to the Blob
13+
*/
14+
private HashMap<String, Blob> presentBlobs;
15+
16+
/*
17+
* Key: Name of blob dependency
18+
* Value: Other blobs that depend on this blob
19+
*/
20+
private HashMap<String, ArrayList<Blob>> dependencyBlobs;
21+
22+
/*
23+
* Key: Name of missing blob dependency
24+
* Value: Null (unused)
25+
*/
26+
private HashMap<String, String> missingBlobs;
27+
28+
private String expandArrayList(ArrayList<Blob> arr) {
29+
StringBuilder expanded = new StringBuilder();
30+
31+
for (Blob blob : arr) {
32+
expanded.append(blob.getName() + "; ");
833
}
934

10-
b.updateMissingBlobs();
11-
b.showMissingBlobs();
35+
return expanded.toString();
36+
}
37+
38+
private ArrayList<String> listDependencies(Blob blob) {
39+
ArrayList<String> dependencies = new ArrayList<String>();
40+
41+
/*
42+
* List blob dependencies using ldd-arm:
43+
* readelf -d $1 | grep "\(NEEDED\)" | sed -r "s/.*\[(.*)\]/\1/"
44+
*/
45+
try {
46+
ProcessBuilder pb = new ProcessBuilder();
47+
pb.command("bash", "-c", "readelf -d " + blob.getFile().getAbsolutePath()
48+
+ " | grep \"\\(NEEDED\\)\" | sed -r \"s/.*\\[(.*)\\]/\\1/\"");
49+
50+
final Process p = pb.start();
51+
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
1252

13-
System.out.println();
14-
System.out.println("Done.");
53+
String dependency;
54+
while ((dependency = br.readLine()) != null) {
55+
dependencies.add(dependency);
56+
}
57+
} catch (Exception ex) {
58+
System.out.println(ex);
59+
}
60+
61+
return dependencies;
62+
}
63+
64+
public MissingBlobs() {
65+
presentBlobs = new HashMap<String, Blob>();
66+
dependencyBlobs = new HashMap<String, ArrayList<Blob>>();
67+
}
68+
69+
public void addBlobDir(String blobPath) {
70+
File blobDir = new File(blobPath);
71+
72+
if (!blobDir.isDirectory()) {
73+
System.out.println("Path is not a directory!");
74+
return;
75+
}
76+
77+
for (File blobFile : blobDir.listFiles()) {
78+
if (!blobFile.isFile())
79+
continue;
80+
81+
Blob blob = new Blob(blobFile);
82+
presentBlobs.put(blob.getName(), blob);
83+
84+
ArrayList<String> dependencies = listDependencies(blob);
85+
86+
for (String dep : dependencies) {
87+
// Assumes all dependencies are *.so files
88+
if (!dep.endsWith(".so"))
89+
continue;
90+
91+
ArrayList<Blob> ar;
92+
93+
// Add or update dependencyBlobs
94+
if (!dependencyBlobs.containsKey(dep)) {
95+
ar = new ArrayList<Blob>();
96+
ar.add(blob);
97+
dependencyBlobs.put(dep, ar);
98+
} else {
99+
dependencyBlobs.get(dep).add(blob);
100+
}
101+
}
102+
}
103+
}
104+
105+
public void updateMissingBlobs() {
106+
missingBlobs = new HashMap<String, String>();
107+
108+
for (Map.Entry<String, ArrayList<Blob>> blob : dependencyBlobs.entrySet()) {
109+
String dependencyName = blob.getKey();
110+
111+
if (missingBlobs.containsKey(dependencyName) || presentBlobs.containsKey(dependencyName))
112+
continue;
113+
114+
missingBlobs.put(dependencyName, null);
115+
}
116+
}
117+
118+
public void showMissingBlobs() {
119+
for (Map.Entry<String, String> blob : missingBlobs.entrySet()) {
120+
String dependencyName = blob.getKey();
121+
ArrayList<Blob> blobsWithDependencies = dependencyBlobs.get(dependencyName);
122+
System.out.println(dependencyName + " required by: " + expandArrayList(blobsWithDependencies));
123+
}
15124
}
16125
}

0 commit comments

Comments
 (0)