Search in sources :

Example 11 with ArtifactContext

use of com.redhat.ceylon.cmr.api.ArtifactContext in project ceylon-compiler by ceylon.

the class CeylonPluginTool method installScripts.

private boolean installScripts(RepositoryManager repositoryManager, ModuleSpec module, boolean errorIfMissing) throws IOException {
    String version = module.getVersion();
    if ((version == null || version.isEmpty()) && !module.getName().equals(Module.DEFAULT_MODULE_NAME)) {
        version = checkModuleVersionsOrShowSuggestions(getRepositoryManager(), module.getName(), null, ModuleQuery.Type.ALL, null, null);
        if (version == null)
            return false;
    }
    File zipSource = null;
    List<File> existingScriptFolders = null;
    if (isSourceModule(module.getName(), version, applyCwd(sourceFolders))) {
        // copy it directly from the source
        existingScriptFolders = findExistingScriptFolders(module.getName(), errorIfMissing);
        if (existingScriptFolders.isEmpty()) {
            return false;
        }
    } else {
        // obtain it from the repo
        ArtifactContext context = new ArtifactContext(module.getName(), version, ArtifactContext.SCRIPTS_ZIPPED);
        ArtifactResult result = repositoryManager.getArtifactResult(context);
        if (result == null) {
            String err = getModuleNotFoundErrorMessage(repositoryManager, module.getName(), version);
            errorAppend(err);
            errorNewline();
            return false;
        }
        zipSource = result.artifact();
    }
    File moduleScriptDir = getModuleScriptDir(module);
    if (moduleScriptDir.exists()) {
        if (force)
            FileUtil.delete(moduleScriptDir);
        else {
            errorMsg("error.module.already.installed", module.getName(), moduleScriptDir);
            return false;
        }
    }
    if (!moduleScriptDir.mkdirs()) {
        errorMsg("error.unable.create.dest.dir", moduleScriptDir);
        return false;
    }
    if (zipSource != null)
        extractScripts(zipSource, moduleScriptDir);
    else {
        copyScripts(existingScriptFolders, moduleScriptDir);
    }
    msg("success.installed", module.getName(), moduleScriptDir);
    newline();
    return true;
}
Also used : ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) File(java.io.File) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Aggregations

ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)11 ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)8 File (java.io.File)6 RepositoryManager (com.redhat.ceylon.cmr.api.RepositoryManager)3 ArrayList (java.util.ArrayList)3 ModuleSpec (com.redhat.ceylon.common.tools.ModuleSpec)2 Module (com.redhat.ceylon.model.typechecker.model.Module)2 IOException (java.io.IOException)2 ModuleDependencyInfo (com.redhat.ceylon.cmr.api.ModuleDependencyInfo)1 ModuleInfo (com.redhat.ceylon.cmr.api.ModuleInfo)1 ModuleVersionDetails (com.redhat.ceylon.cmr.api.ModuleVersionDetails)1 Overrides (com.redhat.ceylon.cmr.api.Overrides)1 ModuleCopycat (com.redhat.ceylon.cmr.ceylon.ModuleCopycat)1 IOUtils (com.redhat.ceylon.cmr.impl.IOUtils)1 InvalidArchiveException (com.redhat.ceylon.cmr.impl.InvalidArchiveException)1 Backends (com.redhat.ceylon.common.Backends)1 LazyModule (com.redhat.ceylon.model.loader.model.LazyModule)1 LazyModuleManager (com.redhat.ceylon.model.loader.model.LazyModuleManager)1 ModuleImport (com.redhat.ceylon.model.typechecker.model.ModuleImport)1 FileNotFoundException (java.io.FileNotFoundException)1