* Import model resolvers are matched to a specific contribution if a location URI is specified,
* otherwise it try to resolve against all the other contributions
*/
public void contributionAdded(ContributionRepository repository, Contribution contribution) {
OSGiRuntime osgiRuntime = null;
try {
if (bundleProcessor.installContributionBundle(contribution) == null) {
return;
} else {
osgiRuntime = OSGiRuntime.getRuntime();
}
} catch (Exception e) {
return;
}
HashSet<Contribution> bundlesToInstall = new HashSet<Contribution>();
// Initialize the contribution imports
for (Import import_ : contribution.getImports()) {
boolean initialized = false;
if (import_ instanceof JavaImport) {
JavaImport javaImport = (JavaImport)import_;
String packageName = javaImport.getPackage();
//Find a matching contribution
if (javaImport.getLocation() != null) {
Contribution targetContribution = repository.getContribution(javaImport.getLocation());
if (targetContribution != null) {
// Find a matching contribution export
for (Export export : targetContribution.getExports()) {
if (export instanceof JavaExport) {
JavaExport javaExport = (JavaExport)export;
if (packageName.equals(javaExport.getPackage())) {
if (osgiRuntime.findBundle(targetContribution.getLocation()) == null)
bundlesToInstall.add(targetContribution);
initialized = true;
}
}
if (initialized)
break;
}
}
}
}
if (!initialized) {
for (Contribution c : repository.getContributions()) {
// Go over all exports in the contribution
for (Export export : c.getExports()) {
// If the export matches our namespace, try to the resolve the model object
if (import_.match(export) && osgiRuntime.findBundle(c.getLocation()) == null) {
bundlesToInstall.add(c);
}
}
}
}