use of org.eclipse.ceylon.cmr.api.RepositoryManager 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.RepositoryManager 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.RepositoryManager in project ceylon by eclipse.
the class NamingTests method getDecls.
protected List<Declaration> getDecls(String resource) throws Exception {
final String name = PKGNAME.replace('.', '/') + "/" + resource;
File file = new File("test/src", name);
if (!file.exists()) {
throw new RuntimeException("Unable to find resource " + name);
}
RepositoryManagerBuilder builder = new RepositoryManagerBuilder(new NullLogger(), false, 20000, java.net.Proxy.NO_PROXY);
RepositoryManager repoManager = builder.buildRepository();
VFS vfs = new VFS();
Context context = new Context(repoManager, vfs);
PhasedUnits pus = new PhasedUnits(context);
// Make the module manager think we're looking at this package
// even though there's no module descriptor
pus.getModuleSourceMapper().push(PKGNAME);
pus.parseUnit(vfs.getFromFile(file), vfs.getFromFile(new File("test-src")));
final java.util.List<PhasedUnit> listOfUnits = pus.getPhasedUnits();
PhasedUnit pu = listOfUnits.get(0);
pu.validateTree();
pu.scanDeclarations();
pu.scanTypeDeclarations();
pu.validateRefinement();
pu.analyseTypes();
pu.analyseFlow();
return pu.getDeclarations();
}
use of org.eclipse.ceylon.cmr.api.RepositoryManager in project ceylon by eclipse.
the class AbstractTest method testListVersions.
protected void testListVersions(String query, String versionQuery, ModuleVersionDetails[] expected) throws Exception {
RepositoryManager manager = getRepositoryManager();
testListVersions(query, versionQuery, expected, manager);
}
use of org.eclipse.ceylon.cmr.api.RepositoryManager in project ceylon by eclipse.
the class AbstractTest method testSearchResultsMember.
protected ModuleSearchResult testSearchResultsMember(String q, Type type, String members, boolean memberSearchExact, boolean memberSearchPackageOnly, ModuleDetails[] expected) throws Exception {
ModuleQuery query = new ModuleQuery(q, type, Retrieval.ANY);
query.setMemberName(members);
query.setMemberSearchExact(memberSearchExact);
query.setMemberSearchPackageOnly(memberSearchPackageOnly);
RepositoryManager manager = getRepositoryManager();
ModuleSearchResult results = manager.searchModules(query);
compareSearchResults(expected, results);
return results;
}
Aggregations