use of org.eclipse.ceylon.model.cmr.ArtifactResult 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;
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class NpmUtils method resolve.
@Override
public ModuleInfo resolve(DependencyContext context, Overrides overrides) {
if (context.ignoreInner()) {
return null;
}
ArtifactResult result = context.result();
File mod = result.artifact();
File pkgFile = findNpmDescriptor(mod);
if (pkgFile != null) {
return readModuleInformation(result.name(), pkgFile, overrides);
} else {
return null;
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class AetherUtils method createArtifactResult.
protected ArtifactResult createArtifactResult(final RepositoryManager manager, CmrRepository repository, final String groupId, final String artifactId, final String classifier, final String dVersion, final boolean shared, final boolean optional, final ModuleScope scope, final String repositoryDisplayString, final List<ExclusionDescriptor> exclusions) {
final String dName = MavenUtils.moduleName(groupId, artifactId, classifier);
return new MavenArtifactResult(repository, dName, dVersion, groupId, artifactId, classifier, repositoryDisplayString) {
private ArtifactResult result;
{
if (exclusions != null) {
List<Exclusion> ret = new ArrayList<>(exclusions.size());
for (ExclusionDescriptor xDescr : exclusions) {
ret.add(new Exclusion(xDescr.getGroupId(), xDescr.getArtifactId()));
}
setExclusions(ret);
}
}
@Override
public boolean exported() {
return shared;
}
@Override
public boolean optional() {
return optional;
}
@Override
public ModuleScope moduleScope() {
return scope;
}
private synchronized ArtifactResult getResult() {
if (result == null) {
result = fetchDependencies(manager, (CmrRepository) repository(), groupId, artifactId, classifier, dVersion, false, repositoryDisplayString);
}
return result;
}
protected File artifactInternal() throws RepositoryException {
return getResult().artifact();
}
public List<ArtifactResult> dependencies() throws RepositoryException {
return getResult().dependencies();
}
};
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class AetherTestCase method testAddRemoveOverrides.
@Test
public void testAddRemoveOverrides() throws Throwable {
CmrRepository repository = createAetherRepository();
RepositoryManager manager = new SimpleRepositoryManager(repository, log, RepositoryManagerBuilder.parseOverrides(getOverridesFileName()));
ArtifactResult result = manager.getArtifactResult(MavenArtifactContext.NAMESPACE, "org.restlet.jse:org.restlet", "2.0.10");
Assert.assertNotNull(result);
File artifact = result.artifact();
boolean exists = false;
try {
Assert.assertNotNull(artifact);
Assert.assertTrue(artifact.exists());
exists = true;
List<ArtifactResult> deps = result.dependencies();
Assert.assertEquals(deps.size(), 1);
Assert.assertEquals("org.slf4j:slf4j-api", deps.get(0).name());
Assert.assertEquals("1.6.1", deps.get(0).version());
log.debug("deps = " + deps);
} finally {
if (exists) {
// delete this one
Assert.assertTrue(artifact.delete());
}
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class AetherTestCase method testAether.
@Test
public void testAether() throws Throwable {
CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
RepositoryManager manager = new SimpleRepositoryManager(repository, log);
ArtifactResult result = manager.getArtifactResult(MavenArtifactContext.NAMESPACE, "org.slf4j:slf4j-api", "1.6.4");
Assert.assertNotNull(result);
File artifact = result.artifact();
boolean exists = false;
try {
Assert.assertNotNull(artifact);
Assert.assertTrue(artifact.exists());
exists = true;
List<ArtifactResult> deps = result.dependencies();
log.debug("deps = " + deps);
} finally {
if (exists) {
// delete this one
Assert.assertTrue(artifact.delete());
}
}
}
Aggregations