use of org.gradle.vcs.internal.VersionRef in project gradle by gradle.
the class VcsDependencyResolver method selectVersion.
private VersionRef selectVersion(ModuleComponentSelector depSelector, VersionControlSpec spec, VersionControlSystem versionControlSystem) {
String cacheKey = cacheKey(spec, depSelector.getVersionConstraint());
if (selectedVersionCache.containsKey(cacheKey)) {
return selectedVersionCache.get(cacheKey);
} else {
VersionRef selectedVersion = selectVersionFromRepository(spec, versionControlSystem, depSelector.getVersionConstraint());
selectedVersionCache.put(cacheKey, selectedVersion);
return selectedVersion;
}
}
use of org.gradle.vcs.internal.VersionRef in project gradle by gradle.
the class VcsDependencyResolver method selectVersionFromRepository.
private VersionRef selectVersionFromRepository(VersionControlSpec spec, VersionControlSystem versionControlSystem, VersionConstraint constraint) {
if (constraint.getBranch() != null) {
return versionControlSystem.getBranch(spec, constraint.getBranch());
}
String version = constraint.getPreferredVersion();
VersionSelector versionSelector = versionSelectorScheme.parseSelector(version);
if (versionSelector instanceof LatestVersionSelector && ((LatestVersionSelector) versionSelector).getSelectorStatus().equals("integration")) {
return versionControlSystem.getDefaultBranch(spec);
}
if (versionSelector.requiresMetadata()) {
// TODO - implement this by moving this resolver to live alongside the external resolvers
return null;
}
Set<VersionRef> versions = versionControlSystem.getAvailableVersions(spec);
Version bestVersion = null;
VersionRef bestCandidate = null;
for (VersionRef candidate : versions) {
Version candidateVersion = VersionParser.INSTANCE.transform(candidate.getVersion());
if (versionSelector.accept(candidateVersion)) {
if (bestCandidate == null || versionComparator.asVersionComparator().compare(candidateVersion, bestVersion) > 0) {
bestVersion = candidateVersion;
bestCandidate = candidate;
}
}
}
return bestCandidate;
}
use of org.gradle.vcs.internal.VersionRef 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.vcs.internal.VersionRef in project gradle by gradle.
the class GitVersionControlSystem method getDefaultBranch.
@Override
public VersionRef getDefaultBranch(VersionControlSpec spec) {
GitVersionControlSpec gitSpec = cast(spec);
Collection<Ref> refs;
try {
refs = Git.lsRemoteRepository().setRemote(normalizeUri(gitSpec.getUrl())).setTags(false).call();
} catch (URISyntaxException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
} catch (GitAPIException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
}
for (Ref ref : refs) {
if (ref.getName().equals("refs/heads/master")) {
return GitVersionRef.from(ref);
}
}
throw new UnsupportedOperationException("Git repository has no master branch");
}
use of org.gradle.vcs.internal.VersionRef in project gradle by gradle.
the class GitVersionControlSystem method getAvailableVersions.
@Override
public Set<VersionRef> getAvailableVersions(VersionControlSpec spec) {
GitVersionControlSpec gitSpec = cast(spec);
Collection<Ref> refs;
try {
refs = Git.lsRemoteRepository().setRemote(normalizeUri(gitSpec.getUrl())).setTags(true).setHeads(false).call();
} catch (URISyntaxException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
} catch (GitAPIException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
}
Set<VersionRef> versions = Sets.newHashSet();
for (Ref ref : refs) {
GitVersionRef gitRef = GitVersionRef.from(ref);
versions.add(gitRef);
}
return versions;
}
Aggregations