use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractOpenNode method findService.
protected <T> T findService(Class<T> serviceType) {
T service = getService(serviceType);
if (service != null)
return service;
for (Node parent : getParents()) {
if (parent instanceof AbstractOpenNode) {
AbstractOpenNode dn = (AbstractOpenNode) parent;
T ps = dn.findService(serviceType);
if (ps != null) {
addService(serviceType, ps);
return ps;
}
}
}
throw new IllegalArgumentException("No such service [" + serviceType + "] found in node chain!");
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractRepository method collectArtifacts.
private void collectArtifacts(Node node, ModuleQuery lookup, ModuleSearchResult result) {
// Winner of the less aptly-named method
boolean isFolder = !node.hasBinaries();
if (isFolder) {
if (ArtifactContext.isDirectoryName(node.getLabel()))
return;
Ret ret = new Ret();
if (hasChildrenContainingArtifact(node, lookup, ret)) {
// we have artifact children, are they of the right type?
if (ret.foundRightType) {
// collect them
String moduleName = toModuleName(node);
ModuleVersionDetails mvd = getSearchResult(moduleName, node, lookup);
if (mvd != null) {
result.addResult(moduleName, mvd);
}
}
} else {
// collect in the children
List<Node> sortedChildren = new ArrayList<Node>();
for (Node child : node.getChildren()) sortedChildren.add(child);
Collections.sort(sortedChildren, AlphabeticalNodeComparator);
for (Node child : sortedChildren) {
collectArtifacts(child, lookup, result);
}
}
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractRepository method completeModules.
@Override
public void completeModules(ModuleQuery query, ModuleSearchResult result) {
// check for delegate
ContentFinderDelegate delegate = root.getService(ContentFinderDelegate.class);
if (delegate != null) {
delegate.completeModules(query, result, getOverrides());
return;
}
// this is only for non-Maven modules
if (ModuleUtil.isMavenModule(query.getName()))
return;
// we NEED the -1 limit here to get empty tokens
String[] paths = query.getName().split("\\.", -1);
// find the right parent
Node parent = root;
for (int i = 0; i < paths.length - 1; i++) {
parent = parent.getChild(paths[i]);
// no completion from here
if (parent == null)
return;
}
String lastPart = paths[paths.length - 1];
// now find a matching child
for (Node child : parent.getChildren()) {
if (child.getLabel().startsWith(lastPart)) {
collectArtifacts(child, query, result);
}
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractRepository method completeVersions.
@Override
public void completeVersions(ModuleVersionQuery lookup, ModuleVersionResult result) {
// check for delegate
ContentFinderDelegate delegate = root.getService(ContentFinderDelegate.class);
if (delegate != null) {
delegate.completeVersions(lookup, result, getOverrides());
return;
}
// this is only for non-Maven modules
if (ModuleUtil.isMavenModule(lookup.getName()))
return;
// FIXME: handle default module
// FIXME: we should really get this splitting done somewhere in common
String name = lookup.getName();
Node namePart = NodeUtils.getNode(root, Arrays.asList(name.split("\\.")));
if (namePart == null)
return;
String memberName = lookup.getMemberName();
// now each child is supposed to be a version part, let's verify that
for (Node child : namePart.getChildren()) {
// Winner of the less aptly-named method
boolean isFolder = !child.hasBinaries();
// ignore non-folders
if (!isFolder)
continue;
// now make sure we can find the artifact we're looking for in there
String version = child.getLabel();
// optional filter on version
if (lookup.getVersion() != null) {
if (lookup.isExactVersionMatch()) {
if (!version.equals(lookup.getVersion()))
continue;
} else {
if (!version.startsWith(lookup.getVersion()))
continue;
}
}
// avoid duplicates
if (result.hasVersion(version))
continue;
// try every known suffix
boolean found = false;
boolean foundInfo = false;
boolean binaryShouldMatch = false;
boolean binaryMatch = false;
// null here and read the info later
ModuleVersionDetails mvd = new ModuleVersionDetails(getNamespace(), name, version, null, null);
String[] suffixes = lookup.getType().getSuffixes();
// When we need to find ALL requested suffixes we maintain a set of those not found yet
HashSet<String> suffixesToFind = null;
if (lookup.getRetrieval() == Retrieval.ALL) {
suffixesToFind = new HashSet<String>(Arrays.asList(suffixes));
}
// Now try to retrieve information for each of the suffixes
for (String suffix : suffixes) {
String artifactName = getArtifactName(name, version, suffix);
Node artifact = child.getChild(artifactName);
if (artifact == null) {
if (lookup.getRetrieval() == Retrieval.ALL) {
break;
} else {
continue;
}
}
if (shouldCheckBinaryVersion(suffix)) {
binaryShouldMatch = true;
if (!checkBinaryVersion(name, version, artifact, lookup, suffix)) {
if (lookup.getRetrieval() == Retrieval.ALL) {
break;
} else {
continue;
}
}
binaryMatch = true;
}
// we found the artifact: let's notify
found = true;
if (lookup.getRetrieval() == Retrieval.ALL) {
suffixesToFind.remove(suffix);
}
// let's see if we can extract some information
switch(addArtifactInfo(artifact, name, version, suffix, memberName, mvd, lookup)) {
case INFO_FOUND:
foundInfo = true;
break;
case NO_MATCH:
continue;
case OTHER:
// nothing;
break;
}
}
// read the artifact's information
if (((found && memberName == null) || foundInfo) && (lookup.getRetrieval() == Retrieval.ANY || suffixesToFind.isEmpty()) && (!binaryShouldMatch || binaryMatch)) {
mvd.setRemote(root.isRemote());
mvd.setOrigin(getDisplayString());
result.addVersion(mvd);
}
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class JarUtils method descriptor.
@Override
public Node descriptor(Node artifact) {
Node parent = NodeUtils.firstParent(artifact);
Node descriptor = parent.getChild(ArtifactContext.MODULE_XML);
if (descriptor == null) {
descriptor = parent.getChild(ArtifactContext.MODULE_PROPERTIES);
}
return descriptor;
}
Aggregations