Search in sources :

Example 1 with RepositoryManager

use of com.redhat.ceylon.cmr.api.RepositoryManager in project ceylon-compiler by ceylon.

the class ModelLoaderTests method verifyRuntimeClassLoading.

protected void verifyRuntimeClassLoading(RunnableTest test) {
    RepositoryManager repoManager = CeylonUtils.repoManager().buildManager();
    VFS vfs = new VFS();
    com.redhat.ceylon.compiler.typechecker.context.Context context = new com.redhat.ceylon.compiler.typechecker.context.Context(repoManager, vfs);
    RuntimeModuleManager moduleManager = new RuntimeModuleManager();
    context.setModules(new Modules());
    moduleManager.initCoreModules(new Modules());
    moduleManager.loadModule(AbstractModelLoader.CEYLON_LANGUAGE, Versions.CEYLON_VERSION_NUMBER, repoManager.getArtifactResult("ceylon.language", Versions.CEYLON_VERSION_NUMBER), getClass().getClassLoader());
    RuntimeModelLoader modelLoader = moduleManager.getModelLoader();
    modelLoader.setupWithNoStandardModules();
    modelLoader.loadStandardModules();
    test.test(modelLoader);
}
Also used : Context(com.sun.tools.javac.util.Context) VFS(com.redhat.ceylon.compiler.typechecker.io.VFS) RuntimeModuleManager(com.redhat.ceylon.compiler.java.runtime.model.RuntimeModuleManager) Modules(com.redhat.ceylon.model.typechecker.model.Modules) RuntimeModelLoader(com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager)

Example 2 with RepositoryManager

use of com.redhat.ceylon.cmr.api.RepositoryManager in project ceylon-compiler by ceylon.

the class CeylonEnter method addOutputModuleToClassPath.

public void addOutputModuleToClassPath(Module module) {
    RepositoryManager repositoryManager = fileManager.getOutputRepositoryManager();
    ArtifactResult artifact = null;
    try {
        ArtifactContext ctx = new ArtifactContext(module.getNameAsString(), module.getVersion(), ArtifactContext.CAR, ArtifactContext.JAR);
        artifact = repositoryManager.getArtifactResult(ctx);
    } catch (InvalidArchiveException e) {
        log.error("ceylon", "Module car " + e.getPath() + " obtained from repository " + e.getRepository() + " has an invalid SHA1 signature: you need to remove it and rebuild the archive, since it" + " may be corrupted.");
    } catch (Exception e) {
        String moduleName = module.getNameAsString();
        if (!module.isDefault())
            moduleName += "/" + module.getVersion();
        log.error("ceylon", "Exception occured while trying to resolve module " + moduleName);
        e.printStackTrace();
    }
    addModuleToClassPath(module, false, artifact);
}
Also used : InvalidArchiveException(com.redhat.ceylon.cmr.impl.InvalidArchiveException) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) InvalidArchiveException(com.redhat.ceylon.cmr.impl.InvalidArchiveException) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Example 3 with RepositoryManager

use of com.redhat.ceylon.cmr.api.RepositoryManager in project ceylon-compiler by ceylon.

the class CeylonDocTool method initialize.

@Override
public void initialize(CeylonTool mainTool) {
    TypeCheckerBuilder builder = new TypeCheckerBuilder();
    for (File src : sourceFolders) {
        builder.addSrcDirectory(src);
    }
    // set up the artifact repository
    RepositoryManager repository = getRepositoryManager();
    builder.setRepositoryManager(repository);
    // make a destination repo
    outputRepositoryManager = getOutputRepositoryManager();
    // create the actual list of modules to process
    List<File> srcs = FileUtil.applyCwd(cwd, sourceFolders);
    List<String> expandedModules = ModuleWildcardsHelper.expandWildcards(srcs, moduleSpecs, null);
    final List<ModuleSpec> modules = ModuleSpec.parseEachList(expandedModules);
    // we need to plug in the module manager which can load from .cars
    builder.moduleManagerFactory(new ModuleManagerFactory() {

        @Override
        public ModuleManager createModuleManager(Context context) {
            return new CeylonDocModuleManager(CeylonDocTool.this, context, modules, outputRepositoryManager, bootstrapCeylon, log);
        }

        @Override
        public ModuleSourceMapper createModuleManagerUtil(Context context, ModuleManager moduleManager) {
            return new CeylonDocModuleSourceMapper(context, (CeylonDocModuleManager) moduleManager, CeylonDocTool.this);
        }
    });
    // only parse what we asked for
    List<String> moduleFilters = new LinkedList<String>();
    for (ModuleSpec spec : modules) {
        moduleFilters.add(spec.getName());
        if (spec.getName().equals(Module.LANGUAGE_MODULE_NAME) && !bootstrapCeylon) {
            throw new CeylondException("error.languageModuleBootstrapOptionMissing");
        }
    }
    builder.setModuleFilters(moduleFilters);
    String fileEncoding = getEncoding();
    if (fileEncoding == null) {
        fileEncoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
    }
    if (fileEncoding != null) {
        builder.encoding(fileEncoding);
    }
    typeChecker = builder.getTypeChecker();
    // collect all units we are typechecking
    initTypeCheckedUnits(typeChecker);
    typeChecker.process();
    if (haltOnError && typeChecker.getErrors() > 0) {
        throw new CeylondException("error.failedParsing", new Object[] { typeChecker.getErrors() }, null);
    }
    initModules(modules);
    initPhasedUnits();
}
Also used : Context(com.redhat.ceylon.compiler.typechecker.context.Context) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) TypeCheckerBuilder(com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder) ModuleManager(com.redhat.ceylon.model.typechecker.util.ModuleManager) LinkedList(java.util.LinkedList) ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager) ModuleSourceMapper(com.redhat.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper) ModuleManagerFactory(com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory) File(java.io.File)

