Search in sources :

Example 1 with Resolution

use of biz.aQute.resolve.ResolverValidator.Resolution in project bnd by bndtools.

the class ResolveCommand method _validate.

public void _validate(ValidateOptions options) throws Exception {
    ResourceBuilder system = new ResourceBuilder();
    system.addEE(options.ee(EE.JavaSE_1_8));
    if (options.core() != null)
        system.addManifest(options.core().getManifest());
    if (options.packages() != null)
        system.addExportPackages(options.packages());
    if (options.capabilities() != null)
        system.addProvideCapabilities(options.capabilities());
    if (options.system() != null) {
        File f = IO.getFile(options.system());
        if (!f.isFile()) {
            error("Specified system file but not found: %s", f);
            return;
        }
        Domain domain = Domain.domain(f);
        system.addManifest(domain);
    }
    List<String> args = options._arguments();
    File index = getFile(args.remove(0));
    logger.debug("validating {}", index);
    ResolverValidator validator = new ResolverValidator(bnd);
    validator.use(bnd);
    validator.addRepository(index.toURI());
    validator.setSystem(system.build());
    List<Resolution> result = validator.validate();
    Set<Requirement> done = new HashSet<>();
    for (Resolution res : result) {
        if (options.all()) {
            bnd.out.format("%s %-60s%n", res.succeeded ? "OK" : "**", res.resource, res.message == null ? "" : res.message);
        }
        if (!res.succeeded) {
            for (Requirement req : res.missing) {
                if (done.contains(req))
                    continue;
                bnd.out.format("    missing   %s%n", req);
                done.add(req);
            }
            if (options.all()) {
                for (Requirement req : res.repos) {
                    bnd.out.format("    repos     %s%n", req);
                }
                for (Requirement req : res.system) {
                    bnd.out.format("    system    %s%n", req);
                }
                for (Requirement req : res.optionals) {
                    bnd.out.format("    optional  %s%n", req);
                }
            }
        }
    }
    bnd.getInfo(validator);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) ResolverValidator(biz.aQute.resolve.ResolverValidator) Domain(aQute.bnd.osgi.Domain) File(java.io.File) Resolution(biz.aQute.resolve.ResolverValidator.Resolution) HashSet(java.util.HashSet)

Example 2 with Resolution

use of biz.aQute.resolve.ResolverValidator.Resolution in project bnd by bndtools.

the class ValidatorTest method testDelibarateFailWithSpecificResources.

public void testDelibarateFailWithSpecificResources() throws Exception {
    try (ResolverValidator validator = new ResolverValidator()) {
        ResourceBuilder system = new ResourceBuilder();
        system.addEE(EE.JavaSE_1_8);
        system.addManifest(OSGI_CORE.R6_0_0.getManifest());
        validator.setSystem(system.build());
        validator.setTrace(true);
        List<Resource> resources = XMLResourceParser.getResources(IO.getFile("testdata/repo5-broken.index.xml").toURI());
        List<Resolution> resolutions = validator.validate(resources);
        assertFalse(validator.check());
        assertEquals(1, resolutions.size());
        String message = resolutions.get(0).message;
        String expectedToContain = "missing requirement org.apache.felix.gogo.api";
        assertTrue(String.format("expected to contain <%s> but was <%s>", expectedToContain, message), message.contains(expectedToContain));
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource) Resolution(biz.aQute.resolve.ResolverValidator.Resolution)

Example 3 with Resolution

use of biz.aQute.resolve.ResolverValidator.Resolution in project bnd by bndtools.

the class ValidatorTest method testDelibarateFail.

public void testDelibarateFail() throws Exception {
    try (ResolverValidator validator = new ResolverValidator()) {
        ResourceBuilder system = new ResourceBuilder();
        system.addEE(EE.JavaSE_1_8);
        system.addManifest(OSGI_CORE.R6_0_0.getManifest());
        validator.setSystem(system.build());
        validator.setTrace(true);
        validator.addRepository(IO.getFile("testdata/repo5-broken.index.xml").toURI());
        List<Resolution> resolutions = validator.validate();
        assertFalse(validator.check());
        assertEquals(1, resolutions.size());
        String message = resolutions.get(0).message;
        String expectedToContain = "missing requirement org.apache.felix.gogo.api";
        assertTrue(String.format("expected to contain <%s> but was <%s>", expectedToContain, message), message.contains(expectedToContain));
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resolution(biz.aQute.resolve.ResolverValidator.Resolution)

Example 4 with Resolution

use of biz.aQute.resolve.ResolverValidator.Resolution in project bnd by bndtools.

the class HugeRepositoryTest method testHugeWithSpecificResourcesAndDuplication.

public void testHugeWithSpecificResourcesAndDuplication() throws Exception {
    try (ResolverValidator validator = new ResolverValidator()) {
        ResourceBuilder resourceBuilder = new ResourceBuilder();
        resourceBuilder.addEE(EE.JavaSE_1_7);
        resourceBuilder.addManifest(OSGI_CORE.R6_0_0.getManifest());
        validator.setSystem(resourceBuilder.build());
        validator.setTrace(true);
        validator.addRepository(IO.getFile("testdata/collaboration-1.0-index.xml.gz").toURI());
        validator.addRepository(IO.getFile("testdata/forms-and-workflow-1.0-index.xml.gz").toURI());
        validator.addRepository(IO.getFile("testdata/foundation-1.0-index.xml.gz").toURI());
        validator.addRepository(IO.getFile("testdata/target.platform.index.xml.gz").toURI());
        validator.addRepository(IO.getFile("testdata/web-experience-1.0-index.xml.gz").toURI());
        List<Resource> resources = XMLResourceParser.getResources(IO.getFile("testdata/foundation-1.0-index.xml.gz").toURI());
        List<Resolution> resolutions = validator.validate(resources);
        assertTrue(validator.check());
        assertEquals(resources.size(), resolutions.size());
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) ResolverValidator(biz.aQute.resolve.ResolverValidator) Resource(org.osgi.resource.Resource) Resolution(biz.aQute.resolve.ResolverValidator.Resolution)

Example 5 with Resolution

use of biz.aQute.resolve.ResolverValidator.Resolution in project bnd by bndtools.

the class HugeRepositoryTest method testHugeWithSpecificResources.

public void testHugeWithSpecificResources() throws Exception {
    try (ResolverValidator validator = new ResolverValidator()) {
        ResourceBuilder system = new ResourceBuilder();
        system.addEE(EE.JavaSE_1_7);
        system.addManifest(OSGI_CORE.R6_0_0.getManifest());
        validator.setSystem(system.build());
        validator.setTrace(true);
        validator.addRepository(IO.getFile("testdata/collaboration-1.0-index.xml.gz").toURI());
        validator.addRepository(IO.getFile("testdata/forms-and-workflow-1.0-index.xml.gz").toURI());
        validator.addRepository(IO.getFile("testdata/foundation-1.0-index.xml.gz").toURI());
        validator.addRepository(IO.getFile("testdata/target.platform.index.xml.gz").toURI());
        List<Resource> resources = XMLResourceParser.getResources(IO.getFile("testdata/web-experience-1.0-index.xml.gz").toURI());
        List<Resolution> resolutions = validator.validate(resources);
        assertTrue(validator.check());
        assertEquals(resources.size(), resolutions.size());
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) ResolverValidator(biz.aQute.resolve.ResolverValidator) Resource(org.osgi.resource.Resource) Resolution(biz.aQute.resolve.ResolverValidator.Resolution)

Aggregations

ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)5 Resolution (biz.aQute.resolve.ResolverValidator.Resolution)5 ResolverValidator (biz.aQute.resolve.ResolverValidator)3 Resource (org.osgi.resource.Resource)3 Domain (aQute.bnd.osgi.Domain)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Requirement (org.osgi.resource.Requirement)1