use of org.eclipse.ceylon.cmr.api.ModuleSearchResult in project ceylon by eclipse.
the class HerdTestCase method testHerdAndRepoSearchPaged2.
@Test
public void testHerdAndRepoSearchPaged2() throws Exception {
// first page
ModuleDetails[] expected = new ModuleDetails[] { ceylonCollectionDetails, frEpardaudTestDetails };
ModuleSearchResult results = testSearchResults("ceylon", Type.JVM, expected, 0L, 2L, getDualRepositoryManager());
// check end indices
long[] pagingInfo = results.getNextPagingInfo();
Assert.assertNotNull(pagingInfo);
Assert.assertEquals(3, pagingInfo.length);
Assert.assertEquals(0, pagingInfo[0]);
Assert.assertEquals(0, pagingInfo[1]);
Assert.assertEquals(2, pagingInfo[2]);
// second page
expected = new ModuleDetails[] { frEpardaudTest2DetailsJvm, new ModuleDetails("ceylon", "hello", null, null, ASL, set("The Ceylon Team"), set("1.2.1"), deps(langmod), types(art(".CAR", 8, 0)), true, "The Herd"), new ModuleDetails("ceylon", "hello2", null, "A test", ASL, set("The Ceylon Team"), set("1.0.0"), deps(langmod), types(art(".CAR", 8, 0)), true, "The Herd"), new ModuleDetails("ceylon", "moduletest", null, null, "GPLv2", set("The Ceylon Team"), set("0.1"), deps(hello), types(art(".CAR", 3, 0)), true, "The Herd") };
results = testSearchResults("ceylon", Type.JVM, expected, 0L, 6L, getDualRepositoryManager(), pagingInfo);
// check end indices
pagingInfo = results.getNextPagingInfo();
Assert.assertNotNull(pagingInfo);
Assert.assertEquals(3, pagingInfo.length);
Assert.assertEquals(3, pagingInfo[0]);
Assert.assertEquals(0, pagingInfo[1]);
Assert.assertEquals(3, pagingInfo[2]);
// again first page
ModuleDetails[] expected2 = new ModuleDetails[] { ceylonCollectionDetails, frEpardaudTestDetails, frEpardaudTest2DetailsJvm, new ModuleDetails("ceylon", "hello", null, null, ASL, set("The Ceylon Team"), set("1.2.1"), deps(langmod), types(art(".CAR", 8, 0)), true, "The Herd") };
ModuleSearchResult results2 = testSearchResults("ceylon", Type.JVM, expected2, 0L, 4L, getDualRepositoryManager());
// check end indices
long[] pagingInfo2 = results2.getNextPagingInfo();
Assert.assertNotNull(pagingInfo2);
Assert.assertEquals(3, pagingInfo2.length);
Assert.assertEquals(1, pagingInfo2[0]);
Assert.assertEquals(0, pagingInfo2[1]);
Assert.assertEquals(3, pagingInfo2[2]);
// second page
expected2 = new ModuleDetails[] { new ModuleDetails("ceylon", "hello2", null, "A test", ASL, set("The Ceylon Team"), set("1.0.0"), deps(langmod), types(art(".CAR", 8, 0)), true, "The Herd"), new ModuleDetails("ceylon", "moduletest", null, null, "GPLv2", set("The Ceylon Team"), set("0.1"), deps(hello), types(art(".CAR", 3, 0)), true, "The Herd") };
results2 = testSearchResults("ceylon", Type.JVM, expected2, 0L, 4L, getDualRepositoryManager(), pagingInfo2);
// check end indices
pagingInfo2 = results2.getNextPagingInfo();
Assert.assertNotNull(pagingInfo2);
Assert.assertEquals(3, pagingInfo2.length);
Assert.assertEquals(3, pagingInfo2[0]);
Assert.assertEquals(0, pagingInfo2[1]);
Assert.assertEquals(3, pagingInfo2[2]);
}
use of org.eclipse.ceylon.cmr.api.ModuleSearchResult in project ceylon by eclipse.
the class SmokeTestCase method testSearchJDKModulesPaged.
@Test
public void testSearchJDKModulesPaged() throws Exception {
Assume.assumeTrue(JDKUtils.jdk == JDKUtils.JDK.JDK8);
RepositoryManager repoManager = getJDKRepositoryManager();
// first page
ModuleDetails[] expected = new ModuleDetails[] { jdkModule("java.auth", "JDK module java.auth"), jdkModule("java.auth.kerberos", "JDK module java.auth.kerberos"), jdkModule("java.base", "JDK module java.base"), jdkModule("java.compiler", "JDK module java.compiler"), jdkModule("java.corba", "JDK module java.corba"), jdkModule("java.desktop", "JDK module java.desktop"), jdkModule("java.instrument", "JDK module java.instrument"), jdkModule("java.jdbc", "JDK module java.jdbc"), jdkModule("java.jdbc.rowset", "JDK module java.jdbc.rowset"), jdkModule("java.logging", "JDK module java.logging"), jdkModule("java.management", "JDK module java.management"), jdkModule("java.prefs", "JDK module java.prefs"), jdkModule("java.rmi", "JDK module java.rmi"), jdkModule("java.security.acl", "JDK module java.security.acl"), jdkModule("java.tls", "JDK module java.tls"), jdkModule("javafx.base", "JDK module javafx.base"), jdkModule("javafx.controls", "JDK module javafx.controls"), jdkModule("javafx.deploy", "JDK module javafx.deploy"), jdkModule("javafx.fxml", "JDK module javafx.fxml"), jdkModule("javafx.graphics", "JDK module javafx.graphics") };
ModuleSearchResult results = testSearchResults("", Type.JVM, expected, 0l, 20l, repoManager);
Assert.assertEquals(20, results.getCount());
Assert.assertEquals(true, results.getHasMoreResults());
Assert.assertEquals(0, results.getStart());
// second page
expected = new ModuleDetails[] { jdkModule("javafx.media", "JDK module javafx.media"), jdkModule("javafx.swing", "JDK module javafx.swing"), jdkModule("javafx.web", "JDK module javafx.web"), jdkModule("javax.annotation", "JDK module javax.annotation"), jdkModule("javax.jaxws", "JDK module javax.jaxws"), jdkModule("javax.naming", "JDK module javax.naming"), jdkModule("javax.script", "JDK module javax.script"), jdkModule("javax.transaction", "JDK module javax.transaction"), jdkModule("javax.xml", "JDK module javax.xml"), jdkModule("javax.xmldsig", "JDK module javax.xmldsig"), jdkModule("oracle.jdk.auth", "JDK module oracle.jdk.auth"), jdkModule("oracle.jdk.base", "JDK module oracle.jdk.base"), jdkModule("oracle.jdk.compat", "JDK module oracle.jdk.compat"), jdkModule("oracle.jdk.corba", "JDK module oracle.jdk.corba"), jdkModule("oracle.jdk.cosnaming", "JDK module oracle.jdk.cosnaming"), jdkModule("oracle.jdk.deploy", "JDK module oracle.jdk.deploy"), jdkModule("oracle.jdk.desktop", "JDK module oracle.jdk.desktop"), jdkModule("oracle.jdk.httpserver", "JDK module oracle.jdk.httpserver"), jdkModule("oracle.jdk.instrument", "JDK module oracle.jdk.instrument"), jdkModule("oracle.jdk.jaxp", "JDK module oracle.jdk.jaxp") };
results = testSearchResults("", Type.JVM, expected, results.getStart() + results.getCount(), 20l, repoManager, results.getNextPagingInfo());
Assert.assertEquals(20, results.getCount());
Assert.assertEquals(true, results.getHasMoreResults());
Assert.assertEquals(20, results.getStart());
// third page
expected = new ModuleDetails[] { jdkModule("oracle.jdk.jaxws", "JDK module oracle.jdk.jaxws"), jdkModule("oracle.jdk.jdbc.rowset", "JDK module oracle.jdk.jdbc.rowset"), jdkModule("oracle.jdk.jndi", "JDK module oracle.jdk.jndi"), jdkModule("oracle.jdk.logging", "JDK module oracle.jdk.logging"), jdkModule("oracle.jdk.management", "JDK module oracle.jdk.management"), jdkModule("oracle.jdk.management.iiop", "JDK module oracle.jdk.management.iiop"), jdkModule("oracle.jdk.rmi", "JDK module oracle.jdk.rmi"), jdkModule("oracle.jdk.scripting", "JDK module oracle.jdk.scripting"), jdkModule("oracle.jdk.sctp", "JDK module oracle.jdk.sctp"), jdkModule("oracle.jdk.security.acl", "JDK module oracle.jdk.security.acl"), jdkModule("oracle.jdk.smartcardio", "JDK module oracle.jdk.smartcardio"), jdkModule("oracle.jdk.tools.base", "JDK module oracle.jdk.tools.base"), jdkModule("oracle.jdk.tools.jaxws", "JDK module oracle.jdk.tools.jaxws"), jdkModule("oracle.jdk.tools.jre", "JDK module oracle.jdk.tools.jre"), jdkModule("oracle.jdk.xmldsig", "JDK module oracle.jdk.xmldsig"), jdkModule("oracle.sun.charsets", "JDK module oracle.sun.charsets") };
results = testSearchResults("", Type.JVM, expected, results.getStart() + results.getCount(), 20l, repoManager, results.getNextPagingInfo());
Assert.assertEquals(16, results.getCount());
Assert.assertEquals(false, results.getHasMoreResults());
Assert.assertEquals(40, results.getStart());
}
use of org.eclipse.ceylon.cmr.api.ModuleSearchResult in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method searchModules.
@Override
public ModuleSearchResult searchModules(ModuleQuery query) {
if (!query.isPaging()) {
// that's pretty simple
ModuleSearchResult result = new ModuleSearchResult();
for (CmrRepository root : getRepositories()) {
if (query.getNamespace() == null || query.getNamespace().equals(root.getNamespace())) {
root.searchModules(query, result);
}
}
return result;
} else {
// we need to merge manually
List<CmrRepository> repos = getRepositories();
ModuleSearchResult[] results = new ModuleSearchResult[repos.size()];
// keep an overall module name ordering
SortedSet<String> names = new TreeSet<>();
int i = 0;
long[] pagingInfo = query.getPagingInfo();
if (pagingInfo != null) {
// check its length
if (pagingInfo.length != repos.size())
throw new IllegalArgumentException("Paging info is not the same size as roots, it must have come from a different RepositoryManager");
}
Long start = query.getStart();
for (CmrRepository root : repos) {
if (query.getNamespace() == null || query.getNamespace().equals(root.getNamespace())) {
ModuleSearchResult result = new ModuleSearchResult();
// adapt the start index if required
if (pagingInfo != null)
query.setStart(pagingInfo[i]);
root.searchModules(query, result);
results[i++] = result;
names.addAll(result.getModuleNames());
}
}
// restore the query start
query.setStart(start);
// now merge results
ModuleSearchResult result = new ModuleSearchResult();
long[] resultPagingInfo = new long[repos.size()];
// initialise it if we need to
if (pagingInfo != null)
System.arraycopy(pagingInfo, 0, resultPagingInfo, 0, resultPagingInfo.length);
result.setNextPagingInfo(resultPagingInfo);
i = 0;
for (String module : names) {
// stop if we exceeded the count
if (query.getCount() != null && i++ == query.getCount())
break;
// collect every module result for that name from the results
int repo = 0;
for (ModuleSearchResult resultPart : results) {
ModuleDetails details = resultPart.getResult(module);
// did we find anything in that repo?
if (details == null) {
repo++;
continue;
} else {
// count one result for this repo
resultPagingInfo[repo++]++;
}
// merge it
result.addResult(module, details);
}
}
// see if there are any records left in next pages
int repo = 0;
for (ModuleSearchResult resultPart : results) {
// if we had more results in the first place then we must have another page
if (resultPart.getHasMoreResults()) {
result.setHasMoreResults(true);
break;
}
// see how many results we added from this repo
long resultsAddedForThisRepo;
if (pagingInfo != null)
resultsAddedForThisRepo = resultPagingInfo[repo] - pagingInfo[repo];
else
resultsAddedForThisRepo = resultPagingInfo[repo];
// did we have more results than we put in?
if (resultPart.getCount() > resultsAddedForThisRepo) {
result.setHasMoreResults(true);
break;
}
repo++;
}
// record where we started (i is one greater than the number of modules added)
if (query.getStart() != null)
result.setStart(query.getStart());
else
result.setStart(0);
// all done
return result;
}
}
use of org.eclipse.ceylon.cmr.api.ModuleSearchResult in project ceylon by eclipse.
the class CeylonInfoTool method getModules.
private Collection<ModuleDetails> getModules(RepositoryManager repoMgr, String namespace, String name, ModuleQuery.Type type, Integer jvmBinaryMajor, Integer jvmBinaryMinor, Integer jsBinaryMajor, Integer jsBinaryMinor) {
String queryString = name;
if (queryString.startsWith("*")) {
queryString = queryString.substring(1);
}
if (queryString.endsWith("*")) {
queryString = queryString.substring(0, queryString.length() - 1);
}
ModuleVersionQuery query = getModuleVersionQuery(namespace, queryString, null, type, jvmBinaryMajor, jvmBinaryMinor, jsBinaryMajor, jsBinaryMinor);
ModuleSearchResult result;
if (!name.startsWith("*") || name.equals("*")) {
result = repoMgr.completeModules(query);
} else {
result = repoMgr.searchModules(query);
}
return result.getResults();
}
Aggregations