Search in sources :

Example 16 with ProjectInternal

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

the class LocalTaskNode method resolveMutations.

@Override
public void resolveMutations() {
    final LocalTaskNode taskNode = this;
    final TaskInternal task = getTask();
    final MutationInfo mutations = getMutationInfo();
    ProjectInternal project = (ProjectInternal) task.getProject();
    ServiceRegistry serviceRegistry = project.getServices();
    final FileCollectionFactory fileCollectionFactory = serviceRegistry.get(FileCollectionFactory.class);
    PropertyWalker propertyWalker = serviceRegistry.get(PropertyWalker.class);
    try {
        taskProperties = DefaultTaskProperties.resolve(propertyWalker, fileCollectionFactory, task);
        addOutputFilesToMutations(taskProperties.getOutputFileProperties());
        addLocalStateFilesToMutations(taskProperties.getLocalStateFiles());
        addDestroyablesToMutations(taskProperties.getDestroyableFiles());
        mutations.hasFileInputs = !taskProperties.getInputFileProperties().isEmpty();
    } catch (Exception e) {
        throw new TaskExecutionException(task, e);
    }
    mutations.resolved = true;
    if (!mutations.destroyablePaths.isEmpty()) {
        if (mutations.hasOutputs) {
            throw new IllegalStateException("Task " + taskNode + " has both outputs and destroyables defined.  A task can define either outputs or destroyables, but not both.");
        }
        if (mutations.hasFileInputs) {
            throw new IllegalStateException("Task " + taskNode + " has both inputs and destroyables defined.  A task can define either inputs or destroyables, but not both.");
        }
        if (mutations.hasLocalState) {
            throw new IllegalStateException("Task " + taskNode + " has both local state and destroyables defined.  A task can define either local state or destroyables, but not both.");
        }
    }
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) PropertyWalker(org.gradle.api.internal.tasks.properties.PropertyWalker) TaskInternal(org.gradle.api.internal.TaskInternal) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory)

Example 17 with ProjectInternal

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

the class DefaultExecutionPlan method createOrdinalRelationships.

private void createOrdinalRelationships(Node node) {
    if (node instanceof TaskNode && ((TaskNode) node).getOrdinal() != TaskNode.UNKNOWN_ORDINAL) {
        TaskNode taskNode = (TaskNode) node;
        TaskClassifier taskClassifier = new TaskClassifier();
        ProjectInternal project = (ProjectInternal) taskNode.getTask().getProject();
        ServiceRegistry serviceRegistry = project.getServices();
        PropertyWalker propertyWalker = serviceRegistry.get(PropertyWalker.class);
        // Walk the properties of the task to determine if it is a destroyer or a producer (or neither)
        propertyWalker.visitProperties(taskNode.getTask(), TypeValidationContext.NOOP, taskClassifier);
        taskNode.getTask().getOutputs().visitRegisteredProperties(taskClassifier);
        ((TaskDestroyablesInternal) taskNode.getTask().getDestroyables()).visitRegisteredProperties(taskClassifier);
        ((TaskLocalStateInternal) taskNode.getTask().getLocalState()).visitRegisteredProperties(taskClassifier);
        if (taskClassifier.isDestroyer()) {
            // Create (or get) a destroyer ordinal node that depends on the dependencies of this task node
            Node ordinalNode = ordinalNodeAccess.getOrCreateDestroyableLocationNode(taskNode.getOrdinal());
            taskNode.getHardSuccessors().forEach(ordinalNode::addDependencySuccessor);
            if (taskNode.getOrdinal() > 0) {
                // Depend on any previous producer ordinal nodes (i.e. any producer ordinal nodes with a lower
                // ordinal)
                ordinalNodeAccess.getPrecedingProducerLocationNodes(taskNode.getOrdinal()).forEach(taskNode::addDependencySuccessor);
            }
        } else if (taskClassifier.isProducer()) {
            // Create (or get) a producer ordinal node that depends on the dependencies of this task node
            Node ordinalNode = ordinalNodeAccess.getOrCreateOutputLocationNode(taskNode.getOrdinal());
            taskNode.getHardSuccessors().forEach(ordinalNode::addDependencySuccessor);
            if (taskNode.getOrdinal() > 0) {
                // Depend on any previous destroyer ordinal nodes (i.e. any destroyer ordinal nodes with a lower
                // ordinal)
                ordinalNodeAccess.getPrecedingDestroyerLocationNodes(taskNode.getOrdinal()).forEach(taskNode::addDependencySuccessor);
            }
        }
    }
}
Also used : PropertyWalker(org.gradle.api.internal.tasks.properties.PropertyWalker) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) TaskDestroyablesInternal(org.gradle.api.internal.tasks.TaskDestroyablesInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) TaskLocalStateInternal(org.gradle.api.internal.tasks.TaskLocalStateInternal)

