Commit 4ef0a2ad authored by Sergei Vorobyov's avatar Sergei Vorobyov Committed by intellij-monorepo-bot
Browse files

IDEA-319522 fix: ignore all user code and data exceptions

Currently, the IDEA doesn't support evaluation of Gradle property providers which require task execution.

(cherry picked from commit e552a71810615ec87750c6354f592eb1570ff750)

IJ-CR-110076

GitOrigin-RevId: 9eb06e74eb6629109a601c871f543c9d81d4b2a8
parent 4fd30c3b
Showing with 35 additions and 14 deletions
+35 -14
......@@ -38,6 +38,7 @@ import org.jetbrains.plugins.gradle.tooling.util.JavaPluginUtil
import org.jetbrains.plugins.gradle.tooling.util.SourceSetCachedFinder
import org.jetbrains.plugins.gradle.tooling.util.resolve.DependencyResolverImpl
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method
import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap
......@@ -756,7 +757,7 @@ class ExternalProjectBuilderImpl extends AbstractModelBuilderService {
if (sourcePaths != null) {
for (Object path : sourcePaths) {
if (isSafeToResolve(path)) {
def files = archiveTask.project.files(path).files
def files = project.files(path).files
outputFiles.removeAll(files)
}
}
......@@ -772,12 +773,10 @@ class ExternalProjectBuilderImpl extends AbstractModelBuilderService {
/**
* Checks that object can be safely resolved using {@link Project#files(java.lang.Object...)} API.
* <br/>
* Some FileCollections implementations may have file definitions that can not
* be resolved during sync, causing {@link org.gradle.api.InvalidUserCodeException}
* and {@link org.gradle.api.InvalidUserDataException}.
*
* @param object
* @return true if object is safe to resolve using {@link Project#files(java.lang.Object...)}
* @see org.jetbrains.plugins.gradle.tooling.builder.ExternalProjectBuilderImpl#unpackPresentProvider
*/
private static boolean isSafeToResolve(Object param) {
Object object = unpackPresentProvider(param)
......@@ -791,6 +790,37 @@ class ExternalProjectBuilderImpl extends AbstractModelBuilderService {
|| object instanceof SourceSetOutput
}
/**
* Some Gradle {@link org.gradle.api.provider.Provider} implementations can not be resolved during sync,
* causing {@link org.gradle.api.InvalidUserCodeException}
* and {@link org.gradle.api.InvalidUserDataException}.
*
* @return provided value or current if value isn't present or cannot be evaluated
*/
private static Object unpackPresentProvider(Object object) {
if (!dynamicCheckInstanceOf(object, "org.gradle.api.provider.Provider")) {
return object
}
try {
def providerClass = object.getClass()
def isPresentMethod = providerClass.getMethod("isPresent")
def getterMethod = providerClass.getMethod("get")
if ((Boolean)isPresentMethod.invoke(object)) {
return getterMethod.invoke(object)
}
return object
}
catch (InvocationTargetException exception) {
Throwable targetException = exception.targetException
boolean isCodeException = dynamicCheckInstanceOf(targetException, "org.gradle.api.InvalidUserCodeException")
boolean isDataException = dynamicCheckInstanceOf(targetException, "org.gradle.api.InvalidUserDataException")
if (isCodeException || isDataException) {
return object
}
throw exception
}
}
private static boolean isCustomJarTask(@NotNull AbstractArchiveTask archiveTask,
@NotNull SourceSetContainer sourceSets) {
for (final SourceSet sourceSet in sourceSets) {
......
......@@ -38,13 +38,4 @@ public final class ReflectionUtil {
}
return result;
}
public static Object unpackPresentProvider(Object object) {
if (dynamicCheckInstanceOf(object, "org.gradle.api.provider.Provider")) {
if (reflectiveCall(object, "isPresent", Boolean.class)) {
return reflectiveCall(object, "get", Object.class);
}
}
return object;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment