Skip to content

Commit

Permalink
Merge pull request AdoptOpenJDK#934 from tzjan/FixExtensionFileCacheL…
Browse files Browse the repository at this point in the history
…ookup

Fix extension file cache lookup
  • Loading branch information
janakmulani authored Feb 12, 2024
2 parents 1be00cf + d3e2008 commit 7a8acf1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ Optional<CacheIndexEntry> 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<CacheIndexEntry> getAllEntriesInCache(final URL resourceHref) {
final List<CacheIndexEntry> all = new ArrayList<>(cacheIndex.getSynchronized(idx -> idx.findAllEntries(resourceHref)));

if (all.size() > 1) {
final Comparator<CacheIndexEntry> versionComparator = comparing(CacheIndexEntry::getVersion);
all.sort(versionComparator);
}

return all.stream()
.filter(entry -> getInfoFile(entry).isCached())
.collect(Collectors.toList());
Expand Down
27 changes: 26 additions & 1 deletion core/src/main/java/net/sourceforge/jnlp/JNLPFileFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
}

Expand Down

0 comments on commit 7a8acf1

Please sign in to comment.