private static ReverseMatchResult reversePathMatch(final String fqcn, final File location) { final List<String> stk = new ArrayList<String>(Arrays.asList(fqcn.split("\\."))); File curr = location; if (!stk.isEmpty()) { // remove the last element -- as that would be the file name. stk.remove(stk.size() - 1); } while (!stk.isEmpty()) { final String el = stk.remove(stk.size() - 1); curr = curr.getParentFile(); if (curr == null || !curr.getName().equals(el)) { break; } } if (curr != null) { curr = curr.getParentFile(); } if (stk.isEmpty()) { return new ReverseMatchResult(true, curr); } else { return new ReverseMatchResult(false, curr); } }
private static void _findMatchingOutputDirectoryByModel(final Set<File> matching, final Map<String, String> toMatch, final File from) { if (from.getName().startsWith(".")) return; if (from.isDirectory()) { final File[] files = from.listFiles(); if (files != null) { for (final File file : files) { _findMatchingOutputDirectoryByModel(matching, toMatch, file); } } } else { String name = from.getName(); if (name.endsWith(".class") && toMatch.containsKey(name = name.substring(0, name.length() - 6)) && Arrays.stream(candidateOutputDirectories).anyMatch(s -> from.getAbsolutePath().contains(s))) { final String full = toMatch.get(name); final ReverseMatchResult res = reversePathMatch(full, from); if (res.isMatch()) { matching.add(res.getMatchRoot()); } } } }
private static void _findMatchingOutputDirectoryByModel(final Set<File> matching, final Map<String, String> toMatch, final File from) { if (from.getName().startsWith(".")) return; if (from.isDirectory()) { final File[] files = from.listFiles(); if (files != null) { for (final File file : files) { _findMatchingOutputDirectoryByModel(matching, toMatch, file); } } } else { String name = from.getName(); if (name.endsWith(".class") && toMatch.containsKey(name = name.substring(0, name.length() - 6)) && Arrays.stream(candidateOutputDirectories).anyMatch(s -> from.getAbsolutePath().contains(s))) { final String full = toMatch.get(name); final ReverseMatchResult res = reversePathMatch(full, from); if (res.isMatch()) { matching.add(res.getMatchRoot()); } } } }
private static ReverseMatchResult reversePathMatch(final String fqcn, final File location) { final List<String> stk = new ArrayList<String>(Arrays.asList(fqcn.split("\\."))); File curr = location; if (!stk.isEmpty()) { // remove the last element -- as that would be the file name. stk.remove(stk.size() - 1); } while (!stk.isEmpty()) { final String el = stk.remove(stk.size() - 1); curr = curr.getParentFile(); if (curr == null || !curr.getName().equals(el)) { break; } } if (curr != null) { curr = curr.getParentFile(); } if (stk.isEmpty()) { return new ReverseMatchResult(true, curr); } else { return new ReverseMatchResult(false, curr); } }