Example 18 with ProjectInternal

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

the class ProjectFinderByTaskPath method findProject.

public ProjectInternal findProject(String projectPath, ProjectInternal startFrom) {
    if (projectPath.equals(Project.PATH_SEPARATOR)) {
        return startFrom.getRootProject();
    }
    Project current = startFrom;
    if (projectPath.startsWith(Project.PATH_SEPARATOR)) {
        current = current.getRootProject();
        projectPath = projectPath.substring(1);
    }
    for (String pattern : projectPath.split(Project.PATH_SEPARATOR)) {
        Map<String, Project> children = current.getChildProjects();
        NameMatcher matcher = new NameMatcher();
        Project child = matcher.find(pattern, children);
        if (child != null) {
            current = child;
            continue;
        }
        throw new ProjectLookupException(matcher.formatErrorMessage("project", current));
    }
    return (ProjectInternal) current;
}
Also used : Project(org.gradle.api.Project) NameMatcher(org.gradle.util.internal.NameMatcher) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 19 with ProjectInternal

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

the class DefaultDependenciesAccessors method createExtensions.

@Override
public void createExtensions(ProjectInternal project) {
    ExtensionContainer container = project.getExtensions();
    ProviderFactory providerFactory = project.getProviders();
    try {
        if (!models.isEmpty()) {
            ImmutableMap.Builder<String, VersionCatalog> catalogs = ImmutableMap.builderWithExpectedSize(models.size());
            for (DefaultVersionCatalog model : models) {
                if (model.isNotEmpty()) {
                    Class<? extends ExternalModuleDependencyFactory> factory;
                    synchronized (this) {
                        factory = factories.computeIfAbsent(model.getName(), n -> loadFactory(classLoaderScope, ACCESSORS_PACKAGE + "." + ACCESSORS_CLASSNAME_PREFIX + StringUtils.capitalize(n)));
                    }
                    if (factory != null) {
                        container.create(model.getName(), factory, model);
                        catalogs.put(model.getName(), new VersionCatalogView(model, providerFactory));
                    }
                }
            }
            container.create(VersionCatalogsExtension.class, "versionCatalogs", DefaultVersionCatalogsExtension.class, catalogs.build());
        }
    } finally {
        if (featurePreviews.isFeatureEnabled(FeaturePreviews.Feature.TYPESAFE_PROJECT_ACCESSORS)) {
            ServiceRegistry services = project.getServices();
            DependencyResolutionManagementInternal drm = services.get(DependencyResolutionManagementInternal.class);
            ProjectFinder projectFinder = services.get(ProjectFinder.class);
            createProjectsExtension(container, drm, projectFinder);
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DirectorySensitivity(org.gradle.internal.fingerprint.DirectorySensitivity) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) Hashing(org.gradle.internal.hash.Hashing) SettingsInternal(org.gradle.api.internal.SettingsInternal) FileValueSupplier(org.gradle.internal.execution.fingerprint.InputFingerprinter.FileValueSupplier) ExecutionResult(org.gradle.internal.execution.ExecutionResult) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) IncubationLogger(org.gradle.util.internal.IncubationLogger) VersionCatalogBuilder(org.gradle.api.initialization.dsl.VersionCatalogBuilder) DependencyResolutionManagementInternal(org.gradle.internal.management.DependencyResolutionManagementInternal) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Map(java.util.Map) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) InputVisitor(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputVisitor) Set(java.util.Set) InputPropertyType(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputPropertyType) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) Hasher(org.gradle.internal.hash.Hasher) Settings(org.gradle.api.initialization.Settings) Collectors(java.util.stream.Collectors) List(java.util.List) ProjectRegistry(org.gradle.api.internal.project.ProjectRegistry) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) DefaultProjectDependencyFactory(org.gradle.api.internal.artifacts.DefaultProjectDependencyFactory) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) Optional(java.util.Optional) ClassPath(org.gradle.internal.classpath.ClassPath) Pattern(java.util.regex.Pattern) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) Inject(javax.inject.Inject) ExecutionEngine(org.gradle.internal.execution.ExecutionEngine) Lists(com.google.common.collect.Lists) FeaturePreviews(org.gradle.api.internal.FeaturePreviews) TreeType(org.gradle.internal.file.TreeType) ProjectDescriptor(org.gradle.api.initialization.ProjectDescriptor) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) WorkspaceProvider(org.gradle.internal.execution.workspace.WorkspaceProvider) DependenciesAccessors(org.gradle.initialization.DependenciesAccessors) VersionCatalogsExtension(org.gradle.api.artifacts.VersionCatalogsExtension) Nullable(javax.annotation.Nullable) UnitOfWork(org.gradle.internal.execution.UnitOfWork) ClassPathRegistry(org.gradle.api.internal.ClassPathRegistry) ClasspathNormalizer(org.gradle.api.tasks.ClasspathNormalizer) Iterator(java.util.Iterator) ProjectFinder(org.gradle.api.internal.artifacts.dsl.dependencies.ProjectFinder) StringWriter(java.io.StringWriter) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) LineEndingSensitivity(org.gradle.internal.fingerprint.LineEndingSensitivity) VersionCatalogBuilderInternal(org.gradle.internal.management.VersionCatalogBuilderInternal) Cast(org.gradle.internal.Cast) Maps(com.google.common.collect.Maps) File(java.io.File) ProviderFactory(org.gradle.api.provider.ProviderFactory) VersionCatalog(org.gradle.api.artifacts.VersionCatalog) Property(org.gradle.api.provider.Property) InvalidUserDataException(org.gradle.api.InvalidUserDataException) Collections(java.util.Collections) ProjectFinder(org.gradle.api.internal.artifacts.dsl.dependencies.ProjectFinder) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) ImmutableMap(com.google.common.collect.ImmutableMap) VersionCatalog(org.gradle.api.artifacts.VersionCatalog) ProviderFactory(org.gradle.api.provider.ProviderFactory) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) DependencyResolutionManagementInternal(org.gradle.internal.management.DependencyResolutionManagementInternal)

