Search in sources :

Example 11 with RepositoryManager

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

the class ModuleSourceMapper method resolveModule.

public void resolveModule(ArtifactResult artifact, Module module, ModuleImport moduleImport, LinkedList<Module> dependencyTree, List<PhasedUnits> phasedUnitsOfDependencies, boolean forCompiledModule) {
    // This implementation relies on the ability to read the model from source
    // the compiler for example subclasses this to read lazily and from the compiled model
    ArtifactContext artifactContext = new ArtifactContext(null, module.getNameAsString(), module.getVersion(), ArtifactContext.SRC);
    RepositoryManager repositoryManager = context.getRepositoryManager();
    Exception exceptionOnGetArtifact = null;
    ArtifactResult sourceArtifact = null;
    try {
        sourceArtifact = repositoryManager.getArtifactResult(artifactContext);
    } catch (Exception e) {
        exceptionOnGetArtifact = e;
    }
    if (sourceArtifact == null) {
        ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, this, true);
    } else {
        PhasedUnits modulePhasedUnits = createPhasedUnits();
        ClosableVirtualFile virtualArtifact = null;
        try {
            virtualArtifact = context.getVfs().getFromZipFile(sourceArtifact.artifact());
            modulePhasedUnits.parseUnit(virtualArtifact);
            // populate module.getDependencies()
            modulePhasedUnits.visitModules();
            addToPhasedUnitsOfDependencies(modulePhasedUnits, phasedUnitsOfDependencies, module);
        } catch (Exception e) {
            StringBuilder error = new StringBuilder("unable to read source artifact for ");
            error.append(artifactContext.toString());
            error.append("\ndue to connection error: ").append(e.getMessage());
            attachErrorToDependencyDeclaration(moduleImport, dependencyTree, error.toString(), true);
        } finally {
            if (virtualArtifact != null) {
                virtualArtifact.close();
            }
        }
    }
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 12 with RepositoryManager

use of org.eclipse.ceylon.cmr.api.RepositoryManager 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 13 with RepositoryManager

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

the class NamingTests method getDecls.

protected List<Declaration> getDecls(String resource) throws Exception {
    final String name = PKGNAME.replace('.', '/') + "/" + resource;
    File file = new File("test/src", name);
    if (!file.exists()) {
        throw new RuntimeException("Unable to find resource " + name);
    }
    RepositoryManagerBuilder builder = new RepositoryManagerBuilder(new NullLogger(), false, 20000, java.net.Proxy.NO_PROXY);
    RepositoryManager repoManager = builder.buildRepository();
    VFS vfs = new VFS();
    Context context = new Context(repoManager, vfs);
    PhasedUnits pus = new PhasedUnits(context);
    // Make the module manager think we're looking at this package
    // even though there's no module descriptor
    pus.getModuleSourceMapper().push(PKGNAME);
    pus.parseUnit(vfs.getFromFile(file), vfs.getFromFile(new File("test-src")));
    final java.util.List<PhasedUnit> listOfUnits = pus.getPhasedUnits();
    PhasedUnit pu = listOfUnits.get(0);
    pu.validateTree();
    pu.scanDeclarations();
    pu.scanTypeDeclarations();
    pu.validateRefinement();
    pu.analyseTypes();
    pu.analyseFlow();
    return pu.getDeclarations();
}
Also used : Context(org.eclipse.ceylon.compiler.typechecker.context.Context) VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) File(java.io.File) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 14 with RepositoryManager

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

the class AbstractTest method testListVersions.

protected void testListVersions(String query, String versionQuery, ModuleVersionDetails[] expected) throws Exception {
    RepositoryManager manager = getRepositoryManager();
    testListVersions(query, versionQuery, expected, manager);
}
Also used : RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager)

Example 15 with RepositoryManager

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

the class AbstractTest method testSearchResultsMember.

protected ModuleSearchResult testSearchResultsMember(String q, Type type, String members, boolean memberSearchExact, boolean memberSearchPackageOnly, ModuleDetails[] expected) throws Exception {
    ModuleQuery query = new ModuleQuery(q, type, Retrieval.ANY);
    query.setMemberName(members);
    query.setMemberSearchExact(memberSearchExact);
    query.setMemberSearchPackageOnly(memberSearchPackageOnly);
    RepositoryManager manager = getRepositoryManager();
    ModuleSearchResult results = manager.searchModules(query);
    compareSearchResults(expected, results);
    return results;
}
Also used : ModuleQuery(org.eclipse.ceylon.cmr.api.ModuleQuery) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ModuleSearchResult(org.eclipse.ceylon.cmr.api.ModuleSearchResult)

Aggregations

RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)95 Test (org.junit.Test)71 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)68 File (java.io.File)47 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)32 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)26 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)23 ModuleDetails (org.eclipse.ceylon.cmr.api.ModuleSearchResult.ModuleDetails)14 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)11 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)8 HashMap (java.util.HashMap)7 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ArrayList (java.util.ArrayList)5 JsModuleManagerFactory (org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory)5 ModuleSearchResult (org.eclipse.ceylon.cmr.api.ModuleSearchResult)4 CeylonRepoManagerBuilder (org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder)4 IOException (java.io.IOException)3 Manifest (java.util.jar.Manifest)3 DefaultRepository (org.eclipse.ceylon.cmr.impl.DefaultRepository)3