Search in sources :

Example 26 with ModuleVersionDetails

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

the class AbstractRepository method addArtifactInfo.

private ArtifactInfoResult addArtifactInfo(Node artifact, String name, String version, String suffix, String memberName, ModuleVersionDetails mvd, ModuleQuery lookup) {
    // let's see if we can extract some information
    try {
        File file = artifact.getContent(File.class);
        if (file != null) {
            ModuleInfoReader reader = getModuleInfoReader(suffix);
            if (reader != null) {
                ModuleVersionDetails mvd2 = reader.readModuleInfo(name, version, file, memberName != null, getOverrides());
                Set<String> matchingMembers = null;
                if (memberName != null) {
                    matchingMembers = matchMembers(mvd2, lookup);
                    if (matchingMembers.isEmpty()) {
                        // just continue to the next suffix/artifact if any
                        return ArtifactInfoResult.NO_MATCH;
                    }
                    mvd.getMembers().addAll(matchingMembers);
                }
                if (mvd2.getGroupId() != null) {
                    mvd.setGroupId(mvd2.getGroupId());
                }
                if (mvd2.getArtifactId() != null) {
                    mvd.setArtifactId(mvd2.getArtifactId());
                }
                if (mvd2.getLabel() != null) {
                    mvd.setLabel(mvd2.getLabel());
                }
                if (mvd2.getDoc() != null) {
                    mvd.setDoc(mvd2.getDoc());
                }
                if (mvd2.getLicense() != null) {
                    mvd.setLicense(mvd2.getLicense());
                }
                mvd.getAuthors().addAll(mvd2.getAuthors());
                mvd.getDependencies().addAll(mvd2.getDependencies());
                mvd.getArtifactTypes().addAll(mvd2.getArtifactTypes());
                return ArtifactInfoResult.INFO_FOUND;
            } else {
                if (memberName == null) {
                    // We didn't get any information but we'll at least add the artifact type to the result
                    mvd.getArtifactTypes().add(new ModuleVersionArtifact(suffix, null, null));
                }
            }
        }
    } catch (Exception e) {
    // bah
    }
    return ArtifactInfoResult.OTHER;
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) File(java.io.File) ModuleInfoReader(org.eclipse.ceylon.cmr.api.ModuleInfoReader)

Example 27 with ModuleVersionDetails

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

the class BytecodeUtils method readModuleInfo.

@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String moduleVersion, File moduleArchive, boolean includeMembers, Overrides overrides) {
    ClassFile moduleInfo = readModuleInfo(moduleName, moduleArchive);
    if (moduleInfo == null)
        return null;
    Annotation moduleAnnotation = ClassFileUtil.findAnnotation(moduleInfo, MODULE_ANNOTATION);
    if (moduleAnnotation == null)
        return null;
    String doc = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "doc");
    String license = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "license");
    String label = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "label");
    Object[] by = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "by");
    Object[] dependencies = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "dependencies");
    String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());
    int[] binver = getBinaryVersions(moduleInfo);
    String groupId, artifactId;
    groupId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "group");
    if (groupId == null || groupId.isEmpty()) {
        String[] coordinates = ModuleUtil.getMavenCoordinates(moduleName);
        groupId = coordinates[0];
        artifactId = coordinates[1];
    } else {
        artifactId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, moduleAnnotation, "artifact");
        if (artifactId == null || artifactId.isEmpty())
            artifactId = moduleName;
    }
    ModuleVersionDetails mvd = new ModuleVersionDetails(moduleName, getVersionFromFilename(moduleName, moduleArchive.getName()), groupId, artifactId);
    mvd.setDoc(doc);
    mvd.setLabel(label);
    mvd.setLicense(license);
    if (by != null) {
        for (Object author : by) {
            mvd.getAuthors().add((String) author);
        }
    }
    mvd.getDependencies().addAll(getDependencies(moduleInfo, dependencies, moduleName, mvd.getVersion(), groupId, artifactId, overrides));
    ModuleVersionArtifact mva = new ModuleVersionArtifact(type, binver[0], binver[1]);
    mvd.getArtifactTypes().add(mva);
    if (includeMembers) {
        mvd.setMembers(getMembers(moduleArchive));
    }
    return mvd;
}
Also used : ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) Annotation(org.eclipse.ceylon.langtools.classfile.Annotation)

