use of org.apache.felix.bundlerepository.Repository in project aries by apache.
the class Aries1523Test method createRepositoryXml.
private URL createRepositoryXml(DataModelHelper helper) throws Exception {
File dir;
String cwd = new File("").getAbsolutePath();
if (cwd.endsWith(File.separator + "target")) {
dir = new File("test-classes/aries1523");
} else {
dir = new File("target/test-classes/aries1523");
}
File jar = new File(dir, "aries1523host.jar");
assertTrue("The host jar does not exist: " + jar.getAbsolutePath(), jar.exists());
Resource resource = helper.createResource(jar.toURI().toURL());
Repository repository = helper.repository(new Resource[] { resource });
File file = new File(dir, "repository.xml");
FileWriter fw = new FileWriter(file);
try {
helper.writeRepository(repository, fw);
return file.toURI().toURL();
} finally {
fw.close();
}
}
use of org.apache.felix.bundlerepository.Repository 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.Repository in project karaf by apache.
the class ObrCommandSupport method persistRepositoryList.
protected void persistRepositoryList(RepositoryAdmin admin) {
try {
StringBuilder sb = new StringBuilder();
for (Repository repo : admin.listRepositories()) {
if (sb.length() > 0) {
sb.append(" ");
}
sb.append(repo.getURI());
}
File etc = new File(System.getProperty("karaf.etc"));
File sys = new File(etc, "config.properties");
File sysTmp = new File(etc, "config.properties.tmp");
boolean modified = false;
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sysTmp)))) {
if (sys.exists()) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(sys)))) {
String line = reader.readLine();
while (line != null) {
if (line.matches("obr\\.repository\\.url[:= ].*")) {
modified = true;
line = "obr.repository.url = " + sb.toString();
}
writer.write(line);
writer.newLine();
line = reader.readLine();
}
}
}
if (!modified) {
writer.newLine();
writer.write("# ");
writer.newLine();
writer.write("# OBR Repository list");
writer.newLine();
writer.write("# ");
writer.newLine();
writer.write("obr.repository.url = " + sb.toString());
writer.newLine();
writer.newLine();
}
}
sys.delete();
sysTmp.renameTo(sys);
} catch (Exception e) {
System.err.println("Error while persisting repository list");
}
}
use of org.apache.felix.bundlerepository.Repository in project aries by apache.
the class MinimumImportsTest method testAppUsingAriesApplicationManager.
@Test
public void testAppUsingAriesApplicationManager() throws Exception {
// Register a BlueprintListener to listen for the events from the BlueprintContainer for the bundle in the appmgrclienttest.eba
AppMgrClientBlueprintListener acbl = new AppMgrClientBlueprintListener();
ServiceRegistration sr = bundleContext.registerService("org.osgi.service.blueprint.container.BlueprintListener", acbl, null);
AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("appmgrclienttest.eba")));
RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
Repository[] repos = repositoryAdmin.listRepositories();
for (Repository repo : repos) {
repositoryAdmin.removeRepository(repo.getURI());
}
repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
AriesApplicationContext ctx = manager.install(app);
ctx.start();
int sleepfor = 3000;
while ((acbl.success == null || acbl.success == false) && sleepfor > 0) {
Thread.sleep(100);
sleepfor -= 100;
}
assertNotNull("Timed out - didn't receive Blueprint CREATED or FAILURE event", acbl.success);
assertTrue("Received Blueprint FAILURE event", acbl.success);
ctx.stop();
manager.uninstall(ctx);
sr.unregister();
}
use of org.apache.felix.bundlerepository.Repository in project aries by apache.
the class OBRAppManagerTest method testAppWithApplicationManifest.
@Test
public void testAppWithApplicationManifest() throws Exception {
RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
Repository[] repos = repositoryAdmin.listRepositories();
for (Repository repo : repos) {
Resource[] resources = repo.getResources();
for (Resource r : resources) {
Capability[] cs = r.getCapabilities();
for (Capability c : cs) {
System.out.println(c.getName() + " : " + c.getProperties());
}
}
}
AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
app = manager.resolve(app);
//installing requires a valid url for the bundle in repository.xml.
AriesApplicationContext ctx = manager.install(app);
ctx.start();
HelloWorld hw = context().getService(HelloWorld.class);
String result = hw.getMessage();
assertEquals(result, "hello world");
ctx.stop();
manager.uninstall(ctx);
}
Aggregations