use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.
the class CeylonBrowseTool method run.
@Override
public void run() throws Exception {
for (ModuleSpec module : modules) {
List<ModuleVersionDetails> versions = new ArrayList<ModuleVersionDetails>(getModuleVersions(getRepositoryManager(), module.getName(), module.getVersion(), ModuleQuery.Type.ALL, null, null));
Collections.sort(versions);
if (versions.isEmpty()) {
String err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion());
errorAppend(err);
errorNewline();
continue;
}
ModuleVersionDetails mvd = versions.get(versions.size() - 1);
browseDoc(mvd);
}
}
use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.
the class CeylonInfoTool method run.
@Override
public void run() throws Exception {
if (showIncompatible != Incompatible.yes) {
binaryMajor = Versions.JVM_BINARY_MAJOR_VERSION;
binaryMinor = Versions.JVM_BINARY_MINOR_VERSION;
}
String msgkey = showIncompatible == Incompatible.no ? "module.not.found.compat" : "module.not.found";
for (ModuleSpec module : modules) {
String name = module.getName();
if (!module.isVersioned() && (name.startsWith("*") || name.endsWith("*"))) {
Collection<ModuleDetails> modules = getModules(getRepositoryManager(), name, queryType, binaryMajor, binaryMinor);
if (modules.isEmpty()) {
String err;
if (name.startsWith("*") || name.endsWith("*")) {
err = CeylonInfoMessages.msg("no.match", name);
} else {
err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion(), msgkey);
}
errorAppend(err);
errorNewline();
continue;
}
outputModules(module, modules);
} else {
Collection<ModuleVersionDetails> versions = getModuleVersions(getRepositoryManager(), module.getName(), module.getVersion(), queryType, binaryMajor, binaryMinor);
if (versions.isEmpty()) {
// try from source
ModuleVersionDetails fromSource = getVersionFromSource(name);
if (fromSource != null) {
// is it the version we're after?
versions = Arrays.asList(fromSource);
} else {
if (showIncompatible == Incompatible.auto && (binaryMajor != null || binaryMinor != null)) {
// If we were called with a specific version and we didn't find a "compatible"
// artifact then lets see if we can find an "incompatible" one
versions = getModuleVersions(getRepositoryManager(), module.getName(), module.getVersion(), queryType, null, null);
}
if (versions.isEmpty()) {
String err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion(), msgkey);
errorAppend(err);
errorNewline();
continue;
}
}
}
if (module.getVersion() == null || module.getVersion().isEmpty() || versions.size() > 1) {
outputVersions(module, versions);
} else {
outputDetails(module, versions.iterator().next());
}
}
}
}
use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.
the class CeylonDocTool method initialize.
@Override
public void initialize(CeylonTool mainTool) {
TypeCheckerBuilder builder = new TypeCheckerBuilder();
for (File src : sourceFolders) {
builder.addSrcDirectory(src);
}
// set up the artifact repository
RepositoryManager repository = getRepositoryManager();
builder.setRepositoryManager(repository);
// make a destination repo
outputRepositoryManager = getOutputRepositoryManager();
// create the actual list of modules to process
List<File> srcs = FileUtil.applyCwd(cwd, sourceFolders);
List<String> expandedModules = ModuleWildcardsHelper.expandWildcards(srcs, moduleSpecs, null);
final List<ModuleSpec> modules = ModuleSpec.parseEachList(expandedModules);
// we need to plug in the module manager which can load from .cars
builder.moduleManagerFactory(new ModuleManagerFactory() {
@Override
public ModuleManager createModuleManager(Context context) {
return new CeylonDocModuleManager(CeylonDocTool.this, context, modules, outputRepositoryManager, bootstrapCeylon, log);
}
@Override
public ModuleSourceMapper createModuleManagerUtil(Context context, ModuleManager moduleManager) {
return new CeylonDocModuleSourceMapper(context, (CeylonDocModuleManager) moduleManager, CeylonDocTool.this);
}
});
// only parse what we asked for
List<String> moduleFilters = new LinkedList<String>();
for (ModuleSpec spec : modules) {
moduleFilters.add(spec.getName());
if (spec.getName().equals(Module.LANGUAGE_MODULE_NAME) && !bootstrapCeylon) {
throw new CeylondException("error.languageModuleBootstrapOptionMissing");
}
}
builder.setModuleFilters(moduleFilters);
String fileEncoding = getEncoding();
if (fileEncoding == null) {
fileEncoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
}
if (fileEncoding != null) {
builder.encoding(fileEncoding);
}
typeChecker = builder.getTypeChecker();
// collect all units we are typechecking
initTypeCheckedUnits(typeChecker);
typeChecker.process();
if (haltOnError && typeChecker.getErrors() > 0) {
throw new CeylondException("error.failedParsing", new Object[] { typeChecker.getErrors() }, null);
}
initModules(modules);
initPhasedUnits();
}
use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.
the class CeylonCopyTool method run.
@Override
public void run() throws Exception {
Set<String> artifacts = new LinkedHashSet<String>();
boolean defaults = js == null && jvm == 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(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(getRepositoryManager(), module.getName(), null, ModuleQuery.Type.ALL, null, null);
module = new ModuleSpec(module.getName(), version);
}
ArtifactContext ac = new ArtifactContext(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(), log, new ModuleCopycat.CopycatFeedback() {
@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();
return true;
}
@Override
public void afterCopyModule(ArtifactContext ac, int count, int max, boolean copied) throws IOException {
if (!logArtifacts) {
append(") ").msg((copied) ? "copying.ok" : "copying.skipped").newline().flush();
}
}
@Override
public boolean beforeCopyArtifact(ArtifactContext ac, ArtifactResult ar, int count, int max) throws IOException {
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 {
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.copyModules(acs);
}
use of com.redhat.ceylon.common.tools.ModuleSpec in project ceylon-compiler by ceylon.
the class ModuleInfo method getExportedPackages.
public List<ModuleSpec> getExportedPackages() {
String value = osgiAttributes.getValue("Export-Package");
List<ModuleSpec> ret = new LinkedList<>();
if (value != null) {
for (String pkg : value.split(",")) {
String[] details = pkg.split(";");
String name = details[0];
// GRRR: API of ModuleInfo
String version = "";
for (int i = 1; i < details.length; i++) {
if (details[i].startsWith("version=")) {
version = unquote(details[i].substring(8));
break;
}
}
ret.add(new ModuleSpec(name, version));
}
}
return ret;
}
Aggregations