use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.
the class BundleRepositoryManagerImpl method getAllBundleRepositories.
public Collection<BundleRepository> getAllBundleRepositories() {
LOGGER.debug(LOG_ENTRY, "getAllBundleRepositories");
ServiceCollection<BundleRepository> providers = new ArrayServiceList<BundleRepository>(bc);
try {
ServiceReference[] refs = bc.getServiceReferences(BundleRepository.class.getName(), null);
if (refs != null) {
for (ServiceReference ref : refs) {
providers.addService(ref);
}
}
} catch (InvalidSyntaxException e) {
LOGGER.error(LOG_EXCEPTION, e);
}
LOGGER.debug(LOG_EXIT, "getAllBundleRepositories");
return providers;
}
use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.
the class BundleRepositoryManagerImpl method getBundleSuggestions.
public Map<DeploymentContent, BundleSuggestion> getBundleSuggestions(Collection<BundleRepository> providers, Collection<DeploymentContent> content) throws ContextException {
LOGGER.debug(LOG_ENTRY, "getBundleSuggestions", new Object[] { content, providers });
Map<DeploymentContent, BundleSuggestion> urlToBeInstalled = new HashMap<DeploymentContent, BundleSuggestion>();
Iterator<DeploymentContent> it = content.iterator();
while (it.hasNext()) {
DeploymentContent bundleToFind = it.next();
Map<Version, List<BundleSuggestion>> bundlesuggestions = new HashMap<Version, List<BundleSuggestion>>();
for (BundleRepository obj : providers) {
BundleSuggestion suggestion = obj.suggestBundleToUse(bundleToFind);
if (suggestion != null) {
List<BundleSuggestion> suggestions = bundlesuggestions.get(suggestion.getVersion());
if (suggestions == null) {
suggestions = new ArrayList<BundleSuggestion>();
bundlesuggestions.put(suggestion.getVersion(), suggestions);
}
suggestions.add(suggestion);
}
}
BundleSuggestion suggestion = null;
if (!!!bundlesuggestions.isEmpty()) {
List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
if (thoughts != null) {
Collections.sort(thoughts, new Comparator<BundleSuggestion>() {
public int compare(BundleSuggestion o1, BundleSuggestion o2) {
return o1.getCost() - o2.getCost();
}
});
suggestion = thoughts.get(0);
}
}
// add the suggestion to the list
if (suggestion != null) {
urlToBeInstalled.put(bundleToFind, suggestion);
} else {
throw new ContextException("Unable to find bundle " + bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
}
}
LOGGER.debug(LOG_EXIT, "getBundleSuggestions", new Object[] { urlToBeInstalled });
return urlToBeInstalled;
}
use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.
the class BundleRepositoryManagerImpl method getBundleRepositoryCollection.
public Collection<BundleRepository> getBundleRepositoryCollection(String appName, String appVersion) {
LOGGER.debug(LOG_ENTRY, "getBundleRepositoryCollection", new Object[] { appName, appVersion });
ServiceCollection<BundleRepository> providers = new ArrayServiceList<BundleRepository>(bc);
String appScope = appName + "_" + appVersion;
String filter = "(|(" + BundleRepository.REPOSITORY_SCOPE + "=" + BundleRepository.GLOBAL_SCOPE + ")(" + BundleRepository.REPOSITORY_SCOPE + "=" + appScope + "))";
try {
ServiceReference[] refs = bc.getServiceReferences(BundleRepository.class.getName(), filter);
if (refs != null) {
for (ServiceReference ref : refs) {
providers.addService(ref);
}
}
} catch (InvalidSyntaxException e) {
LOGGER.error(LOG_EXCEPTION, e);
}
LOGGER.debug(LOG_EXIT, "getBundleRepositoryCollection");
return providers;
}
use of org.apache.aries.application.management.spi.repository.BundleRepository in project aries by apache.
the class IsolationTestUtils method prepareSampleBundleV2.
/**
* Set up the necessary resources for installing version 2 of the org.apache.aries.isolated.sample sample bundle,
* which returns the message "hello brave new world" rather than "hello world"
*
* This means setting up a global bundle repository as well as a global OBR repository
*/
public static void prepareSampleBundleV2(BundleContext runtimeCtx, RepositoryGenerator repoGen, RepositoryAdmin repoAdmin, ModellingManager modellingManager) throws Exception {
BundleRepository repo = new BundleRepository() {
public int getCost() {
return 1;
}
public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
return new BundleSuggestion() {
public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException {
File f = new File("sample_2.0.0.jar");
try {
return framework.getIsolatedBundleContext().installBundle(f.toURL().toString());
} catch (MalformedURLException mue) {
throw new RuntimeException(mue);
}
}
public Version getVersion() {
return new Version("2.0.0");
}
public Set<Content> getImportPackage() {
return Collections.emptySet();
}
public Set<Content> getExportPackage() {
return Collections.emptySet();
}
public int getCost() {
return 1;
}
};
} else {
return null;
}
}
};
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
runtimeCtx.registerService(BundleRepository.class.getName(), repo, props);
Attributes attrs = new Attributes();
attrs.putValue("Bundle-ManifestVersion", "2");
attrs.putValue("Bundle-Version", "2.0.0");
attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
attrs.putValue("Manifest-Version", "1");
ModelledResource res = modellingManager.getModelledResource(new File("sample_2.0.0.jar").toURI().toString(), attrs, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
repoAdmin.addRepository(new File("repo.xml").toURI().toString());
}
Aggregations