use of org.apache.felix.bundlerepository.Repository in project karaf by apache.
the class ResolveCommand method doExecute.
protected void doExecute(RepositoryAdmin admin) throws Exception {
List<Repository> repositories = new ArrayList<>();
repositories.add(admin.getSystemRepository());
if (!noLocal) {
repositories.add(admin.getLocalRepository());
}
if (!noRemote) {
repositories.addAll(Arrays.asList(admin.listRepositories()));
}
Resolver resolver = admin.resolver(repositories.toArray(new Repository[repositories.size()]));
for (Requirement requirement : parseRequirements(admin, requirements)) {
resolver.add(requirement);
}
if (resolver.resolve(optional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
Resource[] resources;
resources = resolver.getRequiredResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println("Required resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
if (why) {
Reason[] req = resolver.getReason(resource);
for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
if (!req[reqIdx].getRequirement().isOptional()) {
Resource r = req[reqIdx].getResource();
if (r != null) {
System.out.println(" - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
} else {
System.out.println(" - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
}
}
}
}
}
}
resources = resolver.getOptionalResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println();
System.out.println("Optional resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
if (why) {
Reason[] req = resolver.getReason(resource);
for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
if (!req[reqIdx].getRequirement().isOptional()) {
Resource r = req[reqIdx].getResource();
if (r != null) {
System.out.println(" - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
} else {
System.out.println(" - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
}
}
}
}
}
}
if (deploy || start) {
try {
System.out.print("\nDeploying...");
resolver.deploy(start ? Resolver.START : 0);
System.out.println("done.");
} catch (IllegalStateException ex) {
System.err.println(ex);
}
}
} else {
Reason[] reqs = resolver.getUnsatisfiedRequirements();
if ((reqs != null) && (reqs.length > 0)) {
System.out.println("Unsatisfied requirement(s):");
printUnderline(System.out, 27);
for (Reason req : reqs) {
System.out.println(" " + req.getRequirement().getName() + ":" + req.getRequirement().getFilter());
System.out.println(" " + req.getResource().getPresentationName());
}
} else {
System.out.println("Could not resolve targets.");
}
}
}
use of org.apache.felix.bundlerepository.Repository in project aries by apache.
the class Aries1522Test 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, "aries1523fragment.jar");
assertTrue("The fragment 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 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.Repository 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);
}
}
use of org.apache.felix.bundlerepository.Repository in project aries by apache.
the class Aries1608Test 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