Example 20 with ProjectInternal

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

the class EclipseClasspath method resolveDependencies.

/**
 * Calculates, resolves and returns dependency entries of this classpath.
 */
public List<ClasspathEntry> resolveDependencies() {
    ProjectInternal projectInternal = (ProjectInternal) this.project;
    IdeArtifactRegistry ideArtifactRegistry = projectInternal.getServices().get(IdeArtifactRegistry.class);
    boolean inferModulePath = false;
    Task javaCompileTask = project.getTasks().findByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);
    if (javaCompileTask instanceof JavaCompile) {
        JavaCompile javaCompile = (JavaCompile) javaCompileTask;
        inferModulePath = javaCompile.getModularity().getInferModulePath().get();
        if (inferModulePath) {
            List<File> sourceRoots = CompilationSourceDirs.inferSourceRoots((FileTreeInternal) javaCompile.getSource());
            inferModulePath = JavaModuleDetector.isModuleSource(true, sourceRoots);
        }
    }
    ClasspathFactory classpathFactory = new ClasspathFactory(this, ideArtifactRegistry, new DefaultGradleApiSourcesResolver(projectInternal.newDetachedResolver()), inferModulePath);
    return classpathFactory.createEntries();
}
Also used : Task(org.gradle.api.Task) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) IdeArtifactRegistry(org.gradle.plugins.ide.internal.IdeArtifactRegistry) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File) DefaultGradleApiSourcesResolver(org.gradle.plugins.ide.internal.resolver.DefaultGradleApiSourcesResolver) ClasspathFactory(org.gradle.plugins.ide.eclipse.model.internal.ClasspathFactory)

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