idegen: Handle symbolic link that targets to current or parent directory
Test: run idegen.sh to generate files for IntelliJ without error Signed-off-by: utzcoz <utzcoz@gmail.com> Change-Id: I80958e94f93a8e1ef546bc34bd929d04a224dc9e
This commit is contained in:
@@ -18,6 +18,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -153,6 +155,17 @@ public class Configuration {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Files.isSymbolicLink(file.toPath())) {
|
||||
Path target = Files.readSymbolicLink(file.toPath()).normalize();
|
||||
if (target.startsWith("") || target.startsWith(".")
|
||||
|| target.startsWith("..")) {
|
||||
// Don't recurse symbolic link that targets to parent
|
||||
// or current directory.
|
||||
Log.debug("Skipped: " + path);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (file.isDirectory()) {
|
||||
// Traverse nested directories.
|
||||
if (excludes.exclude(path)) {
|
||||
@@ -216,8 +229,7 @@ public class Configuration {
|
||||
* found.
|
||||
*/
|
||||
private static String parsePackageName(File file) throws IOException {
|
||||
BufferedReader in = new BufferedReader(new FileReader(file));
|
||||
try {
|
||||
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
String trimmed = line.trim();
|
||||
@@ -230,8 +242,6 @@ public class Configuration {
|
||||
}
|
||||
|
||||
return null;
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user