Search in sources :

Example 6 with CmrRepository

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

the class ModuleValidator method resolveModuleIfRequired.

private void resolveModuleIfRequired(Module module, boolean forCompiledModule, ModuleImport moduleImport, ImportDepth importDepth, LinkedList<Module> dependencyTree, Map<Module, ArtifactResult> alreadySearchedArtifacts) {
    if (!module.isAvailable()) {
        ArtifactResult artifact = null;
        boolean firstTime;
        if (alreadySearchedArtifacts.containsKey(module)) {
            artifact = alreadySearchedArtifacts.get(module);
            firstTime = false;
        } else {
            // try and load the module from the repository
            RepositoryManager repositoryManager = context.getRepositoryManager();
            if (repositoryManager.isValidNamespace(moduleImport.getNamespace())) {
                Exception exceptionOnGetArtifact = null;
                Iterable<String> searchedArtifactExtensions = moduleManager.getSearchedArtifactExtensions();
                ArtifactContext artifactContext = new ArtifactContext(moduleImport.getNamespace(), module.getNameAsString(), module.getVersion(), getArtifactSuffixes(searchedArtifactExtensions));
                listener.retrievingModuleArtifact(module, artifactContext);
                try {
                    artifact = repositoryManager.getArtifactResult(artifactContext);
                } catch (Exception e) {
                    exceptionOnGetArtifact = catchIfPossible(e);
                }
                if (artifact == null) {
                    boolean error = true;
                    if (ModuleUtil.isMavenModule(module.getNameAsString()) && !dependencyTree.isEmpty() && ModuleUtil.isMavenModule(dependencyTree.peekLast().getNameAsString()))
                        error = false;
                    // not there => error
                    ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, moduleManagerUtil, error);
                    listener.retrievingModuleArtifactFailed(module, artifactContext);
                } else {
                    listener.retrievingModuleArtifactSuccess(module, artifact);
                }
            } else {
                StringBuilder msg = new StringBuilder().append("unknown import namespace: '").append(moduleImport.getNamespace()).append("' should be one of ");
                TreeSet<String> namespaces = new TreeSet<String>();
                for (CmrRepository repo : repositoryManager.getRepositories()) {
                    namespaces.add(repo.getNamespace());
                }
                boolean first = true;
                for (String namespace : namespaces) {
                    if (first) {
                        first = false;
                    } else {
                        msg.append(", ");
                    }
                    msg.append("'").append(namespace).append("'");
                }
                // if (!MavenRepository.NAMESPACE.equals(moduleImport.getNamespace())) {
                // msg += " (if this is a Maven import make sure to add a 'maven:' prefix)";
                // }
                moduleManagerUtil.attachErrorToDependencyDeclaration(moduleImport, dependencyTree, msg.toString(), true);
            }
            alreadySearchedArtifacts.put(module, artifact);
            firstTime = true;
        }
        // a compiled module, then it MUST resolve it and make it available, so do try in this case.
        if (artifact != null && (firstTime || forCompiledModule)) {
            // parse module units and build module dependency and carry on
            listener.resolvingModuleArtifact(module, artifact);
            Module moduleOverride = moduleManager.overridesModule(artifact, module, moduleImport);
            if (moduleOverride != null) {
                if (importDepth.equals(ImportDepth.First)) {
                    moduleManagerUtil.attachErrorToDependencyDeclaration(moduleImport, dependencyTree, "project source module import is overridden in module overrides file: '" + moduleOverride.getNameAsString() + "/" + moduleOverride.getVersion() + "' overrides '" + module.getNameAsString() + "/" + module.getVersion() + "'", false);
                }
                module = moduleOverride;
            }
            moduleManagerUtil.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
        }
    }
}
Also used : TreeSet(java.util.TreeSet) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 7 with CmrRepository

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

the class HerdTestCase method getRepositoryManager.

private RepositoryManager getRepositoryManager(File root, boolean offline, int timeout, String apiVersion) throws Exception {
    RepositoryManagerBuilder builder = getRepositoryManagerBuilder(root, offline, timeout, java.net.Proxy.NO_PROXY);
    WebDAVContentStore rcs = new WebDAVContentStore(HERD_URL, log, false, 60000, java.net.Proxy.NO_PROXY, apiVersion);
    CmrRepository repo = new DefaultRepository(rcs.createRoot());
    return builder.addRepository(repo).buildRepository();
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) DefaultRepository(org.eclipse.ceylon.cmr.impl.DefaultRepository) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) WebDAVContentStore(org.eclipse.ceylon.cmr.webdav.WebDAVContentStore)

Example 8 with CmrRepository

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

the class SmokeTestCase method testMavenRemote.

@Test
public void testMavenRemote() throws Exception {
    RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
    CmrRepository externalRepo = MavenRepositoryHelper.getMavenRepository("https://repository.jboss.org/nexus/content/groups/public", log, false, 60000, java.net.Proxy.NO_PROXY);
    builder.addRepository(externalRepo);
    RepositoryManager manager = builder.buildRepository();
    ArtifactContext ac = new ArtifactContext(MavenRepository.NAMESPACE, "org.jboss:jboss-vfs", "3.0.1.GA", ArtifactContext.JAR);
    File file = null;
    try {
        file = manager.getArtifact(ac);
        Assert.assertNotNull(file);
        Assert.assertEquals("jboss-vfs-3.0.1.GA.jar", file.getName());
    } finally {
        // delete the jar, not the car
        ac.setSuffixes(ArtifactContext.JAR);
        manager.removeArtifact(ac);
        // temporary workaround, because the jar is not stored at the right place
        if (file != null)
            Assert.assertTrue(file.delete());
    }
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) Test(org.junit.Test)

Example 9 with CmrRepository

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

the class SmokeTestCase method testGetMultipleCached.

@Test
public void testGetMultipleCached() throws Exception {
    RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
    CmrRepository[] externalRepos = builder.repositoryBuilder().buildRepository(Constants.REPO_URL_CEYLON);
    for (CmrRepository repo : externalRepos) {
        builder.addRepository(repo);
    }
    RepositoryManager manager = builder.buildRepository();
    ArtifactContext artifact1 = new ArtifactContext(null, "ceylon.json", "1.0.0", ArtifactContext.CAR, ArtifactContext.SCRIPTS_ZIPPED, ArtifactContext.JS);
    List<ArtifactResult> json1 = manager.getArtifactResults(artifact1);
    Assert.assertNotNull("Module 'ceylon.json-1.0.0' not found", json1);
    Assert.assertEquals("Expected two artifacts for 'ceylon.json-1.0.0'", 2, json1.size());
    File root = new File(manager.getRepositories().get(1).getDisplayString());
    File missing = new File(root, "ceylon/json/1.0.0/ceylon.json-1.0.0.scripts.zip.missing");
    Assert.assertTrue("Marker file .missing not found", missing.exists());
    ArtifactContext artifact2 = new ArtifactContext(null, "ceylon.json", "1.0.0", ArtifactContext.CAR, ArtifactContext.SCRIPTS_ZIPPED, ArtifactContext.SRC);
    List<ArtifactResult> json2 = manager.getArtifactResults(artifact2);
    Assert.assertNotNull("Module 'ceylon.json-1.0.0' not found", json2);
    Assert.assertEquals("Expected two artifacts for 'ceylon.json-1.0.0'", 2, json2.size());
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Test(org.junit.Test)

Example 10 with CmrRepository

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

the class SmokeTestCase method testPropertiesGet.

@Test
public void testPropertiesGet() throws Exception {
    RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
    RepositoryBuilder rb = builder.repositoryBuilder();
    CmrRepository[] repositories = rb.buildRepository(Constants.REPO_URL_CEYLON);
    for (CmrRepository repo : repositories) {
        builder.addRepository(repo);
    }
    RepositoryManager manager = builder.buildRepository();
    ArtifactContext context = new ArtifactContext(null, "io.undertow.core", "1.0.0.Alpha1-9fdfd5f766", ArtifactContext.JAR);
    try {
        File artifact = manager.getArtifact(context);
        Assert.assertNotNull(artifact);
        File mp = new File(artifact.getParent(), ArtifactContext.MODULE_PROPERTIES);
        Assert.assertNotNull(mp.exists());
    } finally {
        manager.removeArtifact(context);
    }
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) RepositoryBuilder(org.eclipse.ceylon.cmr.api.RepositoryBuilder) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) Test(org.junit.Test)

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