mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-234355 Directories configured in gradle as sourceSetOutput should be excluded from indexing/processing
GitOrigin-RevId: 937d8efc9191ffd67a7141d5f3584e92d405ec1d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3eac423c18
commit
873f15b91e
+1
-9
@@ -1,13 +1,5 @@
|
||||
package com.intellij.openapi.externalSystem.model.project;
|
||||
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
|
||||
/**
|
||||
* Note that current enum duplicates {@link OrderRootType}. We can't use the later directly because it's not properly setup
|
||||
* for serialization/deserialization.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
*/
|
||||
public enum LibraryPathType {
|
||||
BINARY, SOURCE, DOC, ANNOTATION
|
||||
BINARY, SOURCE, DOC, ANNOTATION, EXCLUDED
|
||||
}
|
||||
|
||||
+18
-3
@@ -21,6 +21,7 @@ import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.RootPolicy;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
@@ -84,8 +85,9 @@ public final class LibraryDataService extends AbstractProjectDataService<Library
|
||||
return;
|
||||
}
|
||||
library = modelsProvider.createLibrary(libraryName, ExternalSystemApiUtil.toExternalSource(toImport.getOwner()));
|
||||
final Library.ModifiableModel libraryModel = modelsProvider.getModifiableLibraryModel(library);
|
||||
registerPaths(toImport.isUnresolved(), libraryFiles, libraryModel, libraryName);
|
||||
Library.ModifiableModel libraryModel = modelsProvider.getModifiableLibraryModel(library);
|
||||
Set<String> excludedPaths = toImport.getPaths(LibraryPathType.EXCLUDED);
|
||||
registerPaths(toImport.isUnresolved(), libraryFiles, excludedPaths, libraryModel, libraryName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -107,6 +109,7 @@ public final class LibraryDataService extends AbstractProjectDataService<Library
|
||||
|
||||
static void registerPaths(boolean unresolved,
|
||||
@NotNull Map<OrderRootType, Collection<File>> libraryFiles,
|
||||
@NotNull Set<String> excludedPaths,
|
||||
@NotNull Library.ModifiableModel model,
|
||||
@NotNull String libraryName) {
|
||||
for (Map.Entry<OrderRootType, Collection<File>> entry: libraryFiles.entrySet()) {
|
||||
@@ -150,6 +153,17 @@ public final class LibraryDataService extends AbstractProjectDataService<Library
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (model instanceof LibraryEx.ModifiableModelEx) {
|
||||
LibraryEx.ModifiableModelEx modelEx = (LibraryEx.ModifiableModelEx)model;
|
||||
for (String excludedPath : excludedPaths) {
|
||||
String url = VfsUtil.getUrlForLibraryRoot(new File(excludedPath));
|
||||
String[] urls = modelEx.getExcludedRootUrls();
|
||||
if (!ArrayUtil.contains(url, urls)) {
|
||||
modelEx.addExcludedRoot(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,10 +272,11 @@ public final class LibraryDataService extends AbstractProjectDataService<Library
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> excludedPaths = externalLibrary.getPaths(LibraryPathType.EXCLUDED);
|
||||
for (Map.Entry<OrderRootType, Set<String>> entry: toAdd.entrySet()) {
|
||||
Map<OrderRootType, Collection<File>> roots = new HashMap<>();
|
||||
roots.put(entry.getKey(), ContainerUtil.map(entry.getValue(), PATH_TO_FILE));
|
||||
registerPaths(externalLibrary.isUnresolved(), roots, libraryModel, externalLibrary.getInternalName());
|
||||
registerPaths(externalLibrary.isUnresolved(), roots, excludedPaths, libraryModel, externalLibrary.getInternalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -209,7 +209,8 @@ public class LibraryDependencyDataService extends AbstractDependencyDataService<
|
||||
final LibraryData libraryDependencyDataTarget = libraryDependencyData.getTarget();
|
||||
Map<OrderRootType, Collection<File>> files = ProjectDataService.EP_NAME.findExtensionOrFail(LibraryDataService.class)
|
||||
.prepareLibraryFiles(libraryDependencyDataTarget);
|
||||
LibraryDataService.registerPaths(libraryDependencyDataTarget.isUnresolved(), files, libraryModel, libraryName);
|
||||
Set<String> excludedPaths = libraryDependencyDataTarget.getPaths(LibraryPathType.EXCLUDED);
|
||||
LibraryDataService.registerPaths(libraryDependencyDataTarget.isUnresolved(), files, excludedPaths, libraryModel, libraryName);
|
||||
LibraryOrderEntry orderEntry = findLibraryOrderEntry(moduleRootModel, library, libraryDependencyData.getScope());
|
||||
|
||||
assert orderEntry != null;
|
||||
|
||||
+4
@@ -757,6 +757,10 @@ public class GradleProjectResolverUtil {
|
||||
|
||||
for (File file: ((FileCollectionDependency)mergedDependency).getFiles()) {
|
||||
library.addPath(LibraryPathType.BINARY, file.getAbsolutePath());
|
||||
if (mergedDependency instanceof DefaultFileCollectionDependency &&
|
||||
((DefaultFileCollectionDependency)mergedDependency).isExcludedFromIndexing()) {
|
||||
library.addPath(LibraryPathType.EXCLUDED, file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData);
|
||||
|
||||
+31
-1
@@ -14,6 +14,7 @@ import com.intellij.openapi.externalSystem.service.notification.ExternalSystemPr
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -581,8 +582,37 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase {
|
||||
assertModules("project", "project.main", "project.test");
|
||||
final String path = path("build/generated-resources/main");
|
||||
final String depName = PathUtil.toPresentableUrl(path);
|
||||
assertModuleLibDep("project.main", depName, "file://" + path);
|
||||
String root = "file://" + path;
|
||||
assertModuleLibDep("project.main", depName, root);
|
||||
assertModuleLibDepScope("project.main", depName, DependencyScope.RUNTIME);
|
||||
|
||||
String[] excludedRoots = isNewDependencyResolutionApplicable() ? new String[]{root} : ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
assertLibraryExcludedRoots("project.main", depName, excludedRoots);
|
||||
|
||||
VirtualFile depJar = createProjectJarSubFile("lib/dep.jar");
|
||||
importProject(
|
||||
"apply plugin: 'java'\n" +
|
||||
"sourceSets.main.output.dir file(\"$buildDir/generated-resources/main\")\n" +
|
||||
"dependencies {\n" +
|
||||
" runtime 'junit:junit:4.11'\n" +
|
||||
" runtime files('lib/dep.jar')\n" +
|
||||
"}\n"
|
||||
);
|
||||
|
||||
assertLibraryExcludedRoots("project.main", depName, excludedRoots);
|
||||
assertLibraryExcludedRoots("project.main", depJar.getPresentableUrl(), ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
assertLibraryExcludedRoots("project.main", "Gradle: junit:junit:4.11", ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
private void assertLibraryExcludedRoots(String moduleName, String depName, String ... roots) {
|
||||
List<LibraryOrderEntry> deps = getModuleLibDeps(moduleName, depName);
|
||||
assertThat(deps).hasSize(1);
|
||||
LibraryEx library = (LibraryEx)deps.get(0).getLibrary();
|
||||
|
||||
assertThat(library.getUrls(OrderRootType.CLASSES)).hasSize(1);
|
||||
|
||||
String[] excludedRootUrls = library.getExcludedRootUrls();
|
||||
assertThat(excludedRootUrls).containsExactly(roots);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+12
@@ -2,6 +2,7 @@
|
||||
package org.jetbrains.plugins.gradle.model;
|
||||
|
||||
import org.gradle.internal.impldep.com.google.common.base.Objects;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.DefaultExternalDependencyId;
|
||||
import org.jetbrains.plugins.gradle.tooling.util.BooleanBiFunction;
|
||||
@@ -15,6 +16,7 @@ public final class DefaultFileCollectionDependency extends AbstractExternalDepen
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Collection<File> files;
|
||||
private boolean excludedFromIndexing;
|
||||
|
||||
public DefaultFileCollectionDependency() {
|
||||
this(new ArrayList<File>());
|
||||
@@ -36,6 +38,16 @@ public final class DefaultFileCollectionDependency extends AbstractExternalDepen
|
||||
return files;
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public boolean isExcludedFromIndexing() {
|
||||
return excludedFromIndexing;
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public void setExcludedFromIndexing(boolean excludedFromIndexing) {
|
||||
this.excludedFromIndexing = excludedFromIndexing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
+4
@@ -297,6 +297,9 @@ public class ExternalProjectSerializationService implements SerializationService
|
||||
writer.writeString(FileCollectionDependency.class.getSimpleName());
|
||||
writeDependencyCommonFields(writer, context, dependency);
|
||||
writeFiles(writer, "files", dependency.getFiles());
|
||||
if (dependency instanceof DefaultFileCollectionDependency) {
|
||||
writeBoolean(writer, "excludedFromIndexing", ((DefaultFileCollectionDependency)dependency).isExcludedFromIndexing());
|
||||
}
|
||||
}
|
||||
writer.stepOut();
|
||||
}
|
||||
@@ -629,6 +632,7 @@ public class ExternalProjectSerializationService implements SerializationService
|
||||
else if (externalDependency instanceof DefaultFileCollectionDependency) {
|
||||
DefaultFileCollectionDependency fileCollectionDependency = (DefaultFileCollectionDependency)externalDependency;
|
||||
fileCollectionDependency.getFiles().addAll(readFiles(reader));
|
||||
fileCollectionDependency.setExcludedFromIndexing(readBoolean(reader, "excludedFromIndexing"));
|
||||
}
|
||||
else if (externalDependency instanceof DefaultUnresolvedExternalDependency) {
|
||||
DefaultUnresolvedExternalDependency unresolvedExternalDependency = (DefaultUnresolvedExternalDependency)externalDependency;
|
||||
|
||||
+1
@@ -458,6 +458,7 @@ public class DependencyResolverImpl implements DependencyResolver {
|
||||
if (!runtimeOutputDirs.isEmpty()) {
|
||||
DefaultFileCollectionDependency runtimeOutputDirsDependency = new DefaultFileCollectionDependency(runtimeOutputDirs);
|
||||
runtimeOutputDirsDependency.setScope(RUNTIME_SCOPE);
|
||||
runtimeOutputDirsDependency.setExcludedFromIndexing(true);
|
||||
return runtimeOutputDirsDependency;
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user