Search in sources :

Example 1 with IncludedBuildState

use of org.gradle.internal.build.IncludedBuildState in project gradle by gradle.

the class DefaultIncludedBuildRegistry method registerBuild.

private IncludedBuildState registerBuild(BuildDefinition buildDefinition, boolean isImplicit) {
    // TODO: synchronization
    File buildDir = buildDefinition.getBuildRootDir();
    if (buildDir == null) {
        throw new IllegalArgumentException("Included build must have a root directory defined");
    }
    IncludedBuildState includedBuild = includedBuildsByRootDir.get(buildDir);
    if (includedBuild == null) {
        if (rootBuild == null) {
            throw new IllegalStateException("No root build attached yet.");
        }
        String buildName = buildDefinition.getName();
        if (buildName == null) {
            throw new IllegalStateException("build name is required");
        }
        validateNameIsNotBuildSrc(buildName, buildDir);
        Path idPath = assignPath(rootBuild, buildDefinition.getName(), buildDir);
        BuildIdentifier buildIdentifier = idFor(buildName);
        includedBuild = includedBuildFactory.createBuild(buildIdentifier, idPath, buildDefinition, isImplicit, rootBuild);
        includedBuildsByRootDir.put(buildDir, includedBuild);
        pendingIncludedBuilds.add(includedBuild);
        addBuild(includedBuild);
    } else {
        if (includedBuild.isImplicitBuild() != isImplicit) {
            throw new IllegalStateException("Unexpected state for build.");
        }
    // TODO: verify that the build definition is the same
    }
    return includedBuild;
}
Also used : Path(org.gradle.util.Path) IncludedBuildState(org.gradle.internal.build.IncludedBuildState) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) DefaultBuildIdentifier(org.gradle.api.internal.artifacts.DefaultBuildIdentifier) File(java.io.File)

Example 2 with IncludedBuildState

use of org.gradle.internal.build.IncludedBuildState in project gradle by gradle.

the class DefaultBuildIncluder method includeBuild.

@Override
public IncludedBuildState includeBuild(IncludedBuildSpec includedBuildSpec) {
    BuildDefinition buildDefinition = toBuildDefinition(includedBuildSpec, gradle);
    IncludedBuildState build = buildRegistry.addIncludedBuild(buildDefinition);
    coordinator.prepareForInclusion(build, buildDefinition.isPluginBuild());
    return build;
}
Also used : IncludedBuildState(org.gradle.internal.build.IncludedBuildState) BuildDefinition(org.gradle.api.internal.BuildDefinition)

Example 3 with IncludedBuildState

use of org.gradle.internal.build.IncludedBuildState in project gradle by gradle.

the class VcsDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, VersionSelector rejector, 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) {
            VersionControlRepositoryConnection repository = versionControlSystemFactory.create(spec);
            File dependencyWorkingDir;
            try {
                dependencyWorkingDir = workingDirResolver.selectVersion(depSelector, repository);
            } catch (ModuleVersionResolveException e) {
                result.failed(e);
                return;
            }
            if (dependencyWorkingDir == null) {
                result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
                return;
            }
            File buildRootDir = new File(dependencyWorkingDir, spec.getRootDir());
            BuildDefinition buildDefinition = toBuildDefinition((AbstractVersionControlSpec) spec, buildRootDir);
            IncludedBuildState includedBuild = buildRegistry.addImplicitIncludedBuild(buildDefinition);
            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);
                result.resolved(componentMetaData);
            }
        }
    }
}
Also used : VersionControlRepositoryConnection(org.gradle.vcs.internal.VersionControlRepositoryConnection) ModuleVersionNotFoundException(org.gradle.internal.resolve.ModuleVersionNotFoundException) BuildDefinition(org.gradle.api.internal.BuildDefinition) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) 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) IncludedBuildState(org.gradle.internal.build.IncludedBuildState) 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 IncludedBuildState

use of org.gradle.internal.build.IncludedBuildState in project gradle by gradle.

