use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method putArtifact.
public void putArtifact(ArtifactContext context, InputStream content) throws RepositoryException {
try {
final Node parent = getOrCreateParent(context);
log.debug("Adding artifact " + context + " to cache " + cache.getDisplayString());
log.debug(" -> " + NodeUtils.getFullPath(parent));
final String[] names = cache.getArtifactNames(context);
if (names.length != 1) {
throw new RepositoryException("ArtifactContext should have a single suffix");
}
final String label = names[0];
try {
if (parent instanceof OpenNode) {
final OpenNode on = (OpenNode) parent;
if (on.addContent(label, content, context) == null)
addContent(context, parent, label, content);
} else {
addContent(context, parent, label, content);
}
} catch (IOException e) {
throw new RepositoryException(e);
}
log.debug(" -> [done]");
} finally {
IOUtils.safeClose(content);
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method isSameFile.
// Check if the source file and destination node point to the same file
@Override
public boolean isSameFile(ArtifactContext context, File srcFile) throws RepositoryException {
boolean same = false;
if (!cache.getRoot().isRemote()) {
Node dstParent = getOrCreateParent(context);
Node newChild = dstParent.getChild(srcFile.getName());
if (newChild != null) {
try {
File existing = newChild.getContent(File.class);
same = FileUtil.sameFile(srcFile, existing);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
}
return same;
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method getArtifactResult.
public ArtifactResult getArtifactResult(ArtifactContext context) throws RepositoryException {
context = applyOverrides(context);
final Node node = getLeafNode(context);
if (node != null) {
String foundSuffix = ArtifactContext.getSuffixFromNode(node);
// First handle all the artifact we didn't find
ArtifactResult result = handleNotFound(context, foundSuffix);
if (result != null) {
// Seems we were able to find this artifact anyway, so lets return it
return result;
} else {
// Now return the artifact we found
// Make sure we'll have only one suffix
context.setSuffixes(foundSuffix);
if (ArtifactContext.isDirectoryName(node.getLabel())) {
return getFolder(context, node);
} else {
return getArtifactResult(context, node);
}
}
} else {
return handleNotFound(context, null);
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method removeArtifact.
public void removeArtifact(ArtifactContext context) throws RepositoryException {
Node parent = getFromCacheNode(context, false);
log.debug("Remove artifact " + context + " to repository " + cache.getDisplayString());
if (parent != null) {
final String[] labels = cache.getArtifactNames(context);
for (String label : labels) {
try {
removeNode(parent, label);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
log.debug(" -> [done]");
} else {
log.debug(" -> No such artifact: " + context);
}
}
use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method fromRepository.
protected Node fromRepository(CmrRepository repository, ArtifactContext context, boolean addLeaf) {
log.debug(" Trying repository " + repository.getDisplayString());
Node node = repository.findParent(context);
if (node != null) {
if (addLeaf) {
Node parent = node;
context.toNode(parent);
NodeUtils.keepRepository(parent, repository);
try {
String[] names = repository.getArtifactNames(context);
for (String name : names) {
node = parent.getChild(name);
if (node != null) {
break;
}
}
} finally {
ArtifactContext.removeNode(parent);
}
}
if (node != null) {
NodeUtils.keepRepository(node, repository);
log.debug(" -> Found at " + NodeUtils.getFullPath(node));
}
}
return node;
}
Aggregations