style(logging): improved logging for clang unrecognized dep file collection
@@ -24,11 +24,12 @@ package com.synopsys.integration.detectable.detectables.clang;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -76,10 +77,12 @@ public class ClangExtractor {
final List<Forge> packageForges = currentPackageManager.getPackageManagerInfo().getForges();
final CodeLocation codeLocation = clangPackageDetailsTransformer.toCodeLocation(packageForges, results.getFoundPackages());
- logSummary(results.getUnRecognizedDependencyFiles(), sourceDirectory);
+ logFileCollection("Unrecognized dependency files (all)", results.getUnRecognizedDependencyFiles());
final List<File> unrecognizedIncludeFiles = results.getUnRecognizedDependencyFiles().stream()
.filter(file -> !isFileUnderDir(sourceDirectory, file))
.collect(Collectors.toList());
+ logFileCollection(String.format("Unrecognized dependency files that are outside the compile_commands.json directory (%s) and will be collected", sourceDirectory), unrecognizedIncludeFiles);
+
return new Extraction.Builder()
.unrecognizedPaths(unrecognizedIncludeFiles)
.success(codeLocation).build();
@@ -102,18 +105,13 @@ public class ClangExtractor {
}
}
- private void logSummary(final Set<File> unRecognizedDependencyFiles, final File sourceDirectory) {
- logger.debug("Dependency files outside the build directory that were not recognized by the package manager:");
- for (final File unRecognizedDependencyFile : unRecognizedDependencyFiles) {
- try {
- if (FileUtils.directoryContains(sourceDirectory, unRecognizedDependencyFile)) {
- logger.debug(String.format("\t%s is not managed, but it's in the source.dir, ignoring.", unRecognizedDependencyFile.getAbsolutePath()));
- } else {
- logger.debug(String.format("\t%s", unRecognizedDependencyFile.getAbsolutePath()));
- }
- } catch (final IOException e) {
- logger.debug(String.format("\t%s (may or may not be in the source dir; attempt to verify location failed)", unRecognizedDependencyFile.getAbsolutePath()));
+ private void logFileCollection(final String description, Collection<File> files) {
+ if (files == null) {
+ files = new ArrayList<>(0);
}
+ logger.debug(String.format("%s (%d files):", description, files.size()));
+ for (final File file : files) {
+ logger.debug(String.format("\t%s", file.getAbsolutePath()));
}
}
}
