Search in sources :

Example 6 with ProjectInternal

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

the class DefaultProjectDependencyPublicationResolver method resolve.

@Override
public <T> T resolve(Class<T> coordsType, ProjectDependency dependency) {
    // Could probably apply some caching and some immutable types
    ProjectInternal dependencyProject = (ProjectInternal) dependency.getDependencyProject();
    // Ensure target project is configured
    projectConfigurer.configureFully(dependencyProject);
    List<ProjectPublication> publications = new ArrayList<ProjectPublication>();
    for (ProjectPublication publication : publicationRegistry.getPublications(dependencyProject.getPath())) {
        if (!publication.isLegacy() && publication.getCoordinates(coordsType) != null) {
            publications.add(publication);
        }
    }
    if (publications.isEmpty()) {
        // Project has no publications: simply use the project name in place of the dependency name
        if (coordsType.isAssignableFrom(ModuleVersionIdentifier.class)) {
            return coordsType.cast(new DefaultModuleVersionIdentifier(dependency.getGroup(), dependencyProject.getName(), dependency.getVersion()));
        }
        throw new UnsupportedOperationException(String.format("Could not find any publications of type %s in %s.", coordsType.getSimpleName(), dependencyProject.getDisplayName()));
    }
    // Select all entry points. An entry point is a publication that does not contain a component whose parent is also published
    Set<SoftwareComponent> ignored = new HashSet<SoftwareComponent>();
    for (ProjectPublication publication : publications) {
        if (publication.getComponent() != null && publication.getComponent() instanceof ComponentWithVariants) {
            ComponentWithVariants parent = (ComponentWithVariants) publication.getComponent();
            ignored.addAll(parent.getVariants());
        }
    }
    Set<ProjectPublication> topLevel = new LinkedHashSet<ProjectPublication>();
    for (ProjectPublication publication : publications) {
        if (!publication.isAlias() && (publication.getComponent() == null || !ignored.contains(publication.getComponent()))) {
            topLevel.add(publication);
        }
    }
    // See if all entry points have the same identifier
    Iterator<ProjectPublication> iterator = topLevel.iterator();
    T candidate = iterator.next().getCoordinates(coordsType);
    while (iterator.hasNext()) {
        T alternative = iterator.next().getCoordinates(coordsType);
        if (!candidate.equals(alternative)) {
            TreeFormatter formatter = new TreeFormatter();
            formatter.node("Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates.");
            formatter.node("Found the following publications in " + dependencyProject.getDisplayName());
            formatter.startChildren();
            for (ProjectPublication publication : topLevel) {
                formatter.node(publication.getDisplayName().getCapitalizedDisplayName() + " with coordinates " + publication.getCoordinates(coordsType));
            }
            formatter.endChildren();
            throw new UnsupportedOperationException(formatter.toString());
        }
    }
    return candidate;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ArrayList(java.util.ArrayList) ComponentWithVariants(org.gradle.api.component.ComponentWithVariants) TreeFormatter(org.gradle.internal.text.TreeFormatter) SoftwareComponent(org.gradle.api.component.SoftwareComponent) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with ProjectInternal

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

the class DefaultTaskExecutionPlan method getResolvedTaskMutationInfo.

private TaskMutationInfo getResolvedTaskMutationInfo(TaskInfo taskInfo) {
    TaskInternal task = taskInfo.getTask();
    TaskMutationInfo taskMutationInfo = taskMutations.get(taskInfo);
    if (!taskMutationInfo.resolved) {
        ProjectInternal project = (ProjectInternal) task.getProject();
        ServiceRegistry serviceRegistry = project.getServices();
        PathToFileResolver resolver = serviceRegistry.get(PathToFileResolver.class);
        PropertyWalker propertyWalker = serviceRegistry.get(PropertyWalker.class);
        TaskProperties taskProperties = DefaultTaskProperties.resolve(propertyWalker, resolver, task);
        taskMutationInfo.outputPaths.addAll(getOutputPaths(canonicalizedFileCache, taskInfo, taskProperties.getOutputFiles(), taskProperties.getLocalStateFiles()));
        taskMutationInfo.destroyablePaths.addAll(getDestroyablePaths(canonicalizedFileCache, taskInfo, taskProperties.getDestroyableFiles()));
        taskMutationInfo.hasFileInputs = !taskProperties.getInputFileProperties().isEmpty();
        taskMutationInfo.hasOutputs = taskProperties.hasDeclaredOutputs();
        taskMutationInfo.hasLocalState = !taskProperties.getLocalStateFiles().isEmpty();
        taskMutationInfo.resolved = true;
    }
    return taskMutationInfo;
}
Also used : PathToFileResolver(org.gradle.internal.file.PathToFileResolver) PropertyWalker(org.gradle.api.internal.tasks.properties.PropertyWalker) TaskInternal(org.gradle.api.internal.TaskInternal) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) TaskProperties(org.gradle.api.internal.tasks.execution.TaskProperties) DefaultTaskProperties(org.gradle.api.internal.tasks.execution.DefaultTaskProperties) ServiceRegistry(org.gradle.internal.service.ServiceRegistry)

