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());
}
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);
}
}
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);
}
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());
}
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());
}
Aggregations