use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractRepository method getSearchResult.
private ModuleVersionDetails getSearchResult(String moduleName, Node namePart, ModuleQuery query) {
SortedSet<String> versions = new TreeSet<String>();
String[] suffixes = query.getType().getSuffixes();
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 at least one of the artifacts we're looking for is in there
String version = child.getLabel();
// When we need to find ALL requested suffixes we maintain a set of those not found yet
HashSet<String> suffixesToFind = null;
if (query.getRetrieval() == Retrieval.ALL) {
suffixesToFind = new HashSet<String>(Arrays.asList(suffixes));
}
// try every requested suffix
for (String suffix : suffixes) {
String artifactName = getArtifactName(moduleName, version, suffix);
Node artifact = child.getChild(artifactName);
if (artifact != null) {
if (shouldCheckBinaryVersion(suffix) && !checkBinaryVersion(moduleName, version, artifact, query, suffix)) {
continue;
}
if (query.getRetrieval() == Retrieval.ANY) {
// we found the artifact: store it
versions.add(version);
break;
} else {
// Retrieval.ALL
suffixesToFind.remove(suffix);
}
}
}
if (query.getRetrieval() == Retrieval.ALL && suffixesToFind.isEmpty()) {
// we found the artifact and all of the requested suffixes: store it
versions.add(version);
}
}
// sanity check
if (versions.isEmpty()) {
// We didn't find any versions so we silently skip this result
return null;
}
// find the latest version
String latestVersion = versions.last();
Node versionChild = namePart.getChild(latestVersion);
if (versionChild == null)
throw new RuntimeException("Assertion failed: we didn't find the version child for " + moduleName + "/" + latestVersion);
String memberName = query.getMemberName();
// null group/artifact and fill it up later
ModuleVersionDetails mvd = new ModuleVersionDetails(getNamespace(), moduleName, latestVersion, null, null);
boolean found = false;
// Now try to retrieve information for each of the suffixes
for (String suffix : suffixes) {
Node artifact;
// make sure we don't try to read info from source artifacts
if (ArtifactContext.SRC.equals(suffix)) {
artifact = getBestInfoArtifact(versionChild);
if (artifact == null)
continue;
suffix = ArtifactContext.getSuffixFromNode(artifact);
} else {
String artifactName = getArtifactName(moduleName, latestVersion, suffix);
artifact = versionChild.getChild(artifactName);
}
if (artifact == null)
continue;
// let's see if we can extract some information
switch(addArtifactInfo(artifact, moduleName, latestVersion, suffix, memberName, mvd, query)) {
case INFO_FOUND:
found = true;
// cool, go on
break;
case NO_MATCH:
return null;
case OTHER:
// nothing;
break;
}
}
if (!found)
return null;
mvd.setRemote(root.isRemote());
mvd.setOrigin(getDisplayString());
return mvd;
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class DefaultNode method removeNode.
@Override
public Node removeNode(String label) {
final Node node = super.removeNode(label);
if (node instanceof DefaultNode) {
DefaultNode dn = (DefaultNode) node;
ContentHandle ch = dn.handle;
dn.handle = null;
if (ch != null) {
ch.clean();
}
}
return node;
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class NodeUtils method buildFullPath.
protected static void buildFullPath(Node node, StringBuilder path, String separator, boolean appendSeparator) {
final Iterable<? extends Node> parents = node.getParents();
// noinspection LoopStatementThatDoesntLoop
for (Node parent : parents) {
buildFullPath(parent, path, separator, true);
// just use the first one
break;
}
path.append(node.getLabel());
if (appendSeparator)
path.append(separator);
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class NpmContentStore method getTrueArtifactName.
private String getTrueArtifactName(Node parent) {
final Node node;
try {
node = parent.getChild("package.json");
} catch (NullPointerException ex) {
return null;
}
try {
File json = node.getContent(File.class);
if (json.exists() && json.isFile() && json.canRead()) {
// Parse json, get "main", that's the file we need
Map<String, Object> descriptor = readNpmDescriptor(json);
Object main = descriptor.get("main");
if (main == null) {
return "index.js";
} else if (main instanceof String) {
String string = (String) main;
if (string.endsWith(".js")) {
return string;
} else {
// what the rules really are
if (string.equals("lib") || string.endsWith("/lib")) {
return string + "/index.js";
} else {
return string + ".js";
}
}
} else {
throw new RepositoryException("unexpected value for 'main' in npm descriptor: " + json);
}
} else {
throw new RepositoryException("npm descriptor not found: " + json);
}
} catch (IOException ex) {
throw new RepositoryException("error reading npm descriptor: " + out + "/package.json", ex);
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class RootRepositoryManager method putContent.
private File putContent(ArtifactContext context, Node node, InputStream stream, long length) throws IOException {
log.debug(" Creating local copy of external node: " + node + " at repo: " + (fileContentStore != null ? fileContentStore.getDisplayString() : null));
if (fileContentStore == null)
throw new IOException("No location to place node at: fileContentStore is null");
ArtifactCallback callback = context.getCallback();
if (callback == null) {
callback = ArtifactCallbackStream.getCallback();
}
final File finalFile;
VerifiedDownload dl = new VerifiedDownload(log, context, fileContentStore, node);
try {
dl.fetch(callback, stream, length);
// only check for jars or forced checks
if (ArtifactContext.JAR.equals(context.getSingleSuffix()) || context.forceDescriptorCheck()) {
// transfer descriptor as well, if there is one
final Node descriptor = Configuration.getResolvers(this).descriptor(node);
if (descriptor != null && descriptor.hasBinaries()) {
VerifiedDownload descriptorDl = new VerifiedDownload(log, context, fileContentStore, descriptor);
try {
descriptorDl.fetch(callback, descriptor.getInputStream(), 40);
descriptorDl.commit();
} catch (RuntimeException e) {
dl.rollback(e);
throw e;
} catch (IOException e) {
dl.rollback(e);
throw e;
}
}
}
// ... got descriptor OK, so can now commit
finalFile = dl.commit();
} catch (RuntimeException e) {
dl.rollback(e);
throw e;
} catch (IOException e) {
dl.rollback(e);
throw e;
}
// refresh markers from root to this newly put node
if (getCache() != null) {
final List<String> paths = NodeUtils.toLabelPath(node);
OpenNode current = getCache();
for (String path : paths) {
if (current == null) {
break;
}
current.refresh(false);
final Node tmp = current.peekChild(path);
current = (tmp instanceof OpenNode) ? OpenNode.class.cast(tmp) : null;
}
}
return finalFile;
}
Aggregations