Search in sources :

Example 1 with VersionRef

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;
    }
}
Also used : VersionRef(org.gradle.vcs.internal.VersionRef)

Example 2 with VersionRef

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;
}
Also used : VersionRef(org.gradle.vcs.internal.VersionRef) Version(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector) LatestVersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector) LatestVersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector)

Example 3 with VersionRef

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);
}
Also used : VersionRef(org.gradle.vcs.internal.VersionRef) ModuleVersionNotFoundException(org.gradle.internal.resolve.ModuleVersionNotFoundException) VersionControlSystem(org.gradle.vcs.internal.VersionControlSystem) NestedBuildFactory(org.gradle.initialization.NestedBuildFactory) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) IncludedBuildInternal(org.gradle.composite.internal.IncludedBuildInternal) IncludedBuildRegistry(org.gradle.composite.internal.IncludedBuildRegistry) VersionControlSpec(org.gradle.vcs.VersionControlSpec) AbstractVersionControlSpec(org.gradle.vcs.internal.spec.AbstractVersionControlSpec) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) File(java.io.File) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) Pair(org.gradle.internal.Pair)

Example 4 with VersionRef

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");
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) VersionRef(org.gradle.vcs.internal.VersionRef) Ref(org.eclipse.jgit.lib.Ref) GitVersionControlSpec(org.gradle.vcs.git.GitVersionControlSpec) URISyntaxException(java.net.URISyntaxException)

Example 5 with VersionRef

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;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) VersionRef(org.gradle.vcs.internal.VersionRef) VersionRef(org.gradle.vcs.internal.VersionRef) Ref(org.eclipse.jgit.lib.Ref) GitVersionControlSpec(org.gradle.vcs.git.GitVersionControlSpec) URISyntaxException(java.net.URISyntaxException)

Aggregations

VersionRef (org.gradle.vcs.internal.VersionRef)6 URISyntaxException (java.net.URISyntaxException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ref (org.eclipse.jgit.lib.Ref)3 GitVersionControlSpec (org.gradle.vcs.git.GitVersionControlSpec)3 File (java.io.File)1 Nullable (javax.annotation.Nullable)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 LatestVersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector)1 Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)1 VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)1 IncludedBuildInternal (org.gradle.composite.internal.IncludedBuildInternal)1 IncludedBuildRegistry (org.gradle.composite.internal.IncludedBuildRegistry)1 NestedBuildFactory (org.gradle.initialization.NestedBuildFactory)1 Pair (org.gradle.internal.Pair)1 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)1 ModuleVersionNotFoundException (org.gradle.internal.resolve.ModuleVersionNotFoundException)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1