use of org.eclipse.ceylon.cmr.api.ModuleVersionDetails in project ceylon by eclipse.
the class URLContentStore method parseCompleteVersionsResponse.
protected void parseCompleteVersionsResponse(Parser p, ModuleVersionResult result, Overrides overrides) {
List<String> authors = new LinkedList<String>();
Set<ModuleDependencyInfo> dependencies = new HashSet<ModuleDependencyInfo>();
List<ModuleVersionArtifact> types = new LinkedList<ModuleVersionArtifact>();
p.moveToOpenTag("results");
while (p.moveToOptionalOpenTag("module-version")) {
String module = null, version = null, doc = null, license = null, label = null, groupId = null, artifactId = null;
authors.clear();
dependencies.clear();
types.clear();
while (p.moveToOptionalOpenTag()) {
if (p.isOpenTag("module")) {
// ignored
module = p.contents();
} else if (p.isOpenTag("version")) {
version = p.contents();
} else if (p.isOpenTag("doc")) {
doc = p.contents();
} else if (p.isOpenTag("groupId")) {
groupId = p.contents();
} else if (p.isOpenTag("artifactId")) {
artifactId = p.contents();
} else if (p.isOpenTag("license")) {
license = p.contents();
} else if (p.isOpenTag("label")) {
label = p.contents();
} else if (p.isOpenTag("authors")) {
authors.add(p.contents());
} else if (p.isOpenTag("dependency")) {
dependencies.add(parseDependency(p));
} else if (p.isOpenTag("artifact")) {
types.add(parseArtifact(p));
} else {
throw new RuntimeException("Unknown tag: " + p.tagName());
}
}
if (version == null || version.isEmpty())
throw new RuntimeException("Missing required version");
ModuleVersionDetails newVersion = result.addVersion(null, module, version);
if (newVersion != null) {
if (groupId != null && !groupId.isEmpty())
newVersion.setGroupId(groupId);
if (artifactId != null && !artifactId.isEmpty())
newVersion.setArtifactId(artifactId);
if (doc != null && !doc.isEmpty())
newVersion.setDoc(doc);
if (license != null && !license.isEmpty())
newVersion.setLicense(license);
if (label != null && !label.isEmpty())
newVersion.setLabel(label);
if (!authors.isEmpty())
newVersion.getAuthors().addAll(authors);
if (overrides != null) {
final ModuleInfo info = new ModuleInfo(null, module, version, groupId, artifactId, null, null, dependencies);
dependencies = overrides.applyOverrides(module, version, info).getDependencies();
}
if (!dependencies.isEmpty())
newVersion.getDependencies().addAll(dependencies);
if (!types.isEmpty())
newVersion.getArtifactTypes().addAll(types);
newVersion.setRemote(true);
if (isHerd()) {
newVersion.setOrigin(HERD_ORIGIN + " (" + getDisplayString() + ")");
} else {
newVersion.setOrigin(getDisplayString());
}
}
p.checkCloseTag();
}
p.checkCloseTag();
}
use of org.eclipse.ceylon.cmr.api.ModuleVersionDetails in project ceylon by eclipse.
the class URLContentStore method parseSearchModulesResponse.
protected void parseSearchModulesResponse(Parser p, ModuleSearchResult result, Long start) {
SortedSet<String> authors = new TreeSet<String>();
SortedSet<String> versions = new TreeSet<String>();
SortedSet<ModuleDependencyInfo> dependencies = new TreeSet<ModuleDependencyInfo>();
SortedSet<ModuleVersionArtifact> types = new TreeSet<ModuleVersionArtifact>();
p.moveToOpenTag("results");
String total = p.getAttribute("total");
long totalResults;
try {
if (total == null)
throw new RuntimeException("Missing total from result");
totalResults = Long.parseLong(total);
} catch (NumberFormatException x) {
throw new RuntimeException("Invalid total: " + total);
}
int resultCount = 0;
while (p.moveToOptionalOpenTag("module")) {
String module = null, doc = null, license = null, label = null, groupId = null, artifactId = null;
authors.clear();
versions.clear();
dependencies.clear();
types.clear();
resultCount++;
while (p.moveToOptionalOpenTag()) {
if (p.isOpenTag("name")) {
module = p.contents();
} else if (p.isOpenTag("versions")) {
// TODO This isn't really the way, we should have version tags
// inside the "module" tag containing all the rest of the
// information below
versions.add(p.contents());
} else if (p.isOpenTag("groupId")) {
groupId = p.contents();
} else if (p.isOpenTag("artifactId")) {
artifactId = p.contents();
} else if (p.isOpenTag("doc")) {
doc = p.contents();
} else if (p.isOpenTag("license")) {
license = p.contents();
} else if (p.isOpenTag("label")) {
label = p.contents();
} else if (p.isOpenTag("authors")) {
authors.add(p.contents());
} else if (p.isOpenTag("dependency")) {
dependencies.add(parseDependency(p));
} else if (p.isOpenTag("artifact")) {
ModuleVersionArtifact artifact = parseArtifact(p);
types.add(artifact);
} else {
throw new RuntimeException("Unknown tag: " + p.tagName());
}
}
if (module == null || module.isEmpty())
throw new RuntimeException("Missing required module name");
if (versions.isEmpty()) {
log.debug("Ignoring result for " + module + " because it doesn't have a single version");
} else {
// TODO See TODO above
for (String v : versions) {
ModuleVersionDetails mvd = new ModuleVersionDetails(null, module, v, groupId, artifactId);
mvd.setDoc(doc);
mvd.setLicense(license);
mvd.setLabel(label);
mvd.getAuthors().addAll(authors);
mvd.getDependencies().addAll(dependencies);
mvd.getArtifactTypes().addAll(types);
mvd.setRemote(true);
if (isHerd()) {
mvd.setOrigin(HERD_ORIGIN + " (" + getDisplayString() + ")");
} else {
mvd.setOrigin(getDisplayString());
}
result.addResult(module, mvd);
}
}
p.checkCloseTag();
}
p.checkCloseTag();
// see if we have more results
long realStart = start != null ? start : 0;
long resultsAfterThisPage = realStart + resultCount;
result.setHasMoreResults(resultsAfterThisPage < totalResults);
}
use of org.eclipse.ceylon.cmr.api.ModuleVersionDetails in project ceylon by eclipse.
the class AetherUtils method addSearchResult.
private void addSearchResult(String groupId, String artifactId, String version, ModuleVersionResult result, Overrides overrides, String repositoryDisplayString) throws AetherException {
ArtifactOverrides artifactOverrides = null;
String classifier = null;
if (overrides != null) {
ArtifactContext ctx = new ArtifactContext(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version);
// see if this artifact is replaced
ArtifactContext replaceContext = overrides.replace(ctx);
if (replaceContext != null) {
String[] groupArtifactIds = nameToGroupArtifactIds(replaceContext.getName());
if (groupArtifactIds == null)
// abort
return;
groupId = groupArtifactIds[0];
artifactId = groupArtifactIds[1];
classifier = groupArtifactIds[2];
version = replaceContext.getVersion();
ctx = replaceContext;
} else if (overrides.isVersionOverridden(ctx)) {
// perhaps its version is overridden?
version = overrides.getVersionOverride(ctx);
ctx.setVersion(version);
}
artifactOverrides = overrides.getArtifactOverrides(ctx);
}
DependencyDescriptor info = impl.getDependencies(groupId, artifactId, version, classifier, "pom", false);
if (info != null) {
StringBuilder description = new StringBuilder();
StringBuilder licenseBuilder = new StringBuilder();
collectInfo(info, description, licenseBuilder);
Set<ModuleDependencyInfo> dependencies = new HashSet<>();
Set<ModuleVersionArtifact> artifactTypes = new HashSet<>();
artifactTypes.add(new ModuleVersionArtifact(".jar", null, null));
Set<String> authors = new HashSet<>();
for (DependencyDescriptor dep : info.getDependencies()) {
String namespace = MavenRepository.NAMESPACE;
String depName = MavenUtils.moduleName(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier());
String depVersion = dep.getVersion();
boolean export = false;
boolean optional = dep.isOptional();
if (overrides != null) {
ArtifactContext depCtx = new ArtifactContext(namespace, depName, dep.getVersion());
if (overrides.isRemoved(depCtx) || (artifactOverrides != null && (artifactOverrides.isRemoved(depCtx) || artifactOverrides.isAddedOrUpdated(depCtx))))
continue;
ArtifactContext replaceCtx = overrides.replace(depCtx);
if (replaceCtx != null) {
depCtx = replaceCtx;
namespace = replaceCtx.getNamespace();
depName = replaceCtx.getName();
}
if (overrides.isVersionOverridden(depCtx))
depVersion = overrides.getVersionOverride(depCtx);
if (artifactOverrides != null) {
if (artifactOverrides.isShareOverridden(depCtx))
export = artifactOverrides.isShared(depCtx);
if (artifactOverrides.isOptionalOverridden(depCtx))
optional = artifactOverrides.isOptional(depCtx);
}
}
ModuleDependencyInfo moduleDependencyInfo = new ModuleDependencyInfo(namespace, depName, depVersion, optional, export, Backends.JAVA, toModuleScope(dep));
dependencies.add(moduleDependencyInfo);
}
if (artifactOverrides != null) {
for (DependencyOverride add : artifactOverrides.getAdd()) {
ArtifactContext ac = add.getArtifactContext();
ModuleDependencyInfo moduleDependencyInfo = new ModuleDependencyInfo(ac.getNamespace(), ac.getName(), ac.getVersion(), add.isOptional(), add.isShared(), Backends.JAVA, ModuleScope.COMPILE);
dependencies.add(moduleDependencyInfo);
}
}
ModuleVersionDetails moduleVersionDetails = new ModuleVersionDetails(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version, groupId, artifactId, null, description.length() > 0 ? description.toString() : null, licenseBuilder.length() > 0 ? licenseBuilder.toString() : null, authors, dependencies, artifactTypes, true, repositoryDisplayString);
result.addVersion(moduleVersionDetails);
}
}
use of org.eclipse.ceylon.cmr.api.ModuleVersionDetails in project ceylon by eclipse.
the class AetherTestCase method testListVersionsAether.
@Test
public void testListVersionsAether() throws Exception {
CmrRepository repository = createAetherRepository();
RepositoryManager manager = new SimpleRepositoryManager(repository, log);
ModuleVersionQuery lookup = new ModuleVersionQuery("com.sparkjava:spark-core", "1.", Type.JAR);
ModuleVersionResult result = manager.completeVersions(lookup);
Assert.assertEquals(3, result.getVersions().size());
Assert.assertNotNull(result.getVersions().get("1.0"));
Assert.assertNotNull(result.getVersions().get("1.1"));
Assert.assertNotNull(result.getVersions().get("1.1.1"));
for (ModuleVersionDetails res : result.getVersions().values()) {
Assert.assertEquals("Spark\nA Sinatra inspired java web framework\nhttp://www.sparkjava.com", res.getDoc());
Assert.assertEquals("The Apache Software License, Version 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0.txt", res.getLicense());
NavigableSet<ModuleDependencyInfo> deps = res.getDependencies();
List<ModuleDependencyInfo> compileDeps = new ArrayList<>(deps.size());
for (ModuleDependencyInfo dep : res.getDependencies()) {
if (dep.getModuleScope() == ModuleScope.COMPILE || dep.getModuleScope() == ModuleScope.PROVIDED)
compileDeps.add(dep);
}
Assert.assertEquals(4, compileDeps.size());
}
lookup = new ModuleVersionQuery("com.sparkjava:spark-core", null, Type.JAR);
result = manager.completeVersions(lookup);
// Count the version up to 2.3
int cnt = 0;
for (ModuleVersionDetails mvd : result.getVersions().values()) {
cnt++;
if ("2.3".equals(mvd.getVersion())) {
break;
}
}
Assert.assertEquals(7, cnt);
// now check that we only downloaded the POMs for that, and not the jars
File repo = new File("build/test-classes/maven-settings/repository");
File folder = new File(repo, "com/sparkjava/spark-core/1.0");
Assert.assertTrue(new File(folder, "spark-core-1.0.pom").exists());
Assert.assertFalse(new File(folder, "spark-core-1.0.jar").exists());
Assert.assertFalse(new File(repo, "org/eclipse/jetty/jetty-server/9.0.2.v20130417/jetty-server-9.0.2.v20130417.jar").exists());
// this one has a conflict if we do resolve it non-lazily
lookup = new ModuleVersionQuery("org.hibernate:hibernate-validator", "3.", Type.JAR);
result = manager.completeVersions(lookup);
Assert.assertEquals(4, result.getVersions().size());
}
use of org.eclipse.ceylon.cmr.api.ModuleVersionDetails 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;
}
Aggregations