use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.
the class ComponentResultSerializer method read.
public ComponentResult read(Decoder decoder) throws IOException {
long resultId = decoder.readSmallLong();
ModuleVersionIdentifier id = idSerializer.read(decoder);
ComponentSelectionReason reason = reasonSerializer.read(decoder);
ComponentIdentifier componentId = componentIdSerializer.read(decoder);
String variantName = decoder.readString();
AttributeContainer attributes = attributeContainerSerializer.read(decoder);
return new DetachedComponentResult(resultId, id, reason, componentId, variantName, attributes);
}
use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.
the class RepositoryChainDependencyToComponentIdResolver method resolve.
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint resolvedVersionConstraint, BuildableComponentIdResolveResult result) {
ComponentSelector componentSelector = dependency.getSelector();
if (componentSelector instanceof ModuleComponentSelector) {
ModuleComponentSelector module = (ModuleComponentSelector) componentSelector;
if (resolvedVersionConstraint == null) {
// TODO:DAZ This shouldn't be required, but `ExternalResourceResolverDescriptorParseContext` does not provide a resolved constraint
VersionConstraint raw = module.getVersionConstraint();
resolvedVersionConstraint = new DefaultResolvedVersionConstraint(raw, versionSelectorScheme);
}
VersionSelector preferredSelector = resolvedVersionConstraint.getPreferredSelector();
if (preferredSelector.isDynamic()) {
dynamicRevisionResolver.resolve(toModuleDependencyMetadata(dependency), preferredSelector, resolvedVersionConstraint.getRejectedSelector(), result);
} else {
String version = resolvedVersionConstraint.getPreferredVersion();
ModuleComponentIdentifier id = new DefaultModuleComponentIdentifier(module.getGroup(), module.getModule(), version);
ModuleVersionIdentifier mvId = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getModule(), version);
result.resolved(id, mvId);
}
}
}
use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.
the class GradlePomModuleDescriptorParser method doParsePom.
private void doParsePom(DescriptorParseContext parserSettings, GradlePomModuleDescriptorBuilder mdBuilder, PomReader pomReader) throws IOException, SAXException {
if (pomReader.hasParent()) {
// Is there any other parent properties?
ModuleComponentSelector parentId = DefaultModuleComponentSelector.newSelector(pomReader.getParentGroupId(), pomReader.getParentArtifactId(), new DefaultImmutableVersionConstraint(pomReader.getParentVersion()));
PomReader parentPomReader = parsePomForSelector(parserSettings, parentId, pomReader.getAllPomProperties());
pomReader.setPomParent(parentPomReader);
}
pomReader.resolveGAV();
String groupId = pomReader.getGroupId();
String artifactId = pomReader.getArtifactId();
String version = pomReader.getVersion();
mdBuilder.setModuleRevId(groupId, artifactId, version);
ModuleVersionIdentifier relocation = pomReader.getRelocation();
if (relocation != null) {
if (groupId != null && artifactId != null && artifactId.equals(relocation.getName()) && groupId.equals(relocation.getGroup())) {
LOGGER.error("POM relocation to an other version number is not fully supported in Gradle : {} relocated to {}.", mdBuilder.getComponentIdentifier(), relocation);
LOGGER.warn("Please update your dependency to directly use the correct version '{}'.", relocation);
LOGGER.warn("Resolution will only pick dependencies of the relocated element. Artifacts and other metadata will be ignored.");
PomReader relocatedModule = parsePomForId(parserSettings, DefaultModuleComponentIdentifier.newId(relocation), Maps.<String, String>newHashMap());
addDependencies(mdBuilder, relocatedModule);
} else {
LOGGER.info(mdBuilder.getComponentIdentifier() + " is relocated to " + relocation + ". Please update your dependencies.");
LOGGER.debug("Relocated module will be considered as a dependency");
ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(relocation.getGroup(), relocation.getName(), new DefaultMutableVersionConstraint(relocation.getVersion()));
mdBuilder.addDependencyForRelocation(selector);
}
} else {
overrideDependencyMgtsWithImported(parserSettings, pomReader);
addDependencies(mdBuilder, pomReader);
}
}
use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.
the class VcsDependencyResolver method resolve.
@Override
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint versionConstraint, BuildableComponentIdResolveResult result) {
if (dependency.getSelector() instanceof ModuleComponentSelector) {
final ModuleComponentSelector depSelector = (ModuleComponentSelector) dependency.getSelector();
VersionControlSpec spec = vcsResolver.locateVcsFor(depSelector);
// TODO: Need failure handling, e.g., cannot clone repository
if (spec != null) {
VersionControlSystem versionControlSystem = versionControlSystemFactory.create(spec);
VersionRef selectedVersion = selectVersion(depSelector, spec, versionControlSystem);
if (selectedVersion == null) {
result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
return;
}
File dependencyWorkingDir = new File(populateWorkingDirectory(baseWorkingDir, spec, versionControlSystem, selectedVersion), spec.getRootDir());
// TODO: This shouldn't rely on the service registry to find NestedBuildFactory
IncludedBuildRegistry includedBuildRegistry = serviceRegistry.get(IncludedBuildRegistry.class);
NestedBuildFactory nestedBuildFactory = serviceRegistry.get(NestedBuildFactory.class);
IncludedBuildInternal includedBuild = includedBuildRegistry.addImplicitBuild(((AbstractVersionControlSpec) spec).getBuildDefinition(dependencyWorkingDir), nestedBuildFactory);
Collection<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> moduleToProject = includedBuild.getAvailableModules();
Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry = CollectionUtils.findFirst(moduleToProject, new Spec<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>>() {
@Override
public boolean isSatisfiedBy(Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry) {
ModuleVersionIdentifier possibleMatch = entry.left;
return depSelector.getGroup().equals(possibleMatch.getGroup()) && depSelector.getModule().equals(possibleMatch.getName());
}
});
if (entry == null) {
result.failed(new ModuleVersionResolveException(depSelector, spec.getDisplayName() + " did not contain a project publishing the specified dependency."));
} else {
LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(entry.right);
if (componentMetaData == null) {
result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(includedBuild.getModel(), entry.right.getProjectPath()), spec.getDisplayName() + " could not be resolved into a usable project."));
} else {
result.resolved(componentMetaData);
}
return;
}
}
}
projectDependencyResolver.resolve(dependency, versionConstraint, result);
}
use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.
the class PublicationsBuilder method publications.
private List<DefaultGradlePublication> publications(DefaultProjectIdentifier projectIdentifier) {
List<DefaultGradlePublication> gradlePublications = Lists.newArrayList();
Set<ProjectPublication> projectPublications = publicationRegistry.getPublications(projectIdentifier.getProjectPath());
for (ProjectPublication projectPublication : projectPublications) {
ModuleVersionIdentifier id = projectPublication.getCoordinates(ModuleVersionIdentifier.class);
if (id != null) {
gradlePublications.add(new DefaultGradlePublication().setId(new DefaultGradleModuleVersion(id)).setProjectIdentifier(projectIdentifier));
}
}
return gradlePublications;
}
Aggregations