diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ExternalSystemSourceType.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ExternalSystemSourceType.java index a50d064c32a6..167a21af6631 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ExternalSystemSourceType.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/project/ExternalSystemSourceType.java @@ -15,6 +15,9 @@ public class ExternalSystemSourceType implements Serializable { @NotNull public static final ExternalSystemSourceType SOURCE = new ExternalSystemSourceType("SOURCE"); @NotNull public static final ExternalSystemSourceType TEST = new ExternalSystemSourceType("TEST"); @NotNull public static final ExternalSystemSourceType EXCLUDED = new ExternalSystemSourceType("EXCLUDED"); + @NotNull public static final ExternalSystemSourceType GENERATED = new ExternalSystemSourceType("GENERATED"); + @NotNull public static final ExternalSystemSourceType RESOURCE = new ExternalSystemSourceType("RESOURCE"); + @NotNull public static final ExternalSystemSourceType TEST_RESOURCE = new ExternalSystemSourceType("TEST_RESOURCE"); private static final long serialVersionUID = 1L; diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java index a90b068cd3d8..bcd3e9e7eeba 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java @@ -14,12 +14,17 @@ import com.intellij.openapi.externalSystem.util.Order; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.impl.SourceFolderImpl; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; +import org.jetbrains.jps.model.JpsElement; +import org.jetbrains.jps.model.java.JavaResourceRootType; +import org.jetbrains.jps.model.java.JavaSourceRootProperties; +import org.jetbrains.jps.model.java.JavaSourceRootType; +import org.jetbrains.jps.model.module.JpsModuleSourceRootType; import java.util.Collection; import java.util.List; @@ -93,11 +98,23 @@ public class ContentRootDataService implements ProjectDataService retainedPaths = ContainerUtilRt.newHashSet(); for (String path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) { - createSourceRootIfAbsent(contentEntry, path, module.getName()); + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false); retainedPaths.add(ExternalSystemApiUtil.toCanonicalPath(path)); } for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) { - createTestRootIfAbsent(contentEntry, path, module.getName()); + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false); + retainedPaths.add(ExternalSystemApiUtil.toCanonicalPath(path)); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false); + retainedPaths.add(ExternalSystemApiUtil.toCanonicalPath(path)); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false); + retainedPaths.add(ExternalSystemApiUtil.toCanonicalPath(path)); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.GENERATED)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true); retainedPaths.add(ExternalSystemApiUtil.toCanonicalPath(path)); } for (String path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) { @@ -151,8 +168,10 @@ public class ContentRootDataService implements ProjectDataService folders = entry.getSourceFolders(JavaModuleSourceRootTypes.SOURCES); + private static void createSourceRootIfAbsent( + @NotNull ContentEntry entry, @NotNull String path, @NotNull String moduleName, + @NotNull JpsModuleSourceRootType sourceRootType, boolean generated) { + List folders = entry.getSourceFolders(sourceRootType); for (SourceFolder folder : folders) { VirtualFile file = folder.getFile(); if (file == null) { @@ -163,7 +182,13 @@ public class ContentRootDataService implements ProjectDataService folders = entry.getSourceFolders(JavaModuleSourceRootTypes.TESTS); - for (SourceFolder folder : folders) { - VirtualFile file = folder.getFile(); - if (file == null) { - continue; - } - if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(path)) { - return; - } - } - LOG.info(String.format("Importing test root '%s' for content root '%s' of module '%s'", path, entry.getUrl(), moduleName)); - entry.addSourceFolder(toVfsUrl(path), true); - } - @Override public void removeData(@NotNull Collection toRemove, @NotNull Project project, boolean synchronous) { }