mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[Gradle|Sync|IsolatedProject] fix: removed unused GradleTaskIndex
Issues IDEA-35499 GitOrigin-RevId: 35949e7931841196d227c6917132e08d5a541a4e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6c64308878
commit
0448526272
@@ -7,7 +7,7 @@ import com.intellij.gradle.toolingExtension.impl.model.buildScriptClasspathModel
|
||||
import com.intellij.gradle.toolingExtension.impl.model.projectModel.GradleExternalProjectModelProvider;
|
||||
import com.intellij.gradle.toolingExtension.impl.model.sourceSetDependencyModel.GradleSourceSetDependencyModelProvider;
|
||||
import com.intellij.gradle.toolingExtension.impl.model.sourceSetModel.GradleSourceSetModelProvider;
|
||||
import com.intellij.gradle.toolingExtension.impl.model.taskIndex.GradleTaskIndexModelProvider;
|
||||
import com.intellij.gradle.toolingExtension.impl.model.warmUp.GradleTaskWarmUpModelProvider;
|
||||
import com.intellij.gradle.toolingExtension.impl.model.taskModel.GradleTaskModelProvider;
|
||||
import com.intellij.gradle.toolingExtension.util.GradleVersionUtil;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
@@ -786,7 +786,7 @@ public final class CommonGradleProjectResolverExtension extends AbstractProjectR
|
||||
public @NotNull List<ProjectImportModelProvider> getModelProviders() {
|
||||
return ContainerUtil.append(
|
||||
super.getModelProviders(),
|
||||
new GradleTaskIndexModelProvider(),
|
||||
new GradleTaskWarmUpModelProvider(),
|
||||
new GradleSourceSetModelProvider(),
|
||||
new GradleSourceSetDependencyModelProvider(),
|
||||
new GradleExternalProjectModelProvider(),
|
||||
|
||||
@@ -12,7 +12,7 @@ object GradleModelBuilderMessageCollector : CounterUsagesCollector() {
|
||||
|
||||
override fun getGroup() = GROUP
|
||||
|
||||
private val GROUP: EventLogGroup = EventLogGroup("build.gradle.errors", 18)
|
||||
private val GROUP: EventLogGroup = EventLogGroup("build.gradle.errors", 19)
|
||||
|
||||
private val ACTIVITY_ID = EventFields.Long("ide_activity_id")
|
||||
private val MESSAGE_KIND = EventFields.Enum<Message.Kind>("message_kind")
|
||||
@@ -21,11 +21,7 @@ object GradleModelBuilderMessageCollector : CounterUsagesCollector() {
|
||||
|
||||
Messages.SCALA_PROJECT_MODEL_GROUP,
|
||||
|
||||
Messages.TASK_INDEX_GROUP,
|
||||
Messages.TASK_INDEX_COLLECTING_GROUP,
|
||||
Messages.TASK_INDEX_CACHE_GET_GROUP,
|
||||
Messages.TASK_INDEX_CACHE_SET_GROUP,
|
||||
|
||||
Messages.TASK_WARM_UP_GROUP,
|
||||
Messages.TASK_MODEL_GROUP,
|
||||
|
||||
Messages.SOURCE_SET_MODEL_GROUP,
|
||||
|
||||
@@ -15,12 +15,11 @@ public enum GradleModelFetchPhase {
|
||||
PROJECT_LOADED_PHASE("Project loaded phase"),
|
||||
|
||||
/**
|
||||
* Model provider, in this phase, fetches and caches a Gradle task model into
|
||||
* {@link com.intellij.gradle.toolingExtension.impl.model.taskIndex.GradleTaskIndex}.
|
||||
* This cache is available by {@link org.jetbrains.plugins.gradle.tooling.ModelBuilderContext}.
|
||||
* Model providers, in this phase, warm up Gradle tasks configurations.
|
||||
* <p>
|
||||
* This phase should be first, because this phase evaluates all lazy Task configurations.
|
||||
* These configurations may modify a Gradle project model which is necessary for the following phases.
|
||||
* This phase should be first, because this phase:
|
||||
* 1. Warmed tasks don't throw configuration exceptions during {@link org.gradle.api.Project#getTasks};
|
||||
* 2. It evaluates all lazy task configurations that may modify a Gradle project model which is necessary for the following phases.
|
||||
*
|
||||
* @see org.gradle.tooling.BuildActionExecuter.Builder#buildFinished
|
||||
* @see org.gradle.tooling.BuildActionExecuter#setStreamedValueListener
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
com.intellij.gradle.toolingExtension.impl.model.utilDummyModel.DummyModelBuilder
|
||||
com.intellij.gradle.toolingExtension.impl.model.utilTurnOffDefaultTasksModel.TurnOffDefaultTasksModelBuilder
|
||||
com.intellij.gradle.toolingExtension.impl.model.projectModel.GradleExternalProjectModelBuilder
|
||||
com.intellij.gradle.toolingExtension.impl.model.taskIndex.GradleTaskIndexBuilder
|
||||
com.intellij.gradle.toolingExtension.impl.model.warmUp.GradleTaskWarmUpService
|
||||
com.intellij.gradle.toolingExtension.impl.model.taskModel.GradleTaskModelBuilder
|
||||
com.intellij.gradle.toolingExtension.impl.model.sourceSetModel.GradleSourceSetModelBuilder
|
||||
com.intellij.gradle.toolingExtension.impl.model.sourceSetArtifactIndex.GradleSourceSetArtifactIndexBuilder
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.gradle.toolingExtension.impl.model.taskIndex;
|
||||
|
||||
import com.intellij.gradle.toolingExtension.impl.modelBuilder.Messages;
|
||||
import com.intellij.gradle.toolingExtension.impl.util.GradleProjectUtil;
|
||||
import com.intellij.gradle.toolingExtension.modelAction.GradleModelFetchPhase;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.tooling.model.ProjectIdentifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.tooling.Message;
|
||||
import org.jetbrains.plugins.gradle.tooling.ModelBuilderContext;
|
||||
import org.jetbrains.plugins.gradle.tooling.ModelBuilderContext.DataProvider;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
|
||||
/**
|
||||
* Provides fast access to the {@link Project}'s tasks.
|
||||
*/
|
||||
public final class GradleTaskIndex {
|
||||
|
||||
private final ModelBuilderContext context;
|
||||
private final ConcurrentMap<ProjectIdentifier, Set<Task>> allTasks;
|
||||
|
||||
private GradleTaskIndex(@NotNull ModelBuilderContext context) {
|
||||
this.context = context;
|
||||
this.allTasks = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public Set<Task> getAllTasks(@NotNull Project project) {
|
||||
Set<Task> result = new LinkedHashSet<>(getProjectTasks(project));
|
||||
for (Project subProject : project.getSubprojects()) {
|
||||
result.addAll(getProjectTasks(subProject));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Set<Task> getProjectTasks(@NotNull Project project) {
|
||||
ProjectIdentifier projectIdentifier = GradleProjectUtil.getProjectIdentifier(project);
|
||||
Set<Task> projectTasks = allTasks.get(projectIdentifier);
|
||||
if (projectTasks == null) {
|
||||
context.getMessageReporter().createMessage()
|
||||
.withGroup(Messages.TASK_INDEX_CACHE_GET_GROUP)
|
||||
.withTitle("Task model aren't found")
|
||||
.withText(
|
||||
"Tasks for " + project.getDisplayName() + " wasn't collected. " +
|
||||
"All tasks should be collected during " + GradleModelFetchPhase.WARM_UP_PHASE + "."
|
||||
)
|
||||
.withInternal().withStackTrace()
|
||||
.withKind(Message.Kind.ERROR)
|
||||
.reportMessage(project);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return projectTasks;
|
||||
}
|
||||
|
||||
public void setProjectTasks(@NotNull Project project, @NotNull Set<Task> tasks) {
|
||||
ProjectIdentifier projectIdentifier = GradleProjectUtil.getProjectIdentifier(project);
|
||||
Set<Task> previousTasks = allTasks.put(projectIdentifier, tasks);
|
||||
if (previousTasks != null) {
|
||||
context.getMessageReporter().createMessage()
|
||||
.withGroup(Messages.TASK_INDEX_CACHE_SET_GROUP)
|
||||
.withTitle("Task model redefinition")
|
||||
.withText("Tasks for " + project.getDisplayName() + " was already collected.")
|
||||
.withInternal().withStackTrace()
|
||||
.withKind(Message.Kind.ERROR)
|
||||
.reportMessage(project);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks that a project task model is loaded with errors.
|
||||
* This mark means that error for {@code project} is already processed and reported.
|
||||
*/
|
||||
public void markTaskModelAsError(@NotNull Project project) {
|
||||
ProjectIdentifier projectIdentifier = GradleProjectUtil.getProjectIdentifier(project);
|
||||
allTasks.put(projectIdentifier, Collections.emptySet());
|
||||
}
|
||||
|
||||
private static final @NotNull DataProvider<GradleTaskIndex> INSTANCE_PROVIDER = GradleTaskIndex::new;
|
||||
|
||||
public static @NotNull GradleTaskIndex getInstance(@NotNull ModelBuilderContext context) {
|
||||
return context.getData(INSTANCE_PROVIDER);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.gradle.toolingExtension.impl.model.taskIndex;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Marker interface to request for building task index {@link GradleTaskIndex}.
|
||||
* This index is available only on the Gradle side and cannot be transferred to the IDE.
|
||||
*
|
||||
* @see GradleTaskIndex
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public interface GradleTaskRequest extends Serializable {
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.gradle.toolingExtension.impl.model.taskIndex
|
||||
package com.intellij.gradle.toolingExtension.impl.model.warmUp
|
||||
|
||||
import com.intellij.gradle.toolingExtension.impl.util.GradleModelProviderUtil
|
||||
import com.intellij.gradle.toolingExtension.modelAction.GradleModelFetchPhase
|
||||
@@ -10,7 +10,7 @@ import org.jetbrains.plugins.gradle.model.ProjectImportModelProvider
|
||||
import org.jetbrains.plugins.gradle.model.ProjectImportModelProvider.GradleModelConsumer
|
||||
|
||||
@ApiStatus.Internal
|
||||
class GradleTaskIndexModelProvider : ProjectImportModelProvider {
|
||||
class GradleTaskWarmUpModelProvider : ProjectImportModelProvider {
|
||||
|
||||
override fun getPhase(): GradleModelFetchPhase {
|
||||
return GradleModelFetchPhase.WARM_UP_PHASE
|
||||
@@ -21,6 +21,6 @@ class GradleTaskIndexModelProvider : ProjectImportModelProvider {
|
||||
buildModel: GradleBuild,
|
||||
modelConsumer: GradleModelConsumer,
|
||||
) {
|
||||
GradleModelProviderUtil.buildModels(controller, buildModel, GradleTaskRequest::class.java, GradleModelConsumer.NOOP)
|
||||
GradleModelProviderUtil.buildModels(controller, buildModel, GradleTaskWarmUpRequest::class.java, GradleModelConsumer.NOOP)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.gradle.toolingExtension.impl.model.warmUp;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Marker interface to request for warming-up task configurations.
|
||||
*
|
||||
* @see com.intellij.gradle.toolingExtension.modelAction.GradleModelFetchPhase#WARM_UP_PHASE
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public interface GradleTaskWarmUpRequest extends Serializable {
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.gradle.toolingExtension.impl.model.taskIndex;
|
||||
package com.intellij.gradle.toolingExtension.impl.model.warmUp;
|
||||
|
||||
import com.intellij.gradle.toolingExtension.impl.modelBuilder.Messages;
|
||||
import com.intellij.gradle.toolingExtension.impl.util.GradleResultUtil;
|
||||
import com.intellij.gradle.toolingExtension.util.GradleVersionUtil;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.internal.tasks.DefaultTaskContainer;
|
||||
import org.gradle.api.tasks.TaskContainer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -14,61 +13,34 @@ import org.jetbrains.plugins.gradle.tooling.AbstractModelBuilderService;
|
||||
import org.jetbrains.plugins.gradle.tooling.Message;
|
||||
import org.jetbrains.plugins.gradle.tooling.ModelBuilderContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class GradleTaskIndexBuilder extends AbstractModelBuilderService {
|
||||
public class GradleTaskWarmUpService extends AbstractModelBuilderService {
|
||||
|
||||
private static final boolean TASKS_REFRESH_REQUIRED = GradleVersionUtil.isCurrentGradleOlderThan("5.0");
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canBuild(String modelName) {
|
||||
return GradleTaskRequest.class.getName().equals(modelName);
|
||||
return GradleTaskWarmUpRequest.class.getName().equals(modelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object buildAll(@NotNull String modelName, @NotNull Project project, @NotNull ModelBuilderContext context) {
|
||||
Set<Task> projectTasks = collectProjectTasks(project, context);
|
||||
|
||||
GradleTaskIndex.getInstance(context)
|
||||
.setProjectTasks(project, projectTasks);
|
||||
|
||||
GradleResultUtil.runOrRetryOnce(() -> {
|
||||
if (TASKS_REFRESH_REQUIRED) {
|
||||
refreshProjectTasks(project);
|
||||
}
|
||||
});
|
||||
GradleResultUtil.runOrRetryOnce(() -> {
|
||||
project.getTasks().forEach(__ -> {});
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Set<Task> collectProjectTasks(@NotNull Project project, @NotNull ModelBuilderContext context) {
|
||||
try {
|
||||
GradleResultUtil.runOrRetryOnce(() -> {
|
||||
if (TASKS_REFRESH_REQUIRED) {
|
||||
refreshProjectTasks(project);
|
||||
}
|
||||
});
|
||||
return GradleResultUtil.runOrRetryOnce(() -> {
|
||||
return new TreeSet<>(project.getTasks());
|
||||
});
|
||||
}
|
||||
catch (Exception exception) {
|
||||
context.getMessageReporter().createMessage()
|
||||
.withGroup(Messages.TASK_INDEX_COLLECTING_GROUP)
|
||||
.withTitle("Tasks collecting failure")
|
||||
.withText("Tasks for " + project + " cannot be collected due to plugin exception.")
|
||||
.withException(exception)
|
||||
.withKind(Message.Kind.WARNING)
|
||||
.reportMessage(project);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
private static void refreshProjectTasks(@NotNull Project project) {
|
||||
TaskContainer tasks = project.getTasks();
|
||||
if (tasks instanceof DefaultTaskContainer) {
|
||||
((DefaultTaskContainer)tasks).discoverTasks();
|
||||
SortedSet<String> taskNames = tasks.getNames();
|
||||
for (String taskName : taskNames) {
|
||||
for (String taskName : tasks.getNames()) {
|
||||
tasks.findByName(taskName);
|
||||
}
|
||||
}
|
||||
@@ -81,13 +53,10 @@ public class GradleTaskIndexBuilder extends AbstractModelBuilderService {
|
||||
@NotNull ModelBuilderContext context,
|
||||
@NotNull Exception exception
|
||||
) {
|
||||
GradleTaskIndex.getInstance(context)
|
||||
.markTaskModelAsError(project);
|
||||
|
||||
context.getMessageReporter().createMessage()
|
||||
.withGroup(Messages.TASK_INDEX_GROUP)
|
||||
.withGroup(Messages.TASK_WARM_UP_GROUP)
|
||||
.withKind(Message.Kind.WARNING)
|
||||
.withTitle("Task model building failure")
|
||||
.withTitle("Task warming-up failure")
|
||||
.withText("Unable to warm-up Gradle task model")
|
||||
.withException(exception)
|
||||
.reportMessage(project);
|
||||
@@ -12,11 +12,7 @@ public final class Messages {
|
||||
|
||||
public final static @NotNull String SCALA_PROJECT_MODEL_GROUP = "gradle.scalaProjectModel.group";
|
||||
|
||||
public final static @NotNull String TASK_INDEX_GROUP = "gradle.taskIndex.group";
|
||||
public final static @NotNull String TASK_INDEX_COLLECTING_GROUP = "gradle.taskIndex.collecting.group";
|
||||
public final static @NotNull String TASK_INDEX_CACHE_GET_GROUP = "gradle.taskIndex.cacheGet.group";
|
||||
public final static @NotNull String TASK_INDEX_CACHE_SET_GROUP = "gradle.taskIndex.cacheSet.group";
|
||||
|
||||
public final static @NotNull String TASK_WARM_UP_GROUP = "gradle.taskWarmUp.group";
|
||||
public final static @NotNull String TASK_MODEL_GROUP = "gradle.taskModel.group";
|
||||
|
||||
public final static @NotNull String SOURCE_SET_MODEL_GROUP = "gradle.sourceSetModel.group";
|
||||
|
||||
Reference in New Issue
Block a user