mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-83595 Allow adding more than one gradle project
1. Clarified ProjectDataService.importData() contract; 2. Corrected ModuleDataService and LibraryDataService accordingly;
This commit is contained in:
+19
@@ -57,6 +57,25 @@ public interface ProjectDataService<T> {
|
||||
@NotNull
|
||||
Key<T> getTargetDataKey();
|
||||
|
||||
/**
|
||||
* It's assumed that given data nodes present at the ide when this method returns. I.e. the method should behave as below for
|
||||
* every of the given data nodes:
|
||||
* <pre>
|
||||
* <ul>
|
||||
* <li>there is an existing project entity for the given data node and it has the same state. Do nothing for it then;</li>
|
||||
* <li>
|
||||
* there is an existing project entity for the given data node but it has different state (e.g. a module dependency
|
||||
* is configured as 'exported' at the ide but not at external system). Reset the state to the external system's one then;
|
||||
* </li>
|
||||
* <li> there is no corresponding project entity at the ide side. Create it then; </li>
|
||||
* </ul>
|
||||
* </pre>
|
||||
* are created, updated or left as-is if they have the
|
||||
*
|
||||
* @param toImport
|
||||
* @param project
|
||||
* @param synchronous
|
||||
*/
|
||||
void importData(@NotNull Collection<DataNode<T>> toImport, @NotNull Project project, boolean synchronous);
|
||||
|
||||
void removeData(@NotNull Collection<DataNode<T>> toRemove, @NotNull Project project, boolean synchronous);
|
||||
|
||||
+36
-16
@@ -27,10 +27,7 @@ import com.intellij.util.containers.ContainerUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
@@ -40,6 +37,13 @@ import java.util.Set;
|
||||
public class LibraryDataService implements ProjectDataService<LibraryData> {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#" + LibraryDataService.class.getName());
|
||||
@NotNull public static final NotNullFunction<String, File> PATH_TO_FILE = new NotNullFunction<String, File>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public File fun(String path) {
|
||||
return new File(path);
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull private final PlatformFacade myPlatformFacade;
|
||||
@NotNull private final ProjectStructureHelper myProjectStructureHelper;
|
||||
@@ -68,19 +72,19 @@ public class LibraryDataService implements ProjectDataService<LibraryData> {
|
||||
}
|
||||
|
||||
public void importLibrary(@NotNull final LibraryData toImport, @NotNull final Project project, boolean synchronous) {
|
||||
Map<OrderRootType, Collection<File>> libraryFiles = new HashMap<OrderRootType, Collection<File>>();
|
||||
Map<OrderRootType, Collection<File>> libraryFiles = ContainerUtilRt.newHashMap();
|
||||
for (LibraryPathType pathType : LibraryPathType.values()) {
|
||||
final Set<String> paths = toImport.getPaths(pathType);
|
||||
if (paths.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
libraryFiles.put(myLibraryPathTypeMapper.map(pathType), ContainerUtil.map(paths, new NotNullFunction<String, File>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public File fun(String path) {
|
||||
return new File(path);
|
||||
}
|
||||
}));
|
||||
libraryFiles.put(myLibraryPathTypeMapper.map(pathType), ContainerUtil.map(paths, PATH_TO_FILE));
|
||||
}
|
||||
|
||||
Library library = myProjectStructureHelper.findIdeLibrary(toImport, project);
|
||||
if (library != null) {
|
||||
syncPaths(toImport, library, project, synchronous);
|
||||
return;
|
||||
}
|
||||
importLibrary(toImport.getName(), toImport.getOwner(), libraryFiles, project, synchronous);
|
||||
}
|
||||
@@ -186,13 +190,13 @@ public class LibraryDataService implements ProjectDataService<LibraryData> {
|
||||
});
|
||||
}
|
||||
|
||||
public void syncPaths(@NotNull LibraryData externalLibrary,
|
||||
public void syncPaths(@NotNull final LibraryData externalLibrary,
|
||||
@NotNull final Library ideLibrary,
|
||||
@NotNull Project project,
|
||||
boolean synchronous)
|
||||
{
|
||||
Set<String> toRemove = ContainerUtilRt.newHashSet();
|
||||
Set<String> toAdd = ContainerUtilRt.newHashSet(externalLibrary.getPaths(LibraryPathType.BINARY));
|
||||
final Set<String> toRemove = ContainerUtilRt.newHashSet();
|
||||
final Set<String> toAdd = ContainerUtilRt.newHashSet(externalLibrary.getPaths(LibraryPathType.BINARY));
|
||||
for (VirtualFile ideFile : ideLibrary.getFiles(OrderRootType.CLASSES)) {
|
||||
String idePath = ExternalSystemApiUtil.getLocalFileSystemPath(ideFile);
|
||||
if (!toAdd.remove(idePath)) {
|
||||
@@ -202,6 +206,22 @@ public class LibraryDataService implements ProjectDataService<LibraryData> {
|
||||
if (toRemove.isEmpty() && toAdd.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// TODO den implement
|
||||
ExternalSystemApiUtil.executeProjectChangeAction(project, externalLibrary.getOwner(), ideLibrary, synchronous, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Library.ModifiableModel model = ideLibrary.getModifiableModel();
|
||||
try {
|
||||
for (String path : toRemove) {
|
||||
model.removeRoot(path, OrderRootType.CLASSES);
|
||||
}
|
||||
Map<OrderRootType, Collection<File>> roots = ContainerUtilRt.newHashMap();
|
||||
roots.put(OrderRootType.CLASSES, ContainerUtil.map(toAdd, PATH_TO_FILE));
|
||||
registerPaths(roots, model, externalLibrary.getName());
|
||||
}
|
||||
finally {
|
||||
model.commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+20
-2
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -75,7 +76,11 @@ public class ModuleDataService implements ProjectDataService<ModuleData> {
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeExistingModulesConfigs(toImport, project);
|
||||
final Collection<DataNode<ModuleData>> toCreate = filterExistingModules(toImport, project);
|
||||
if (toCreate.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
removeExistingModulesConfigs(toCreate, project);
|
||||
Application application = ApplicationManager.getApplication();
|
||||
final Map<DataNode<ModuleData>, Module> moduleMappings = ContainerUtilRt.newHashMap();
|
||||
application.runWriteAction(new Runnable() {
|
||||
@@ -84,7 +89,7 @@ public class ModuleDataService implements ProjectDataService<ModuleData> {
|
||||
final ModuleManager moduleManager = ModuleManager.getInstance(project);
|
||||
final ProjectEntityChangeListener publisher
|
||||
= project.getMessageBus().syncPublisher(ProjectEntityChangeListener.TOPIC);
|
||||
for (DataNode<ModuleData> module : toImport) {
|
||||
for (DataNode<ModuleData> module : toCreate) {
|
||||
publisher.onChangeStart(module, module.getData().getOwner());
|
||||
try {
|
||||
importModule(moduleManager, module);
|
||||
@@ -143,6 +148,19 @@ public class ModuleDataService implements ProjectDataService<ModuleData> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<DataNode<ModuleData>> filterExistingModules(@NotNull Collection<DataNode<ModuleData>> modules,
|
||||
@NotNull Project project)
|
||||
{
|
||||
Collection<DataNode<ModuleData>> result = ContainerUtilRt.newArrayList();
|
||||
for (DataNode<ModuleData> node : modules) {
|
||||
if (myProjectStructureHelper.findIdeModule(node.getData(), project) == null) {
|
||||
result.add(node);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void removeExistingModulesConfigs(@NotNull final Collection<DataNode<ModuleData>> nodes, @NotNull Project project) {
|
||||
if (nodes.isEmpty()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user