Search in sources :

Example 16 with Repository

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.");
        }
    }
}
Also used : Requirement(org.apache.felix.bundlerepository.Requirement) Repository(org.apache.felix.bundlerepository.Repository) Resolver(org.apache.felix.bundlerepository.Resolver) ArrayList(java.util.ArrayList) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason)

Example 17 with Repository

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();
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) FileWriter(java.io.FileWriter) Resource(org.apache.felix.bundlerepository.Resource) File(java.io.File)

Example 18 with Repository

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);
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) BundleContext(org.osgi.framework.BundleContext)

Example 19 with Repository

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);
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) BundleContext(org.osgi.framework.BundleContext)

Example 20 with Repository

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);
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Repository (org.apache.felix.bundlerepository.Repository)24 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)13 File (java.io.File)12 Resource (org.apache.felix.bundlerepository.Resource)10 AriesApplication (org.apache.aries.application.management.AriesApplication)8 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)8 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)8 Test (org.junit.Test)8 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)5 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)5 ArrayList (java.util.ArrayList)4 FileWriter (java.io.FileWriter)3 InputStreamReader (java.io.InputStreamReader)3 PlatformRepository (org.apache.aries.application.management.spi.repository.PlatformRepository)3 BundleContext (org.osgi.framework.BundleContext)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Content (org.apache.aries.application.Content)2 DeploymentContent (org.apache.aries.application.DeploymentContent)2 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)2