OBRRepositoryConnectorImpl implements OBRRepositoryService { protected List<String> getHighestBundleVersions(String... filenames) { if(filenames==null) return Collections.emptyList(); SortedSetMultimap<String, String> map = TreeMultimap.create(Collator.getInstance(), new VersionComparator()); for (String string : filenames) { Matcher matcher = BUNDLE_PATTERN.matcher(string); if(matcher.matches()) { String name = matcher.group(1); String version = matcher.group(2); map.put(name, version); } else { logger.warn("{} does not match the pattern {}. Skipping",string,BUNDLE_PATTERN); } } Set<Entry<String, Collection<String>>> entrySet = map.asMap().entrySet(); List<String> result = new ArrayList<String>(entrySet.size()); for (Entry<String, Collection<String>> entry : entrySet) { result.add(entry.getKey()+"_"+entry.getValue().iterator().next()+".jar"); } return result; }  @Activate void activate(); @Override List<Bundle> listInstalledBundles(); @Override List<Resource> getAvailableResources(ResourceFilter filter); @Override void install(String resourceId); @Override void install(Resource... resources); @Override Resource[] findResources(String id);  }
@Test public void testGetHighestBundleVersions() { List<String> versions = fixture.getHighestBundleVersions("a.b_1.0.0.jar","a.b_1.0.1.jar","a.b_2.0.0.jar","a.b_19.0.1.jar"); assertEquals(1, versions.size()); assertEquals("a.b_19.0.1.jar", versions.get(0)); }
@Test public void testGetHighestBundleVersionsMixed() { List<String> versions = fixture.getHighestBundleVersions("a.b_1.0.0.jar","a.b_1.0.1.jar","b_2.0.0.jar"); assertEquals(2, versions.size()); assertEquals("a.b_1.0.1.jar", versions.get(0)); assertEquals("b_2.0.0.jar", versions.get(1)); }
@Test public void testGetHighestBundleVersionsSnapshot() { List<String> versions = fixture.getHighestBundleVersions("a_1.0.0.SNAPSHOT.jar","a_1.0.0.jar"); assertEquals(1, versions.size()); assertEquals("a_1.0.0.jar", versions.get(0)); }
@Test public void testGetHighestBundleVersionsShort() { List<String> versions = fixture.getHighestBundleVersions("a_2.0.0.jar","a_2.1.jar"); assertEquals(1, versions.size()); assertEquals("a_2.1.jar", versions.get(0)); }