Skip to content

Commit

Permalink
WIP - cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rudsberg committed Sep 5, 2024
1 parent c4c9cec commit ae6f898
Showing 1 changed file with 3 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private Optional<Set<Path>> resolveDirectoriesWithClasses(FileSystem jarFileSyst
originalClassFiles.add(fileName.toString());
}
});
Optional<Set<Path>> optionalPaths = resolveDirectoryFromClassNameMatching(artifact, originalClassFiles);
Optional<Set<Path>> optionalPaths = resolveDirectoriesFromClassNameMatching(artifact, originalClassFiles);
if (optionalPaths.isPresent()) {
Set<Path> paths = optionalPaths.get();
visitedPathToClassFileDirectories.addAll(paths);
Expand Down Expand Up @@ -261,36 +261,10 @@ private Set<Path> notVisitedPaths() {
return difference;
}

// private Optional<Path> resolveDirectoryFromClassNameMatching(ArtifactAdapter artifact, Set<String> originalClassFiles) throws IOException {
// for (Path potentialDirectory : pathToClassFilesDirectories) { // notVisistedPaths
// /* Use AtomicBoolean as a wrapper class to allow updating the value from the anonymous inner class. */
// AtomicBoolean successfulMatching = new AtomicBoolean(true);
// Files.walkFileTree(potentialDirectory, new SimpleFileVisitor<>() {
// @Override
// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
// if (file.toString().endsWith(".class")) {
// String fileName = file.getFileName().toString();
// if (originalClassFiles.contains(fileName)) {
// return FileVisitResult.CONTINUE;
// } else {
// successfulMatching.set(false);
// return FileVisitResult.TERMINATE;
// }
// }
// return FileVisitResult.CONTINUE;
// }
// });
// if (successfulMatching.get()) {
// return Optional.of(potentialDirectory);
// }
// }
// System.out.printf("❌ Failed matching for %s:%s\n", artifact.groupId, artifact.artifactId);
// return Optional.empty();
// }
private Optional<Set<Path>> resolveDirectoryFromClassNameMatching(ArtifactAdapter artifact, Set<String> originalClassFiles) throws IOException {
private Optional<Set<Path>> resolveDirectoriesFromClassNameMatching(ArtifactAdapter artifact, Set<String> originalClassFiles) throws IOException {
Set<Path> matchingDirectories = new HashSet<>();

for (Path potentialDirectory : pathToClassFilesDirectories) { // notVisitedPaths
for (Path potentialDirectory : pathToClassFilesDirectories) {
AtomicBoolean successfulMatching = new AtomicBoolean(true);

try (DirectoryStream<Path> stream = Files.newDirectoryStream(potentialDirectory)) {
Expand All @@ -314,69 +288,8 @@ private Optional<Set<Path>> resolveDirectoryFromClassNameMatching(ArtifactAdapte
return Optional.empty();
}
return Optional.of(matchingDirectories);

// // Find the directories with the fewest components
// OptionalInt minComponents = matchingDirectories.stream()
// .mapToInt(Path::getNameCount)
// .min();
//
// if (minComponents.isPresent()) {
// // Collect all directories that have the minimum number of components
// Set<Path> smallestDirectories = matchingDirectories.stream()
// .filter(path -> path.getNameCount() == minComponents.getAsInt())
// .collect(Collectors.toSet());
//
// // If there's only one directory with the fewest components, return it
// if (smallestDirectories.size() == 1) {
// return Optional.of(smallestDirectories.iterator().next());
// }
//
// // If there is a tie, take one of the directories and return its parent
// Path oneOfTheTiedDirectories = smallestDirectories.iterator().next();
// Path parent = oneOfTheTiedDirectories.getParent();
//
// // Return the parent, even if it's not part of matchingDirectories
// return Optional.of(parent);
// }
//
// return Optional.empty();
}


// /**
// * Collects directories that contain .class files using a breadth-first search.
// * Processes files before adding directories to ensure no further directories are visited once a .class file is found.
// */
// private Set<Path> collectPotentialDirectories(Path rootPath) throws IOException {
// Set<Path> potentialDirectories = new HashSet<>();
// Queue<Path> directoriesToVisit = new LinkedList<>();
// directoriesToVisit.add(rootPath);
//
// while (!directoriesToVisit.isEmpty()) {
// Path currentDir = directoriesToVisit.poll();
// List<Path> subdirectories = new ArrayList<>();
// try (DirectoryStream<Path> stream = Files.newDirectoryStream(currentDir)) {
// boolean classFileFound = false;
//
// for (Path entry : stream) {
// if (Files.isDirectory(entry) && !entry.getFileName().toString().equals("META-INF")) {
// subdirectories.add(entry);
// } else if (entry.toString().endsWith(".class")) {
// potentialDirectories.add(currentDir);
// classFileFound = true;
// break;
// }
// }
//
// if (!classFileFound) {
// directoriesToVisit.addAll(subdirectories);
// }
// }
// }
//
// return potentialDirectories;
// }

private Set<Path> collectPotentialDirectories(Path rootPath) throws IOException {
Set<Path> potentialDirectories = new HashSet<>();
Files.walkFileTree(rootPath, new SimpleFileVisitor<>() {
Expand Down

0 comments on commit ae6f898

Please sign in to comment.