Search in sources :

Example 1 with ModuleSpec

use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.

the class ModuleInfo method getImportedModules.

public List<ModuleSpec> getImportedModules() {
    String value = osgiAttributes.getValue("Require-Bundle");
    List<ModuleSpec> ret = new LinkedList<>();
    if (value != null) {
        for (String pkg : value.split(",")) {
            String[] details = pkg.split(";");
            String name = details[0];
            // skip some modules
            if (CeylonP2Tool.skipModule(name))
                continue;
            // GRRR: API of ModuleInfo
            String version = "";
            for (int i = 1; i < details.length; i++) {
                if (details[i].startsWith("bundle-version=")) {
                    version = unquote(details[i].substring(15));
                    break;
                }
            }
            ret.add(new ModuleSpec(name, version));
        }
    }
    return ret;
}
Also used : ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) LinkedList(java.util.LinkedList)

Example 2 with ModuleSpec

use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.

the class ModuleInfo method getImportedPackages.

public List<ModuleSpec> getImportedPackages() {
    String value = osgiAttributes.getValue("Import-Package");
    List<ModuleSpec> ret = new LinkedList<>();
    if (value != null) {
        for (String pkg : value.split(",")) {
            String[] details = pkg.split(";");
            String name = details[0];
            // GRRR: API of ModuleInfo
            String version = "";
            for (int i = 1; i < details.length; i++) {
                if (details[i].startsWith("version=")) {
                    version = unquote(details[i].substring(8));
                    break;
                }
            }
            ret.add(new ModuleSpec(name, version));
        }
    }
    return ret;
}
Also used : ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) LinkedList(java.util.LinkedList)

Example 3 with ModuleSpec

use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.

the class CeylonSrcTool method run.

@Override
public void run() throws Exception {
    // First check if all the arguments point to source archives
    for (ModuleSpec module : modules) {
        if (module != ModuleSpec.DEFAULT_MODULE && !module.isVersioned()) {
            if (checkModuleVersionsOrShowSuggestions(getRepositoryManager(), module.getName(), null, ModuleQuery.Type.SRC, null, null) == null) {
                return;
            }
        }
    }
    // If all are correct we unpack them
    for (ModuleSpec module : modules) {
        String version = module.getVersion();
        if (module != ModuleSpec.DEFAULT_MODULE && !module.isVersioned()) {
            version = checkModuleVersionsOrShowSuggestions(getRepositoryManager(), module.getName(), null, ModuleQuery.Type.SRC, null, null);
        }
        msg("retrieving.module", module).newline();
        ArtifactContext allArtifacts = new ArtifactContext(module.getName(), version, ArtifactContext.SRC, ArtifactContext.RESOURCES, ArtifactContext.DOCS, ArtifactContext.SCRIPTS_ZIPPED);
        List<ArtifactResult> results = getRepositoryManager().getArtifactResults(allArtifacts);
        if (results == null) {
            String err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion());
            errorAppend(err);
            errorNewline();
            continue;
        }
        String modFolder = module.getName().replace('.', File.separatorChar);
        boolean hasSources = false;
        for (ArtifactResult result : results) {
            String suffix = ArtifactContext.getSuffixFromFilename(result.artifact().getName());
            if (ArtifactContext.SRC.equals(suffix)) {
                append("    ").msg("extracting.sources").newline();
                extractArchive(result, applyCwd(src), "source");
                hasSources = true;
            } else if (ArtifactContext.SCRIPTS_ZIPPED.equals(suffix)) {
                append("    ").msg("extracting.scripts").newline();
                extractArchive(result, new File(applyCwd(script), modFolder), "script");
            } else if (ArtifactContext.RESOURCES.equals(suffix)) {
                append("    ").msg("extracting.resources").newline();
                copyResources(result, applyCwd(resource));
            } else if (ArtifactContext.DOCS.equals(suffix)) {
                append("    ").msg("extracting.docs").newline();
                copyFiles(result, "doc", new File(applyCwd(doc), modFolder), "doc");
            }
        }
        if (!hasSources) {
            msg("no.sources.found", module).newline();
        }
    }
}
Also used : ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) File(java.io.File) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Example 4 with ModuleSpec

use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.

the class CeylonInfoTool method run.

