use of com.redhat.ceylon.cmr.api.ArtifactContext in project ceylon-compiler by ceylon.
the class CeylonDocTool method makeDoc.
private void makeDoc() throws IOException {
buildNodesMaps();
if (includeSourceCode) {
copySourceFiles();
}
collectSubclasses();
collectAnnotationConstructors();
// document every module
boolean documentedOne = false;
for (Module module : modules) {
if (isEmpty(module)) {
log.warning(CeylondMessages.msg("warn.moduleHasNoDeclaration", module.getNameAsString()));
} else {
documentedOne = true;
}
documentModule(module);
ArtifactContext artifactDocs = new ArtifactContext(module.getNameAsString(), module.getVersion(), ArtifactContext.DOCS);
// find all doc folders to copy
File outputDocFolder = getDocOutputFolder(module);
for (File docFolder : docFolders) {
File moduleDocFolder = new File(docFolder, join("/", module.getName()));
if (moduleDocFolder.exists()) {
FileUtil.copyAll(moduleDocFolder, outputDocFolder);
}
}
repositoryRemoveArtifact(outputRepositoryManager, artifactDocs);
repositoryPutArtifact(outputRepositoryManager, artifactDocs, getOutputFolder(module, null));
}
if (!documentedOne) {
log.warning(CeylondMessages.msg("warn.couldNotFindAnyDeclaration"));
}
if (browse) {
for (Module module : modules) {
if (isEmpty(module)) {
continue;
}
ArtifactContext docArtifact = new ArtifactContext(module.getNameAsString(), module.getVersion(), ArtifactContext.DOCS);
File docFolder = outputRepositoryManager.getArtifact(docArtifact);
File docIndex = new File(docFolder, "api/index.html");
if (docIndex.isFile()) {
try {
Desktop.getDesktop().browse(docIndex.toURI());
} catch (Exception e) {
log.error(CeylondMessages.msg("error.unableBrowseModuleDoc", docIndex.toURI()));
}
}
}
}
}
use of com.redhat.ceylon.cmr.api.ArtifactContext in project ceylon-compiler by ceylon.
the class CeylonP2Tool method collectModules.
private void collectModules(RepositoryManager repoManager, String name, String version, Map<String, ModuleInfo> allModules) throws IOException {
// ignore JDK dependencies
if (CeylonP2Tool.skipModule(name))
return;
String key = name + "/" + version;
if (allModules.containsKey(key))
return;
ArtifactResult artifact = repoManager.getArtifactResult(new ArtifactContext(name, version, ArtifactContext.CAR, ArtifactContext.JAR));
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(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);
}
}
}
use of com.redhat.ceylon.cmr.api.ArtifactContext in project ceylon-compiler by ceylon.
the class CeylonPluginTool method addScripts.
private boolean addScripts(RepositoryManager outputRepositoryManager, ModuleSpec module, boolean errorIfMissing) throws IOException {
// find all doc folders to zip
List<File> existingScriptFolders = findExistingScriptFolders(module.getName(), errorIfMissing);
if (existingScriptFolders.isEmpty()) {
return false;
}
String version;
if (!module.getName().equals(Module.DEFAULT_MODULE_NAME)) {
ModuleVersionDetails mvd = getVersionFromSource(module.getName());
if (mvd == null) {
errorMsg("error.no.script.version", module.getName());
return false;
}
version = mvd.getVersion();
} else {
version = null;
}
ArtifactContext artifactScriptsZip = new ArtifactContext(module.getName(), version, ArtifactContext.SCRIPTS_ZIPPED);
// make the doc zip roots
IOUtils.ZipRoot[] roots = new IOUtils.ZipRoot[existingScriptFolders.size()];
int d = 0;
for (File scriptFolder : existingScriptFolders) {
roots[d] = new IOUtils.ZipRoot(scriptFolder, "");
}
File scriptZipFile = IOUtils.zipFolders(roots);
File scriptZipSha1File = ShaSigner.sign(scriptZipFile, log, verbose != null);
if (!repositoryRemoveArtifact(outputRepositoryManager, artifactScriptsZip))
return true;
if (!repositoryRemoveArtifact(outputRepositoryManager, artifactScriptsZip.getSha1Context()))
return true;
if (!repositoryPutArtifact(outputRepositoryManager, artifactScriptsZip, scriptZipFile))
return true;
if (!repositoryPutArtifact(outputRepositoryManager, artifactScriptsZip.getSha1Context(), scriptZipSha1File))
return true;
scriptZipFile.delete();
scriptZipSha1File.delete();
msg("success.packed", module.getName());
newline();
return true;
}
use of com.redhat.ceylon.cmr.api.ArtifactContext 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();
}
}
}
use of com.redhat.ceylon.cmr.api.ArtifactContext in project ceylon-compiler by ceylon.
the class CeylonEnter method addOutputModuleToClassPath.
public void addOutputModuleToClassPath(Module module) {
RepositoryManager repositoryManager = fileManager.getOutputRepositoryManager();
ArtifactResult artifact = null;
try {
ArtifactContext ctx = new ArtifactContext(module.getNameAsString(), module.getVersion(), ArtifactContext.CAR, ArtifactContext.JAR);
artifact = repositoryManager.getArtifactResult(ctx);
} catch (InvalidArchiveException e) {
log.error("ceylon", "Module car " + e.getPath() + " obtained from repository " + e.getRepository() + " has an invalid SHA1 signature: you need to remove it and rebuild the archive, since it" + " may be corrupted.");
} catch (Exception e) {
String moduleName = module.getNameAsString();
if (!module.isDefault())
moduleName += "/" + module.getVersion();
log.error("ceylon", "Exception occured while trying to resolve module " + moduleName);
e.printStackTrace();
}
addModuleToClassPath(module, false, artifact);
}
Aggregations