use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.
the class DeployedBundlesImpl method getRequiredUseBundle.
/**
* Get the subset of bundles specified in use-bundle that are actually required to
* satisfy direct requirements of deployed content.
* @return a set of bundle metadata.
* @throws ResolverException if the requirements could not be resolved.
*/
public Collection<ModelledResource> getRequiredUseBundle() throws ResolverException {
logger.debug(LOG_ENTRY, "getRequiredUseBundle");
Collection<ModelledResource> usedUseBundles = cachedRequiredUseBundle;
if (usedUseBundles == null) {
Collection<ImportedPackage> externalReqs = getExternalPackageRequirements();
usedUseBundles = new HashSet<ModelledResource>();
for (ImportedPackage req : externalReqs) {
// Find a match from the supplied bundle capabilities.
ExportedPackage match = getPackageMatch(req, deployedUseBundle);
if (match != null) {
usedUseBundles.add(match.getBundle());
}
}
cachedRequiredUseBundle = usedUseBundles;
}
logger.debug(LOG_EXIT, "getRequiredUseBundle", usedUseBundles);
return usedUseBundles;
}
use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.
the class DeployedBundlesImpl method getPackageMatch.
/**
* Get a package match between the specified requirement and a capability of the supplied
* bundles. The resulting match object might not refer to any matching capability.
* @param requirement the {@link ImportedPackageImpl} to be matched.
* @param bundles the bundles to be searched for matching capabilities.
* @return an ExportedPackageImpl or null if no match is found.
*/
private ExportedPackage getPackageMatch(ImportedPackage requirement, Collection<ModelledResource> bundles) {
logger.debug(LOG_ENTRY, "getPackageMatch", new Object[] { requirement, bundles });
ExportedPackage result = null;
outer: for (ModelledResource bundle : bundles) {
for (ExportedPackage pkg : bundle.getExportedPackages()) {
if (requirement.isSatisfied(pkg)) {
result = pkg;
break outer;
}
}
}
logger.debug(LOG_EXIT, "getPackageMatch", new Object[] { result });
return result;
}
use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.
the class DeployedBundlesImpl method getExternalPackageRequirements.
/**
* Get all the requirements of bundles in deployed content that are not satisfied
* by other bundles in deployed content.
* @return a collection of package requirements.
* @throws ResolverException if the requirements could not be resolved.
*/
private Collection<ImportedPackage> getExternalPackageRequirements() throws ResolverException {
logger.debug(LOG_ENTRY, "getExternalPackageRequirements");
Collection<ImportedPackage> result = cachedExternalRequirements;
if (result == null) {
// Get all the internal requirements.
Collection<ImportedPackage> requirements = new ArrayList<ImportedPackage>();
Collection<ExportedPackage> internalExports = new ArrayList<ExportedPackage>();
for (ModelledResource bundle : deployedContent) {
requirements.addAll(bundle.getImportedPackages());
internalExports.addAll(bundle.getExportedPackages());
}
// Filter out requirements satisfied by internal capabilities.
result = new ArrayList<ImportedPackage>();
for (ImportedPackage req : requirements) {
boolean satisfied = false;
for (ExportedPackage export : internalExports) {
if (req.isSatisfied(export)) {
satisfied = true;
break;
}
}
//If we didn't find a match then it must come from outside
if (!satisfied)
result.add(req);
}
PackageRequirementMerger merger = new PackageRequirementMerger(result);
if (!merger.isMergeSuccessful()) {
List<String> pkgNames = new ArrayList<String>(merger.getInvalidRequirements());
StringBuilder buff = new StringBuilder();
for (String pkgName : merger.getInvalidRequirements()) {
buff.append(pkgName).append(", ");
}
int buffLen = buff.length();
String pkgString = (buffLen > 0 ? buff.substring(0, buffLen - 2) : "");
ResolverException re = new ResolverException(MessageUtil.getMessage("INCOMPATIBLE_PACKAGE_VERSION_REQUIREMENTS", new Object[] { assetName, pkgString }));
re.setUnsatisfiedRequirements(pkgNames);
logger.debug(LOG_EXIT, "getExternalPackageRequirements", re);
throw re;
}
result = merger.getMergedRequirements();
cachedExternalRequirements = result;
}
logger.debug(LOG_EXIT, "getExternalPackageRequirements", result);
return result;
}
use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.
the class ExportedPackageTest method testEqualsForIdenticalPackages.
@Test
public void testEqualsForIdenticalPackages() {
String packageName = "package.name";
String version = "1.0.0";
ExportedPackage package1 = instantiatePackage(packageName, version);
// I should hope so!
assertEquals(package1, package1);
}
use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.
the class ExportedPackageTest method testEqualsForEqualPackagesWithDifferentAttributes.
@Test
public void testEqualsForEqualPackagesWithDifferentAttributes() {
String packageName = "package.name";
String version = "1.0.0";
ExportedPackage package1 = instantiatePackage(packageName, version, "att=something");
ExportedPackage package2 = instantiatePackage(packageName, version, "att=something.else");
assertFalse("Unexpectedly reported as equal" + package1 + "==" + package2, package1.equals(package2));
}
Aggregations