use of org.eclipse.ceylon.cmr.api.CmrRepository 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.CmrRepository in project ceylon by eclipse.
the class HerdTestCase method getRepositoryManager.
private RepositoryManager getRepositoryManager(File root, boolean offline, int timeout, String apiVersion) throws Exception {
RepositoryManagerBuilder builder = getRepositoryManagerBuilder(root, offline, timeout, java.net.Proxy.NO_PROXY);
WebDAVContentStore rcs = new WebDAVContentStore(HERD_URL, log, false, 60000, java.net.Proxy.NO_PROXY, apiVersion);
CmrRepository repo = new DefaultRepository(rcs.createRoot());
return builder.addRepository(repo).buildRepository();
}
use of org.eclipse.ceylon.cmr.api.CmrRepository in project ceylon by eclipse.
the class SmokeTestCase method testMavenRemote.
@Test
public void testMavenRemote() throws Exception {
RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
CmrRepository externalRepo = MavenRepositoryHelper.getMavenRepository("https://repository.jboss.org/nexus/content/groups/public", log, false, 60000, java.net.Proxy.NO_PROXY);
builder.addRepository(externalRepo);
RepositoryManager manager = builder.buildRepository();
ArtifactContext ac = new ArtifactContext(MavenRepository.NAMESPACE, "org.jboss:jboss-vfs", "3.0.1.GA", ArtifactContext.JAR);
File file = null;
try {
file = manager.getArtifact(ac);
Assert.assertNotNull(file);
Assert.assertEquals("jboss-vfs-3.0.1.GA.jar", file.getName());
} finally {
// delete the jar, not the car
ac.setSuffixes(ArtifactContext.JAR);
manager.removeArtifact(ac);
// temporary workaround, because the jar is not stored at the right place
if (file != null)
Assert.assertTrue(file.delete());
}
}
use of org.eclipse.ceylon.cmr.api.CmrRepository in project ceylon by eclipse.
the class SmokeTestCase method testGetMultipleCached.
@Test
public void testGetMultipleCached() throws Exception {
RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
CmrRepository[] externalRepos = builder.repositoryBuilder().buildRepository(Constants.REPO_URL_CEYLON);
for (CmrRepository repo : externalRepos) {
builder.addRepository(repo);
}
RepositoryManager manager = builder.buildRepository();
ArtifactContext artifact1 = new ArtifactContext(null, "ceylon.json", "1.0.0", ArtifactContext.CAR, ArtifactContext.SCRIPTS_ZIPPED, ArtifactContext.JS);
List<ArtifactResult> json1 = manager.getArtifactResults(artifact1);
Assert.assertNotNull("Module 'ceylon.json-1.0.0' not found", json1);
Assert.assertEquals("Expected two artifacts for 'ceylon.json-1.0.0'", 2, json1.size());
File root = new File(manager.getRepositories().get(1).getDisplayString());
File missing = new File(root, "ceylon/json/1.0.0/ceylon.json-1.0.0.scripts.zip.missing");
Assert.assertTrue("Marker file .missing not found", missing.exists());
ArtifactContext artifact2 = new ArtifactContext(null, "ceylon.json", "1.0.0", ArtifactContext.CAR, ArtifactContext.SCRIPTS_ZIPPED, ArtifactContext.SRC);
List<ArtifactResult> json2 = manager.getArtifactResults(artifact2);
Assert.assertNotNull("Module 'ceylon.json-1.0.0' not found", json2);
Assert.assertEquals("Expected two artifacts for 'ceylon.json-1.0.0'", 2, json2.size());
}
use of org.eclipse.ceylon.cmr.api.CmrRepository in project ceylon by eclipse.
the class SmokeTestCase method testPropertiesGet.
@Test
public void testPropertiesGet() throws Exception {
RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
RepositoryBuilder rb = builder.repositoryBuilder();
CmrRepository[] repositories = rb.buildRepository(Constants.REPO_URL_CEYLON);
for (CmrRepository repo : repositories) {
builder.addRepository(repo);
}
RepositoryManager manager = builder.buildRepository();
ArtifactContext context = new ArtifactContext(null, "io.undertow.core", "1.0.0.Alpha1-9fdfd5f766", ArtifactContext.JAR);
try {
File artifact = manager.getArtifact(context);
Assert.assertNotNull(artifact);
File mp = new File(artifact.getParent(), ArtifactContext.MODULE_PROPERTIES);
Assert.assertNotNull(mp.exists());
} finally {
manager.removeArtifact(context);
}
}
Aggregations