Search in sources :

Example 6 with CheckResult

use of aQute.bnd.deployer.repository.api.CheckResult in project bnd by bndtools.

the class TestR5Recognition method testUndecidable.

public static void testUndecidable() throws Exception {
    String testdata;
    ByteArrayInputStream stream;
    CheckResult result;
    testdata = "<?xml version='1.0' encoding='utf-8'?><repository name='index1'/>";
    stream = new ByteArrayInputStream(testdata.getBytes());
    assertEquals(undecided, new R5RepoContentProvider().checkStream("xxx", stream).getDecision());
    testdata = "<repository><resource/></repository>";
    stream = new ByteArrayInputStream(testdata.getBytes());
    result = new R5RepoContentProvider().checkStream("xxx", stream);
    assertEquals(undecided, result.getDecision());
    testdata = "<repository><referral/></repository>";
    stream = new ByteArrayInputStream(testdata.getBytes());
    result = new R5RepoContentProvider().checkStream("xxx", stream);
    assertEquals(undecided, result.getDecision());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CheckResult(aQute.bnd.deployer.repository.api.CheckResult)

Example 7 with CheckResult

use of aQute.bnd.deployer.repository.api.CheckResult in project bnd by bndtools.

the class RepoResourceUtils method readIndex.

public static void readIndex(String name, URI baseUri, InputStream stream, Collection<IRepositoryContentProvider> contentProviders, IRepositoryIndexProcessor listener, LogService log) throws Exception {
    // Make sure we have a buffering stream
    try (InputStream bufferedStream = stream.markSupported() ? stream : new BufferedInputStream(stream)) {
        // Find a compatible content provider for the input
        IRepositoryContentProvider selectedProvider = null;
        IRepositoryContentProvider maybeSelectedProvider = null;
        for (IRepositoryContentProvider provider : contentProviders) {
            CheckResult checkResult;
            try {
                bufferedStream.mark(READ_AHEAD_MAX);
                checkResult = provider.checkStream(name, new ProtectedStream(bufferedStream));
            } finally {
                bufferedStream.reset();
            }
            if (checkResult.getDecision() == Decision.accept) {
                selectedProvider = provider;
                break;
            } else if (checkResult.getDecision() == Decision.undecided) {
                log.log(LogService.LOG_WARNING, String.format("Content provider '%s' was unable to determine compatibility with index at URL '%s': %s", provider.getName(), baseUri, checkResult.getMessage()));
                if (maybeSelectedProvider == null)
                    maybeSelectedProvider = provider;
            }
        }
        // undecided provider, with an appropriate warning.
        if (selectedProvider == null) {
            if (maybeSelectedProvider != null) {
                selectedProvider = maybeSelectedProvider;
                log.log(LogService.LOG_WARNING, String.format("No content provider matches the specified index unambiguously. Selected '%s' arbitrarily.", selectedProvider.getName()));
            } else {
                throw new IOException("Invalid repository index: no configured content provider understands the specified index.");
            }
        }
        // Finally, parse the damn file.
        selectedProvider.parseIndex(bufferedStream, baseUri, listener, log);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) CheckResult(aQute.bnd.deployer.repository.api.CheckResult) IRepositoryContentProvider(aQute.bnd.deployer.repository.api.IRepositoryContentProvider) IOException(java.io.IOException)

Example 8 with CheckResult

use of aQute.bnd.deployer.repository.api.CheckResult in project bnd by bndtools.

the class TestObrRecognition method testUnparseable.

public static void testUnparseable() throws Exception {
    String testdata = "<?xml version='1.0' encoding='utf-8'?>" + "<repository name='index1'>";
    ByteArrayInputStream stream = new ByteArrayInputStream(testdata.getBytes());
    CheckResult result = new ObrContentProvider(indexer).checkStream("xxx", stream);
    assertEquals(reject, result.getDecision());
    assertTrue(result.getException() != null && result.getException() instanceof XMLStreamException);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) CheckResult(aQute.bnd.deployer.repository.api.CheckResult)

Example 9 with CheckResult

use of aQute.bnd.deployer.repository.api.CheckResult in project bnd by bndtools.

the class TestObrRecognition method testRejectOnCapabilityChildElementName.

public static void testRejectOnCapabilityChildElementName() throws Exception {
    String testdata;
    ByteArrayInputStream stream;
    CheckResult result;
    // Definitely wrong
    testdata = "<repository><resource><capability><XXX/></capability></resource><repo...";
    stream = new ByteArrayInputStream(testdata.getBytes());
    result = new ObrContentProvider(indexer).checkStream("xxx", stream);
    assertEquals(reject, result.getDecision());
    assertNull(result.getException());
    // Definitely right
    testdata = "<repository><resource><capability><p/></capability></resource><repo...";
    stream = new ByteArrayInputStream(testdata.getBytes());
    result = new ObrContentProvider(indexer).checkStream("xxx", stream);
    assertEquals(accept, result.getDecision());
    // Arbitrary elements under resource are allowed
    testdata = "<repository><resource><XXX/><YYY/><capability><p/></capability><ZZZ/></resource><repo...";
    stream = new ByteArrayInputStream(testdata.getBytes());
    result = new ObrContentProvider(indexer).checkStream("xxx", stream);
    assertEquals(accept, result.getDecision());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CheckResult(aQute.bnd.deployer.repository.api.CheckResult)

Example 10 with CheckResult

use of aQute.bnd.deployer.repository.api.CheckResult in project bnd by bndtools.

the class TestR5Recognition method testAcceptExtensionElementOtherNamespace.

public static void testAcceptExtensionElementOtherNamespace() throws Exception {
    String testdata;
    ByteArrayInputStream stream;
    CheckResult result;
    // Arbitrary elements under resource are allowed
    testdata = "<repository><resource><foo:XXX xmlns:foo='http://org.example/ns'/><YYY/><capability><attribute/></capability><ZZZ/></resource><repo...";
    stream = new ByteArrayInputStream(testdata.getBytes());
    result = new R5RepoContentProvider().checkStream("xxx", stream);
    assertEquals(accept, result.getDecision());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CheckResult(aQute.bnd.deployer.repository.api.CheckResult)

Aggregations

CheckResult (aQute.bnd.deployer.repository.api.CheckResult)12 ByteArrayInputStream (java.io.ByteArrayInputStream)9 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 IRepositoryContentProvider (aQute.bnd.deployer.repository.api.IRepositoryContentProvider)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1