diff --git a/core/src/main/java/net/adoptopenjdk/icedteaweb/jnlp/element/resource/ExtensionDesc.java b/core/src/main/java/net/adoptopenjdk/icedteaweb/jnlp/element/resource/ExtensionDesc.java index 305c2322a..2ac1137bb 100644 --- a/core/src/main/java/net/adoptopenjdk/icedteaweb/jnlp/element/resource/ExtensionDesc.java +++ b/core/src/main/java/net/adoptopenjdk/icedteaweb/jnlp/element/resource/ExtensionDesc.java @@ -131,7 +131,7 @@ public URL getLocation() { */ public void resolve() throws ParseException, IOException { if (file == null) { - file = new JNLPFileFactory().create(location); + file = new JNLPFileFactory().create(location, version); LOG.debug("Resolve: {}", file.getInformation().getTitle()); diff --git a/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/cache/CacheImpl.java b/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/cache/CacheImpl.java index fe144bc5a..8c5217dee 100644 --- a/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/cache/CacheImpl.java +++ b/core/src/main/java/net/adoptopenjdk/icedteaweb/resources/cache/CacheImpl.java @@ -238,14 +238,14 @@ Optional getBestMatchingEntryInCache(final URL resourceHref, fi .findFirst(); } + /** + * Return all valid cache entries with this URL, regardless of whether they have a version or not. They are not sorted. + * @param resourceHref + * @return + */ List getAllEntriesInCache(final URL resourceHref) { final List all = new ArrayList<>(cacheIndex.getSynchronized(idx -> idx.findAllEntries(resourceHref))); - if (all.size() > 1) { - final Comparator versionComparator = comparing(CacheIndexEntry::getVersion); - all.sort(versionComparator); - } - return all.stream() .filter(entry -> getInfoFile(entry).isCached()) .collect(Collectors.toList()); diff --git a/core/src/main/java/net/sourceforge/jnlp/JNLPFileFactory.java b/core/src/main/java/net/sourceforge/jnlp/JNLPFileFactory.java index 952ad1516..37a109c21 100644 --- a/core/src/main/java/net/sourceforge/jnlp/JNLPFileFactory.java +++ b/core/src/main/java/net/sourceforge/jnlp/JNLPFileFactory.java @@ -49,6 +49,31 @@ public JNLPFile create(final URL location) throws IOException, ParseException { return create(location, new ParserSettings()); } + /** + * Generate unique key from file URL + * @param location + */ + private String createUniqueKey(final URL location) { + return Calendar.getInstance().getTimeInMillis() + "-" + ((int) (Math.random() * Integer.MAX_VALUE)) + "-" + location; + } + + /** + * Create a JNLPFile from a URL and version and checking for + * updates using the default policy. + * + * @param location the location of the JNLP file + * @param version the version of the JNLP file + * @throws IOException if an IO exception occurred + * @throws ParseException if the JNLP file was invalid + */ + public JNLPFile create(final URL location, final VersionString version) throws IOException, ParseException { + return create(location, + createUniqueKey(location), + version, + new ParserSettings(), + JNLPRuntime.getDefaultUpdatePolicy()); + } + /** * Create a JNLPFile from a URL checking for updates using the * default policy. @@ -59,7 +84,7 @@ public JNLPFile create(final URL location) throws IOException, ParseException { * @throws ParseException if the JNLP file was invalid */ public JNLPFile create(final URL location, final ParserSettings settings) throws IOException, ParseException { - final String uniqueKey = Calendar.getInstance().getTimeInMillis() + "-" + ((int) (Math.random() * Integer.MAX_VALUE)) + "-" + location; + final String uniqueKey = createUniqueKey(location); return create(location, uniqueKey, null, settings, JNLPRuntime.getDefaultUpdatePolicy()); }