use of org.apache.felix.bundlerepository.DataModelHelper in project aries by apache.
the class OBRAriesResolver method getConfiguredObrResolver.
private Resolver getConfiguredObrResolver(String appName, String appVersion, Collection<ModelledResource> byValueBundles, boolean noExtraRepositories) throws ResolverException {
log.debug(LOG_ENTRY, "getConfiguredObrResolver", new Object[] { appName, appVersion, byValueBundles });
DataModelHelper helper = repositoryAdmin.getHelper();
Repository appRepo;
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
RepositoryGeneratorImpl.generateRepository(repositoryAdmin, appName + "_" + appVersion, byValueBundles, bytesOut);
appRepo = helper.readRepository(new InputStreamReader(new ByteArrayInputStream(bytesOut.toByteArray())));
} catch (Exception e) {
throw new ResolverException(e);
}
List<Repository> resolveRepos = new ArrayList<Repository>();
// add system repository
resolveRepos.add(repositoryAdmin.getSystemRepository());
// add application repository
resolveRepos.add(appRepo);
if (!!!noExtraRepositories) {
// add local repository if configured
if (!(excludeLocalRuntime())) {
resolveRepos.add(getLocalRepository(repositoryAdmin));
}
// Need to refresh the repositories added to repository admin
// add user-defined repositories
Repository[] repos = repositoryAdmin.listRepositories();
for (Repository r : repos) {
resolveRepos.add(r);
}
}
Resolver obrResolver = repositoryAdmin.resolver(resolveRepos.toArray(new Repository[resolveRepos.size()]));
addPlatformRepositories(obrResolver, appName, platformRepository);
log.debug(LOG_EXIT, "getConfiguredObrResolver", obrResolver);
return obrResolver;
}
use of org.apache.felix.bundlerepository.DataModelHelper in project aries by apache.
the class OBRCapability method getProperties.
public Property[] getProperties() {
logger.debug(LOG_ENTRY, "getProperties");
DataModelHelper helper = repositoryAdmin.getHelper();
List<Property> properties = new ArrayList<Property>();
// we then get OBR to parse. This is really convoluted and nasty.
for (final Map.Entry<String, Object> entry : _props.entrySet()) {
String propXML = helper.writeProperty(new Property() {
@Override
public String getValue() {
Object value = entry.getValue();
if (value instanceof String[]) {
String newValue = Arrays.toString((String[]) value);
value = newValue.substring(1, newValue.length() - 1);
} else if (value instanceof Collection) {
//We can't rely on Collections having a sensible toString() as it isn't
//part of the API (although all base Java ones do). We can use an array
//to get consistency
String newValue = Arrays.toString(((Collection<?>) value).toArray());
value = newValue.substring(1, newValue.length() - 1);
}
return String.valueOf(value);
}
@Override
public String getType() {
String name = entry.getKey();
String type = null;
if (Constants.VERSION_ATTRIBUTE.equals(name) || (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name))) {
type = "version";
} else if (Constants.OBJECTCLASS.equals(name) || (Constants.MANDATORY_DIRECTIVE + ":").equals(name) || entry.getValue() instanceof String[] || entry.getValue() instanceof Collection)
type = "set";
return type;
}
@Override
public String getName() {
return entry.getKey();
}
@Override
public Object getConvertedValue() {
return null;
}
});
try {
properties.add(helper.readProperty(propXML));
} catch (Exception e) {
// Do nothing and hope it OBR doesn't generate XML it can't parse.
}
}
logger.debug(LOG_EXIT, "getProperties", properties);
return properties.toArray(new Property[properties.size()]);
}
use of org.apache.felix.bundlerepository.DataModelHelper in project aries by apache.
the class OBRAriesResolver method addPlatformRepositories.
/* A 'platform repository' describes capabilities of the target runtime environment
* These should be added to the resolver without being listed as coming from a particular
* repository or bundle.
*/
private void addPlatformRepositories(Resolver obrResolver, String appName, PlatformRepository platformRepository) {
log.debug(LOG_ENTRY, "addPlatformRepositories", new Object[] { obrResolver, appName });
DataModelHelper helper = repositoryAdmin.getHelper();
if (platformRepository != null) {
Collection<URI> uris = platformRepository.getPlatformRepositoryURLs();
if ((uris != null) && (!uris.isEmpty())) {
for (URI uri : uris) {
InputStream is = null;
try {
is = uri.toURL().openStream();
Reader repoReader = new InputStreamReader(is);
Repository aPlatformRepo = helper.readRepository(repoReader);
Resource[] resources = aPlatformRepo.getResources();
for (Resource r : resources) {
Capability[] caps = r.getCapabilities();
for (Capability c : caps) {
obrResolver.addGlobalCapability(c);
}
}
} catch (Exception e) {
// not a big problem
log.error(MessageUtil.getMessage("RESOLVER_UNABLE_TO_READ_REPOSITORY_EXCEPTION", new Object[] { appName, uri }));
} finally {
IOUtils.close(is);
}
}
}
}
log.debug(LOG_EXIT, "addPlatformRepositories");
}
use of org.apache.felix.bundlerepository.DataModelHelper in project aries by apache.
the class Aries1522Test method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
BundleContext context = context();
ServiceReference<RepositoryAdmin> ref = context.getServiceReference(RepositoryAdmin.class);
assertNotNull("The RepositoryAdmin service does not exist", ref);
try {
repositoryAdmin = (RepositoryAdmin) context.getService(ref);
DataModelHelper helper = repositoryAdmin.getHelper();
url = createRepositoryXml(helper);
Repository repository = repositoryAdmin.addRepository(url);
Resource resource = repository.getResources()[0];
System.out.println(resource.getURI());
} finally {
context.ungetService(ref);
}
}
use of org.apache.felix.bundlerepository.DataModelHelper in project aries by apache.
the class Aries1523Test method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
BundleContext context = context();
ServiceReference<RepositoryAdmin> ref = context.getServiceReference(RepositoryAdmin.class);
assertNotNull("The RepositoryAdmin service does not exist", ref);
try {
repositoryAdmin = (RepositoryAdmin) context.getService(ref);
DataModelHelper helper = repositoryAdmin.getHelper();
url = createRepositoryXml(helper);
Repository repository = repositoryAdmin.addRepository(url);
Resource resource = repository.getResources()[0];
System.out.println(resource.getURI());
} finally {
context.ungetService(ref);
}
}
Aggregations