Search in sources :

Example 1 with ModuleVersionArtifact

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

the class CeylonInfoTool method outputArtifacts.

private RepoUsingTool outputArtifacts(Set<ModuleVersionArtifact> types) throws IOException {
    if (!types.isEmpty()) {
        msg("module.artifacts");
        boolean skipComma = true;
        boolean js = false;
        boolean docs = false;
        for (ModuleVersionArtifact type : types) {
            if (!skipComma) {
                append(", ");
            }
            String suffix = type.getSuffix();
            int major = (type.getMajorBinaryVersion() != null) ? type.getMajorBinaryVersion() : 0;
            int minor = (type.getMinorBinaryVersion() != null) ? type.getMinorBinaryVersion() : 0;
            if (suffix.equalsIgnoreCase(ArtifactContext.CAR)) {
                append("JVM (#");
                append(major);
                if (minor != 0) {
                    append(".");
                    append(minor);
                }
                if (!Versions.isJvmBinaryVersionSupported(major, minor)) {
                    append(" ");
                    msg("label.incompatible.version");
                }
                append(")");
            } else if (suffix.equalsIgnoreCase(ArtifactContext.JAR)) {
                append("JVM (legacy)");
            } else if (suffix.equalsIgnoreCase(ArtifactContext.JS) || suffix.equalsIgnoreCase(ArtifactContext.JS_MODEL)) {
                if (js) {
                    skipComma = true;
                    continue;
                }
                append("JavaScript (#");
                append(major);
                if (minor != 0) {
                    append(".");
                    append(minor);
                }
                if (!Versions.isJsBinaryVersionSupported(major, minor)) {
                    append(" ");
                    msg("label.incompatible.version");
                }
                append(")");
                js = true;
            } else if (suffix.equalsIgnoreCase(ArtifactContext.DART)) {
                append("Dart");
            } else if (suffix.equalsIgnoreCase(ArtifactContext.RESOURCES)) {
                append("non-JVM Resources");
            } else if (suffix.equalsIgnoreCase(ArtifactContext.DOCS)) {
                if (docs) {
                    skipComma = true;
                    continue;
                }
                append("Documentation");
                docs = true;
            } else if (suffix.equalsIgnoreCase(ArtifactContext.SCRIPTS_ZIPPED)) {
                append("Script Plugins");
            } else if (suffix.equalsIgnoreCase(ArtifactContext.SRC)) {
                append("Sources");
            } else if (suffix.startsWith(".")) {
                append(suffix.substring(1).toUpperCase());
            } else {
                // We might need to add some special cases
                // for these in the above list
                append(type);
            }
            skipComma = false;
        }
        newline();
    }
    return this;
}
Also used : ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)

Example 2 with ModuleVersionArtifact

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

the class URLContentStore method parseCompleteVersionsResponse.

protected void parseCompleteVersionsResponse(Parser p, ModuleVersionResult result, Overrides overrides) {
    List<String> authors = new LinkedList<String>();
    Set<ModuleDependencyInfo> dependencies = new HashSet<ModuleDependencyInfo>();
    List<ModuleVersionArtifact> types = new LinkedList<ModuleVersionArtifact>();
    p.moveToOpenTag("results");
    while (p.moveToOptionalOpenTag("module-version")) {
        String module = null, version = null, doc = null, license = null, label = null, groupId = null, artifactId = null;
        authors.clear();
        dependencies.clear();
        types.clear();
        while (p.moveToOptionalOpenTag()) {
            if (p.isOpenTag("module")) {
                // ignored
                module = p.contents();
            } else if (p.isOpenTag("version")) {
                version = p.contents();
            } else if (p.isOpenTag("doc")) {
                doc = p.contents();
            } else if (p.isOpenTag("groupId")) {
                groupId = p.contents();
            } else if (p.isOpenTag("artifactId")) {
                artifactId = p.contents();
            } else if (p.isOpenTag("license")) {
                license = p.contents();
            } else if (p.isOpenTag("label")) {
                label = p.contents();
            } else if (p.isOpenTag("authors")) {
                authors.add(p.contents());
            } else if (p.isOpenTag("dependency")) {
                dependencies.add(parseDependency(p));
            } else if (p.isOpenTag("artifact")) {
                types.add(parseArtifact(p));
            } else {
                throw new RuntimeException("Unknown tag: " + p.tagName());
            }
        }
        if (version == null || version.isEmpty())
            throw new RuntimeException("Missing required version");
        ModuleVersionDetails newVersion = result.addVersion(null, module, version);
        if (newVersion != null) {
            if (groupId != null && !groupId.isEmpty())
                newVersion.setGroupId(groupId);
            if (artifactId != null && !artifactId.isEmpty())
                newVersion.setArtifactId(artifactId);
            if (doc != null && !doc.isEmpty())
                newVersion.setDoc(doc);
            if (license != null && !license.isEmpty())
                newVersion.setLicense(license);
            if (label != null && !label.isEmpty())
                newVersion.setLabel(label);
            if (!authors.isEmpty())
                newVersion.getAuthors().addAll(authors);
            if (overrides != null) {
                final ModuleInfo info = new ModuleInfo(null, module, version, groupId, artifactId, null, null, dependencies);
                dependencies = overrides.applyOverrides(module, version, info).getDependencies();
            }
            if (!dependencies.isEmpty())
                newVersion.getDependencies().addAll(dependencies);
            if (!types.isEmpty())
                newVersion.getArtifactTypes().addAll(types);
            newVersion.setRemote(true);
            if (isHerd()) {
                newVersion.setOrigin(HERD_ORIGIN + " (" + getDisplayString() + ")");
            } else {
                newVersion.setOrigin(getDisplayString());
            }
        }
        p.checkCloseTag();
    }
    p.checkCloseTag();
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 3 with ModuleVersionArtifact

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

the class URLContentStore method parseSearchModulesResponse.

protected void parseSearchModulesResponse(Parser p, ModuleSearchResult result, Long start) {
    SortedSet<String> authors = new TreeSet<String>();
    SortedSet<String> versions = new TreeSet<String>();
    SortedSet<ModuleDependencyInfo> dependencies = new TreeSet<ModuleDependencyInfo>();
    SortedSet<ModuleVersionArtifact> types = new TreeSet<ModuleVersionArtifact>();
    p.moveToOpenTag("results");
    String total = p.getAttribute("total");
    long totalResults;
    try {
        if (total == null)
            throw new RuntimeException("Missing total from result");
        totalResults = Long.parseLong(total);
    } catch (NumberFormatException x) {
        throw new RuntimeException("Invalid total: " + total);
    }
    int resultCount = 0;
    while (p.moveToOptionalOpenTag("module")) {
        String module = null, doc = null, license = null, label = null, groupId = null, artifactId = null;
        authors.clear();
        versions.clear();
        dependencies.clear();
        types.clear();
        resultCount++;
        while (p.moveToOptionalOpenTag()) {
            if (p.isOpenTag("name")) {
                module = p.contents();
            } else if (p.isOpenTag("versions")) {
                // TODO This isn't really the way, we should have version tags
                // inside the "module" tag containing all the rest of the
                // information below
                versions.add(p.contents());
            } else if (p.isOpenTag("groupId")) {
                groupId = p.contents();
            } else if (p.isOpenTag("artifactId")) {
                artifactId = p.contents();
            } else if (p.isOpenTag("doc")) {
                doc = p.contents();
            } else if (p.isOpenTag("license")) {
                license = p.contents();
            } else if (p.isOpenTag("label")) {
                label = p.contents();
            } else if (p.isOpenTag("authors")) {
                authors.add(p.contents());
            } else if (p.isOpenTag("dependency")) {
                dependencies.add(parseDependency(p));
            } else if (p.isOpenTag("artifact")) {
                ModuleVersionArtifact artifact = parseArtifact(p);
                types.add(artifact);
            } else {
                throw new RuntimeException("Unknown tag: " + p.tagName());
            }
        }
        if (module == null || module.isEmpty())
            throw new RuntimeException("Missing required module name");
        if (versions.isEmpty()) {
            log.debug("Ignoring result for " + module + " because it doesn't have a single version");
        } else {
            // TODO See TODO above
            for (String v : versions) {
                ModuleVersionDetails mvd = new ModuleVersionDetails(null, module, v, groupId, artifactId);
                mvd.setDoc(doc);
                mvd.setLicense(license);
                mvd.setLabel(label);
                mvd.getAuthors().addAll(authors);
                mvd.getDependencies().addAll(dependencies);
                mvd.getArtifactTypes().addAll(types);
                mvd.setRemote(true);
                if (isHerd()) {
                    mvd.setOrigin(HERD_ORIGIN + " (" + getDisplayString() + ")");
                } else {
                    mvd.setOrigin(getDisplayString());
                }
                result.addResult(module, mvd);
            }
        }
        p.checkCloseTag();
    }
    p.checkCloseTag();
    // see if we have more results
    long realStart = start != null ? start : 0;
    long resultsAfterThisPage = realStart + resultCount;
    result.setHasMoreResults(resultsAfterThisPage < totalResults);
}
Also used : TreeSet(java.util.TreeSet) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)

