+ this.localCache = localCache;
+ }
+
+ protected String constructUrl(String baseUrl, String relativeUrl) {
+ try {
+ if (relativeUrl.indexOf('*') >= 0) {
+ if (!baseUrl.startsWith("file:"))
+ throw new IllegalArgumentException(
+ "Wildcard support only for file:, badly formatted " + baseUrl + " and " + relativeUrl);
+ Path basePath = Paths.get(new URI(baseUrl));
+ // Path basePath = Paths.get(new URI(baseUrl));
+ // int li = relativeUrl.lastIndexOf('/');
+ // String relativeDir = relativeUrl.substring(0, li);
+ // String relativeFile = relativeUrl.substring(li,
+ // relativeUrl.length());
+ String pattern = "glob:" + basePath + '/' + relativeUrl;
+ PathMatcher pm = basePath.getFileSystem().getPathMatcher(pattern);
+ SortedMap<Version, Path> res = new TreeMap<>();
+ checkDir(basePath, pm, res);
+ if (res.size() == 0)
+ throw new OsgiBootException("No file matching " + relativeUrl + " found in " + baseUrl);
+ return res.get(res.firstKey()).toUri().toString();
+ } else {
+ return baseUrl + relativeUrl;
+ }
+ } catch (Exception e) {
+ throw new OsgiBootException("Cannot build URL from " + baseUrl + " and " + relativeUrl, e);
+ }
+ }
+
+ private void checkDir(Path dir, PathMatcher pm, SortedMap<Version, Path> res) throws IOException {
+ try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir)) {
+ for (Path path : ds) {
+ if (Files.isDirectory(path))
+ checkDir(path, pm, res);
+ else if (pm.matches(path)) {
+ String fileName = path.getFileName().toString();
+ fileName = fileName.substring(0, fileName.lastIndexOf('.'));
+ if (fileName.endsWith("-SNAPSHOT"))
+ fileName = fileName.substring(0, fileName.lastIndexOf('-')) + ".SNAPSHOT";
+ fileName = fileName.substring(fileName.lastIndexOf('-') + 1);
+ Version version = new Version(fileName);
+ res.put(version, path);
+ }
+ }
+ }