Skip to content

Commit 0e0d313

Browse files
committed
2 parents 2b376b9 + 6bd7101 commit 0e0d313

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

lib/utils/DiffUtil.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ public static int getChangedLineCount(String diffStr, String mode) {
5353
return count;
5454
}
5555

56-
public static List<Integer> getChangedLineNumListInNewVersion(String diffFilePath) {
57-
56+
public static List<Integer> getChangedLineNumListInNewVersion(String diffStr) {
5857
List<Integer> changedLineNumList = new ArrayList<>();
5958
try {
60-
List<String> diffFileStrList = FileUtil.readFileToLineList(diffFilePath);
61-
for (String line : diffFileStrList) {
59+
for (String line : diffStr.split("\n")) {
6260
if (line.startsWith("@@")) {
6361
for (String tmp : line.split(" ")) {
6462
if (tmp.trim().startsWith("+")) {
@@ -73,7 +71,6 @@ public static List<Integer> getChangedLineNumListInNewVersion(String diffFilePat
7371
}
7472
} catch (Exception e) {
7573
// TODO: handle exception
76-
System.out.println(diffFilePath);
7774
e.printStackTrace();
7875
}
7976
return changedLineNumList;

lib/utils/FileUtil.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,20 @@ public static Boolean copyFile2File(File srcFile, File dstFile) {
155155
return true;
156156
}
157157

158-
public static boolean deleteDirectory(String dirPath) {
159-
File directoryToBeDeleted = new File(dirPath);
158+
public static boolean deleteDirectory(Path dirPath) {
159+
File directoryToBeDeleted = dirPath.toFile();
160160
File[] allContents = directoryToBeDeleted.listFiles();
161161
if (allContents != null) {
162162
for (File file : allContents) {
163-
deleteDirectory(file.getAbsolutePath());
163+
deleteDirectory(file.toPath());
164164
}
165165
}
166166
return directoryToBeDeleted.delete();
167167
}
168168

169-
public static void copyDirectory(String srcDirStr, String destDirStr) {
170-
File source = new File(srcDirStr);
171-
File dest = new File(destDirStr);
169+
public static void copyDirectory(Path srcDirPath, Path destDirPath) {
170+
File source = srcDirPath.toFile();
171+
File dest = destDirPath.toFile();
172172
try {
173173
FileUtils.copyDirectory(source, dest);
174174
} catch (IOException e) {
@@ -263,7 +263,7 @@ public static List<String> readFileToLineList(String filePath) {
263263
public static void createFolder(String dirStr, Boolean deleteIfExist) {
264264
File dir = new File(dirStr);
265265
if (deleteIfExist && dir.exists()) {
266-
deleteDirectory(dir.getAbsolutePath());
266+
deleteDirectory(dir.toPath());
267267
dir.mkdirs();
268268
} else if (!dir.exists()) {
269269
dir.mkdirs();
@@ -280,11 +280,11 @@ public static boolean deleteDirectory(File directoryToBeDeleted) {
280280
return directoryToBeDeleted.delete();
281281
}
282282

283-
public static List<File> findFilePathofSpecifcTypeRecusive(String tarDir, String extension) {
283+
public static List<File> findFilePathofSpecifcTypeRecusive(Path tarDir, String extension) {
284284

285285
List<File> fileList = new ArrayList<File>();
286286
try {
287-
Files.walk(Paths.get(tarDir)).filter(Files::isRegularFile).forEach((f) -> {
287+
Files.walk(tarDir).filter(Files::isRegularFile).forEach((f) -> {
288288
String filepath = f.toString();
289289
if (filepath.endsWith(extension))
290290
// System.out.println(file + " found!");

lib/utils/GitUtil.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static Boolean clone(String repoName, String usrName, Path targetDir) {
1414
}
1515
targetDir.toFile().mkdirs();
1616

17-
String cmd = "timeout 300 git clone https://github.com/" + repoName + "/" + usrName + " " + targetDir;
17+
String cmd = "timeout 600 git clone https://github.com/" + repoName + "/" + usrName + " " + targetDir;
1818

1919
ProcessUtil.ProcessReporter pr = ProcessUtil.executeCMD(cmd, null, targetDir, 0);
2020
if (pr.exitCode == 0) {
@@ -166,13 +166,18 @@ public static Boolean checkout(Path repoDir, String com, Boolean ifForce) {
166166
ProcessUtil.ProcessReporter pr = new ProcessUtil.ProcessReporter();
167167

168168
if (ifForce) {
169-
String resetCMD = "timeout 300 git reset --hard";
169+
String resetCMD = "timeout 600 git reset --hard";
170170
pr = ProcessUtil.executeCMD(resetCMD, null, repoDir, 0);
171171
}
172172

173+
String defaultBranchNameString = getDefaultBranch(repoDir);
174+
if (defaultBranchNameString == null || defaultBranchNameString == "") {
175+
defaultBranchNameString = "master";
176+
}
177+
173178
String checkoutCMD = null;
174179
if (com == null) { // checkout latest if null
175-
checkoutCMD = "timeout 300 git checkout master";
180+
checkoutCMD = "timeout 300 git checkout " + defaultBranchNameString;
176181
} else {
177182
checkoutCMD = "timeout 300 git checkout " + com;
178183
}
@@ -207,4 +212,13 @@ public static Boolean checkout(Path repoDir, String com, Boolean ifForce) {
207212
}
208213
}
209214

215+
private static String getDefaultBranch(Path gitDirPath) {
216+
// TODO Auto-generated method stub
217+
String cmdString = "git symbolic-ref refs/remotes/origin/HEAD";
218+
ProcessUtil.ProcessReporter pr = ProcessUtil.executeCMD(cmdString, null, gitDirPath, 0);
219+
// output refs/remotes/origin/master
220+
return pr.out.trim().split("refs/remotes/origin/")[1].trim();
221+
222+
}
223+
210224
}

lib/utils/SRCUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ public static void changePackage(String oriSRCPath, String dstSRCPath, String ne
2121
FileUtil.writeStringToFile(dstSRCPath, wrtStr);
2222

2323
}
24+
25+
26+
public static void changePackage(String srcPath, String newPackName) {
27+
List<String> srcStrList = FileUtil.readFileToLineList(srcPath);
28+
29+
Boolean ifchanged = false;
30+
String wrtStr = "";
31+
for (int i = 0; i < srcStrList.size(); i++) {
32+
String line = srcStrList.get(i);
33+
if (line.trim().startsWith("package ") && !ifchanged) {
34+
line = "package " + newPackName + ";";
35+
ifchanged = true;
36+
}
37+
wrtStr += (line + "\n");
38+
}
39+
40+
FileUtil.writeStringToFile(srcPath, wrtStr);
41+
42+
}
2443

2544
public static void main(String[] args) {
2645
/*

0 commit comments

Comments
 (0)