Search in sources :

Example 1 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class ModuleWildcardsHelper method expandSpecWildcards.

/**
 * Given a list of source directories and a list of ModuleSpecs
 * that possibly contain wildcards it returns a expanded list of
 * ModuleSpecs of modules that were actually found in the given
 * source directories. ModuleSpecs that didn't contain wildcards
 * are left alone (it's not checked if they exist or not).
 * If a Backend is passed expanded modules will be checked if
 * they support it (they either don't have a native annotation
 * or it is for the correct backend).
 * @param dirs The list of source directories
 * @param names The list of ModuleSpecs
 * @param forBackend The Backend for which we work or null
 * @return An expanded list of ModuleSpecs
 */
public static List<ModuleSpec> expandSpecWildcards(List<File> dirs, List<ModuleSpec> modules, Backend forBackend) {
    List<ModuleSpec> result = new ArrayList<ModuleSpec>(modules.size());
    for (ModuleSpec spec : modules) {
        List<String> names = new ArrayList<String>();
        expandWildcard(names, dirs, spec.getName(), forBackend);
        for (String name : names) {
            result.add(new ModuleSpec(spec.getNamespace(), name, spec.getVersion()));
        }
    }
    return result;
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ArrayList(java.util.ArrayList)

Example 2 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

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(module.getName(), null, ModuleQuery.Type.SRC, null, null, 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(module.getName(), null, ModuleQuery.Type.SRC, null, null, null, null);
        }
        msg("retrieving.module", module).newline();
        ArtifactContext allArtifacts = new ArtifactContext(null, 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", false);
            }
        }
        if (!hasSources) {
            msg("no.sources.found", module).newline();
        }
    }
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 3 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class CeylonWarTool method run.

@Override
public void run() throws Exception {
    String moduleName = null;
    String moduleVersion = null;
    for (ModuleSpec module : modules) {
        String name = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(name, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            continue;
        if (!loadModule(null, name, version))
            throw new ToolUsageError(CeylonWarMessages.msg("abort.missing.modules"));
        // save the first module
        if (moduleName == null) {
            moduleName = name;
            moduleVersion = version;
        }
    }
    loader.resolve();
    List<ArtifactResult> staticMetamodelEntries = new ArrayList<>();
    addLibEntries(staticMetamodelEntries);
    addResources();
    if (this.name == null) {
        this.name = moduleVersion != null && !moduleVersion.isEmpty() ? String.format("%s-%s.war", moduleName, moduleVersion) : String.format("%s.war", moduleName);
        debug("default.name", this.name);
    }
    final File jarFile = getJarFile();
    writeJarFile(jarFile, staticMetamodelEntries);
    String descr = moduleVersion != null && !moduleVersion.isEmpty() ? moduleName + "/" + moduleVersion : moduleName;
    append(CeylonWarMessages.msg("archive.created", descr, jarFile.getAbsolutePath()));
    newline();
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) ArrayList(java.util.ArrayList) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 4 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class CeylonCopyTool method run.

@Override
public void run() throws Exception {
    Set<String> artifacts = new LinkedHashSet<String>();
    boolean defaults = js == null && jvm == null && dart == null && src == null && scripts == null && docs == null && all == null;
    if (BooleanUtil.isTrue(all)) {
        artifacts.addAll(Arrays.asList(ArtifactContext.allSuffixes()));
    }
    if (BooleanUtil.isTrue(js) || defaults) {
        artifacts.add(ArtifactContext.JS);
        artifacts.add(ArtifactContext.JS_MODEL);
        artifacts.add(ArtifactContext.RESOURCES);
    } else if (BooleanUtil.isFalse(js)) {
        artifacts.remove(ArtifactContext.JS);
        artifacts.remove(ArtifactContext.JS_MODEL);
        artifacts.remove(ArtifactContext.RESOURCES);
    }
    if (BooleanUtil.isTrue(jvm) || defaults) {
        // put the CAR first since its presence will shortcut the other three
        artifacts.add(ArtifactContext.CAR);
        artifacts.add(ArtifactContext.JAR);
        artifacts.add(ArtifactContext.MODULE_PROPERTIES);
        artifacts.add(ArtifactContext.MODULE_XML);
    } else if (BooleanUtil.isFalse(jvm)) {
        artifacts.remove(ArtifactContext.CAR);
        artifacts.remove(ArtifactContext.JAR);
        artifacts.remove(ArtifactContext.MODULE_PROPERTIES);
        artifacts.remove(ArtifactContext.MODULE_XML);
    }
    if (BooleanUtil.isTrue(dart) || defaults) {
        artifacts.add(ArtifactContext.DART);
        artifacts.add(ArtifactContext.DART_MODEL);
        artifacts.add(ArtifactContext.RESOURCES);
    } else if (BooleanUtil.isFalse(dart)) {
        artifacts.remove(ArtifactContext.DART);
        artifacts.remove(ArtifactContext.DART_MODEL);
        artifacts.remove(ArtifactContext.RESOURCES);
    }
    if (BooleanUtil.isTrue(src)) {
        artifacts.add(ArtifactContext.SRC);
    } else if (BooleanUtil.isFalse(src)) {
        artifacts.remove(ArtifactContext.SRC);
    }
    if (BooleanUtil.isTrue(scripts)) {
        artifacts.add(ArtifactContext.SCRIPTS_ZIPPED);
    } else if (BooleanUtil.isFalse(scripts)) {
        artifacts.remove(ArtifactContext.SCRIPTS_ZIPPED);
    }
    if (BooleanUtil.isTrue(docs)) {
        artifacts.add(ArtifactContext.DOCS);
    } else if (BooleanUtil.isFalse(docs)) {
        artifacts.remove(ArtifactContext.DOCS);
    }
    // Create the list of ArtifactContexts to copy
    List<ArtifactContext> acs = new ArrayList<ArtifactContext>();
    String[] artifactsArray = new String[artifacts.size()];
    artifacts.toArray(artifactsArray);
    for (ModuleSpec module : modules) {
        if (module != ModuleSpec.DEFAULT_MODULE && !module.isVersioned()) {
            String version = checkModuleVersionsOrShowSuggestions(module.getName(), null, ModuleQuery.Type.ALL, null, null, null, null);
            module = new ModuleSpec(module.getNamespace(), module.getName(), version);
        }
        ArtifactContext ac = new ArtifactContext(null, module.getName(), module.getVersion(), artifactsArray);
        ac.setIgnoreDependencies(!withDependencies);
        ac.setForceOperation(true);
        acs.add(ac);
    }
    // Now do the actual copying
    final boolean logArtifacts = verbose != null && (verbose.contains("all") || verbose.contains("files"));
    ModuleCopycat copier = new ModuleCopycat(getRepositoryManager(), getOutputRepositoryManager(), getLogger(), new ModuleCopycat.CopycatFeedback() {

        boolean haveSeenArtifacts = false;

        @Override
        public boolean beforeCopyModule(ArtifactContext ac, int count, int max) throws IOException {
            String module = ModuleUtil.makeModuleName(ac.getName(), ac.getVersion());
            msg("copying.module", module, count + 1, max).flush();
            haveSeenArtifacts = false;
            return true;
        }

        @Override
        public void afterCopyModule(ArtifactContext ac, int count, int max, boolean copied) throws IOException {
            if (!logArtifacts || !haveSeenArtifacts) {
                String msg;
                if (copied) {
                    msg = OSUtil.color(Messages.msg(bundle, "copying.ok"), OSUtil.Color.green);
                } else {
                    msg = OSUtil.color(Messages.msg(bundle, "copying.skipped"), OSUtil.Color.yellow);
                }
                if (haveSeenArtifacts) {
                    append(")");
                }
                append(" ").append(msg).newline().flush();
            }
        }

        @Override
        public boolean beforeCopyArtifact(ArtifactContext ac, ArtifactResult ar, int count, int max) throws IOException {
            haveSeenArtifacts = true;
            if (logArtifacts) {
                if (count == 0) {
                    append(" -- ");
                    append(ar.repositoryDisplayString());
                    newline().flush();
                }
                append("    ").msg("copying.artifact", ar.artifact().getName(), count + 1, max).flush();
            } else {
                if (count > 0) {
                    append(", ");
                } else {
                    append(" (");
                }
                String name = ArtifactContext.getSuffixFromFilename(ar.artifact().getName());
                if (name.startsWith(".") || name.startsWith("-")) {
                    name = name.substring(1);
                } else if ("module-doc".equals(name)) {
                    name = "doc";
                }
                append(name);
            }
            return true;
        }

        @Override
        public void afterCopyArtifact(ArtifactContext ac, ArtifactResult ar, int count, int max, boolean copied) throws IOException {
            haveSeenArtifacts = true;
            if (logArtifacts) {
                append(" ").msg((copied) ? "copying.ok" : "copying.skipped").newline().flush();
            }
        }

        @Override
        public void notFound(ArtifactContext ac) throws IOException {
            String err = getModuleNotFoundErrorMessage(getRepositoryManager(), ac.getName(), ac.getVersion());
            errorAppend(err);
            errorNewline();
        }
    });
    copier.includeLanguage(includeLanguage).excludeModules(excludeModules).copyModules(acs);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) ModuleCopycat(org.eclipse.ceylon.cmr.ceylon.ModuleCopycat) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec)

Example 5 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class Feature method parseXml.

private void parseXml(Element root) {
    this.label = root.getAttribute("label");
    this.provider = root.getAttribute("provider-name");
    this.description = CeylonP2Tool.getContent(root, "description");
    this.license = CeylonP2Tool.getContent(root, "license");
    this.copyright = CeylonP2Tool.getContent(root, "copyright");
    NodeList nodes = root.getElementsByTagName("plugin");
    for (int i = 0; i < nodes.getLength(); i++) {
        Element plugin = (Element) nodes.item(i);
        dependencies.add(new ModuleSpec(null, plugin.getAttribute("id"), plugin.getAttribute("version")));
    }
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Aggregations

ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)35 File (java.io.File)18 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)13 ArrayList (java.util.ArrayList)11 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 ZipFile (java.util.zip.ZipFile)5 ModuleGraph (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph)5 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)4 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)4 List (java.util.List)3 ZipEntry (java.util.zip.ZipEntry)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 Module (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module)3 Ignore (org.junit.Ignore)3 BufferedReader (java.io.BufferedReader)2 FileOutputStream (java.io.FileOutputStream)2