-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditFile.java
More file actions
83 lines (80 loc) · 2.61 KB
/
editFile.java
File metadata and controls
83 lines (80 loc) · 2.61 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
public class Test {
private static final String dir = "E:\\vstsworkspace\\project2009\\source\\server\\extension\\src\\";
private static final HashMap<String, String> file_package = new HashMap<>();
static{
try {
try(BufferedReader br = new BufferedReader(new FileReader("files.txt"))){
String line;
while ((line = br.readLine()) != null) {
int lastdot = line.lastIndexOf(".");
String packageName = line.substring(0, lastdot);
String className = line.substring(lastdot + 1, line.length());
file_package.put(className + ".java", packageName);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
static int anInt = 1;
public static void main(String[] args) {
System.out.println(file_package);
File f = new File(dir);
updateFile(f);
}
static void updateFile(File f) {
if (f.isDirectory()) {
for (File sf : f.listFiles()) {
updateFile(sf);
}
} else {
// System.out.println(f.getName());
if (file_package.containsKey(f.getName())) {
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
String line;
StringBuilder stringBuilder = new StringBuilder();
boolean imported = false;
while ((line = br.readLine()) != null) {
int index = line.indexOf("package");
if (index >= 0) {
String packagename = line.substring(index + 7, line.indexOf(";")).trim();
if(!file_package.get(f.getName()).equals(packagename)){
// System.out.println(file_package.get(f.getName()));
return;
}
System.out.println(String.valueOf(anInt++) + ". " + f.getName() + "=" + packagename);
}
if (line.startsWith("import") && !imported) {
stringBuilder.append("import com.altratek.altraserver.extensions.annotation.BeginDate;\r\n");
imported = true;
}
index = line.indexOf("extends HolidayResponder");
if (index >= 0) {
stringBuilder.append("@BeginDate(\"2000-01-01\")\r\n");
}
stringBuilder.append(line).append("\r\n");
}
RandomAccessFile randomAccessFile = new RandomAccessFile(f, "rw");
randomAccessFile.write(stringBuilder.toString().getBytes(StandardCharsets.UTF_8));
randomAccessFile.close();
} catch (Throwable t) {
t.printStackTrace();
System.exit(0);
return;
}
}
}
}
}