-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IJ plugin] Support IJ platform 232 #5095
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...j-plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/GradleExecutionHelperCompat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.apollographql.ijplugin.gradle | ||
|
||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId | ||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener | ||
import org.gradle.tooling.BuildLauncher | ||
import org.gradle.tooling.ModelBuilder | ||
import org.gradle.tooling.ProjectConnection | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper | ||
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings | ||
|
||
class GradleExecutionHelperCompat { | ||
private val gradleExecutionHelper = GradleExecutionHelper() | ||
|
||
/** | ||
* < 232: | ||
* ``` | ||
* public BuildLauncher getBuildLauncher( | ||
* @NotNull final ExternalSystemTaskId id, | ||
* @NotNull ProjectConnection connection, | ||
* @Nullable GradleExecutionSettings settings, | ||
* @NotNull ExternalSystemTaskNotificationListener listener | ||
* ) | ||
* ``` | ||
*/ | ||
private val getBuildLauncherMethodPre232 = GradleExecutionHelper::class.java.methods.firstOrNull { | ||
it.name == "getBuildLauncher" && it.parameterCount == 4 | ||
} | ||
|
||
/** | ||
* ≥ 232: | ||
* ``` | ||
* public @NotNull BuildLauncher getBuildLauncher( | ||
* @NotNull ProjectConnection connection, | ||
* @NotNull ExternalSystemTaskId id, | ||
* @NotNull List<String> tasksAndArguments, | ||
* @NotNull GradleExecutionSettings settings, | ||
* @NotNull ExternalSystemTaskNotificationListener listener | ||
* ) | ||
* ``` | ||
*/ | ||
private val getBuildLauncherMethodPost232 = GradleExecutionHelper::class.java.methods.firstOrNull { | ||
it.name == "getBuildLauncher" && it.parameterCount == 5 | ||
} | ||
|
||
/** | ||
* < 232: | ||
* ``` | ||
* public <T> ModelBuilder<T> getModelBuilder( | ||
* @NotNull Class<T> modelType, | ||
* @NotNull final ExternalSystemTaskId id, | ||
* @Nullable GradleExecutionSettings settings, | ||
* @NotNull ProjectConnection connection, | ||
* @NotNull ExternalSystemTaskNotificationListener listener | ||
* ) | ||
*/ | ||
private val getModelBuilderMethodPre232 = GradleExecutionHelper::class.java.methods.firstOrNull { | ||
it.name == "getModelBuilder" && it.parameterTypes[1] == ExternalSystemTaskId::class.java | ||
} | ||
|
||
/** | ||
* ≥ 232: | ||
* ``` | ||
* public <T> @NotNull ModelBuilder<T> getModelBuilder( | ||
* @NotNull Class<T> modelType, | ||
* @NotNull ProjectConnection connection, | ||
* @NotNull ExternalSystemTaskId id, | ||
* @NotNull GradleExecutionSettings settings, | ||
* @NotNull ExternalSystemTaskNotificationListener listener | ||
* ) | ||
*/ | ||
private val getModelBuilderMethodPost232 = GradleExecutionHelper::class.java.methods.firstOrNull { | ||
it.name == "getModelBuilder" && it.parameterTypes[1] == ProjectConnection::class.java | ||
} | ||
|
||
fun <T> execute( | ||
projectPath: String, | ||
settings: GradleExecutionSettings?, | ||
f: (ProjectConnection) -> T, | ||
): T { | ||
return gradleExecutionHelper.execute(projectPath, settings, f) | ||
} | ||
|
||
fun getBuildLauncher( | ||
connection: ProjectConnection, | ||
id: ExternalSystemTaskId, | ||
tasksAndArguments: List<String>, | ||
settings: GradleExecutionSettings, | ||
listener: ExternalSystemTaskNotificationListener, | ||
): BuildLauncher { | ||
return if (getBuildLauncherMethodPre232 != null) { | ||
getBuildLauncherMethodPre232.invoke(gradleExecutionHelper, id, connection, settings, listener) as BuildLauncher | ||
} else { | ||
if (getBuildLauncherMethodPost232 == null) { | ||
error("Could not find GradleExecutionHelper.getBuildLauncher method for either < 232 or ≥ 232") | ||
} | ||
getBuildLauncherMethodPost232.invoke(gradleExecutionHelper, connection, id, tasksAndArguments, settings, listener) as BuildLauncher | ||
} | ||
} | ||
|
||
fun <T> getModelBuilder( | ||
modelType: Class<T>, | ||
connection: ProjectConnection, | ||
id: ExternalSystemTaskId, | ||
settings: GradleExecutionSettings, | ||
listener: ExternalSystemTaskNotificationListener, | ||
): ModelBuilder<T> { | ||
@Suppress("UNCHECKED_CAST") | ||
return if (getModelBuilderMethodPre232 != null) { | ||
getModelBuilderMethodPre232.invoke(gradleExecutionHelper, modelType, id, settings, connection, listener) as ModelBuilder<T> | ||
} else { | ||
if (getModelBuilderMethodPost232 == null) { | ||
error("Could not find GradleExecutionHelper.getModelBuilder method for either < 232 or ≥ 232") | ||
} | ||
getModelBuilderMethodPost232.invoke(gradleExecutionHelper, modelType, connection, id, settings, listener) as ModelBuilder<T> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes but also 👍