@Override
public void run() throws Exception {
    if (showIncompatible != Incompatible.yes) {
        binaryMajor = Versions.JVM_BINARY_MAJOR_VERSION;
        binaryMinor = Versions.JVM_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(), name, queryType, binaryMajor, binaryMinor);
            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.getName(), module.getVersion(), queryType, binaryMajor, binaryMinor);
            if (versions.isEmpty()) {
                // try from source
                ModuleVersionDetails fromSource = getVersionFromSource(name);
                if (fromSource != null) {
                    // is it the version we're after?
                    versions = Arrays.asList(fromSource);
                } else {
                    if (showIncompatible == Incompatible.auto && (binaryMajor != null || binaryMinor != 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.getName(), module.getVersion(), queryType, 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(com.redhat.ceylon.common.tools.ModuleSpec) ModuleVersionDetails(com.redhat.ceylon.cmr.api.ModuleVersionDetails) ModuleDetails(com.redhat.ceylon.cmr.api.ModuleSearchResult.ModuleDetails)

Example 5 with ModuleSpec

use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.

the class CeylonP2Tool method printUnitFeature.

private void printUnitFeature(XMLStreamWriter writer, Feature feature, boolean group) throws XMLStreamException {
    writer.writeStartElement("unit");
    String name = feature.name + (group ? ".feature.group" : ".feature.jar");
    writer.writeAttribute("id", name);
    writer.writeAttribute("version", feature.version);
    if (group) {
        writer.writeAttribute("singleton", "false");
        {
            writer.writeEmptyElement("update");
            writer.writeAttribute("id", name);
            writer.writeAttribute("range", "[0.0.0," + feature.version + ")");
            writer.writeAttribute("severity", "0");
        }
    }
    {
        writer.writeStartElement("properties");
        SortedMap<String, String> properties = feature.getProperties();
        writer.writeAttribute("size", String.valueOf(properties.size() + (group ? 1 : 0)));
        for (Map.Entry<String, String> property : properties.entrySet()) {
            writer.writeEmptyElement("property");
            writer.writeAttribute("name", property.getKey());
            writer.writeAttribute("value", property.getValue());
        }
        if (group) {
            writer.writeEmptyElement("property");
            writer.writeAttribute("name", "org.eclipse.equinox.p2.type.group");
            writer.writeAttribute("value", "true");
        }
        writer.writeEndElement();
    }
    {
        writer.writeStartElement("provides");
        writer.writeAttribute("size", group ? "1" : "3");
        {
            writer.writeEmptyElement("provided");
            writer.writeAttribute("namespace", "org.eclipse.equinox.p2.iu");
            writer.writeAttribute("name", name);
            writer.writeAttribute("version", feature.version);
        }
        if (!group) {
            {
                writer.writeEmptyElement("provided");
                writer.writeAttribute("namespace", "org.eclipse.equinox.p2.eclipse.type");
                writer.writeAttribute("name", "feature");
                writer.writeAttribute("version", "1.0.0");
            }
            {
                writer.writeEmptyElement("provided");
                writer.writeAttribute("namespace", "org.eclipse.update.feature");
                writer.writeAttribute("name", feature.name);
                writer.writeAttribute("version", feature.version);
            }
        }
        writer.writeEndElement();
    }
    if (group) {
        writer.writeStartElement("requires");
        List<ModuleSpec> importedModules = feature.getImportedModules();
        writer.writeAttribute("size", String.valueOf(importedModules.size() + 1));
        for (ModuleSpec mod : importedModules) {
            writer.writeEmptyElement("required");
            writer.writeAttribute("namespace", "org.eclipse.equinox.p2.iu");
            writer.writeAttribute("name", mod.getName());
            writer.writeAttribute("range", "[" + mod.getVersion() + "," + mod.getVersion() + "]");
        }
        {
            writer.writeStartElement("required");
            writer.writeAttribute("namespace", "org.eclipse.equinox.p2.iu");
            writer.writeAttribute("name", feature.name + ".feature.jar");
            writer.writeAttribute("range", "[" + feature.version + "," + feature.version + "]");
            {
                writer.writeStartElement("filter");
                writer.writeCharacters("(org.eclipse.update.install.features=true)");
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    } else {
        writer.writeStartElement("filter");
        writer.writeCharacters("(org.eclipse.update.install.features=true)");
        writer.writeEndElement();
        {
            writer.writeStartElement("artifacts");
            writer.writeAttribute("size", "1");
            {
                writer.writeEmptyElement("artifact");
                writer.writeAttribute("classifier", "org.eclipse.update.feature");
                writer.writeAttribute("id", feature.name);
                writer.writeAttribute("version", feature.version);
            }
            writer.writeEndElement();
        }
    }
    {
        writer.writeEmptyElement("touchpoint");
        writer.writeAttribute("id", group ? "null" : "org.eclipse.equinox.p2.osgi");
        writer.writeAttribute("version", group ? "0.0.0" : "1.0.0");
    }
    if (!group) {
        writer.writeStartElement("touchpointData");
        writer.writeAttribute("size", "1");
        {
            writer.writeStartElement("instructions");
            writer.writeAttribute("size", "1");
            {
                writer.writeStartElement("instruction");
                writer.writeAttribute("key", "zipped");
                writer.writeCharacters("true");
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
    {
        writer.writeStartElement("licenses");
        writer.writeAttribute("size", "1");
        {
            writer.writeStartElement("license");
            writer.writeAttribute("uri", "");
            writer.writeAttribute("url", "");
            writer.writeCharacters(feature.getLicense());
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
    {
        writer.writeStartElement("copyright");
        writer.writeCharacters(feature.getCopyright());
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
Also used : Entry(java.util.Map.Entry) ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) SortedMap(java.util.SortedMap)

Aggregations

ModuleSpec (com.redhat.ceylon.common.tools.ModuleSpec)11 LinkedList (java.util.LinkedList)4 ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)3 ModuleVersionDetails (com.redhat.ceylon.cmr.api.ModuleVersionDetails)2 RepositoryManager (com.redhat.ceylon.cmr.api.RepositoryManager)2 ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ModuleDetails (com.redhat.ceylon.cmr.api.ModuleSearchResult.ModuleDetails)1 ModuleCopycat (com.redhat.ceylon.cmr.ceylon.ModuleCopycat)1 TypeCheckerBuilder (com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder)1 ModuleSourceMapper (com.redhat.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper)1 Context (com.redhat.ceylon.compiler.typechecker.context.Context)1 ModuleManagerFactory (com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory)1 ModuleManager (com.redhat.ceylon.model.typechecker.util.ModuleManager)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Entry (java.util.Map.Entry)1 SortedMap (java.util.SortedMap)1