use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint in project gradle by gradle.
the class GradlePomModuleDescriptorBuilder method doAddDependency.
private void doAddDependency(PomDependencyMgt dep, boolean optional, boolean useCompileScope) {
MavenScope scope;
if (useCompileScope) {
scope = MavenScope.Compile;
} else {
String scopeString = dep.getScope();
if (scopeString == null || scopeString.length() == 0) {
scopeString = getDefaultScope(dep);
}
if (SCOPES.containsKey(scopeString)) {
scope = SCOPES.get(scopeString);
} else {
// unknown scope, defaulting to 'compile'
scope = MavenScope.Compile;
}
}
String version = determineVersion(dep);
String mappedVersion = convertVersionFromMavenSyntax(version);
ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(dep.getGroupId(), dep.getArtifactId(), new DefaultImmutableVersionConstraint(mappedVersion));
// Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
if (selector.getGroup().equals(componentIdentifier.getGroup()) && selector.getModule().equals(componentIdentifier.getModule())) {
return;
}
IvyArtifactName dependencyArtifact = null;
boolean hasClassifier = dep.getClassifier() != null && dep.getClassifier().length() > 0;
boolean hasNonJarType = dep.getType() != null && !"jar".equals(dep.getType());
if (hasClassifier || hasNonJarType) {
String type = "jar";
if (dep.getType() != null) {
type = dep.getType();
}
String ext = determineExtension(type);
String classifier = hasClassifier ? dep.getClassifier() : getClassifierForType(type);
dependencyArtifact = new DefaultIvyArtifactName(selector.getModule(), type, ext, classifier);
}
// experimentation shows the following, excluded modules are
// inherited from parent POMs if either of the following is true:
// the <exclusions> element is missing or the <exclusions> element
// is present, but empty.
List<ExcludeMetadata> excludes = Lists.newArrayList();
List<ModuleIdentifier> excluded = dep.getExcludedModules();
if (excluded.isEmpty()) {
excluded = getDependencyMgtExclusions(dep);
}
for (ModuleIdentifier excludedModule : excluded) {
DefaultExclude rule = new DefaultExclude(excludedModule);
excludes.add(rule);
}
dependencies.add(new MavenDependencyDescriptor(scope, optional, selector, dependencyArtifact, excludes));
}
use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint in project gradle by gradle.
the class ComponentSelectorSerializer method readVersionConstraint.
ImmutableVersionConstraint readVersionConstraint(Decoder decoder) throws IOException {
String requires = decoder.readString();
String prefers = decoder.readString();
String strictly = decoder.readString();
int rejectCount = decoder.readSmallInt();
List<String> rejects = Lists.newArrayListWithCapacity(rejectCount);
for (int i = 0; i < rejectCount; i++) {
rejects.add(decoder.readString());
}
String branch = decoder.readNullableString();
return new DefaultImmutableVersionConstraint(prefers, requires, strictly, rejects, branch);
}
use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint in project gradle by gradle.
the class DefaultIvyModulePublishMetadata method normalizeVersionForIvy.
/**
* [1.0] is a valid version in maven, but not in Ivy: strip the surrounding '[' and ']' characters for ivy publish.
*/
private static LocalOriginDependencyMetadata normalizeVersionForIvy(LocalOriginDependencyMetadata dependency) {
if (dependency.getSelector() instanceof ModuleComponentSelector) {
ModuleComponentSelector selector = (ModuleComponentSelector) dependency.getSelector();
VersionConstraint versionConstraint = selector.getVersionConstraint();
DefaultImmutableVersionConstraint transformedConstraint = new DefaultImmutableVersionConstraint(VERSION_TRANSFORMER.transform(versionConstraint.getPreferredVersion()), VERSION_TRANSFORMER.transform(versionConstraint.getRequiredVersion()), VERSION_TRANSFORMER.transform(versionConstraint.getStrictVersion()), CollectionUtils.collect(versionConstraint.getRejectedVersions(), VERSION_TRANSFORMER), versionConstraint.getBranch());
ModuleComponentSelector newSelector = DefaultModuleComponentSelector.newSelector(selector.getModuleIdentifier(), transformedConstraint, selector.getAttributes(), selector.getRequestedCapabilities());
return dependency.withTarget(newSelector);
}
return dependency;
}
use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint in project gradle by gradle.
the class GradlePomModuleDescriptorParser method parseImportedDependencyMgts.
/**
* Parses imported dependency management information.
*
* @param parseContext Parse context
* @param currentDependencyMgts Current dependency management information
* @return Imported dependency management information
*/
private Map<MavenDependencyKey, PomDependencyMgt> parseImportedDependencyMgts(DescriptorParseContext parseContext, Collection<PomDependencyMgt> currentDependencyMgts) throws IOException, SAXException {
Map<MavenDependencyKey, PomDependencyMgt> importedDependencyMgts = new LinkedHashMap<>();
for (PomDependencyMgt currentDependencyMgt : currentDependencyMgts) {
if (isDependencyImportScoped(currentDependencyMgt)) {
ModuleComponentSelector importedId = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(currentDependencyMgt.getGroupId(), currentDependencyMgt.getArtifactId()), new DefaultImmutableVersionConstraint(currentDependencyMgt.getVersion()));
PomReader importedPom = parsePomForSelector(parseContext, importedId, Maps.newHashMap());
for (Map.Entry<MavenDependencyKey, PomDependencyMgt> entry : importedPom.getDependencyMgt().entrySet()) {
if (!importedDependencyMgts.containsKey(entry.getKey())) {
importedDependencyMgts.put(entry.getKey(), entry.getValue());
}
}
}
}
return importedDependencyMgts;
}
use of org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint in project gradle by gradle.
the class IvyModuleDescriptorConverter method addDependency.
private void addDependency(List<IvyDependencyDescriptor> result, DependencyDescriptor dependencyDescriptor) {
ModuleRevisionId revisionId = dependencyDescriptor.getDependencyRevisionId();
ModuleComponentSelector requested = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(revisionId.getOrganisation(), revisionId.getName()), new DefaultImmutableVersionConstraint(revisionId.getRevision()));
ListMultimap<String, String> configMappings = ArrayListMultimap.create();
for (Map.Entry<String, List<String>> entry : readConfigMappings(dependencyDescriptor).entrySet()) {
configMappings.putAll(entry.getKey(), entry.getValue());
}
List<Artifact> artifacts = Lists.newArrayList();
for (DependencyArtifactDescriptor ivyArtifact : dependencyDescriptor.getAllDependencyArtifacts()) {
IvyArtifactName ivyArtifactName = new DefaultIvyArtifactName(ivyArtifact.getName(), ivyArtifact.getType(), ivyArtifact.getExt(), (String) ivyArtifact.getExtraAttributes().get(CLASSIFIER));
artifacts.add(new Artifact(ivyArtifactName, Sets.newHashSet(ivyArtifact.getConfigurations())));
}
List<Exclude> excludes = Lists.newArrayList();
for (ExcludeRule excludeRule : dependencyDescriptor.getAllExcludeRules()) {
excludes.add(forIvyExclude(excludeRule));
}
result.add(new IvyDependencyDescriptor(requested, dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision(), dependencyDescriptor.isChanging(), dependencyDescriptor.isTransitive(), false, configMappings, artifacts, excludes));
}
Aggregations