use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class NodeUtils method toLabelPath.
/**
* Return path queue, with root being on top.
*
* @param node the node
* @return paths queue
*/
public static List<String> toLabelPath(Node node) {
final LinkedList<String> paths = new LinkedList<String>();
Node current = node;
Node parent = firstParent(node);
// ignore root path, should equal to ""
while (parent != null) {
paths.addFirst(current.getLabel());
current = parent;
parent = firstParent(current);
}
return paths;
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class RootRepositoryManager method artifactNotFound.
@Override
protected ArtifactResult artifactNotFound(ArtifactContext context) throws RepositoryException {
boolean hasRemote = false;
StringBuilder reps = new StringBuilder();
for (CmrRepository rep : getRepositories()) {
if (rep.getRoot().isRemote() && !isOffline(rep)) {
hasRemote = true;
reps.append(rep.getDisplayString());
reps.append('\n');
}
}
if (hasRemote && cache != null) {
// Create a .missing file in the cache to mark that we tried to locate the file but it didn't exist
Node parent = cache.findParent(context);
if (parent != null) {
context.toNode(parent);
try {
// fileContentStore cannot be null if we have a cache
File parentDir = fileContentStore.getFile(parent);
String[] names = cache.getArtifactNames(context);
File missingFile = new File(parentDir, names[0].concat(MISSING));
if (!missingFile.exists()) {
if (context.getSearchRepository() == cache) {
ArtifactContext unpreferred = new ArtifactContext(context.getNamespace(), context.getName(), context.getVersion(), context.getSuffixes());
unpreferred.copySettingsFrom(context);
return getArtifactResult(unpreferred);
} else {
FileUtil.mkdirs(parentDir);
try (FileWriter writer = new FileWriter(missingFile, false)) {
// We write the list of remote repositories we tried
// This is not currently used but might be useful in the future
writer.write(reps.toString());
} catch (IOException e) {
log.error(e.toString());
}
}
}
} finally {
ArtifactContext.removeNode(parent);
}
}
}
return super.artifactNotFound(context);
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class RootRepositoryManager method removeNode.
@Override
protected void removeNode(Node parent, String child) throws IOException {
final Node node = parent.getChild(child);
if (fileContentStore != null) {
try {
if (node != null) {
final Node sl = parent.getChild(child + SHA1 + LOCAL);
if (sl != null) {
fileContentStore.removeFile(sl);
}
final Node origin = parent.getChild(child + ORIGIN);
if (origin != null) {
fileContentStore.removeFile(origin);
}
final Node descriptor = Configuration.getResolvers(this).descriptor(node);
if (descriptor != null) {
fileContentStore.removeFile(descriptor);
}
}
} catch (Exception ignored) {
}
}
try {
super.removeNode(parent, child);
} finally {
if (node != null) {
fileContentStore.removeFile(node);
}
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method putFolder.
@Override
protected void putFolder(ArtifactContext context, File folder) throws RepositoryException {
Node parent = getOrCreateParent(context);
log.debug("Adding folder " + context + " to cache " + cache.getDisplayString());
log.debug(" -> " + NodeUtils.getFullPath(parent));
// fast-path for Herd
if (!canHandleFolders()) {
uploadZipped(parent, context, folder);
return;
}
final String[] names = cache.getArtifactNames(context);
if (names.length != 1) {
throw new RepositoryException("ArtifactContext should have a single suffix");
}
final String label = names[0];
if (parent instanceof OpenNode) {
final OpenNode on = (OpenNode) parent;
final OpenNode curent = on.createNode(label);
try {
for (// ignore folder, it should match new root
File f : // ignore folder, it should match new root
folder.listFiles()) putFiles(curent, f, context);
} catch (RepositoryException e) {
throw e;
} catch (Exception e) {
removeArtifact(context);
throw new RepositoryException(e);
}
} else {
throw new RepositoryException("Cannot put folder [" + folder + "] to non-open node: " + context);
}
log.debug(" -> [done]");
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractOpenNode method removeNode.
@Override
public Node removeNode(String label) {
// get node, so we actually have the right instance to fully remove
final Node node = getChild(label);
if (node != null) {
children.remove(label);
children.remove(label + NODE_MARKER);
}
return node;
}
Aggregations