Skip to content

Commit 17c2795

Browse files
committed
v0.1
1 parent 2cdd932 commit 17c2795

File tree

10 files changed

+236
-109
lines changed

10 files changed

+236
-109
lines changed

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
1-
repo under construction, sorry
2-
3-
# AndroidObfuscatorPlugin
1+
# String Care Android Plugin
42

53
Gradle implementation
64
------------
75

86
root_project/build.gradle
97
```groovy
10-
apply plugin: com.efraespada.stringobfuscatorplugin.StringObfuscatorPlugin
8+
// root_project/build.gradle
9+
10+
apply plugin: com.stringcare.SCPlugin
1111
1212
buildscript {
13+
14+
ext {
15+
stringcare_version = '0.1'
16+
}
17+
1318
repositories {
14-
mavenLocal()
19+
jcenter()
1520
}
21+
1622
dependencies {
17-
// ...
18-
classpath files('../AndroidLibrary/build/libs/stringobfuscatorplugin-1.0-SNAPSHOT.jar')
19-
// ...
23+
classpath "com.stringcare:plugin:$stringcare_version"
2024
}
25+
2126
}
2227
28+
stringcare {
29+
30+
modules {
31+
32+
sample {
33+
stringFiles = ['strings.xml',"other_file.xml"]
34+
srcFolders = ['src/main', "other_folder"]
35+
}
36+
37+
// root_folder/sample/src/main/res/.../strings.xml
38+
// root_folder/sample/src/main/res/.../other_file.xml
39+
// root_folder/sample/other_folder/res/.../strings.xml
40+
// root_folder/sample/other_folder/res/.../other_file.xml
41+
42+
other_module {
43+
srcFolders = ['src/moduleB']
44+
}
45+
46+
// root_folder/other_module/src/moduleB/res/.../strings.xml
47+
48+
other_module_ {} //
49+
50+
// root_folder/other_module_/src/main/res/.../strings.xml
51+
52+
}
53+
54+
}
2355
```

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ apply plugin: 'idea'
2020
apply plugin: 'java'
2121
apply plugin: 'com.jfrog.bintray'
2222

23-
group 'com.efraespada'
23+
group 'com.stringcare'
2424
version '0.1'
2525

2626

