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;
}
Aggregations