the class GradleBuildBuilder method addIncludedBuilds.

private void addIncludedBuilds(GradleInternal gradle, DefaultGradleBuild model, Map<BuildState, DefaultGradleBuild> all) {
    for (IncludedBuildInternal reference : gradle.includedBuilds()) {
        BuildState target = reference.getTarget();
        if (target instanceof IncludedBuildState) {
            IncludedBuildState includedBuildState = (IncludedBuildState) target;
            DefaultGradleBuild convertedIncludedBuild = convert(includedBuildState, all);
            model.addIncludedBuild(convertedIncludedBuild);
        } else if (target instanceof RootBuildState) {
            DefaultGradleBuild rootBuild = convert(target, all);
            model.addIncludedBuild(rootBuild);
        } else {
            throw new IllegalStateException("Unknown build type: " + reference.getClass().getName());
        }
    }
}
Also used : IncludedBuildInternal(org.gradle.internal.composite.IncludedBuildInternal) RootBuildState(org.gradle.internal.build.RootBuildState) DefaultGradleBuild(org.gradle.plugins.ide.internal.tooling.model.DefaultGradleBuild) IncludedBuildState(org.gradle.internal.build.IncludedBuildState) BuildState(org.gradle.internal.build.BuildState) RootBuildState(org.gradle.internal.build.RootBuildState) IncludedBuildState(org.gradle.internal.build.IncludedBuildState)

Example 5 with IncludedBuildState

use of org.gradle.internal.build.IncludedBuildState in project gradle by gradle.

the class IdeaModelBuilder method applyIdeaPlugin.

private void applyIdeaPlugin(ProjectInternal root, List<GradleInternal> alreadyProcessed) {
    Set<Project> allProjects = root.getAllprojects();
    for (Project p : allProjects) {
        p.getPluginManager().apply(IdeaPlugin.class);
    }
    for (IncludedBuildInternal reference : root.getGradle().includedBuilds()) {
        BuildState target = reference.getTarget();
        if (target instanceof IncludedBuildState) {
            target.ensureProjectsConfigured();
            GradleInternal build = target.getMutableModel();
            if (!alreadyProcessed.contains(build)) {
                alreadyProcessed.add(build);
                applyIdeaPlugin(build.getRootProject(), alreadyProcessed);
            }
        }
    }
}
Also used : IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) Project(org.gradle.api.Project) DefaultIdeaProject(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaProject) DefaultGradleProject(org.gradle.plugins.ide.internal.tooling.model.DefaultGradleProject) IncludedBuildInternal(org.gradle.internal.composite.IncludedBuildInternal) GradleInternal(org.gradle.api.internal.GradleInternal) IncludedBuildState(org.gradle.internal.build.IncludedBuildState) BuildState(org.gradle.internal.build.BuildState) IncludedBuildState(org.gradle.internal.build.IncludedBuildState)

Aggregations

IncludedBuildState (org.gradle.internal.build.IncludedBuildState)11 BuildState (org.gradle.internal.build.BuildState)5 IncludedBuildInternal (org.gradle.internal.composite.IncludedBuildInternal)5 GradleInternal (org.gradle.api.internal.GradleInternal)4 Project (org.gradle.api.Project)3 RootBuildState (org.gradle.internal.build.RootBuildState)3 File (java.io.File)2 BuildDefinition (org.gradle.api.internal.BuildDefinition)2 DefaultGradleProject (org.gradle.plugins.ide.internal.tooling.model.DefaultGradleProject)2 LinkedHashSet (java.util.LinkedHashSet)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 SettingsInternal (org.gradle.api.internal.SettingsInternal)1 DefaultBuildIdentifier (org.gradle.api.internal.artifacts.DefaultBuildIdentifier)1 BuildClientMetaData (org.gradle.initialization.BuildClientMetaData)1 IncludedBuildSpec (org.gradle.initialization.IncludedBuildSpec)1 Pair (org.gradle.internal.Pair)1 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)1