use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.
the class MavenUtils method getDependencies.
public static ModuleInfo getDependencies(InputStream stream, String name, String version) throws IOException {
Document doc;
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(stream);
} catch (ParserConfigurationException e) {
throw new IOException(e);
} catch (SAXException e) {
throw new IOException(e);
}
doc.getDocumentElement().normalize();
Element root = doc.getDocumentElement();
String modGroupId = getText(root, "groupId");
// can be null, inherited from parent
if (modGroupId == null) {
Element parent = getFirstElement(root, "parent");
if (parent != null)
modGroupId = getText(parent, "groupId");
}
String modArtifactId = getText(root, "artifactId");
String classifier = getText(root, "classifier");
String modVersion = getText(root, "version");
// can be null, inherited from parent
if (modVersion == null) {
Element parent = getFirstElement(root, "parent");
if (parent != null)
modVersion = getText(parent, "version");
}
String modName = modGroupId + ":" + modArtifactId;
if (name != null && !name.equals(modName))
return null;
if (version != null && !version.equals(modVersion))
return null;
Element deps = getFirstElement(root, "dependencies");
Set<ModuleDependencyInfo> ret = new HashSet<>();
if (deps != null) {
NodeList depList = deps.getElementsByTagName("dependency");
if (depList != null) {
for (int i = 0; i < depList.getLength(); i++) {
Element dep = (Element) depList.item(i);
String depGroupId = getText(dep, "groupId");
String depArtifactId = getText(dep, "artifactId");
String depClassifier = getText(dep, "classifier");
String depVersion = getText(dep, "version");
String depScope = getText(dep, "scope");
String depOptional = getText(dep, "optional");
ModuleScope scope;
// keep compile, runtime, provided
if (depScope != null && (depScope.equals("system") || depScope.equals("test")))
continue;
if ("provided".equals(depScope))
scope = ModuleScope.PROVIDED;
else if ("runtime".equals(depScope))
scope = ModuleScope.RUNTIME;
else
scope = ModuleScope.COMPILE;
ret.add(new ModuleDependencyInfo(MavenRepository.NAMESPACE, moduleName(depGroupId, depArtifactId, depClassifier), depVersion, "true".equals(depOptional), false, Backends.JAVA, scope));
}
}
}
return new ModuleInfo(MavenRepository.NAMESPACE, modName, modVersion, modGroupId, modArtifactId, classifier, null, ret);
}
use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.
the class ResolverTestCase method testMavenDependecyResolver.
@Test
public void testMavenDependecyResolver() throws Exception {
final MavenDependencyResolver resolver = new MavenDependencyResolver();
doTest(new Tester() {
public void run(CmrRepository repository, final File artifact) {
ModuleInfo infos = resolver.resolve(new TestArtifactResult(repository, "org.apache.camel:camel-core", "2.9.2", artifact), null);
Assert.assertNotNull(infos);
Assert.assertEquals(String.valueOf(infos), 3, infos.getDependencies().size());
}
});
}
use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.
the class NpmUtils method getModuleInfo.
private ModuleInfo getModuleInfo(Object obj, String moduleName, String version, Overrides overrides) {
if (obj == null) {
return new ModuleInfo(NpmRepository.NAMESPACE, moduleName, version, null, null, null, null, NO_DEPS);
}
if (!(obj instanceof Map)) {
throw new RuntimeException("Expected an Object");
}
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj;
Set<ModuleDependencyInfo> deps = new HashSet<ModuleDependencyInfo>();
for (String depName : map.keySet()) {
String depVersion = asString(map.get(depName));
deps.add(new ModuleDependencyInfo(NpmRepository.NAMESPACE, depName, depVersion, false, false, Backends.JS));
}
ModuleInfo result = new ModuleInfo(NpmRepository.NAMESPACE, moduleName, version, null, null, null, null, deps);
if (overrides != null)
result = overrides.applyOverrides(moduleName, version, result);
return result;
}
use of org.eclipse.ceylon.cmr.api.ModuleInfo in project ceylon by eclipse.
the class JarUtils method getDependencies.
private static ModuleInfo getDependencies(File moduleArchive, String name, String version, Overrides overrides) {
// FIXME: also look inside the dependencies for descriptors
File xml = new File(moduleArchive.getParentFile(), "module.xml");
ModuleInfo result = getDependenciesFromFile(xml, name, version, overrides);
if (result != null) {
return result;
}
File props = new File(moduleArchive.getParentFile(), "module.properties");
return getDependenciesFromFile(props, name, version, overrides);
}
use of org.eclipse.ceylon.cmr.api.ModuleInfo 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);
}
}
Aggregations