Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 3d94f71

Browse files
committed
changed API to Shark
1 parent 44cb152 commit 3d94f71

File tree

1 file changed

+33
-32
lines changed
  • ClassySharkWS/src/com/google/classyshark

1 file changed

+33
-32
lines changed

ClassySharkWS/src/com/google/classyshark/API.java renamed to ClassySharkWS/src/com/google/classyshark/Shark.java

+33-32
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,29 @@
2828
/**
2929
* The ClassyShark API usually used by build & continues integration toolchains
3030
*/
31-
public class API {
31+
public class Shark {
32+
33+
private File archiveFile;
34+
35+
private Shark(File archiveFile) {
36+
this.archiveFile = archiveFile;
37+
}
38+
39+
public static Shark with(File archiveFile) {
40+
return new Shark(archiveFile);
41+
}
3242

3343
/**
34-
*
35-
* @param archive jar/apk
3644
* @param className class name to generate such as "com.bumptech.glide.request.target.BaseTarget"
3745
* @return
3846
*/
39-
public static String getGeneratedClass(File archive, String className) {
47+
public String getGeneratedClass(String className) {
4048
String result;
41-
ContentReader loader = new ContentReader(archive);
49+
ContentReader loader = new ContentReader(archiveFile);
4250
loader.load();
4351

4452
Translator translator =
45-
TranslatorFactory.createTranslator(className, archive,
53+
TranslatorFactory.createTranslator(className, archiveFile,
4654
loader.getAllClassNames());
4755
try {
4856
translator.apply();
@@ -55,68 +63,61 @@ public static String getGeneratedClass(File archive, String className) {
5563
}
5664

5765
/**
58-
*
59-
* @param archive jar/apk
6066
* @return list of class names
6167
*/
62-
public static List<String> getAllClassNames(File archive) {
63-
ContentReader loader = new ContentReader(archive);
68+
public List<String> getAllClassNames() {
69+
ContentReader loader = new ContentReader(archiveFile);
6470
loader.load();
6571
return loader.getAllClassNames();
6672
}
6773

6874
/**
69-
*
70-
* @param apk apk
7175
* @return manifest
7276
*/
73-
public static String getManifest(File apk) {
74-
if (!apk.getName().endsWith(".apk")) {
77+
public String getManifest() {
78+
if (!archiveFile.getName().endsWith(".apk")) {
7579
return new String();
7680
}
7781
Translator translator =
78-
TranslatorFactory.createTranslator("AndroidManifest.xml", apk);
82+
TranslatorFactory.createTranslator("AndroidManifest.xml", archiveFile);
7983
translator.apply();
8084
return translator.toString();
8185
}
8286

8387
/**
84-
*
85-
* @param apk apk
8688
* @return all methods
8789
*/
88-
public static List<String> getAllMethods(File apk) {
89-
if (!apk.getName().endsWith(".apk")) {
90+
public List<String> getAllMethods() {
91+
if (!archiveFile.getName().endsWith(".apk")) {
9092
return new LinkedList<>();
9193
}
92-
List<String> allMethods = DexMethodsDumper.dumpMethods(apk);
94+
List<String> allMethods = DexMethodsDumper.dumpMethods(archiveFile);
9395
return allMethods;
9496
}
9597

9698
/**
97-
*
98-
* @param apk apk
9999
* @return all strings from all string tables
100100
*/
101-
public static List<String> getAllStrings(File apk) {
102-
if (!apk.getName().endsWith(".apk")) {
101+
public List<String> getAllStrings() {
102+
if (!archiveFile.getName().endsWith(".apk")) {
103103
return new LinkedList<>();
104104
}
105105

106-
List<String> allStrings = DexStringsDumper.dumpStrings(apk);
106+
List<String> allStrings = DexStringsDumper.dumpStrings(archiveFile);
107107
return allStrings;
108108
}
109109

110110
public static void main(String[] args) {
111111
File apk =
112-
new File( "/Users/bfarber/Desktop/Scenarios/4 APKs/"
112+
new File("/Users/bfarber/Desktop/Scenarios/4 APKs/"
113113
+ "com.google.samples.apps.iosched-333.apk");
114+
Shark shark = Shark.with(apk);
114115

115-
System.out.println(API.getGeneratedClass(apk,
116-
"com.bumptech.glide.request.target.BaseTarget"));
117-
System.out.println(API.getAllClassNames(apk));
118-
System.out.println(API.getManifest(apk));
119-
System.out.println(API.getAllMethods(apk));
120-
System.out.println(API.getAllStrings(apk));
116+
System.out.println(
117+
shark.getGeneratedClass("com.bumptech.glide.request.target.BaseTarget"));
118+
System.out.println(shark.getAllClassNames());
119+
System.out.println(shark.getManifest());
120+
System.out.println(shark.getAllMethods());
121+
System.out.println(shark.getAllStrings());
121122
}
122123
}

0 commit comments

Comments
 (0)