Search in sources :

Example 1 with ModuleNotFoundException

use of org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException in project ceylon by eclipse.

the class ModuleLoaderTest method testBug7084.

@Test
public void testBug7084() throws IOException {
    Path flatRepo = Files.createTempDirectory("flat-repo");
    try {
        RepositoryManager repositoryManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").userRepos(Arrays.asList("flat:" + flatRepo.toAbsolutePath().toString())).buildManager();
        File artifact = repositoryManager.getArtifact(null, "ceylon.collection", "1.3.2");
        Assert.assertNotNull(artifact);
        Files.copy(artifact.toPath(), flatRepo.resolve("ceylon.collection-1.3.2.jar"));
        ModuleLoader moduleLoader = new FlatpathModuleLoader(repositoryManager, null, Collections.<String, String>emptyMap(), true);
        try {
            moduleLoader.loadModule("ceylon.collection", "1.3.2");
        } catch (ModuleNotFoundException e) {
            throw new RuntimeException(e);
        }
    } finally {
        IOUtils.deleteRecursively(flatRepo.toFile());
    }
}
Also used : Path(java.nio.file.Path) FlatpathModuleLoader(org.eclipse.ceylon.module.loader.FlatpathModuleLoader) ModuleLoader(org.eclipse.ceylon.cmr.ceylon.loader.ModuleLoader) FlatpathModuleLoader(org.eclipse.ceylon.module.loader.FlatpathModuleLoader) ModuleNotFoundException(org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) File(java.io.File) Test(org.junit.Test)

Example 2 with ModuleNotFoundException

use of org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException in project ceylon by eclipse.

the class LazyModuleSourceMapper method preResolveDependenciesIfRequired.

@Override
public void preResolveDependenciesIfRequired(RepositoryManager repositoryManager) {
    AbstractModelLoader modelLoader = getModuleManager().getModelLoader();
    if (!modelLoader.isFullyExportMavenDependencies())
        return;
    if (statusPrinter != null) {
        statusPrinter.clearLine();
        statusPrinter.log("Pre-resolving dependencies");
    }
    if (verbose) {
        log.printRawLines(WriterKind.NOTICE, "[Pre-resolving dependencies]");
    }
    Set<Module> compiledModules = getCompiledModules();
    Map<String, String> modules = new HashMap<>();
    ModuleImport anyImport = null;
    for (Module module : compiledModules) {
        for (ModuleImport imp : module.getImports()) {
            if (imp.getModule() == null || !compiledModules.contains(imp.getModule())) {
                if (anyImport == null)
                    anyImport = imp;
                String name = imp.getModule().getNameAsString();
                if (imp.getNamespace() != null)
                    name = imp.getNamespace() + ":" + name;
                modules.put(name, imp.getModule().getVersion());
            }
        }
    }
    if (statusPrinter != null) {
        statusPrinter.clearLine();
        statusPrinter.log("Pre-resolving found " + modules.size() + " to pre-resolve");
    }
    if (verbose) {
        log.printRawLines(WriterKind.NOTICE, "[Pre-resolving " + modules.size() + " modules]");
    }
    if (modules.isEmpty())
        return;
    Entry<String, String> first = modules.entrySet().iterator().next();
    CompilerModuleLoader ml = new CompilerModuleLoader(repositoryManager, null, modules, verbose, statusPrinter, log);
    boolean giveup = false;
    try {
        ml.loadModule(first.getKey(), first.getValue(), ModuleScope.COMPILE);
    } catch (ModuleNotFoundException e) {
        attachErrorToDependencyDeclaration(anyImport, "Pre-resolving of module failed: " + e.getMessage(), true);
        giveup = true;
    }
    if (statusPrinter != null) {
        statusPrinter.clearLine();
        // don't try to read the module count if pre-resolving failed
        if (giveup)
            statusPrinter.log("Pre-resolving failed");
        else
            statusPrinter.log("Pre-resolving resolved " + ml.getModuleCount());
    }
    if (verbose) {
        // don't try to read the module count if pre-resolving failed
        if (giveup)
            log.printRawLines(WriterKind.NOTICE, "[Pre-resolved failed]");
        else
            log.printRawLines(WriterKind.NOTICE, "[Pre-resolved " + ml.getModuleCount() + " modules]");
    }
    if (giveup)
        return;
    Overrides overrides = repositoryManager.getOverrides();
    if (overrides == null) {
        overrides = Overrides.create();
        repositoryManager.setOverrides(overrides);
    }
    ml.setupOverrides(overrides);
    ml.cleanup();
}
Also used : AbstractModelLoader(org.eclipse.ceylon.model.loader.AbstractModelLoader) ModuleNotFoundException(org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException) HashMap(java.util.HashMap) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) Overrides(org.eclipse.ceylon.cmr.api.Overrides) CompilerModuleLoader(org.eclipse.ceylon.compiler.java.loader.CompilerModuleLoader) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Aggregations

ModuleNotFoundException (org.eclipse.ceylon.cmr.ceylon.loader.ModuleNotFoundException)2 File (java.io.File)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Overrides (org.eclipse.ceylon.cmr.api.Overrides)1 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)1 ModuleLoader (org.eclipse.ceylon.cmr.ceylon.loader.ModuleLoader)1 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)1 CompilerModuleLoader (org.eclipse.ceylon.compiler.java.loader.CompilerModuleLoader)1 AbstractModelLoader (org.eclipse.ceylon.model.loader.AbstractModelLoader)1 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)1 Module (org.eclipse.ceylon.model.typechecker.model.Module)1 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)1 FlatpathModuleLoader (org.eclipse.ceylon.module.loader.FlatpathModuleLoader)1 Test (org.junit.Test)1