@@ -41,7 +41,7 @@ install {
4141
pom {
4242
project {
4343
packaging 'aar'
44-
name 'SAndroid'
44+
name 'StringCareAndroidPlugin'
4545
url siteUrl
4646
// Set your license
4747
licenses {
@@ -75,7 +75,7 @@ bintray {
7575
configurations = ['archives']
7676
pkg {
7777
repo = "maven"
78-
name = "stringcare:plugin"
78+
name = "StringCareAndroidPlugin"
7979
websiteUrl = siteUrl
8080
vcsUrl = gitUrl
8181
licenses = ["Apache-2.0"]

src/main/java/com/efraespada/stringobfuscatorplugin/AES.java renamed to src/main/groovy/com/stringcare/AES.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.efraespada.stringobfuscatorplugin;
1+
package com.stringcare;
22

33
import javax.crypto.Cipher;
44
import javax.crypto.IllegalBlockSizeException;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.stringcare;
2+
3+
import java.util.List;
4+
5+
public class Config {
6+
7+
List<String> stringFiles;
8+
List<String> srcFolders;
9+
10+
Config() {
11+
// nothing to do here
12+
}
13+
14+
List<String> getStringFiles() {
15+
return stringFiles;
16+
}
17+
18+
void setStringFiles(List<String> stringFiles) {
19+
this.stringFiles = stringFiles;
20+
}
21+
22+
List<String> getSrcFolders() {
23+
return srcFolders;
24+
}
25+
26+
void setSrcFolders(List<String> srcFolders) {
27+
this.srcFolders = srcFolders;
28+
}
29+
30+
}

src/main/java/com/efraespada/stringobfuscatorplugin/CredentialUtils.java renamed to src/main/groovy/com/stringcare/CredentialUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package com.efraespada.stringobfuscatorplugin;
1+
package com.stringcare;
22

33
import java.io.BufferedReader;
44
import java.io.IOException;
55
import java.io.InputStream;
66
import java.io.InputStreamReader;
77

8-
import static com.efraespada.stringobfuscatorplugin.PrintUtils.print;
8+
import static com.stringcare.PrintUtils.print;
99

1010
public class CredentialUtils {
1111

src/main/java/com/efraespada/stringobfuscatorplugin/FileUtils.java renamed to src/main/groovy/com/stringcare/FileUtils.java

Lines changed: 79 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
package com.efraespada.stringobfuscatorplugin;
1+
package com.stringcare;
22

33
import java.io.*;
4-
import java.nio.channels.FileChannel;
5-
import java.nio.file.Files;
6-
import java.util.HashMap;
7-
import java.util.Map;
84

9-
import static com.efraespada.stringobfuscatorplugin.PrintUtils.print;
5+
import static com.stringcare.PrintUtils.print;
106

117
public class FileUtils {
128

13-
private static String variant;
149
private static String module;
1510
private static String key;
11+
private static Config config;
1612

1713
final static int maxToShow = 15;
1814

19-
20-
private static final Map<String, String> files = new HashMap<>();
21-
2215
private FileUtils() {
2316
// nothing to do here
2417
}
2518

26-
public static void init(String key, String module, String variant) {
27-
files.clear();
19+
public static void init(String key, String module, String variant, Config config) {
2820
FileUtils.key = key;
2921
FileUtils.module = module;
30-
FileUtils.variant = variant;
22+
FileUtils.config = config;
3123
}
3224

3325
public static String getTextFromFilePath(String path) {
@@ -37,8 +29,6 @@ public static String getTextFromFilePath(String path) {
3729
String xml = "";
3830
String inputFilePath = path;
3931

40-
if (true) print("reading " + inputFilePath);
41-
4232
String message = "";
4333

4434
File file = new File(inputFilePath);
@@ -83,41 +73,58 @@ public static String getString(BufferedReader br) {
8373
// detect multiple sourceSet res.srcDirs
8474
public static void backupStringResources() {
8575
String currentPath = getCurrentPath();
86-
currentPath += module + File.separator + "src" + File.separator + "main" + File.separator + "res" + File.separator;
87-
File file = new File(currentPath);
88-
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
89-
for (String dir : directories) {
90-
String pathToCopy = currentPath + dir + File.separator;
91-
String pathToCheck = getCurrentPath() + module + File.separator + "resbackup" + File.separator + dir + File.separator;
92-
93-
try {
94-
File toCopy = new File(pathToCopy + "strings.xml");
95-
File toCheck = new File(pathToCheck + "strings.xml");
96-
if (toCheck.exists()) {
97-
toCheck.delete();
98-
}
99-
if (toCopy.exists()) {
100-
copyFile(toCopy, toCheck);
76+
for (String folder : config.getSrcFolders()) {
77+
currentPath += module + File.separator + folder + File.separator + "res" + File.separator;
78+
File file = new File(currentPath);
79+
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
80+
if (directories != null) {
81+
for (String dir : directories) {
82+
String pathToCopy = currentPath + dir + File.separator;
83+
String pathToCheck = getCurrentPath() + module + File.separator + "resbackup" + File.separator + dir + File.separator;
84+
85+
for (String sFile : config.getStringFiles()) {
86+
try {
87+
File toCopy = new File(pathToCopy + sFile);
88+
File toCheck = new File(pathToCheck + sFile);
89+
if (toCheck.exists()) {
90+
toCheck.delete();
91+
}
92+
if (toCopy.exists()) {
93+
print("- " + toCopy.getParentFile().getName() + File.separator + toCopy.getName(), true);
94+
copyFile(toCopy, toCheck);
95+
}
96+
} catch (IOException e) {
97+
e.printStackTrace();
98+
// TODO HANDLE ERROR
99+
}
100+
}
101101
}
102-
} catch (IOException e) {
103-
e.printStackTrace();
104-
// TODO HANDLE ERROR
102+
} else {
103+
PrintUtils.print("source folder not found: " + folder, true);
105104
}
106105
}
107106
}
108107

109108
public static void encryptStringResources() {
110109
String currentPath = getCurrentPath();
111-
currentPath += module + File.separator + "src" + File.separator + "main" + File.separator + "res" + File.separator;
112-
File file = new File(currentPath);
113-
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
114-
for (String dir : directories) {
115-
String pathToEncrypt = currentPath + dir + File.separator;
116-
117-
File toEncrypt = new File(pathToEncrypt + "strings.xml");
118-
if (toEncrypt.exists()) {
119-
String encrypted = find(getTextFromFilePath(toEncrypt.getAbsolutePath()));
120-
writeFile(toEncrypt, encrypted);
110+
for (String folder : config.getSrcFolders()) {
111+
currentPath += module + File.separator + folder + File.separator + "res" + File.separator;
112+
File file = new File(currentPath);
113+
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
114+
if (directories != null) {
115+
for (String dir : directories) {
116+
String pathToEncrypt = currentPath + dir + File.separator;
117+
for (String sFile : config.getStringFiles()) {
118+
File toEncrypt = new File(pathToEncrypt + sFile);
119+
if (toEncrypt.exists()) {
120+
PrintUtils.print("- " + toEncrypt.getParentFile().getName() + File.separator + toEncrypt.getName(), true);
121+
String encrypted = find(getTextFromFilePath(toEncrypt.getAbsolutePath()));
122+
writeFile(toEncrypt, encrypted);
123+
}
124+
}
125+
}
126+
} else {
127+
PrintUtils.print("source folder not found: " + folder, true);
121128
}
122129
}
123130
}
@@ -126,23 +133,35 @@ public static void restoreStringResources() {
126133
String currentPath = getCurrentPath() + module + File.separator + "resbackup" + File.separator;
127134
File file = new File(currentPath);
128135
String[] directories = file.list((current, name) -> new File(current, name).isDirectory());
129-
for (String dir : directories) {
130-
String pathToEncrypt = currentPath + dir + File.separator;
131-
String pathRes = getCurrentPath() + module + File.separator + "src" + File.separator + "main" + File.separator + "res" + File.separator + dir + File.separator;
132-
133-
File toRestore = new File(pathToEncrypt + "strings.xml");
134-
File toCheck = new File(pathRes + "strings.xml");
135-
136-
try {
137-
copyFile(toRestore, toCheck);
138-
} catch (IOException e) {
139-
e.printStackTrace();
136+
if (directories != null) {
137+
File toRestore;
138+
for (String dir : directories) {
139+
String pathToRestore = currentPath + dir + File.separator;
140+
for (String folder : config.getSrcFolders()) {
141+
String pathRes = getCurrentPath() + module + File.separator + folder + File.separator + "res" + File.separator + dir + File.separator;
142+
143+
for (String sFile : config.getStringFiles()) {
144+
toRestore = new File(pathToRestore + sFile);
145+
File toCheck = new File(pathRes + sFile);
146+
if (toRestore.exists()) {
147+
try {
148+
PrintUtils.print("- " + toCheck.getParentFile().getName() + File.separator + toCheck.getName(), true);
149+
copyFile(toRestore, toCheck);
150+
} catch (IOException e) {
151+
e.printStackTrace();
152+
}
153+
154+
toRestore.delete();
155+
toRestore.getParentFile().delete();
156+
}
157+
}
158+
}
140159
}
141-
142-
toRestore.delete();
143-
}
144-
if (file.isDirectory()) {
145-
file.delete();
160+
if (file.isDirectory()) {
161+
file.delete();
162+
}
163+
} else {
164+
PrintUtils.print("restore folder not found");
146165
}
147166
}
148167

@@ -192,7 +211,7 @@ public static String find(String xmlO) {
192211

193212
toShow = toShow.length() > maxToShow ? toShow.substring(0, maxToShow) + ".." : toShow;
194213
encrypted = encrypted.length() > maxToShow ? encrypted.substring(0, maxToShow) + ".." : encrypted;
195-
print("[" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : ""));
214+
print("\t[" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : ""), true);
196215
} catch (Exception e) {
197216
print("error on " + result);
198217
e.printStackTrace();
@@ -204,8 +223,6 @@ public static String find(String xmlO) {
204223
if (xml1.indexOf(toFind1) <= 0) break;
205224
}
206225

207-
print(content);
208-
209226
return content;
210227
}
211228

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.efraespada.stringobfuscatorplugin.interfaces;
1+
package com.stringcare;
22

33
public interface GradleHandlerCallback {
44

src/main/java/com/efraespada/stringobfuscatorplugin/PrintUtils.java renamed to src/main/groovy/com/stringcare/PrintUtils.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
package com.efraespada.stringobfuscatorplugin;
1+
package com.stringcare;
22

33
public class PrintUtils {
44

5-
private final static String TAG = "stringobfuscatorplugin";
65
private static String variant;
76
private static String module;
87

@@ -20,8 +19,15 @@ public static void init(String module, String variant) {
2019
* @param message
2120
*/
2221
public static void print(String message) {
22+
print(message, false);
23+
}
24+
public static void print(String message, boolean tab) {
2325
if (variant != null && module != null) {
24-
System.out.println(":" + module + ":" + TAG + " - " + message);
26+
if (!tab) {
27+
System.out.println(":" + module + ":" + message);
28+
} else {
29+
System.out.println("\t" + message);
30+
}
2531
} else {
2632
System.out.println(message);
2733
}

0 commit comments

Comments
 (0)