Example 4 with ModuleVersionArtifact

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

the class AetherUtils method addSearchResult.

private void addSearchResult(String groupId, String artifactId, String version, ModuleVersionResult result, Overrides overrides, String repositoryDisplayString) throws AetherException {
    ArtifactOverrides artifactOverrides = null;
    String classifier = null;
    if (overrides != null) {
        ArtifactContext ctx = new ArtifactContext(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version);
        // see if this artifact is replaced
        ArtifactContext replaceContext = overrides.replace(ctx);
        if (replaceContext != null) {
            String[] groupArtifactIds = nameToGroupArtifactIds(replaceContext.getName());
            if (groupArtifactIds == null)
                // abort
                return;
            groupId = groupArtifactIds[0];
            artifactId = groupArtifactIds[1];
            classifier = groupArtifactIds[2];
            version = replaceContext.getVersion();
            ctx = replaceContext;
        } else if (overrides.isVersionOverridden(ctx)) {
            // perhaps its version is overridden?
            version = overrides.getVersionOverride(ctx);
            ctx.setVersion(version);
        }
        artifactOverrides = overrides.getArtifactOverrides(ctx);
    }
    DependencyDescriptor info = impl.getDependencies(groupId, artifactId, version, classifier, "pom", false);
    if (info != null) {
        StringBuilder description = new StringBuilder();
        StringBuilder licenseBuilder = new StringBuilder();
        collectInfo(info, description, licenseBuilder);
        Set<ModuleDependencyInfo> dependencies = new HashSet<>();
        Set<ModuleVersionArtifact> artifactTypes = new HashSet<>();
        artifactTypes.add(new ModuleVersionArtifact(".jar", null, null));
        Set<String> authors = new HashSet<>();
        for (DependencyDescriptor dep : info.getDependencies()) {
            String namespace = MavenRepository.NAMESPACE;
            String depName = MavenUtils.moduleName(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier());
            String depVersion = dep.getVersion();
            boolean export = false;
            boolean optional = dep.isOptional();
            if (overrides != null) {
                ArtifactContext depCtx = new ArtifactContext(namespace, depName, dep.getVersion());
                if (overrides.isRemoved(depCtx) || (artifactOverrides != null && (artifactOverrides.isRemoved(depCtx) || artifactOverrides.isAddedOrUpdated(depCtx))))
                    continue;
                ArtifactContext replaceCtx = overrides.replace(depCtx);
                if (replaceCtx != null) {
                    depCtx = replaceCtx;
                    namespace = replaceCtx.getNamespace();
                    depName = replaceCtx.getName();
                }
                if (overrides.isVersionOverridden(depCtx))
                    depVersion = overrides.getVersionOverride(depCtx);
                if (artifactOverrides != null) {
                    if (artifactOverrides.isShareOverridden(depCtx))
                        export = artifactOverrides.isShared(depCtx);
                    if (artifactOverrides.isOptionalOverridden(depCtx))
                        optional = artifactOverrides.isOptional(depCtx);
                }
            }
            ModuleDependencyInfo moduleDependencyInfo = new ModuleDependencyInfo(namespace, depName, depVersion, optional, export, Backends.JAVA, toModuleScope(dep));
            dependencies.add(moduleDependencyInfo);
        }
        if (artifactOverrides != null) {
            for (DependencyOverride add : artifactOverrides.getAdd()) {
                ArtifactContext ac = add.getArtifactContext();
                ModuleDependencyInfo moduleDependencyInfo = new ModuleDependencyInfo(ac.getNamespace(), ac.getName(), ac.getVersion(), add.isOptional(), add.isShared(), Backends.JAVA, ModuleScope.COMPILE);
                dependencies.add(moduleDependencyInfo);
            }
        }
        ModuleVersionDetails moduleVersionDetails = new ModuleVersionDetails(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version, groupId, artifactId, null, description.length() > 0 ? description.toString() : null, licenseBuilder.length() > 0 ? licenseBuilder.toString() : null, authors, dependencies, artifactTypes, true, repositoryDisplayString);
        result.addVersion(moduleVersionDetails);
    }
}
Also used : ArtifactOverrides(org.eclipse.ceylon.cmr.api.ArtifactOverrides) DependencyDescriptor(org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) MavenArtifactContext(org.eclipse.ceylon.cmr.api.MavenArtifactContext) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) DependencyOverride(org.eclipse.ceylon.cmr.api.DependencyOverride) HashSet(java.util.HashSet)