Example 28 with ModuleVersionDetails

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

the class JarUtils method readModuleInfo.

@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String version, File moduleArchive, boolean includeMembers, Overrides overrides) {
    ModuleInfo info = getDependencies(moduleArchive, moduleName, version, overrides);
    ModuleVersionDetails mvd = new ModuleVersionDetails(moduleName, version, info != null ? info.getGroupId() : null, info != null ? info.getArtifactId() : null);
    mvd.getArtifactTypes().add(new ModuleVersionArtifact(ArtifactContext.JAR, null, null));
    if (info != null) {
        mvd.getDependencies().addAll(info.getDependencies());
    }
    if (includeMembers) {
        mvd.setMembers(getMembers(moduleArchive));
    }
    return mvd;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)

Example 29 with ModuleVersionDetails

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

the class CeylonCompileJsTool method run.

@Override
public void run() throws Exception {
    AppendableWriter writer = new AppendableWriter(getOutAppendable());
    final Options opts = new Options().cwd(cwd).repos(getRepositoryAsStrings()).sourceDirs(roots).resourceDirs(resources).resourceRootName(resourceRootName).systemRepo(systemRepo).outRepo(getOut()).user(user).pass(pass).optimize(optimize).modulify(modulify).comment(comments).verbose(getVerbose()).profile(profile).stdin(false).generateSourceArchive(!skipSrc).encoding(encoding).includeDependencies(includeDependencies).diagnosticListener(diagnosticListener).outWriter(writer).suppressWarnings(suppwarns);
    final TypeChecker typeChecker;
    if (opts.hasVerboseFlag("cmr")) {
        append("Using repositories: " + getRepositoryAsStrings());
        newline();
    }
    final RepositoryManager repoman = getRepositoryManager();
    long t0, t1, t2, t3, t4;
    final TypeCheckerBuilder tcb;
    List<File> onlySources = null;
    List<File> onlyResources = null;
    if (opts.isStdin()) {
        VirtualFile src = new VirtualFile() {

            @Override
            public boolean exists() {
                return true;
            }

            @Override
            public boolean isFolder() {
                return false;
            }

            @Override
            public String getName() {
                return "SCRIPT.ceylon";
            }

            @Override
            public String getPath() {
                return getName();
            }

            @Override
            public String getRelativePath(VirtualFile file) {
                return "";
            }

            @Override
            public InputStream getInputStream() {
                return System.in;
            }

            @Override
            public List<VirtualFile> getChildren() {
                return Collections.emptyList();
            }

            @Override
            public int hashCode() {
                return getPath().hashCode();
            }

            @Override
            public boolean equals(Object obj) {
                if (obj instanceof VirtualFile) {
                    return ((VirtualFile) obj).getPath().equals(getPath());
                } else {
                    return super.equals(obj);
                }
            }

            @Override
            public int compareTo(VirtualFile o) {
                return getPath().compareTo(o.getPath());
            }
        };
        t0 = System.nanoTime();
        tcb = new TypeCheckerBuilder().addSrcDirectory(src);
    } else {
        t0 = System.nanoTime();
        tcb = new TypeCheckerBuilder();
        SourceArgumentsResolver resolver = new SourceArgumentsResolver(roots, resources, Constants.CEYLON_SUFFIX, Constants.JS_SUFFIX);
        resolver.cwd(cwd).expandAndParse(files, Backend.JavaScript);
        if (includeDependencies != null && !COMPILE_NEVER.equals(includeDependencies)) {
            // Determine any dependencies that might need compiling as well
            SourceDependencyResolver sdr = new SourceDependencyResolver(getModuleVersionReader(), roots, Backends.JS);
            if (sdr.traverseDependencies(resolver.getSourceFiles())) {
                for (ModuleVersionDetails mvd : sdr.getAdditionalModules()) {
                    if (COMPILE_FORCE.equals(includeDependencies) || (COMPILE_CHECK.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JS, true)) || (COMPILE_ONCE.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JS, false))) {
                        files.add(mvd.getModule());
                        resolver.expandAndParse(files, Backend.JavaScript);
                    }
                }
            }
        }
        onlySources = resolver.getSourceFiles();
        onlyResources = resolver.getResourceFiles();
        if (onlySources.isEmpty()) {
            String msg = CeylonCompileJsMessages.msg("error.no.sources");
            if (ModuleWildcardsHelper.onlyGlobArgs(files)) {
                throw new NonFatalToolMessage(msg);
            } else {
                throw new ToolUsageError(msg);
            }
        }
        if (opts.isVerbose()) {
            append("Adding source directories to typechecker:" + roots).newline();
        }
        for (File root : roots) {
            File cwdRoot = applyCwd(root);
            if (cwdRoot.exists() && cwdRoot.isDirectory()) {
                tcb.addSrcDirectory(cwdRoot);
            }
        }
        tcb.setSourceFiles(onlySources);
        if (!resolver.getSourceModules().isEmpty()) {
            tcb.setModuleFilters(resolver.getSourceModules());
        }
        tcb.statistics(opts.isProfile());
        JsModuleManagerFactory.setVerbose(opts.hasVerboseFlag("loader"));
        tcb.moduleManagerFactory(new JsModuleManagerFactory(encoding));
    }
    // getting the type checker does process all types in the source directory
    tcb.verbose(opts.hasVerboseFlag("ast")).setRepositoryManager(repoman);
    tcb.usageWarnings(false).encoding(encoding);
    typeChecker = tcb.getTypeChecker();
    t1 = System.nanoTime();
    TypeCache.doWithoutCaching(new Runnable() {

        @Override
        public void run() {
            typeChecker.process(true);
        }
    });
    t2 = System.nanoTime();
    JsCompiler jsc = new JsCompiler(typeChecker, opts);
    if (onlySources != null) {
        if (opts.isVerbose()) {
            append("Only these files will be compiled: " + onlySources).newline();
        }
        jsc.setSourceFiles(onlySources);
    }
    if (onlyResources != null) {
        jsc.setResourceFiles(onlyResources);
    }
    t3 = System.nanoTime();
    if (!jsc.generate()) {
        if (jsc.getExitCode() != 0) {
            if (throwOnError)
                throw new RuntimeException("Compiler exited with non-zero exit code: " + jsc.getExitCode());
            else {
                jsc.printErrorsAndCount(writer);
                System.exit(jsc.getExitCode());
            }
        }
        int count = jsc.printErrorsAndCount(writer);
        String msg = (count > 1) ? "There were %d errors." : "There was %d error.";
        flush();
        throw new CompilerErrorException(String.format(msg, count));
    } else {
        // We still call this here for any warning there might be
        jsc.printErrorsAndCount(writer);
    }
    t4 = System.nanoTime();
    if (opts.isProfile() || opts.hasVerboseFlag("benchmark")) {
        System.err.println("PROFILING INFORMATION");
        System.err.printf("TypeChecker creation:   %6d nanos%n", t1 - t0);
        System.err.printf("TypeChecker processing: %6d nanos%n", t2 - t1);
        System.err.printf("JS compiler creation:   %6d nanos%n", t3 - t2);
        System.err.printf("JS compilation:         %6d nanos%n", t4 - t3);
        System.out.println("Compilation finished.");
    }
}
Also used : VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) Options(org.eclipse.ceylon.compiler.js.util.Options) DefaultToolOptions(org.eclipse.ceylon.common.config.DefaultToolOptions) JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) SourceArgumentsResolver(org.eclipse.ceylon.common.tools.SourceArgumentsResolver) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) SourceDependencyResolver(org.eclipse.ceylon.common.tools.SourceDependencyResolver) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) NonFatalToolMessage(org.eclipse.ceylon.common.tool.NonFatalToolMessage) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 30 with ModuleVersionDetails

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

