aboutsummaryrefslogtreecommitdiff
path: root/tools/dependency_mapper/src
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dependency_mapper/src')
-rw-r--r--tools/dependency_mapper/src/com/android/dependencymapper/DependencyMapper.java8
-rw-r--r--tools/dependency_mapper/src/com/android/dependencymapper/JavaSourceAnalyzer.java23
-rw-r--r--tools/dependency_mapper/src/com/android/dependencymapper/Utils.java13
3 files changed, 31 insertions, 13 deletions
diff --git a/tools/dependency_mapper/src/com/android/dependencymapper/DependencyMapper.java b/tools/dependency_mapper/src/com/android/dependencymapper/DependencyMapper.java
index ecf520c7d8..bf476c17a5 100644
--- a/tools/dependency_mapper/src/com/android/dependencymapper/DependencyMapper.java
+++ b/tools/dependency_mapper/src/com/android/dependencymapper/DependencyMapper.java
@@ -127,15 +127,17 @@ public class DependencyMapper {
combinedClassDependencies.forEach((className, dependencies) -> {
String sourceFile = mClassToSourceMap.get(className);
if (sourceFile == null) {
- throw new IllegalArgumentException("Class '" + className
+ System.err.println("Class '" + className
+ "' does not have a corresponding source file.");
+ return;
}
mFileDependencies.computeIfAbsent(sourceFile, k -> new HashSet<>());
dependencies.forEach(dependency -> {
String dependencySource = mClassToSourceMap.get(dependency);
if (dependencySource == null) {
- throw new IllegalArgumentException("Dependency '" + dependency
+ System.err.println("Dependency '" + dependency
+ "' does not have a corresponding source file.");
+ return;
}
mFileDependencies.get(sourceFile).add(dependencySource);
});
@@ -145,7 +147,7 @@ public class DependencyMapper {
private void buildSourceToClassMap() {
mClassToSourceMap.forEach((className, sourceFile) ->
mSourceToClasses.computeIfAbsent(sourceFile, k ->
- new HashSet<>()).add(className));
+ new HashSet<>()).add(Utils.convertClassToFileBasedPath(className)));
}
private DependencyProto.FileDependencyList createFileDependencies() {
diff --git a/tools/dependency_mapper/src/com/android/dependencymapper/JavaSourceAnalyzer.java b/tools/dependency_mapper/src/com/android/dependencymapper/JavaSourceAnalyzer.java
index 3a4efadd77..4bb69a0790 100644
--- a/tools/dependency_mapper/src/com/android/dependencymapper/JavaSourceAnalyzer.java
+++ b/tools/dependency_mapper/src/com/android/dependencymapper/JavaSourceAnalyzer.java
@@ -19,7 +19,6 @@ import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@@ -33,19 +32,29 @@ public class JavaSourceAnalyzer {
// Regex that matches against "package abc.xyz.lmn;" declarations in a java file.
private static final String PACKAGE_REGEX = "^package\\s+([a-zA-Z_][a-zA-Z0-9_.]*);";
+ // Match either a single-quoted string, OR a sequence of non-whitespace characters.
+ private static final String FILE_PATH_REGEX = "'([^']*)'|(\\S+)";
public static List<JavaSourceData> analyze(Path srcRspFile) {
List<JavaSourceData> javaSourceDataList = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(srcRspFile.toFile()))) {
String line;
while ((line = reader.readLine()) != null) {
- // Split the line by spaces, tabs, multiple java files can be on a single line.
- String[] files = line.trim().split("\\s+");
+ List<String> files = new ArrayList<>();
+ Pattern pattern = Pattern.compile(FILE_PATH_REGEX);
+ Matcher matcher = pattern.matcher(line);
+ while (matcher.find()) {
+ if (matcher.group(1) != null) {
+ // Group 1: Single-quoted string (without the quotes)
+ files.add(matcher.group(1));
+ } else {
+ // Group 2: Non-whitespace sequence
+ files.add(matcher.group(2));
+ }
+ }
for (String file : files) {
- Path p = Paths.get("", file);
- System.out.println(p.toAbsolutePath().toString());
- javaSourceDataList
- .add(new JavaSourceData(file, constructPackagePrependedFileName(file)));
+ javaSourceDataList.add(new JavaSourceData(file,
+ constructPackagePrependedFileName(file)));
}
}
} catch (IOException e) {
diff --git a/tools/dependency_mapper/src/com/android/dependencymapper/Utils.java b/tools/dependency_mapper/src/com/android/dependencymapper/Utils.java
index 5dd5f35bb9..931f45a9c2 100644
--- a/tools/dependency_mapper/src/com/android/dependencymapper/Utils.java
+++ b/tools/dependency_mapper/src/com/android/dependencymapper/Utils.java
@@ -40,6 +40,11 @@ public class Utils {
return fileBasedPath.replaceAll("\\..*", "").replaceAll("/", ".");
}
+ public static String convertClassToFileBasedPath(String packageBasedClass) {
+ // Remove ".class" from the fileBasedPath, then replace "/" with "."
+ return packageBasedClass.replaceAll("\\.", "/") + ".class";
+ }
+
public static String buildPackagePrependedClassSource(String qualifiedClassPath,
String classSource) {
// Find the location of the start of classname in the qualifiedClassPath
@@ -52,8 +57,10 @@ public class Utils {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Map<String, Set<String>> jsonMap = new HashMap<>();
for (DependencyProto.FileDependency fileDependency : contents.getFileDependencyList()) {
- jsonMap.putIfAbsent(fileDependency.getFilePath(),
- Set.copyOf(fileDependency.getFileDependenciesList()));
+ jsonMap.putIfAbsent(fileDependency.getFilePath(), new HashSet<>(Set.copyOf(fileDependency.getFileDependenciesList())));
+ if (fileDependency.getIsDependencyToAll()) {
+ jsonMap.get(fileDependency.getFilePath()).add("isDepToAll");
+ }
}
String json = gson.toJson(jsonMap);
try (FileWriter file = new FileWriter(jsonOut.toFile())) {
@@ -67,7 +74,7 @@ public class Utils {
public static void writeContentsToProto(DependencyProto.FileDependencyList usages, Path protoOut) {
try {
OutputStream outputStream = Files.newOutputStream(protoOut);
- usages.writeDelimitedTo(outputStream);
+ usages.writeTo(outputStream);
} catch (IOException e) {
System.err.println("Error writing proto output to: " + protoOut);
throw new RuntimeException(e);