Example 4 with RepositoryManager

use of com.redhat.ceylon.cmr.api.RepositoryManager in project ceylon-compiler by ceylon.

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(com.redhat.ceylon.compiler.typechecker.context.Context) VFS(com.redhat.ceylon.compiler.typechecker.io.VFS) RepositoryManagerBuilder(com.redhat.ceylon.cmr.api.RepositoryManagerBuilder) PhasedUnits(com.redhat.ceylon.compiler.typechecker.context.PhasedUnits) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager) File(java.io.File) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Example 5 with RepositoryManager

use of com.redhat.ceylon.cmr.api.RepositoryManager in project ceylon-compiler by ceylon.

the class ModuleLoadingTool method internalLoadModule.

private boolean internalLoadModule(String name, String version, boolean optional) throws IOException {
    String key = name + "/" + version;
    if (loadedModules.containsKey(key))
        return true;
    if (shouldExclude(name)) {
        // let's not check the version and assume it's provided
        // treat it as a missing optional for the purpose of classpath
        loadedModules.put(key, null);
        return true;
    }
    // remember which version we loaded
    SortedSet<String> loadedVersions = loadedModuleVersions.get(name);
    if (loadedVersions == null) {
        loadedVersions = new TreeSet<>(VersionComparator.INSTANCE);
        loadedModuleVersions.put(name, loadedVersions);
    }
    loadedVersions.add(version);
    RepositoryManager repositoryManager = getRepositoryManager();
    ArtifactContext artifactContext = new ArtifactContext(name, version, ArtifactContext.CAR, ArtifactContext.JAR);
    ArtifactResult result = repositoryManager.getArtifactResult(artifactContext);
    if (!optional && (result == null || result.artifact() == null || !result.artifact().exists())) {
        String err = getModuleNotFoundErrorMessage(repositoryManager, name, version);
        errorAppend(err);
        errorNewline();
        return false;
    }
    // save even missing optional modules as nulls to not re-resolve them
    loadedModules.put(key, result);
    if (result != null) {
        for (ArtifactResult dep : result.dependencies()) {
            internalLoadModule(dep.name(), dep.version(), dep.importType() == ImportType.OPTIONAL);
        }
    }
    return true;
}
Also used : RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Aggregations

RepositoryManager (com.redhat.ceylon.cmr.api.RepositoryManager)7 ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)4 File (java.io.File)3 ModuleSpec (com.redhat.ceylon.common.tools.ModuleSpec)2 Context (com.redhat.ceylon.compiler.typechecker.context.Context)2 VFS (com.redhat.ceylon.compiler.typechecker.io.VFS)2 ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)2 RepositoryManagerBuilder (com.redhat.ceylon.cmr.api.RepositoryManagerBuilder)1 InvalidArchiveException (com.redhat.ceylon.cmr.impl.InvalidArchiveException)1 RuntimeModelLoader (com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader)1 RuntimeModuleManager (com.redhat.ceylon.compiler.java.runtime.model.RuntimeModuleManager)1 TypeCheckerBuilder (com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder)1 ModuleSourceMapper (com.redhat.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper)1 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)1 PhasedUnits (com.redhat.ceylon.compiler.typechecker.context.PhasedUnits)1 ModuleManagerFactory (com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory)1 Modules (com.redhat.ceylon.model.typechecker.model.Modules)1 ModuleManager (com.redhat.ceylon.model.typechecker.util.ModuleManager)1 Context (com.sun.tools.javac.util.Context)1 ArrayList (java.util.ArrayList)1