Search in sources :

Example 6 with ModuleDependencyInfo

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

the class LegacyImporter method listPackages.

/**
 * Tries to determine which packages belong to which modules. If called with
 * <code>makeSuggestions</code> being <code>false</code> it will just detect
 * Java SDK modules and list any remaining packages. If passed <code>true</code>
 * it will also try to find matching modules in the <code>lookupRepository</code>
 * that was passed in the constructor. And finally it will list any classes
 * that are not in any package.
 * Feedback methods called: <code>beforeJdkModules()</code>, <code>aftrerJdkModules()</code>,
 * <code>dependency()</code>, <code>beforePackages()</code>, <code>afterPackages()</code>,
 * <code>packageName()</code>, <code>beforeClasses()</code>, <code>afterClasses()</code> and
 * <code>className()</code>.
 * @param makeSuggestions
 * @throws Exception
 */
public LegacyImporter listPackages(boolean makeSuggestions) throws Exception {
    gatherExternalClasses(null);
    if (scanner.hasExternalClasses()) {
        Set<String> externalPackages = scanner.getExternalPackages();
        Set<String> publicApiExternalPackages = scanner.getPublicApiExternalPackages();
        if (!externalPackages.isEmpty()) {
            Set<String> jdkModules = scanner.gatherJdkModules(externalPackages);
            Set<String> publicApiJdkModules = scanner.gatherJdkModules(publicApiExternalPackages);
            // the java.base import is always implied, let's not complain about it, unless we need to share it
            if (jdkModules.contains("java.base") && !publicApiJdkModules.contains("java.base"))
                jdkModules.remove("java.base");
            if (!jdkModules.isEmpty()) {
                feedback.beforeJdkModules();
                for (String mod : jdkModules) {
                    ModuleDependencyInfo dep = new ModuleDependencyInfo(null, mod, jdkProvider.getJDKVersion(), false, publicApiJdkModules.contains(mod), Backends.JAVA);
                    feedback.dependency(DependencyResults.DEP_JDK, dep);
                    expectedDependencies.add(dep);
                }
                feedback.afterJdkModules();
            }
            if (!externalPackages.isEmpty()) {
                feedback.beforePackages();
                for (String pkg : externalPackages) {
                    feedback.packageName(pkg, publicApiExternalPackages.contains(pkg));
                    if (makeSuggestions) {
                        outputSuggestions(pkg);
                    }
                }
                hasErrors = true;
                feedback.afterPackages();
            }
        }
        Set<String> externalDefaultClasses = scanner.getDefaultPackageClasses();
        Set<String> publicApiExternalDefaultClasses = scanner.getPublicApiDefaultPackageClasses();
        if (!externalDefaultClasses.isEmpty()) {
            feedback.beforeClasses();
            for (String cls : externalDefaultClasses) {
                feedback.className(cls, publicApiExternalDefaultClasses.contains(cls));
            }
            hasErrors = true;
            feedback.afterClasses();
        }
    }
    return this;
}
Also used : ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)

Example 7 with ModuleDependencyInfo

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

the class LegacyImporter method updateDescriptorProperties.

private void updateDescriptorProperties() throws IOException {
    Properties deps = new Properties();
    for (ModuleDependencyInfo mdi : expectedDependencies) {
        String key = mdi.getName();
        String val = mdi.getVersion();
        if (mdi.isExport()) {
            key = "+" + key;
        }
        if (mdi.isOptional()) {
            key = key + "?";
        }
        deps.setProperty(key, val);
    }
    try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(descriptorFile), "UTF-8")) {
        deps.store(out, "Generated by 'ceylon import-jar'");
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) OutputStreamWriter(java.io.OutputStreamWriter) Properties(java.util.Properties)

Example 8 with ModuleDependencyInfo

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

the class ModuleCopycat method copyModuleInternal.

private void copyModuleInternal(ArtifactContext context) throws Exception {
    assert (context != null);
    if (!shouldExclude(context.getName())) {
        String module = ModuleUtil.makeModuleName(context.getName(), context.getVersion());
        // Skip all duplicates and artifacts from repositories that don't support copying
        if (!copiedModules.add(module) || !canBeCopied(context)) {
            // Faking a copy here for feedback because it was already done and we never copy twice
            if (feedback != null) {
                feedback.beforeCopyModule(context, count++, maxCount);
            }
            if (feedback != null) {
                feedback.afterCopyModule(context, count, maxCount, false);
            }
            return;
        }
        Collection<ModuleVersionDetails> versions = getModuleVersions(srcRepoman, context.getName(), context.getVersion(), ModuleQuery.Type.ALL, null, null, null, null);
        if (!versions.isEmpty()) {
            ArtifactContext depContext = context.copy();
            ModuleVersionDetails ver = versions.iterator().next();
            boolean copyModule = true;
            if (feedback != null) {
                copyModule = feedback.beforeCopyModule(context, count++, maxCount);
            }
            boolean copiedModule = false;
            if (copyModule) {
                List<ArtifactResult> results = srcRepoman.getArtifactResults(context);
                int artCnt = 0;
                for (ArtifactResult r : results) {
                    boolean copyArtifact = true;
                    if (feedback != null) {
                        copyArtifact = feedback.beforeCopyArtifact(context, r, artCnt++, results.size());
                    }
                    boolean copied = copyArtifact && copyArtifact(context, r);
                    if (feedback != null) {
                        feedback.afterCopyArtifact(context, r, artCnt, results.size(), copied);
                    }
                    copiedModule |= copied;
                }
            }
            if (feedback != null) {
                feedback.afterCopyModule(context, count, maxCount, copiedModule);
            }
            if (copyModule && !context.isIgnoreDependencies()) {
                maxCount += countNonExcludedDeps(ver.getDependencies());
                for (ModuleDependencyInfo dep : ver.getDependencies()) {
                    if (skipDependency(dep)) {
                        continue;
                    }
                    ModuleSpec depModule = new ModuleSpec(dep.getNamespace(), dep.getName(), dep.getVersion());
                    ArtifactContext copyContext = depContext.copy();
                    copyContext.setNamespace(dep.getNamespace());
                    copyContext.setName(depModule.getName());
                    copyContext.setVersion(depModule.getVersion());
                    copyModuleInternal(copyContext);
                }
            }
        } else {
            if (feedback != null) {
                feedback.notFound(context);
            }
        }
    }
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 9 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo 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 10 with ModuleDependencyInfo

use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo 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)

Aggregations

ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)29 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)12 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)10 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)5 IOException (java.io.IOException)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)3 Backends (org.eclipse.ceylon.common.Backends)3 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 File (java.io.File)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 TreeSet (java.util.TreeSet)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 DependencyDescriptor (org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor)2 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)2