Search in sources :

Example 1 with ClosableVirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile in project ceylon by eclipse.

the class MainForLanguage method main.

/**
 * Files that are not under a proper module structure are
 * placed under a <nomodule> module.
 */
public static void main(String[] args) throws Exception {
    ClosableVirtualFile latestZippedLanguageSourceFile = MainHelper.getLatestZippedLanguageSourceFile();
    RepositoryManager repositoryManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").logger(new LeakingLogger()).buildManager();
    TypeChecker typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    latestZippedLanguageSourceFile.close();
    if (typeChecker.getErrors() > 0) {
        System.exit(1);
    }
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) LeakingLogger(org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)

Example 2 with ClosableVirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile 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 3 with ClosableVirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile in project ceylon by eclipse.

the class MainHelper method getLatestZippedLanguageSourceFile.

public static final ClosableVirtualFile getLatestZippedLanguageSourceFile() {
    VFS vfs = new VFS();
    File langDir = new File("../dist/dist/repo/ceylon/language");
    if (!langDir.exists()) {
        System.err.println("Unable to test language module, not found in repository: " + langDir);
        System.exit(-1);
    }
    String[] versions = langDir.list();
    Arrays.sort(versions);
    // last
    String version = versions[versions.length - 1];
    return vfs.getFromZipFile(new File(langDir, version + "/ceylon.language-" + version + ".src"));
}
Also used : VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Example 4 with ClosableVirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile in project ceylon by eclipse.

the class MainForTest method main.

/**
 * Files that are not under a proper module structure are
 * placed under a <nomodule> module.
 */
public static void main(String[] args) throws Exception {
    long start = System.nanoTime();
    RepositoryManager repositoryManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test/modules").logger(new LeakingLogger()).buildManager();
    TypeChecker typeChecker = new TypeCheckerBuilder().statistics(true).verbose(false).addSrcDirectory(new File("test/main")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    int errors = typeChecker.getErrors();
    Tree.CompilationUnit compilationUnit = typeChecker.getPhasedUnitFromRelativePath("ceylon/language/Object.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in .src");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("capture/Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in real src dir");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("org/eclipse/sample/multisource/Boo.ceylon").getCompilationUnit();
    Module module = compilationUnit.getUnit().getPackage().getModule();
    if (!"org.eclipse.sample.multisource".equals(module.getNameAsString())) {
        throw new RuntimeException("Unable to extract module name");
    }
    if (!"0.2".equals(module.getVersion())) {
        throw new RuntimeException("Unable to extract module version");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/main/capture")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for top level files (no package) in real src dir");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/moduledep1")).addSrcDirectory(new File("test/moduledep2")).addSrcDirectory(new File("test/moduletest")).addSrcDirectory(new File("test/restricted")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    ClosableVirtualFile latestZippedLanguageSourceFile = MainHelper.getLatestZippedLanguageSourceFile();
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    latestZippedLanguageSourceFile.close();
    System.out.println("Tests took " + ((System.nanoTime() - start) / 1000000) + " ms");
    if (errors > 0) {
        System.exit(1);
    }
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) LeakingLogger(org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Example 5 with ClosableVirtualFile

use of org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile in project ceylon by eclipse.

the class ModelLoaderTests method getLatestZippedLanguageSourceFile.

private static final ClosableVirtualFile getLatestZippedLanguageSourceFile() {
    VFS vfs = new VFS();
    File langDir = new File("../dist/dist/repo/ceylon/language");
    if (!langDir.exists()) {
        System.err.println("Unable to test language module, not found in repository: " + langDir);
        System.exit(-1);
    }
    String[] versions = langDir.list();
    Arrays.sort(versions);
    // last
    String version = versions[versions.length - 1];
    return vfs.getFromZipFile(new File(langDir, version + "/ceylon.language-" + version + ".src"));
}
Also used : VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Aggregations

ClosableVirtualFile (org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile)6 File (java.io.File)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)3 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)3 VFS (org.eclipse.ceylon.compiler.typechecker.io.VFS)2 LeakingLogger (org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger)2 Module (org.eclipse.ceylon.model.typechecker.model.Module)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 CeylonModelLoader (org.eclipse.ceylon.compiler.java.loader.CeylonModelLoader)1 RuntimeModelLoader (org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader)1 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)1 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)1 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)1 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)1 AbstractModelLoader (org.eclipse.ceylon.model.loader.AbstractModelLoader)1 ModelLoader (org.eclipse.ceylon.model.loader.ModelLoader)1 DeclarationType (org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType)1