Search in sources :

Example 1 with ProjectInternal

use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.

the class TaskSelector method getFilter.

public Spec<Task> getFilter(String path) {
    final ResolvedTaskPath taskPath = taskPathResolver.resolvePath(path, gradle.getDefaultProject());
    if (!taskPath.isQualified()) {
        ProjectInternal targetProject = taskPath.getProject();
        configurer.configure(targetProject);
        if (taskNameResolver.tryFindUnqualifiedTaskCheaply(taskPath.getTaskName(), taskPath.getProject())) {
            // An exact match in the target project - can just filter tasks by path to avoid configuring sub-projects at this point
            return new TaskPathSpec(targetProject, taskPath.getTaskName());
        }
    }
    final Set<Task> selectedTasks = getSelection(path, gradle.getDefaultProject()).getTasks();
    return new Spec<Task>() {

        public boolean isSatisfiedBy(Task element) {
            return !selectedTasks.contains(element);
        }
    };
}
Also used : ResolvedTaskPath(org.gradle.execution.taskpath.ResolvedTaskPath) Task(org.gradle.api.Task) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Spec(org.gradle.api.specs.Spec)

Example 2 with ProjectInternal

use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.

the class TaskSelector method getSelection.

private TaskSelection getSelection(String path, ProjectInternal project) {
    ResolvedTaskPath taskPath = taskPathResolver.resolvePath(path, project);
    ProjectInternal targetProject = taskPath.getProject();
    if (taskPath.isQualified()) {
        configurer.configure(targetProject);
    } else {
        configurer.configureHierarchy(targetProject);
    }
    TaskSelectionResult tasks = taskNameResolver.selectWithName(taskPath.getTaskName(), taskPath.getProject(), !taskPath.isQualified());
    if (tasks != null) {
        // An exact match
        return new TaskSelection(taskPath.getProject().getPath(), path, tasks);
    }
    Map<String, TaskSelectionResult> tasksByName = taskNameResolver.selectAll(taskPath.getProject(), !taskPath.isQualified());
    NameMatcher matcher = new NameMatcher();
    String actualName = matcher.find(taskPath.getTaskName(), tasksByName.keySet());
    if (actualName != null) {
        return new TaskSelection(taskPath.getProject().getPath(), taskPath.getPrefix() + actualName, tasksByName.get(actualName));
    }
    throw new TaskSelectionException(matcher.formatErrorMessage("task", taskPath.getProject()));
}
Also used : ResolvedTaskPath(org.gradle.execution.taskpath.ResolvedTaskPath) NameMatcher(org.gradle.util.NameMatcher) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 3 with ProjectInternal

use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.

the class InstantiatingBuildLoader method addProjects.

private void addProjects(ProjectInternal parent, ProjectDescriptor parentProjectDescriptor, GradleInternal gradle, ClassLoaderScope buildRootClassLoaderScope) {
    for (ProjectDescriptor childProjectDescriptor : parentProjectDescriptor.getChildren()) {
        ProjectInternal childProject = projectFactory.createProject(childProjectDescriptor, parent, gradle, parent.getClassLoaderScope().createChild("project-" + childProjectDescriptor.getName()), buildRootClassLoaderScope);
        addProjects(childProject, childProjectDescriptor, gradle, buildRootClassLoaderScope);
    }
}
Also used : ProjectDescriptor(org.gradle.api.initialization.ProjectDescriptor) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 4 with ProjectInternal

use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.

the class ProjectDependencyPublicationResolver method resolve.

public ModuleVersionIdentifier resolve(ProjectDependency dependency) {
    Project dependencyProject = dependency.getDependencyProject();
    ((ProjectInternal) dependencyProject).evaluate();
    PublishingExtension publishing = dependencyProject.getExtensions().findByType(PublishingExtension.class);
    if (publishing == null || publishing.getPublications().withType(PublicationInternal.class).isEmpty()) {
        // Project does not apply publishing (or has no publications): simply use the project name in place of the dependency name
        return new DefaultModuleVersionIdentifier(dependency.getGroup(), dependencyProject.getName(), dependency.getVersion());
    }
    // See if all publications have the same identifier
    Set<? extends PublicationInternal> publications = publishing.getPublications().withType(PublicationInternal.class);
    Iterator<? extends PublicationInternal> iterator = publications.iterator();
    ModuleVersionIdentifier candidate = iterator.next().getCoordinates();
    while (iterator.hasNext()) {
        ModuleVersionIdentifier alternative = iterator.next().getCoordinates();
        if (!candidate.equals(alternative)) {
            throw new UnsupportedOperationException("Publishing is not yet able to resolve a dependency on a project with multiple different publications.");
        }
    }
    return candidate;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) Project(org.gradle.api.Project) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Example 5 with ProjectInternal

use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.

the class DefaultBuildController method getTargetProject.

private ProjectInternal getTargetProject(Object target) {
    ProjectInternal project;
    if (target == null) {
        project = gradle.getDefaultProject();
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity projectIdentity = (GradleProjectIdentity) target;
        GradleInternal build = findBuild(projectIdentity);
        project = findProject(build, projectIdentity);
    } else if (target instanceof GradleBuildIdentity) {
        GradleBuildIdentity buildIdentity = (GradleBuildIdentity) target;
        project = findBuild(buildIdentity).getDefaultProject();
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    return project;
}
Also used : GradleInternal(org.gradle.api.internal.GradleInternal) GradleBuildIdentity(org.gradle.tooling.internal.gradle.GradleBuildIdentity) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) GradleProjectIdentity(org.gradle.tooling.internal.gradle.GradleProjectIdentity)

Aggregations

ProjectInternal (org.gradle.api.internal.project.ProjectInternal)58 File (java.io.File)13 Project (org.gradle.api.Project)11 Task (org.gradle.api.Task)6 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)6 Inject (javax.inject.Inject)5 Plugin (org.gradle.api.Plugin)5 ProjectStateRegistry (org.gradle.api.internal.project.ProjectStateRegistry)5 Map (java.util.Map)4 Configuration (org.gradle.api.artifacts.Configuration)4 FileResolver (org.gradle.api.internal.file.FileResolver)4 Lists (com.google.common.collect.Lists)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Callable (java.util.concurrent.Callable)3 Collectors (java.util.stream.Collectors)3 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)3