Skip to content

Commit 7a8acf1

Browse files
authored
Merge pull request #934 from tzjan/FixExtensionFileCacheLookup
Fix extension file cache lookup
2 parents 1be00cf + d3e2008 commit 7a8acf1

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

core/src/main/java/net/adoptopenjdk/icedteaweb/jnlp/element/resource/ExtensionDesc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public URL getLocation() {
131131
*/
132132
public void resolve() throws ParseException, IOException {
133133
if (file == null) {
134-
file = new JNLPFileFactory().create(location);
134+
file = new JNLPFileFactory().create(location, version);
135135

136136
LOG.debug("Resolve: {}", file.getInformation().getTitle());
137137

core/src/main/java/net/adoptopenjdk/icedteaweb/resources/cache/CacheImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ Optional<CacheIndexEntry> getBestMatchingEntryInCache(final URL resourceHref, fi
238238
.findFirst();
239239
}
240240

241+
/**
242+
* Return all valid cache entries with this URL, regardless of whether they have a version or not. They are not sorted.
243+
* @param resourceHref
244+
* @return
245+
*/
241246
List<CacheIndexEntry> getAllEntriesInCache(final URL resourceHref) {
242247
final List<CacheIndexEntry> all = new ArrayList<>(cacheIndex.getSynchronized(idx -> idx.findAllEntries(resourceHref)));
243248

244-
if (all.size() > 1) {
245-
final Comparator<CacheIndexEntry> versionComparator = comparing(CacheIndexEntry::getVersion);
246-
all.sort(versionComparator);
247-
}
248-
249249
return all.stream()
250250
.filter(entry -> getInfoFile(entry).isCached())
251251
.collect(Collectors.toList());

core/src/main/java/net/sourceforge/jnlp/JNLPFileFactory.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ public JNLPFile create(final URL location) throws IOException, ParseException {
4949
return create(location, new ParserSettings());
5050
}
5151

52+
/**
53+
* Generate unique key from file URL
54+
* @param location
55+
*/
56+
private String createUniqueKey(final URL location) {
57+
return Calendar.getInstance().getTimeInMillis() + "-" + ((int) (Math.random() * Integer.MAX_VALUE)) + "-" + location;
58+
}
59+
60+
/**
61+
* Create a JNLPFile from a URL and version and checking for
62+
* updates using the default policy.
63+
*
64+
* @param location the location of the JNLP file
65+
* @param version the version of the JNLP file
66+
* @throws IOException if an IO exception occurred
67+
* @throws ParseException if the JNLP file was invalid
68+
*/
69+
public JNLPFile create(final URL location, final VersionString version) throws IOException, ParseException {
70+
return create(location,
71+
createUniqueKey(location),
72+
version,
73+
new ParserSettings(),
74+
JNLPRuntime.getDefaultUpdatePolicy());
75+
}
76+
5277
/**
5378
* Create a JNLPFile from a URL checking for updates using the
5479
* default policy.
@@ -59,7 +84,7 @@ public JNLPFile create(final URL location) throws IOException, ParseException {
5984
* @throws ParseException if the JNLP file was invalid
6085
*/
6186
public JNLPFile create(final URL location, final ParserSettings settings) throws IOException, ParseException {
62-
final String uniqueKey = Calendar.getInstance().getTimeInMillis() + "-" + ((int) (Math.random() * Integer.MAX_VALUE)) + "-" + location;
87+
final String uniqueKey = createUniqueKey(location);
6388
return create(location, uniqueKey, null, settings, JNLPRuntime.getDefaultUpdatePolicy());
6489
}
6590

0 commit comments

Comments
 (0)