in src/main/java/com/uber/scip/aggregator/ConfigLoader.java [24:100]
public static FileAnalyzer loadFromFile(String configFilePath, @Nullable String rootDir)
throws IOException {
Properties properties = new Properties();
try (FileInputStream fis = new FileInputStream(configFilePath)) {
properties.load(fis);
}
FileAnalyzer aggregator = new FileAnalyzer();
// Load classpath
String classpath = properties.getProperty("classpath");
if (classpath != null && !classpath.isEmpty()) {
// Qualify classpath with rootDir if it's a relative path
String qualifiedClasspath =
String.join(":", qualifyPaths(Arrays.asList(classpath.split(":")), rootDir));
aggregator.withClasspath(qualifiedClasspath);
}
// Load compiler options
String options = properties.getProperty("options");
if (options != null && !options.isEmpty()) {
aggregator.withOptions(Arrays.asList(options.split(",")));
}
// Load SemanticDB source root
String sourceRoot = properties.getProperty("semanticdb.sourceRoot");
if (sourceRoot != null && !sourceRoot.isEmpty()) {
// Qualify source root with rootDir if it's a relative path
String qualifiedSourceRoot = qualifyPath(sourceRoot.trim(), rootDir);
aggregator.withSemanticDbSourceRoot(qualifiedSourceRoot);
}
// Load SemanticDB target root
String targetRoot = properties.getProperty("semanticdb.targetRoot");
if (targetRoot != null && !targetRoot.isEmpty()) {
// Qualify target root with rootDir if it's a relative path
String qualifiedTargetRoot = qualifyPath(targetRoot, rootDir);
aggregator.withSemanticDbTargetRoot(qualifiedTargetRoot);
}
// Load SemanticDB target root
String semanticdbPlugin = properties.getProperty("semanticdb_plugin");
if (semanticdbPlugin != null && !semanticdbPlugin.isEmpty()) {
// Qualify semanticdb plugin path with rootDir if it's a relative path
String qualifiedSemanticdbPlugin = qualifyPath(semanticdbPlugin, rootDir);
aggregator.withSemanticDbPlugin(qualifiedSemanticdbPlugin);
}
// Load files to analyze
String files = properties.getProperty("files");
if (files != null && !files.isEmpty()) {
List<String> filesList = Arrays.asList(files.split(","));
// Qualify file paths with rootDir if they're relative paths
List<String> qualifiedFiles = qualifyPaths(filesList, rootDir);
aggregator.withFiles(qualifiedFiles);
}
// Ability to load files from a file
String listOfFiles = properties.getProperty("files_file");
if (listOfFiles != null && !listOfFiles.isEmpty()) {
// Qualify the files_file path with rootDir if it's a relative path
List<String> paths = Files.readAllLines(Paths.get(qualifyPath(listOfFiles, rootDir)));
// Qualify file paths with rootDir if they're relative paths
List<String> qualifiedPaths = qualifyPaths(paths, rootDir);
aggregator.withFiles(qualifiedPaths);
}
// Load files to analyze
String output = properties.getProperty("output");
if (output != null && !output.isEmpty()) {
// Qualify output path with rootDir if it's a relative path
String qualifiedOutput = qualifyPath(output, rootDir);
aggregator.withOutputPath(qualifiedOutput);
}
return aggregator;
}