the class CeylonInfoTool method run.

@Override
public void run() throws Exception {
    if (showIncompatible != Incompatible.yes) {
        if (queryType.includes(ArtifactContext.CAR)) {
            jvmBinaryMajor = Versions.JVM_BINARY_MAJOR_VERSION;
            jvmBinaryMinor = Versions.JVM_BINARY_MINOR_VERSION;
        }
        if (queryType.includes(ArtifactContext.JS)) {
            jsBinaryMajor = Versions.JS_BINARY_MAJOR_VERSION;
            jsBinaryMinor = Versions.JS_BINARY_MINOR_VERSION;
        }
    }
    String msgkey = showIncompatible == Incompatible.no ? "module.not.found.compat" : "module.not.found";
    for (ModuleSpec module : modules) {
        String name = module.getName();
        if (!module.isVersioned() && (name.startsWith("*") || name.endsWith("*"))) {
            Collection<ModuleDetails> modules = getModules(getRepositoryManager(), module.getNamespace(), name, queryType, jvmBinaryMajor, jvmBinaryMinor, jsBinaryMajor, jsBinaryMinor);
            if (modules.isEmpty()) {
                String err;
                if (name.startsWith("*") || name.endsWith("*")) {
                    err = CeylonInfoMessages.msg("no.match", name);
                } else {
                    err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion(), msgkey);
                }
                errorAppend(err);
                errorNewline();
                continue;
            }
            outputModules(module, modules);
        } else {
            Collection<ModuleVersionDetails> versions = getModuleVersions(getRepositoryManager(), module.getNamespace(), module.getName(), module.getVersion(), false, queryType, jvmBinaryMajor, jvmBinaryMinor, jsBinaryMajor, jsBinaryMinor);
            if (versions.isEmpty()) {
                // try from source
                ModuleVersionDetails fromSource = getModuleVersionDetailsFromSource(name);
                if (fromSource != null) {
                    // is it the version we're after?
                    versions = Arrays.asList(fromSource);
                } else {
                    if (showIncompatible == Incompatible.auto && (jvmBinaryMajor != null || jvmBinaryMinor != null || jsBinaryMajor != null || jsBinaryMinor != null)) {
                        // If we were called with a specific version and we didn't find a "compatible"
                        // artifact then lets see if we can find an "incompatible" one
                        versions = getModuleVersions(getRepositoryManager(), module.getNamespace(), module.getName(), module.getVersion(), false, queryType, null, null, null, null);
                    }
                    if (versions.isEmpty()) {
                        String err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion(), msgkey);
                        errorAppend(err);
                        errorNewline();
                        continue;
                    }
                }
            }
            if (module.getVersion() == null || module.getVersion().isEmpty() || versions.size() > 1) {
                outputVersions(module, versions);
            } else {
                outputDetails(module, versions.iterator().next());
            }
        }
    }
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDetails(org.eclipse.ceylon.cmr.api.ModuleSearchResult.ModuleDetails)

Aggregations

ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)32 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)10 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)10 File (java.io.File)7 ArrayList (java.util.ArrayList)6 ModuleVersionQuery (org.eclipse.ceylon.cmr.api.ModuleVersionQuery)5 ModuleVersionResult (org.eclipse.ceylon.cmr.api.ModuleVersionResult)5 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)5 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)4 Node (org.eclipse.ceylon.cmr.spi.Node)4 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)4 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 List (java.util.List)2 Map (java.util.Map)2 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)2 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)2