Search in sources :

Example 6 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult 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 7 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult 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 8 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class CeylonP2Tool method collectModules.

private void collectModules(RepositoryManager repoManager, String name, String version, Map<String, ModuleInfo> allModules) throws IOException {
    // ignore JDK dependencies
    if (skipModule(name, version))
        return;
    String key = name + "/" + version;
    if (allModules.containsKey(key))
        return;
    ArtifactResult artifact = null;
    try {
        artifact = repoManager.getArtifactResult(new ArtifactContext(null, name, version, ArtifactContext.CAR, ArtifactContext.JAR));
    } catch (RuntimeException e) {
        if (e.getCause() instanceof IOException) {
            getLogger().warning(e.toString());
        } else {
            throw e;
        }
    }
    File artifactJar = null;
    if (artifact == null) {
        // try to find it in the plugins folder
        File pluginJar = new File(out, "plugins/" + name + "_" + version + ".jar");
        if (pluginJar.exists()) {
            artifactJar = pluginJar;
        }
    } else {
        artifactJar = artifact.artifact();
    }
    allModules.put(key, artifactJar != null ? new ModuleInfo(this, name, version, artifactJar) : null);
    if (artifact == null) {
        errorMsg("module.not.found", name + "/" + version, out + "/plugins");
    } else {
        msg("module.found", name + "/" + version, artifact != null ? artifact.repositoryDisplayString() : artifactJar.getPath());
        newline();
        for (ArtifactResult dep : artifact.dependencies()) {
            // FIXME: deal with optionals
            collectModules(repoManager, dep.name(), dep.version(), allModules);
        }
    }
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 9 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class ModuleLoadingTool method initialize.

@Override
public void initialize(CeylonTool mainTool) throws Exception {
    super.initialize(mainTool);
    loader = new ToolModuleLoader(this, getRepositoryManager(), getLoaderSuffixes());
    if (jdkProviderModule != null) {
        ModuleSpec moduleSpec = ModuleSpec.parse(jdkProviderModule);
        if (!internalLoadModule(null, moduleSpec.getName(), moduleSpec.getVersion())) {
            throw new ToolUsageError(Messages.msg(bundle, "jdk.provider.not.found", jdkProviderModule));
        }
        ArtifactResult result = loader.getModuleArtifact(moduleSpec.getName());
        jdkProvider = new JdkProvider(moduleSpec.getName(), moduleSpec.getVersion(), null, result.artifact());
    }
// else keep the JDK one
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) JdkProvider(org.eclipse.ceylon.model.loader.JdkProvider) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 10 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class AbstractCeylonArtifactResult method dependencies.

@Override
public List<ArtifactResult> dependencies() throws RepositoryException {
    ModuleInfo infos = resolve();
    // TODO -- perhaps null is not valid?
    if (infos == null || infos.getDependencies().isEmpty())
        return Collections.emptyList();
    final List<ArtifactResult> results = new ArrayList<ArtifactResult>();
    for (ModuleDependencyInfo mi : getOrderedDependencies(infos)) {
        results.add(new LazyArtifactResult(manager, mi.getNamespace(), mi.getName(), mi.getVersion(), mi.isExport(), mi.isOptional(), mi.getModuleScope()));
    }
    return results;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ArrayList(java.util.ArrayList) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Aggregations

ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)79 File (java.io.File)40 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)32 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)28 Test (org.junit.Test)28 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)25 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)15 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)13 FileOutputStream (java.io.FileOutputStream)6 InputStream (java.io.InputStream)5 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)5 Module (org.eclipse.ceylon.model.typechecker.model.Module)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ZipEntry (java.util.zip.ZipEntry)4 FileInputStream (java.io.FileInputStream)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3