Search in sources :

Example 36 with CmrRepository

use of org.eclipse.ceylon.cmr.api.CmrRepository in project ceylon by eclipse.

the class ModuleLoaderTest method testNoDots.

@Test
public void testNoDots() throws ModuleNotFoundException {
    CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    Map<String, String> extraModules = new HashMap<>();
    extraModules.put("maven:aopalliance:aopalliance", "1.0");
    TestableModuleLoader moduleLoader = new TestableModuleLoader(manager, null, extraModules, true);
    // org.antlr:stringtemplate:3.2.1
    // com.google.inject:guice:4.0
    moduleLoader.loadModule("maven:antlr:antlr", "2.7.7", ModuleScope.RUNTIME);
    // Check that we got them
    Assert.assertEquals("2.7.7", moduleLoader.getModuleVersion("maven:antlr:antlr"));
    Assert.assertEquals("1.0", moduleLoader.getModuleVersion("maven:aopalliance:aopalliance"));
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) HashMap(java.util.HashMap) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) Test(org.junit.Test)

Example 37 with CmrRepository

use of org.eclipse.ceylon.cmr.api.CmrRepository in project ceylon by eclipse.

the class ModuleLoaderTest method testNoDotsFromMaven.

@Test
public void testNoDotsFromMaven() throws ModuleNotFoundException {
    CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    Map<String, String> extraModules = new HashMap<>();
    extraModules.put("org.antlr:stringtemplate", "3.2.1");
    TestableModuleLoader moduleLoader = new TestableModuleLoader(manager, null, extraModules, true);
    moduleLoader.loadModule("com.google.inject:guice", "4.0", ModuleScope.RUNTIME);
    // Check that we got them
    Assert.assertEquals("2.7.7", moduleLoader.getModuleVersion("maven:antlr:antlr"));
    Assert.assertEquals("1.0", moduleLoader.getModuleVersion("maven:aopalliance:aopalliance"));
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) HashMap(java.util.HashMap) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) Test(org.junit.Test)

Example 38 with CmrRepository

use of org.eclipse.ceylon.cmr.api.CmrRepository in project ceylon by eclipse.

the class ModuleLoaderTest method testModuleLoaderDirectImportsNotExcluded.

@Test
public void testModuleLoaderDirectImportsNotExcluded() throws ModuleNotFoundException {
    CmrRepository repository = AetherRepository.createRepository(log, settings, false, 60000, null);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    Map<String, String> extraModules = new HashMap<>();
    extraModules.put("org.springframework.cloud:spring-cloud-starter-eureka-server", "1.1.0.RC1");
    TestableModuleLoader moduleLoader = new TestableModuleLoader(manager, null, extraModules, false);
    moduleLoader.loadModule("org.springframework.cloud:spring-cloud-starter-eureka-server", "1.1.0.RC1", ModuleScope.RUNTIME);
    // Those should not be there
    Assert.assertNull(moduleLoader.getModuleVersion("jackson-dataformat-xml:com.fasterxml.jackson.dataformat"));
    moduleLoader.cleanup();
    // now add a direct import
    moduleLoader.loadModule("com.fasterxml.jackson.dataformat:jackson-dataformat-xml", "2.6.5", ModuleScope.RUNTIME);
    // Should be there
    Assert.assertEquals("2.6.5", moduleLoader.getModuleVersion("com.fasterxml.jackson.dataformat:jackson-dataformat-xml"));
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) HashMap(java.util.HashMap) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) Test(org.junit.Test)

Example 39 with CmrRepository

use of org.eclipse.ceylon.cmr.api.CmrRepository 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;
    }
}
Also used : ModuleDetails(org.eclipse.ceylon.cmr.api.ModuleSearchResult.ModuleDetails) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) ModuleSearchResult(org.eclipse.ceylon.cmr.api.ModuleSearchResult) TreeSet(java.util.TreeSet)

Example 40 with CmrRepository

use of org.eclipse.ceylon.cmr.api.CmrRepository in project ceylon by eclipse.

the class AbstractNodeRepositoryManager method getRepositoriesForContext.

private List<CmrRepository> getRepositoriesForContext(ArtifactContext context) {
    List<CmrRepository> reps = getRepositories();
    CmrRepository rep = (CmrRepository) context.getSearchRepository();
    if (rep != null) {
        if (reps.contains(rep)) {
            return Collections.singletonList(rep);
        } else {
            return Collections.emptyList();
        }
    }
    return reps;
}
Also used : CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository)

Aggregations

CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)43 File (java.io.File)26 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)26 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)24 Test (org.junit.Test)24 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)15 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)9 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)5 DefaultRepository (org.eclipse.ceylon.cmr.impl.DefaultRepository)4 Node (org.eclipse.ceylon.cmr.spi.Node)3 IOException (java.io.IOException)2 URL (java.net.URL)2 TreeSet (java.util.TreeSet)2 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)2 ModuleSearchResult (org.eclipse.ceylon.cmr.api.ModuleSearchResult)2 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)2 ModuleVersionQuery (org.eclipse.ceylon.cmr.api.ModuleVersionQuery)2