use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class JSUtils method readModuleInfo.
@SuppressWarnings("unchecked")
@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String moduleVersion, File moduleArchive, boolean includeMembers, Overrides overrides) {
Map<String, Object> model = loadJsonModel(moduleArchive);
String name = asString(metaModelProperty(model, "$mod-name"));
if (!moduleName.equals(name)) {
throw new RuntimeException("Incorrect module");
}
String version = asString(metaModelProperty(model, "$mod-version"));
Set<ModuleDependencyInfo> dependencies = getModuleInfo(model, moduleName, version, overrides).getDependencies();
String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());
Integer major = null, minor = null;
String bin = asString(metaModelProperty(model, "$mod-bin"));
if (bin != null) {
int p = bin.indexOf('.');
if (p >= 0) {
major = Integer.parseInt(bin.substring(0, p));
minor = Integer.parseInt(bin.substring(p + 1));
} else {
major = Integer.parseInt(bin);
}
}
ModuleVersionDetails mvd = new ModuleVersionDetails(moduleName, version, null, null);
mvd.getArtifactTypes().add(new ModuleVersionArtifact(type, major, minor));
mvd.getDependencies().addAll(dependencies);
Object anns = metaModelProperty(model, "$mod-anns");
List<Map<String, Object>> annotations = null;
if (anns instanceof Map) {
// Pre-10.0 style annotations
annotations = new ArrayList<Map<String, Object>>(1);
annotations.add((Map<String, Object>) anns);
} else if (anns instanceof List) {
// 10.0+ style annotations
annotations = (List<Map<String, Object>>) anns;
}
if (annotations != null) {
for (Map<String, Object> annot : annotations) {
if (annot.containsKey("doc")) {
mvd.setDoc(asString(annot.get("doc")));
}
if (annot.containsKey("label")) {
mvd.setLabel(asString(annot.get("label")));
}
if (annot.containsKey("license")) {
mvd.setLicense(asString(annot.get("license")));
}
if (annot.containsKey("by")) {
Iterable<String> by = (Iterable<String>) annot.get("by");
if (by != null) {
for (String author : by) {
mvd.getAuthors().add(author);
}
}
}
}
}
if (includeMembers) {
mvd.setMembers(getMembers(moduleName, moduleArchive));
}
return mvd;
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class PropertiesDependencyResolver method resolveFromInputStream.
@Override
public ModuleInfo resolveFromInputStream(InputStream stream, String moduleName, String moduleVersion, Overrides overrides) {
try {
final Properties properties = new Properties();
properties.load(stream);
Set<ModuleDependencyInfo> infos = new LinkedHashSet<>();
for (Map.Entry<?, ?> entry : properties.entrySet()) {
String depUri = entry.getKey().toString();
String version = entry.getValue().toString();
boolean optional = false;
boolean shared = false;
if (depUri.startsWith("+")) {
depUri = depUri.substring(1);
shared = true;
}
if (depUri.endsWith("?")) {
depUri = depUri.substring(0, depUri.length() - 1);
optional = true;
}
String namespace = ModuleUtil.getNamespaceFromUri(depUri);
String modName = ModuleUtil.getModuleNameFromUri(depUri);
infos.add(new ModuleDependencyInfo(namespace, modName, version, optional, shared, Backends.JAVA));
}
ModuleInfo ret = new ModuleInfo(null, moduleName, moduleVersion, // FIXME: store this
ModuleUtil.getMavenGroupIdIfMavenModule(moduleName), ModuleUtil.getMavenArtifactIdIfMavenModule(moduleName), ModuleUtil.getMavenClassifierIfMavenModule(moduleName), null, infos);
if (overrides != null)
ret = overrides.applyOverrides(moduleName, moduleVersion, ret);
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class ModuleSourceMapper method overrideModuleImports.
protected void overrideModuleImports(Module module, ArtifactResult artifact) {
Overrides overrides = getContext().getRepositoryManager().getOverrides();
if (overrides != null) {
Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
for (ModuleImport i : module.getImports()) {
Module m = i.getModule();
if (m != null) {
existingModuleDependencies.add(new ModuleDependencyInfo(i.getNamespace(), m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport(), i.getNativeBackends()));
}
}
ModuleInfo sourceModuleInfo = new ModuleInfo(artifact.namespace(), artifact.name(), artifact.version(), artifact.groupId(), artifact.artifactId(), artifact.classifier(), null, existingModuleDependencies);
ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
List<ModuleImport> newModuleImports = new ArrayList<>();
for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
Module dependency = getModuleManager().getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
Backends backends = dependency.getNativeBackends();
ModuleImport newImport = new ModuleImport(dep.getNamespace(), dependency, dep.isOptional(), dep.isExport(), backends);
newModuleImports.add(newImport);
}
module.overrideImports(newModuleImports);
}
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class AbstractTestTool method findTestVersionInDependecies.
private String findTestVersionInDependecies(String moduleAndVersion) {
String moduleName = ModuleUtil.moduleName(moduleAndVersion);
String moduleVersion = ModuleUtil.moduleVersion(moduleAndVersion);
ModuleDependencyInfo root = new ModuleDependencyInfo(null, moduleName, moduleVersion, false, false);
Queue<ModuleDependencyInfo> queue = new LinkedList<ModuleDependencyInfo>();
queue.add(root);
while (!queue.isEmpty()) {
String foundVersion = findTestVersionInDependecies(queue.poll(), queue);
if (foundVersion != null) {
return foundVersion;
}
}
return null;
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class XmlDependencyResolver method resolveFromInputStream.
@Override
public ModuleInfo resolveFromInputStream(InputStream stream, String name, String version, Overrides overrides) {
try {
final Module module = parse(stream);
final Set<ModuleDependencyInfo> infos = new LinkedHashSet<>();
for (ModuleIdentifier mi : module.getDependencies()) {
infos.add(new ModuleDependencyInfo(null, mi.getName(), mi.getSlot(), mi.isOptional(), mi.isExport(), Backends.JAVA));
}
ModuleInfo ret = new ModuleInfo(null, name, version, module.getGroupId(), module.getArtifactId(), null, module.getFilter(), infos);
if (overrides != null)
ret = overrides.applyOverrides(name, version, ret);
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations