//doesn't yield the expected results (the latest versions are not returned), so we rely on a fuzzier search
//and refine the results.
Map<String, IndexedArtifact> values = index.search(a, IIndex.SEARCH_PLUGIN);
if(!values.isEmpty()) {
SortedSet<ComparableVersion> versions = new TreeSet<ComparableVersion>();
ComparableVersion referenceComparableVersion = referenceVersion == null ? null : new ComparableVersion(
referenceVersion);
for(Map.Entry<String, IndexedArtifact> e : values.entrySet()) {
if(!(e.getKey().endsWith(partialKey))) {
continue;
}
for(IndexedArtifactFile f : e.getValue().getFiles()) {
if(groupId.equals(f.group) && artifactId.equals(f.artifact) && !f.version.contains("-SNAPSHOT")) { //$NON-NLS-1$
ComparableVersion v = new ComparableVersion(f.version);
if(referenceComparableVersion == null || v.compareTo(referenceComparableVersion) > 0) {
versions.add(v);
}
}
}
if(!versions.isEmpty()) {
List<String> sorted = new ArrayList<String>(versions.size());
for(ComparableVersion v : versions) {
sorted.add(v.toString());
}
Collections.reverse(sorted);
version = sorted.iterator().next();
}
}