use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class ModuleSourceMapper method resolveModule.
public void resolveModule(ArtifactResult artifact, Module module, ModuleImport moduleImport, LinkedList<Module> dependencyTree, List<PhasedUnits> phasedUnitsOfDependencies, boolean forCompiledModule) {
// This implementation relies on the ability to read the model from source
// the compiler for example subclasses this to read lazily and from the compiled model
ArtifactContext artifactContext = new ArtifactContext(null, module.getNameAsString(), module.getVersion(), ArtifactContext.SRC);
RepositoryManager repositoryManager = context.getRepositoryManager();
Exception exceptionOnGetArtifact = null;
ArtifactResult sourceArtifact = null;
try {
sourceArtifact = repositoryManager.getArtifactResult(artifactContext);
} catch (Exception e) {
exceptionOnGetArtifact = e;
}
if (sourceArtifact == null) {
ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, this, true);
} else {
PhasedUnits modulePhasedUnits = createPhasedUnits();
ClosableVirtualFile virtualArtifact = null;
try {
virtualArtifact = context.getVfs().getFromZipFile(sourceArtifact.artifact());
modulePhasedUnits.parseUnit(virtualArtifact);
// populate module.getDependencies()
modulePhasedUnits.visitModules();
addToPhasedUnitsOfDependencies(modulePhasedUnits, phasedUnitsOfDependencies, module);
} catch (Exception e) {
StringBuilder error = new StringBuilder("unable to read source artifact for ");
error.append(artifactContext.toString());
error.append("\ndue to connection error: ").append(e.getMessage());
attachErrorToDependencyDeclaration(moduleImport, dependencyTree, error.toString(), true);
} finally {
if (virtualArtifact != null) {
virtualArtifact.close();
}
}
}
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class ModuleValidator method resolveModuleIfRequired.
private void resolveModuleIfRequired(Module module, boolean forCompiledModule, ModuleImport moduleImport, ImportDepth importDepth, LinkedList<Module> dependencyTree, Map<Module, ArtifactResult> alreadySearchedArtifacts) {
if (!module.isAvailable()) {
ArtifactResult artifact = null;
boolean firstTime;
if (alreadySearchedArtifacts.containsKey(module)) {
artifact = alreadySearchedArtifacts.get(module);
firstTime = false;
} else {
// try and load the module from the repository
RepositoryManager repositoryManager = context.getRepositoryManager();
if (repositoryManager.isValidNamespace(moduleImport.getNamespace())) {
Exception exceptionOnGetArtifact = null;
Iterable<String> searchedArtifactExtensions = moduleManager.getSearchedArtifactExtensions();
ArtifactContext artifactContext = new ArtifactContext(moduleImport.getNamespace(), module.getNameAsString(), module.getVersion(), getArtifactSuffixes(searchedArtifactExtensions));
listener.retrievingModuleArtifact(module, artifactContext);
try {
artifact = repositoryManager.getArtifactResult(artifactContext);
} catch (Exception e) {
exceptionOnGetArtifact = catchIfPossible(e);
}
if (artifact == null) {
boolean error = true;
if (ModuleUtil.isMavenModule(module.getNameAsString()) && !dependencyTree.isEmpty() && ModuleUtil.isMavenModule(dependencyTree.peekLast().getNameAsString()))
error = false;
// not there => error
ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, moduleManagerUtil, error);
listener.retrievingModuleArtifactFailed(module, artifactContext);
} else {
listener.retrievingModuleArtifactSuccess(module, artifact);
}
} else {
StringBuilder msg = new StringBuilder().append("unknown import namespace: '").append(moduleImport.getNamespace()).append("' should be one of ");
TreeSet<String> namespaces = new TreeSet<String>();
for (CmrRepository repo : repositoryManager.getRepositories()) {
namespaces.add(repo.getNamespace());
}
boolean first = true;
for (String namespace : namespaces) {
if (first) {
first = false;
} else {
msg.append(", ");
}
msg.append("'").append(namespace).append("'");
}
// if (!MavenRepository.NAMESPACE.equals(moduleImport.getNamespace())) {
// msg += " (if this is a Maven import make sure to add a 'maven:' prefix)";
// }
moduleManagerUtil.attachErrorToDependencyDeclaration(moduleImport, dependencyTree, msg.toString(), true);
}
alreadySearchedArtifacts.put(module, artifact);
firstTime = true;
}
// a compiled module, then it MUST resolve it and make it available, so do try in this case.
if (artifact != null && (firstTime || forCompiledModule)) {
// parse module units and build module dependency and carry on
listener.resolvingModuleArtifact(module, artifact);
Module moduleOverride = moduleManager.overridesModule(artifact, module, moduleImport);
if (moduleOverride != null) {
if (importDepth.equals(ImportDepth.First)) {
moduleManagerUtil.attachErrorToDependencyDeclaration(moduleImport, dependencyTree, "project source module import is overridden in module overrides file: '" + moduleOverride.getNameAsString() + "/" + moduleOverride.getVersion() + "' overrides '" + module.getNameAsString() + "/" + module.getVersion() + "'", false);
}
module = moduleOverride;
}
moduleManagerUtil.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
}
}
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class CallbackTestCase method testThreadLocal.
@Test
public void testThreadLocal() throws Exception {
TestArtifactCallback callback = new TestArtifactCallback();
ArtifactCallbackStream.setCallback(callback);
try {
ArtifactContext context = new ArtifactContext(null, name, version);
doTest(context, callback);
} finally {
ArtifactCallbackStream.setCallback(null);
}
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class CallbackTestCase method testErr.
@Test
public void testErr() throws Exception {
TestArtifactCallback callback = new TestArtifactCallback();
callback.ts = String.valueOf(System.currentTimeMillis());
ArtifactContext context = new ArtifactContext(null, name, version);
context.setCallback(callback);
doTest(context, callback);
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class SmokeTestCase method testInnerProperties.
@Test
public void testInnerProperties() throws Exception {
RepositoryManager manager = getRepositoryManager();
ArtifactContext context = new ArtifactContext(null, "org.mood.lw", "1.0", ArtifactContext.JAR);
try {
manager.putArtifact(context, mockJar("META-INF/jbossmodules/org/mood/lw/1.0/module.properties", "moduletest=0.1\n".getBytes()));
File file = manager.getArtifact(context);
Assert.assertNotNull(file);
} finally {
manager.removeArtifact(context);
}
}
Aggregations