Example 5 with ModuleVersionArtifact

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

the class JSUtils method readModuleInfo.

@SuppressWarnings("unchecked")
@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String moduleVersion, File moduleArchive, boolean includeMembers, Overrides overrides) {
    Map<String, Object> model = loadJsonModel(moduleArchive);
    String name = asString(metaModelProperty(model, "$mod-name"));
    if (!moduleName.equals(name)) {
        throw new RuntimeException("Incorrect module");
    }
    String version = asString(metaModelProperty(model, "$mod-version"));
    Set<ModuleDependencyInfo> dependencies = getModuleInfo(model, moduleName, version, overrides).getDependencies();
    String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());
    Integer major = null, minor = null;
    String bin = asString(metaModelProperty(model, "$mod-bin"));
    if (bin != null) {
        int p = bin.indexOf('.');
        if (p >= 0) {
            major = Integer.parseInt(bin.substring(0, p));
            minor = Integer.parseInt(bin.substring(p + 1));
        } else {
            major = Integer.parseInt(bin);
        }
    }
    ModuleVersionDetails mvd = new ModuleVersionDetails(moduleName, version, null, null);
    mvd.getArtifactTypes().add(new ModuleVersionArtifact(type, major, minor));
    mvd.getDependencies().addAll(dependencies);
    Object anns = metaModelProperty(model, "$mod-anns");
    List<Map<String, Object>> annotations = null;
    if (anns instanceof Map) {
        // Pre-10.0 style annotations
        annotations = new ArrayList<Map<String, Object>>(1);
        annotations.add((Map<String, Object>) anns);
    } else if (anns instanceof List) {
        // 10.0+ style annotations
        annotations = (List<Map<String, Object>>) anns;
    }
    if (annotations != null) {
        for (Map<String, Object> annot : annotations) {
            if (annot.containsKey("doc")) {
                mvd.setDoc(asString(annot.get("doc")));
            }
            if (annot.containsKey("label")) {
                mvd.setLabel(asString(annot.get("label")));
            }
            if (annot.containsKey("license")) {
                mvd.setLicense(asString(annot.get("license")));
            }
            if (annot.containsKey("by")) {
                Iterable<String> by = (Iterable<String>) annot.get("by");
                if (by != null) {
                    for (String author : by) {
                        mvd.getAuthors().add(author);
                    }
                }
            }
        }
    }
    if (includeMembers) {
        mvd.setMembers(getMembers(moduleName, moduleArchive));
    }
    return mvd;
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)11 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)10 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)5 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 ArtifactOverrides (org.eclipse.ceylon.cmr.api.ArtifactOverrides)1 DependencyOverride (org.eclipse.ceylon.cmr.api.DependencyOverride)1 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)1 ModuleInfoReader (org.eclipse.ceylon.cmr.api.ModuleInfoReader)1 DependencyDescriptor (org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor)1 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)1 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)1