use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.
the class JvmBackendUtil method loadStaticMetamodel.
public static void loadStaticMetamodel(InputStream is, List<String> dexEntries, StaticMetamodelLoader staticMetamodelLoader) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
String line;
ModuleSpec module = null;
SortedSet<String> packages = new TreeSet<>();
List<ArtifactResult> imports = new LinkedList<ArtifactResult>();
while ((line = reader.readLine()) != null) {
if (line.startsWith("=")) {
if (module != null)
finishLoadingModule(module, packages, imports, dexEntries, staticMetamodelLoader);
module = ModuleSpec.parse(line.substring(1));
packages.clear();
imports.clear();
continue;
}
boolean _optional = false;
boolean _shared = false;
if (line.startsWith("?")) {
_optional = true;
line = line.substring(1);
}
if (line.startsWith("+")) {
_shared = true;
line = line.substring(1);
}
// SERIOUSLY!!
final boolean optional = _optional;
final boolean shared = _shared;
if (line.startsWith("@")) {
packages.add(line.substring(1));
continue;
}
// it's an import
ModuleSpec importSpec = ModuleSpec.parse(line);
final String namespace = ModuleUtil.getNamespaceFromUri(importSpec.getName());
final String name = ModuleUtil.getModuleNameFromUri(importSpec.getName());
final String version = importSpec.getVersion();
imports.add(new ArtifactResult() {
@Override
public String namespace() {
return namespace;
}
@Override
public String name() {
return name;
}
@Override
public String version() {
return version;
}
@Override
public boolean optional() {
return optional;
}
@Override
public boolean exported() {
return shared;
}
@Override
public ArtifactResultType type() {
// Is this important?
return ArtifactResultType.OTHER;
}
@Override
public VisibilityType visibilityType() {
return VisibilityType.STRICT;
}
@Override
public File artifact() throws RepositoryException {
return null;
}
@Override
public PathFilter filter() {
return null;
}
@Override
public List<ArtifactResult> dependencies() throws RepositoryException {
return null;
}
@Override
public String artifactId() {
return ModuleUtil.getMavenArtifactIdIfMavenModule(name);
}
@Override
public String groupId() {
return ModuleUtil.getMavenGroupIdIfMavenModule(name);
}
@Override
public String classifier() {
return ModuleUtil.getMavenClassifierIfMavenModule(name);
}
@Override
public String repositoryDisplayString() {
return "Android dependency";
}
@Override
public Repository repository() {
return null;
}
@Override
public ModuleScope moduleScope() {
return ModuleScope.COMPILE;
}
@Override
public List<Exclusion> getExclusions() {
return null;
}
});
}
if (module != null)
finishLoadingModule(module, packages, imports, dexEntries, staticMetamodelLoader);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.
the class RootRepositoryManager method getArtifactResult.
@Override
protected ArtifactResult getArtifactResult(ArtifactContext context, Node node) throws RepositoryException {
if (node.isRemote()) {
final boolean forceOp = context.isForceOperation();
try {
// just force the ops
context.setForceOperation(true);
log.debug("Looking up artifact " + context + " from " + node + " to cache it");
SizedInputStream sizedInputStream = node.getSizedInputStream();
// in theory we should not have nodes with null streams, but at least provide a helpful exception
if (sizedInputStream == null) {
throw new RepositoryException("Node " + node + " for repository " + this + " returned a null stream");
}
try {
log.debug(" -> Found it, now caching it");
final File file = putContent(context, node, sizedInputStream.getInputStream(), sizedInputStream.getSize());
log.debug(" Caching done: " + file);
String repositoryDisplayString = NodeUtils.getRepositoryDisplayString(node);
File originalRepoFile = new File(file.getParentFile(), file.getName().concat(ORIGIN));
FileWriter writer = new FileWriter(originalRepoFile, false);
try {
writer.write(repositoryDisplayString);
writer.close();
} catch (IOException e) {
log.error(e.toString());
}
// we expect the remote nodes to support Ceylon module info
return new FileArtifactResult(NodeUtils.getRepository(node), this, context.getName(), context.getVersion(), file, repositoryDisplayString);
} finally {
IOUtils.safeClose(sizedInputStream.getInputStream());
}
} catch (IOException e) {
throw new RepositoryException(e);
} finally {
context.setForceOperation(forceOp);
}
} else {
return toArtifactResult(node);
}
}
use of org.eclipse.ceylon.model.cmr.RepositoryException 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.model.cmr.RepositoryException in project ceylon by eclipse.
the class CachingRepositoryManager method putArtifact.
@Override
public void putArtifact(ArtifactContext context, InputStream content) throws RepositoryException {
// first copy to local
caching.putArtifact(context, content);
// should be here
final File file = caching.getArtifact(context);
try {
// upload
super.putArtifact(context, new FileInputStream(file));
} catch (RepositoryException e) {
throw e;
} catch (Exception e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.
the class CachingRepositoryManager method getArtifactResult.
protected ArtifactResult getArtifactResult(ArtifactContext context, Node node) throws RepositoryException {
try {
ArtifactResult result = caching.getArtifactResult(context);
if (result != null) {
boolean valid = false;
File file = result.artifact();
if (file.exists()) {
long lm = node.getLastModified();
valid = (lm == -1 || lm < file.lastModified());
}
if (valid) {
return result;
}
}
final boolean previous = context.isForceOperation();
context.setForceOperation(true);
try {
// Make sure we'll have only one suffix
context.setSuffixes(ArtifactContext.getSuffixFromNode(node));
caching.putArtifact(context, node.getInputStream());
} finally {
context.setForceOperation(previous);
}
return caching.getArtifactResult(context);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
Aggregations