use of org.apache.aries.application.management.ResolverException in project aries by apache.
the class DeployedBundlesTest method testGetRequiredUseBundle_Valid.
@Test
public void testGetRequiredUseBundle_Valid() throws Exception {
// Get a valid set of deployment information.
DeployedBundles deployedBundles = validDeployedBundles();
packagesResolve(deployedBundles);
// Check all the use-bundle entries are required.
Collection<ModelledResource> requiredUseBundle = null;
try {
requiredUseBundle = deployedBundles.getRequiredUseBundle();
} catch (ResolverException e) {
e.printStackTrace();
Assert.fail(e.toString());
}
Assert.assertTrue("RequiredUseBundle=" + requiredUseBundle, requiredUseBundle.size() == 2);
}
use of org.apache.aries.application.management.ResolverException in project aries by apache.
the class DeployedBundlesTest method testGetImportPackage_Valid.
@Test
public void testGetImportPackage_Valid() throws Exception {
// Check the import package entry is correct.
String importPackageEntry = null;
try {
DeployedBundles deployedBundles = validDeployedBundles();
packagesResolve(deployedBundles);
importPackageEntry = deployedBundles.getImportPackage();
} catch (ResolverException e) {
e.printStackTrace();
Assert.fail(e.toString());
}
String expectedResult = "package.c;version=\"1.0.0\";bundle-symbolic-name=\"bundle.c\";bundle-version=\"[1.0.0,1.0.0]\"," + "package.d;version=\"1.0.0\";bundle-symbolic-name=\"bundle.d\";bundle-version=\"[1.0.0,1.0.0]\"," + "package.e;version=\"[1.0.0,2.0.0)\"," + "package.g;version=\"0.0.0\"";
/*
* String expectedResult = "package.c;bundle-symbolic-name=bundle.c;bundle-version=\"[1.0.0,1.0.0]\""
+ ",package.d;version=\"1.0.0\";bundle-symbolic-name=bundle.d;bundle-version=\"[1.0.0,1.0.0]\""
+ ",package.e;version=\"[1.0.0,2.0.0)\""
+ ",package.g";
*/
Assert.assertTrue("ImportPackage=" + importPackageEntry, isEqual(importPackageEntry, expectedResult));
}
use of org.apache.aries.application.management.ResolverException in project aries by apache.
the class DeployedBundlesTest method testGetImportPackage_InvalidDuplicates.
@Test
public void testGetImportPackage_InvalidDuplicates() throws Exception {
DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.CONTENT, ternary.NONE);
deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.c;version=\"[1.0.0,2.0.0)\""), new ArrayList<String>()));
deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.c;version=2.0.0"), new ArrayList<String>()));
deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", new ArrayList<String>(), Arrays.asList("package.c;version=2.0.0;was_internal=true")));
// Check that the incompatible version requirements cannot be resolved.
String importPackageEntry = null;
try {
importPackageEntry = deployedBundles.getImportPackage();
Assert.fail("Expected exception. ImportPackage=" + importPackageEntry);
} catch (ResolverException e) {
// We expect to reach this point if the test passes.
}
}
use of org.apache.aries.application.management.ResolverException in project aries by apache.
the class DeployedBundlesImpl method validateOtherImports.
/**
* Create entries for the Import-Package header corresponding to the supplied
* packages, referring to bundles not in Use-Bundle.
* @param requirements packages for which entries should be created.
* @return manifest header entries.
* @throws ResolverException if the imports are invalid.
*/
private void validateOtherImports(Collection<ImportedPackage> requirements) throws ResolverException {
logger.debug(LOG_ENTRY, "validateOtherImports", requirements);
for (ImportedPackage req : requirements) {
String pkgName = req.getPackageName();
for (String name : req.getAttributes().keySet()) {
if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(name) || Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name)) {
ResolverException re = new ResolverException(MessageUtil.getMessage("INVALID_PACKAGE_REQUIREMENT_ATTRIBUTES", new Object[] { assetName, name, pkgName }));
re.setUnsatisfiedRequirements(Arrays.asList(pkgName));
logger.debug(LOG_EXIT, "validateOtherImports", re);
throw re;
}
}
}
logger.debug(LOG_EXIT, "validateOtherImports");
}
use of org.apache.aries.application.management.ResolverException 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;
}
Aggregations