From 3a1642d14e610c7b97397c4fe37d02d6abb2c6cf Mon Sep 17 00:00:00 2001 From: Ramid Khan Date: Mon, 14 Oct 2019 16:35:18 +1100 Subject: [PATCH] Add an option to follow symbolic links Solves an issue when two library files link to the same file, causing a FileSystemAlreadyExistsException --- src/matcher/gui/menu/NewProjectPane.java | 32 +++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/matcher/gui/menu/NewProjectPane.java b/src/matcher/gui/menu/NewProjectPane.java index df083b31..e19f905f 100644 --- a/src/matcher/gui/menu/NewProjectPane.java +++ b/src/matcher/gui/menu/NewProjectPane.java @@ -80,8 +80,10 @@ private void init() { add(createFilesSelectionPane("Class path B", classPathB, window, true, false), 1, 1); HBox hbox = new HBox(GuiConstants.padding); - Button swapButton = new Button("swap A ⇄ B"); + Button swapButton = new Button("Swap A ⇄ B"); + Button findShared = new Button("Share libraries"); hbox.getChildren().add(swapButton); + hbox.getChildren().add(findShared); swapButton.setOnAction(event -> { List paths = new ArrayList<>(pathsA); pathsA.clear(); @@ -102,6 +104,34 @@ private void init() { nonObfuscatedMemberPatternA.setText(nonObfuscatedMemberPatternB.getText()); nonObfuscatedMemberPatternB.setText(tmp); }); + findShared.setOnAction(event -> { + List add = new ArrayList<>(); + List removeA = new ArrayList<>(); + List removeB = new ArrayList<>(); + + for (Path a : classPathA) { + for (Path b : classPathB) { + try { + // Follow symlinks + Path realA = a.toRealPath(); + Path realB = b.toRealPath(); + + if (realA.equals(realB)) { + add.add(realA); + removeA.add(a); + removeB.add(b); + } + } catch (IOException exception) { + System.out.println("Could not read symbolic links"); + exception.printStackTrace(); + } + } + } + + classPathA.removeAll(removeA); + classPathB.removeAll(removeB); + sharedClassPath.addAll(add); + }); add(hbox, 0, 2, 2, 1); add(createFilesSelectionPane("Shared class path", sharedClassPath, window, true, true), 0, 3, 2, 1);