mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-76142: Gradle support - cannot update IDEA projects once one of build.gradle files changes
Don't trigger 'refresh gradle project' on project structure changes performed by the gradle integration
This commit is contained in:
@@ -5,6 +5,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Defines callback for the gradle config structure change.
|
||||
* <p/>
|
||||
* Implementations of this interface are not obliged to be thread-safe.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 1/17/12 1:02 PM
|
||||
|
||||
+8
-1
@@ -36,7 +36,14 @@ public class GradleLibraryImporter {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doImportLibrary(library, project);
|
||||
final GradleProjectEntityImportListener publisher = project.getMessageBus().syncPublisher(GradleProjectEntityImportListener.TOPIC);
|
||||
publisher.onImportStart(library);
|
||||
try {
|
||||
doImportLibrary(library, project);
|
||||
}
|
||||
finally {
|
||||
publisher.onImportEnd(library);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+8
@@ -123,12 +123,15 @@ public class GradleModuleDependencyImporter {
|
||||
// Register library dependencies.
|
||||
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel();
|
||||
final GradleProjectEntityImportListener publisher
|
||||
= module.getProject().getMessageBus().syncPublisher(GradleProjectEntityImportListener.TOPIC);
|
||||
try {
|
||||
for (GradleLibraryDependency dependency : dependencies) {
|
||||
final Library library = gradle2intellij.get(dependency.getTarget());
|
||||
if (library == null) {
|
||||
continue;
|
||||
}
|
||||
publisher.onImportStart(library);
|
||||
LibraryOrderEntry orderEntry = moduleRootModel.addLibraryEntry(library);
|
||||
orderEntry.setExported(dependency.isExported());
|
||||
orderEntry.setScope(dependency.getScope());
|
||||
@@ -136,6 +139,11 @@ public class GradleModuleDependencyImporter {
|
||||
}
|
||||
finally {
|
||||
moduleRootModel.commit();
|
||||
for (GradleLibraryDependency dependency : dependencies) {
|
||||
if (dependency != null) {
|
||||
publisher.onImportEnd(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+35
-23
@@ -64,36 +64,48 @@ public class GradleModuleImporter {
|
||||
@Override
|
||||
public void run() {
|
||||
final ModuleManager moduleManager = ModuleManager.getInstance(project);
|
||||
final GradleProjectEntityImportListener publisher
|
||||
= project.getMessageBus().syncPublisher(GradleProjectEntityImportListener.TOPIC);
|
||||
for (GradleModule module : modules) {
|
||||
final Module created = moduleManager.newModule(module.getModuleFilePath(), StdModuleTypes.JAVA);
|
||||
|
||||
// Ensure that the dependencies are clear (used to be not clear when manually removing the module and importing it via gradle)
|
||||
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(created);
|
||||
final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel();
|
||||
RootPolicy<Object> visitor = new RootPolicy<Object>() {
|
||||
@Override
|
||||
public Object visitLibraryOrderEntry(LibraryOrderEntry libraryOrderEntry, Object value) {
|
||||
moduleRootModel.removeOrderEntry(libraryOrderEntry);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitModuleOrderEntry(ModuleOrderEntry moduleOrderEntry, Object value) {
|
||||
moduleRootModel.removeOrderEntry(moduleOrderEntry);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
publisher.onImportStart(module);
|
||||
try {
|
||||
for (OrderEntry orderEntry : moduleRootModel.getOrderEntries()) {
|
||||
orderEntry.accept(visitor, null);
|
||||
}
|
||||
importModule(moduleManager, module);
|
||||
}
|
||||
finally {
|
||||
moduleRootModel.commit();
|
||||
publisher.onImportEnd(module);
|
||||
}
|
||||
moduleMappings.put(module, created);
|
||||
}
|
||||
}
|
||||
|
||||
private void importModule(@NotNull ModuleManager moduleManager, @NotNull GradleModule module) {
|
||||
final Module created = moduleManager.newModule(module.getModuleFilePath(), StdModuleTypes.JAVA);
|
||||
|
||||
// Ensure that the dependencies are clear (used to be not clear when manually removing the module and importing it via gradle)
|
||||
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(created);
|
||||
final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel();
|
||||
RootPolicy<Object> visitor = new RootPolicy<Object>() {
|
||||
@Override
|
||||
public Object visitLibraryOrderEntry(LibraryOrderEntry libraryOrderEntry, Object value) {
|
||||
moduleRootModel.removeOrderEntry(libraryOrderEntry);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitModuleOrderEntry(ModuleOrderEntry moduleOrderEntry, Object value) {
|
||||
moduleRootModel.removeOrderEntry(moduleOrderEntry);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
try {
|
||||
for (OrderEntry orderEntry : moduleRootModel.getOrderEntries()) {
|
||||
orderEntry.accept(visitor, null);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
moduleRootModel.commit();
|
||||
}
|
||||
moduleMappings.put(module, created);
|
||||
}
|
||||
});
|
||||
if (!recursive) {
|
||||
return;
|
||||
|
||||
@@ -114,6 +114,11 @@ public class GradleModulesImporter {
|
||||
AccessToken writeLock = application.acquireWriteActionLock(getClass());
|
||||
try {
|
||||
final List<ModifiableRootModel> rootModels = new ArrayList<ModifiableRootModel>();
|
||||
final GradleProjectEntityImportListener publisher =
|
||||
intellijProject.getMessageBus().syncPublisher(GradleProjectEntityImportListener.TOPIC);
|
||||
for (GradleModule module : modules) {
|
||||
publisher.onImportStart(module);
|
||||
}
|
||||
try {
|
||||
Map<GradleModule, Module> moduleMappings = doImportModules(modules, model, rootModels);
|
||||
result.putAll(moduleMappings);
|
||||
@@ -127,6 +132,9 @@ public class GradleModulesImporter {
|
||||
ProjectRootManager projectRootManager = ProjectRootManager.getInstance(intellijProject);
|
||||
ModifiableRootModel[] modelsAsArray = rootModels.toArray(new ModifiableRootModel[rootModels.size()]);
|
||||
projectRootManager.multiCommit(model, modelsAsArray);
|
||||
for (GradleModule module : modules) {
|
||||
publisher.onImportEnd(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package org.jetbrains.plugins.gradle.importing;
|
||||
|
||||
import com.intellij.util.messages.Topic;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Defines contract for the callback to be notified on project structure changes triggered by the gradle integrations.
|
||||
* <p/>
|
||||
* Implementations of this interface are not obliged to be thread-safe.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/24/12 1:05 PM
|
||||
*/
|
||||
public interface GradleProjectEntityImportListener {
|
||||
|
||||
Topic<GradleProjectEntityImportListener> TOPIC = Topic.create("Gradle config", GradleProjectEntityImportListener.class);
|
||||
|
||||
/**
|
||||
* Is called <b>before</b> the given entity is imported.
|
||||
*
|
||||
* @param entity target entity being imported
|
||||
*/
|
||||
void onImportStart(@NotNull Object entity);
|
||||
|
||||
/**
|
||||
* Is called <b>after</b> the given entity has been imported.
|
||||
*
|
||||
* @param entity target entity that has been imported
|
||||
*/
|
||||
void onImportEnd(@NotNull Object entity);
|
||||
}
|
||||
Reference in New Issue
Block a user