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.");
}
}
}
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);
}
}
}
}
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;
}
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);
}
}
}
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();
}
Aggregations