Map<String, ? super Object> params,
LibProvidersLookup libProvidersLookup) {
+ libProvidersLookup.setPackageLookup(file -> {
+ Path realPath = file.toRealPath();
+
+ try {
+ // Try the real path first as it works better on newer Ubuntu versions
+ return findProvidingPackages(realPath);
+ } catch (IOException ex) {
+ // Try the default path if differ
+ if (!realPath.toString().equals(file.toString())) {
+ return findProvidingPackages(file);
+ } else {
+ throw ex;
+ }
+ }
+ });
+ }
+
+ private static Stream<String> findProvidingPackages(Path file) throws IOException {
//
// `dpkg -S` command does glob pattern lookup. If not the absolute path
// to the file is specified it might return mltiple package names.
// 4. Arch suffix should be stripped from accepted package names.
//
- libProvidersLookup.setPackageLookup(file -> {
- Set<String> archPackages = new HashSet<>();
- Set<String> otherPackages = new HashSet<>();
-
- Executor.of(TOOL_DPKG, "-S", file.toString())
- .saveOutput(true).executeExpectSuccess()
- .getOutput().forEach(line -> {
- Matcher matcher = PACKAGE_NAME_REGEX.matcher(line);
- if (matcher.find()) {
- String name = matcher.group(1);
- if (name.endsWith(":" + DEB_ARCH)) {
- // Strip arch suffix
- name = name.substring(0,
- name.length() - (DEB_ARCH.length() + 1));
- archPackages.add(name);
- } else {
- otherPackages.add(name);
- }
+ Set<String> archPackages = new HashSet<>();
+ Set<String> otherPackages = new HashSet<>();
+
+ Executor.of(TOOL_DPKG, "-S", file.toString())
+ .saveOutput(true).executeExpectSuccess()
+ .getOutput().forEach(line -> {
+ Matcher matcher = PACKAGE_NAME_REGEX.matcher(line);
+ if (matcher.find()) {
+ String name = matcher.group(1);
+ if (name.endsWith(":" + DEB_ARCH)) {
+ // Strip arch suffix
+ name = name.substring(0,
+ name.length() - (DEB_ARCH.length() + 1));
+ archPackages.add(name);
+ } else {
+ otherPackages.add(name);
}
- });
+ }
+ });
- if (!archPackages.isEmpty()) {
- return archPackages.stream();
- }
- return otherPackages.stream();
- });
+ if (!archPackages.isEmpty()) {
+ return archPackages.stream();
+ }
+ return otherPackages.stream();
}
@Override