Maven: add the support to reimport maven projects in the ExternalSystemProjectsWatcher API

This commit is contained in:
Vladislav.Soroka
2017-09-28 20:34:06 +03:00
parent 8167c325eb
commit ef6654c0af
4 changed files with 48 additions and 0 deletions
@@ -23,6 +23,7 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.event.*;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.externalSystem.ExternalSystemAutoImportAware;
import com.intellij.openapi.externalSystem.ExternalSystemManager;
import com.intellij.openapi.externalSystem.model.DataNode;
@@ -64,6 +65,7 @@ import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import gnu.trove.THashSet;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -81,6 +83,10 @@ import static com.intellij.util.ui.update.MergingUpdateQueue.ANY_COMPONENT;
*/
public class ExternalSystemProjectsWatcherImpl extends ExternalSystemTaskNotificationListenerAdapter
implements ExternalSystemProjectsWatcher {
private static final ExtensionPointName<Contributor> EP_NAME =
ExtensionPointName.create("com.intellij.externalProjectWatcherContributor");
private static final Key<Long> CRC_WITHOUT_SPACES_CURRENT =
Key.create("ExternalSystemProjectsWatcher.CRC_WITHOUT_SPACES_CURRENT");
private static final Key<Long> CRC_WITHOUT_SPACES_BEFORE_LAST_IMPORT =
@@ -137,11 +143,17 @@ public class ExternalSystemProjectsWatcherImpl extends ExternalSystemTaskNotific
@Override
public void markDirtyAllExternalProjects() {
findLinkedProjectsSettings().forEach(this::scheduleUpdate);
for (Contributor contributor : EP_NAME.getExtensions()) {
contributor.markDirtyAllExternalProjects(myProject);
}
}
@Override
public void markDirty(Module module) {
scheduleUpdate(ExternalSystemApiUtil.getExternalProjectPath(module));
for (Contributor contributor : EP_NAME.getExtensions()) {
contributor.markDirty(module);
}
}
@Override
@@ -709,4 +721,12 @@ public class ExternalSystemProjectsWatcherImpl extends ExternalSystemTaskNotific
}
return newCrc;
}
@ApiStatus.Experimental
public interface Contributor {
void markDirtyAllExternalProjects(@NotNull Project project);
void markDirty(@NotNull Module module);
}
}
@@ -21,5 +21,7 @@
interface="com.intellij.openapi.externalSystem.execution.ExternalSystemExecutionConsoleManager"/>
<extensionPoint name="externalSystemViewContributor" interface="com.intellij.openapi.externalSystem.view.ExternalSystemViewContributor"/>
<extensionPoint name="externalProjectStructureCustomizer" interface="com.intellij.openapi.externalSystem.importing.ExternalProjectStructureCustomizer"/>
<extensionPoint name="externalProjectWatcherContributor"
interface="com.intellij.openapi.externalSystem.service.project.autoimport.ExternalSystemProjectsWatcherImpl$Contributor"/>
</extensionPoints>
</idea-plugin>
@@ -34,6 +34,7 @@ import com.intellij.openapi.components.State;
import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager;
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider;
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl;
import com.intellij.openapi.externalSystem.service.project.autoimport.ExternalSystemProjectsWatcherImpl;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbAwareRunnable;
@@ -75,6 +76,7 @@ import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@State(name = "MavenProjectsManager")
@@ -1276,4 +1278,27 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
default void importAndResolveScheduled() {
}
}
public static class MavenProjectsWatcherContributor implements ExternalSystemProjectsWatcherImpl.Contributor {
@Override
public void markDirtyAllExternalProjects(@NotNull Project project) {
runWhenFullyOpen(project, (manager) -> manager.doScheduleUpdateProjects(null, true, true));
}
@Override
public void markDirty(@NotNull Module module) {
runWhenFullyOpen(module.getProject(), (manager) -> {
MavenProject mavenProject = manager.findProject(module);
if (mavenProject != null) {
manager.doScheduleUpdateProjects(ContainerUtil.list(mavenProject), true, true);
}
});
}
private static void runWhenFullyOpen(@NotNull Project project, @NotNull Consumer<MavenProjectsManager> consumer) {
MavenProjectsManager manager = getInstance(project);
manager.runWhenFullyOpen(() -> consumer.accept(manager));
}
}
}
@@ -65,6 +65,7 @@
<stepsBeforeRunProvider implementation="org.jetbrains.idea.maven.tasks.MavenBeforeRunTasksProvider"/>
<externalSystemKeymapProvider implementation="org.jetbrains.idea.maven.tasks.MavenKeymapExtension"/>
<externalSystemWorkspaceContributor implementation="org.jetbrains.idea.maven.importing.MavenWorkspaceContributor"/>
<externalProjectWatcherContributor implementation="org.jetbrains.idea.maven.project.MavenProjectsManager$MavenProjectsWatcherContributor"/>
<configurationType implementation="org.jetbrains.idea.maven.execution.MavenRunConfigurationType"/>
<configurationProducer implementation="org.jetbrains.idea.maven.execution.MavenConfigurationProducer"/>
<orderEnumerationHandlerFactory implementation="org.jetbrains.idea.maven.execution.MavenOrderEnumeratorHandler$FactoryImpl"/>