use of org.eclipse.ceylon.cmr.api.Overrides in project ceylon by eclipse.
the class ModuleLoaderTest method testNoDotsFromMavenWithOverrides.
@Test
public void testNoDotsFromMavenWithOverrides() throws ModuleNotFoundException {
CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
Overrides ov = RepositoryManagerBuilder.parseOverrides(overrides);
Assert.assertTrue(ov.getAddedArtifacts().isEmpty());
RepositoryManager manager = new SimpleRepositoryManager(repository, log, ov);
Map<String, String> extraModules = new HashMap<>();
extraModules.put("org.antlr:stringtemplate", "3.2.1");
// this one has an override that adds aopalliance:aopalliance/1.0
extraModules.put("org.postgresql:postgresql", "9.4.1208");
TestableModuleLoader moduleLoader = new TestableModuleLoader(manager, null, extraModules, true);
moduleLoader.loadModule("com.google.inject:guice", "4.0", ModuleScope.RUNTIME);
// Check that we got them
Assert.assertEquals("2.7.7", moduleLoader.getModuleVersion("maven:antlr:antlr"));
Assert.assertEquals("1.0", moduleLoader.getModuleVersion("maven:aopalliance:aopalliance"));
}
use of org.eclipse.ceylon.cmr.api.Overrides in project ceylon by eclipse.
the class LazyModuleSourceMapper method preResolveDependenciesIfRequired.
@Override
public void preResolveDependenciesIfRequired(RepositoryManager repositoryManager) {
AbstractModelLoader modelLoader = getModuleManager().getModelLoader();
if (!modelLoader.isFullyExportMavenDependencies())
return;
if (statusPrinter != null) {
statusPrinter.clearLine();
statusPrinter.log("Pre-resolving dependencies");
}
if (verbose) {
log.printRawLines(WriterKind.NOTICE, "[Pre-resolving dependencies]");
}
Set<Module> compiledModules = getCompiledModules();
Map<String, String> modules = new HashMap<>();
ModuleImport anyImport = null;
for (Module module : compiledModules) {
for (ModuleImport imp : module.getImports()) {
if (imp.getModule() == null || !compiledModules.contains(imp.getModule())) {
if (anyImport == null)
anyImport = imp;
String name = imp.getModule().getNameAsString();
if (imp.getNamespace() != null)
name = imp.getNamespace() + ":" + name;
modules.put(name, imp.getModule().getVersion());
}
}
}
if (statusPrinter != null) {
statusPrinter.clearLine();
statusPrinter.log("Pre-resolving found " + modules.size() + " to pre-resolve");
}
if (verbose) {
log.printRawLines(WriterKind.NOTICE, "[Pre-resolving " + modules.size() + " modules]");
}
if (modules.isEmpty())
return;
Entry<String, String> first = modules.entrySet().iterator().next();
CompilerModuleLoader ml = new CompilerModuleLoader(repositoryManager, null, modules, verbose, statusPrinter, log);
boolean giveup = false;
try {
ml.loadModule(first.getKey(), first.getValue(), ModuleScope.COMPILE);
} catch (ModuleNotFoundException e) {
attachErrorToDependencyDeclaration(anyImport, "Pre-resolving of module failed: " + e.getMessage(), true);
giveup = true;
}
if (statusPrinter != null) {
statusPrinter.clearLine();
// don't try to read the module count if pre-resolving failed
if (giveup)
statusPrinter.log("Pre-resolving failed");
else
statusPrinter.log("Pre-resolving resolved " + ml.getModuleCount());
}
if (verbose) {
// don't try to read the module count if pre-resolving failed
if (giveup)
log.printRawLines(WriterKind.NOTICE, "[Pre-resolved failed]");
else
log.printRawLines(WriterKind.NOTICE, "[Pre-resolved " + ml.getModuleCount() + " modules]");
}
if (giveup)
return;
Overrides overrides = repositoryManager.getOverrides();
if (overrides == null) {
overrides = Overrides.create();
repositoryManager.setOverrides(overrides);
}
ml.setupOverrides(overrides);
ml.cleanup();
}
use of org.eclipse.ceylon.cmr.api.Overrides in project ceylon by eclipse.
the class ModuleSourceMapper method overrideModuleImports.
protected void overrideModuleImports(Module module, ArtifactResult artifact) {
Overrides overrides = getContext().getRepositoryManager().getOverrides();
if (overrides != null) {
Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
for (ModuleImport i : module.getImports()) {
Module m = i.getModule();
if (m != null) {
existingModuleDependencies.add(new ModuleDependencyInfo(i.getNamespace(), m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport(), i.getNativeBackends()));
}
}
ModuleInfo sourceModuleInfo = new ModuleInfo(artifact.namespace(), artifact.name(), artifact.version(), artifact.groupId(), artifact.artifactId(), artifact.classifier(), null, existingModuleDependencies);
ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
List<ModuleImport> newModuleImports = new ArrayList<>();
for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
Module dependency = getModuleManager().getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
Backends backends = dependency.getNativeBackends();
ModuleImport newImport = new ModuleImport(dep.getNamespace(), dependency, dep.isOptional(), dep.isExport(), backends);
newModuleImports.add(newImport);
}
module.overrideImports(newModuleImports);
}
}
use of org.eclipse.ceylon.cmr.api.Overrides in project ceylon by eclipse.
the class Main method setup.
/**
* Sets up the Ceylon metamodel by adding the specified module to it. This does not run any Ceylon code,
* nor does it reset the metamodel first. You can repeatedly invoke this method to add new Ceylon modules
* to the metamodel.
*
* @param module the module name to load.
* @param version the version to load. Ignored if the module is the default module.
*/
public void setup(String module, String version) {
Overrides parsedOverrides = Overrides.getDistOverrides();
if (overrides != null) {
try {
parsedOverrides = parsedOverrides.append(overrides);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Metamodel.resetModuleManager(new OverridesRuntimeResolver(parsedOverrides));
if (moduleClassLoader == null)
setupModuleClassLoader(module);
if (classPath == null) {
classPath = new ClassPath(parsedOverrides);
visited = new HashSet<ClassPath.Module>();
registerInMetamodel("ceylon.language", Versions.CEYLON_VERSION_NUMBER, false);
registerInMetamodel("org.eclipse.ceylon.common", Versions.CEYLON_VERSION_NUMBER, false);
registerInMetamodel("org.eclipse.ceylon.model", Versions.CEYLON_VERSION_NUMBER, false);
}
if (module.equals(org.eclipse.ceylon.model.typechecker.model.Module.DEFAULT_MODULE_NAME))
version = null;
registerInMetamodel(module, version, false);
}
use of org.eclipse.ceylon.cmr.api.Overrides in project ceylon by eclipse.
the class AetherUtils method fetchDependencies.
private ArtifactResult fetchDependencies(RepositoryManager manager, CmrRepository repository, String groupId, String artifactId, String classifier, String version, boolean fetchSingleArtifact, String repositoryDisplayString) {
Overrides overrides = repository.getRoot().getService(Overrides.class);
ArtifactOverrides ao = null;
log.debug("Overrides for " + canonicalForm(groupId, artifactId, classifier, version) + " in " + overrides.getSource());
ArtifactContext context = getArtifactContext(groupId, artifactId, classifier, version);
if (overrides != null) {
ao = overrides.getArtifactOverrides(context);
log.debug(ao != null ? "-> found overrides" : "-> no overrides");
}
// entire replacement
ArtifactContext replacementContext = null;
if (ao != null && ao.getReplace() != null) {
replacementContext = ao.getReplace().getArtifactContext();
} else if (overrides != null) {
replacementContext = overrides.replace(context);
}
if (replacementContext != null) {
log.debug(String.format("[Maven-Overrides] Replacing %s with %s.", context, replacementContext));
// replace fetched dependency
String[] nameToGroupArtifactIds = nameToGroupArtifactIds(replacementContext.getName());
if (nameToGroupArtifactIds != null) {
groupId = nameToGroupArtifactIds[0];
artifactId = nameToGroupArtifactIds[1];
classifier = nameToGroupArtifactIds[2];
version = replacementContext.getVersion();
// new AO
context = getArtifactContext(groupId, artifactId, classifier, version);
ao = overrides.getArtifactOverrides(context);
}
}
// version replacement
if (overrides != null && overrides.isVersionOverridden(context)) {
version = overrides.getVersionOverride(context);
context.setVersion(version);
}
if (ao != null && ao.hasVersion()) {
version = ao.getVersion();
context.setVersion(version);
log.debug("Using version " + version);
}
// classifier replacement
if (ao != null && ao.hasClassifier()) {
classifier = ao.getClassifier();
log.debug("Using classifier " + classifier);
}
final String name = MavenUtils.moduleName(groupId, artifactId, classifier);
// only used for messages
final String coordinates = canonicalForm(groupId, artifactId, classifier, version);
try {
DependencyDescriptor info = impl.getDependencies(groupId, artifactId, version, classifier, null, fetchSingleArtifact);
if (info == null) {
log.debug("No artifact found: " + coordinates);
return null;
}
final SingleArtifactResult result;
if (fetchSingleArtifact) {
result = new SingleArtifactResult(repository, name, version, groupId, artifactId, classifier, info.getFile(), repositoryDisplayString);
} else {
final List<ArtifactResult> dependencies = new ArrayList<>();
for (DependencyDescriptor dep : info.getDependencies()) {
String dGroupId = dep.getGroupId();
String dArtifactId = dep.getArtifactId();
String dClassifier = dep.getClassifier();
String dVersion = dep.getVersion();
boolean export = false;
boolean optional = dep.isOptional();
boolean isCeylon = false;
ModuleScope scope = toModuleScope(dep);
ArtifactContext dContext = null;
if (overrides != null)
dContext = getArtifactContext(dGroupId, dArtifactId, dClassifier, dVersion);
if (overrides != null) {
if (overrides.isRemoved(dContext) || (ao != null && ao.isRemoved(dContext))) {
log.debug(String.format("[Maven-Overrides] Removing %s from %s.", dep, context));
// skip dependency
continue;
}
if (ao != null && ao.isAddedOrUpdated(dContext)) {
log.debug(String.format("[Maven-Overrides] Replacing %s from %s.", dep, context));
// skip dependency
continue;
}
ArtifactContext replace = overrides.replace(dContext);
if (replace != null) {
dContext = replace;
String[] groupArtifactIds = nameToGroupArtifactIds(replace.getName());
if (groupArtifactIds == null) {
isCeylon = true;
} else {
dGroupId = groupArtifactIds[0];
dArtifactId = groupArtifactIds[1];
dClassifier = groupArtifactIds[2];
}
dVersion = replace.getVersion();
}
if (ao != null) {
if (ao.isShareOverridden(dContext))
export = ao.isShared(dContext);
if (ao.isOptionalOverridden(dContext))
optional = ao.isOptional(dContext);
}
}
// do we have a version update?
if (overrides != null && overrides.isVersionOverridden(dContext)) {
dVersion = overrides.getVersionOverride(dContext);
}
ArtifactResult dr;
if (isCeylon)
dr = createArtifactResult(manager, dContext.getNamespace(), dContext.getName(), dVersion, export, optional, scope, repositoryDisplayString);
else
dr = createArtifactResult(manager, repository, dGroupId, dArtifactId, dClassifier, dVersion, export, optional, scope, repositoryDisplayString, dep.getExclusions());
dependencies.add(dr);
}
if (ao != null) {
for (DependencyOverride addon : ao.getAdd()) {
ArtifactContext dContext = addon.getArtifactContext();
String dVersion = overrides.getVersionOverride(dContext);
dependencies.add(createArtifactResult(manager, repository, dContext, dVersion, addon.isShared(), addon.isOptional(), ModuleScope.COMPILE, repositoryDisplayString, null));
log.debug(String.format("[Maven-Overrides] Added %s to %s.", addon.getArtifactContext(), context));
}
}
result = new AetherArtifactResult(repository, name, version, groupId, artifactId, classifier, info.getFile(), dependencies, repositoryDisplayString);
}
if (ao != null && ao.getFilter() != null) {
result.setFilter(PathFilterParser.parse(ao.getFilter()));
}
return result;
} catch (IOException e) {
throw new IllegalStateException(e);
} catch (AetherException e) {
log.debug("Could not resolve artifact [" + coordinates + "] : " + e);
return null;
}
}
Aggregations