Example 8 with ProjectInternal

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

the class ValidatingTaskExecuter method execute.

public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    List<String> messages = Lists.newArrayList();
    FileResolver resolver = ((ProjectInternal) task.getProject()).getFileResolver();
    final TaskValidationContext validationContext = new DefaultTaskValidationContext(resolver, messages);
    try {
        context.getTaskProperties().validate(validationContext);
    } catch (Exception ex) {
        throw new TaskExecutionException(task, ex);
    }
    if (!messages.isEmpty()) {
        List<String> firstMessages = messages.subList(0, Math.min(5, messages.size()));
        if (!validationContext.getHighestSeverity().report(task, firstMessages, state)) {
            return;
        }
    }
    executer.execute(task, state, context);
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) DefaultTaskValidationContext(org.gradle.api.internal.tasks.DefaultTaskValidationContext) TaskValidationContext(org.gradle.api.internal.tasks.TaskValidationContext) DefaultTaskValidationContext(org.gradle.api.internal.tasks.DefaultTaskValidationContext) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) FileResolver(org.gradle.api.internal.file.FileResolver) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException)

Example 9 with ProjectInternal

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

the class GroovyCompile method getCompiler.

private Compiler<GroovyJavaJointCompileSpec> getCompiler(GroovyJavaJointCompileSpec spec) {
    if (compiler == null) {
        ProjectInternal projectInternal = (ProjectInternal) getProject();
        WorkerDaemonFactory workerDaemonFactory = getServices().get(WorkerDaemonFactory.class);
        IsolatedClassloaderWorkerFactory inProcessWorkerFactory = getServices().get(IsolatedClassloaderWorkerFactory.class);
        FileResolver fileResolver = getServices().get(FileResolver.class);
        GroovyCompilerFactory groovyCompilerFactory = new GroovyCompilerFactory(projectInternal, workerDaemonFactory, inProcessWorkerFactory, fileResolver);
        Compiler<GroovyJavaJointCompileSpec> delegatingCompiler = groovyCompilerFactory.newCompiler(spec);
        compiler = new CleaningGroovyCompiler(delegatingCompiler, getOutputs());
    }
    return compiler;
}
Also used : GroovyCompilerFactory(org.gradle.api.internal.tasks.compile.GroovyCompilerFactory) IsolatedClassloaderWorkerFactory(org.gradle.workers.internal.IsolatedClassloaderWorkerFactory) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) GroovyJavaJointCompileSpec(org.gradle.api.internal.tasks.compile.GroovyJavaJointCompileSpec) DefaultGroovyJavaJointCompileSpec(org.gradle.api.internal.tasks.compile.DefaultGroovyJavaJointCompileSpec) CleaningGroovyCompiler(org.gradle.api.internal.tasks.compile.CleaningGroovyCompiler) FileResolver(org.gradle.api.internal.file.FileResolver) WorkerDaemonFactory(org.gradle.workers.internal.WorkerDaemonFactory)

Example 10 with ProjectInternal

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

the class SelectedTaskExecutionAction method bindAllReferencesOfProject.

private void bindAllReferencesOfProject(TaskExecutionGraph graph) {
    Set<Project> seen = Sets.newHashSet();
    for (Task task : graph.getAllTasks()) {
        if (seen.add(task.getProject())) {
            ProjectInternal projectInternal = (ProjectInternal) task.getProject();
            projectInternal.bindAllModelRules();
        }
    }
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

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