mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
[gradle][IDEA-346728] do not modify buildscript repositories before downloading sources
GitOrigin-RevId: 49774b242158fac327a5277601ec17570c6d36e5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ea7146d0a8
commit
7ab8560477
@@ -35,7 +35,7 @@ object GradleDependencySourceDownloader {
|
|||||||
private const val INIT_SCRIPT_FILE_PREFIX = "ijDownloadSources"
|
private const val INIT_SCRIPT_FILE_PREFIX = "ijDownloadSources"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun downloadSources(project: Project, executionName: @Nls String, sourceArtifactNotation: String, externalProjectPath: String)
|
fun downloadSources(project: Project, executionName: @Nls String, sourceArtifactNotation: String, projectPath: String)
|
||||||
: CompletableFuture<File> {
|
: CompletableFuture<File> {
|
||||||
var sourcesLocationFilePath: String
|
var sourcesLocationFilePath: String
|
||||||
var sourcesLocationFile: File
|
var sourcesLocationFile: File
|
||||||
@@ -51,12 +51,12 @@ object GradleDependencySourceDownloader {
|
|||||||
val taskName = "ijDownloadSources" + UUID.randomUUID().toString().substring(0, 12)
|
val taskName = "ijDownloadSources" + UUID.randomUUID().toString().substring(0, 12)
|
||||||
val settings = ExternalSystemTaskExecutionSettings().also {
|
val settings = ExternalSystemTaskExecutionSettings().also {
|
||||||
it.executionName = executionName
|
it.executionName = executionName
|
||||||
it.externalProjectPath = externalProjectPath
|
it.externalProjectPath = projectPath
|
||||||
it.taskNames = listOf(taskName)
|
it.taskNames = listOf(taskName)
|
||||||
it.vmOptions = GradleSettings.getInstance(project).getGradleVmOptions()
|
it.vmOptions = GradleSettings.getInstance(project).getGradleVmOptions()
|
||||||
it.externalSystemIdString = GradleConstants.SYSTEM_ID.id
|
it.externalSystemIdString = GradleConstants.SYSTEM_ID.id
|
||||||
}
|
}
|
||||||
val userData = prepareUserData(sourceArtifactNotation, taskName, sourcesLocationFilePath)
|
val userData = prepareUserData(sourceArtifactNotation, taskName, sourcesLocationFilePath, projectPath)
|
||||||
val resultWrapper = CompletableFuture<File>()
|
val resultWrapper = CompletableFuture<File>()
|
||||||
val callback = object : TaskCallback {
|
val callback = object : TaskCallback {
|
||||||
override fun onSuccess() {
|
override fun onSuccess() {
|
||||||
@@ -94,14 +94,15 @@ object GradleDependencySourceDownloader {
|
|||||||
return resultWrapper
|
return resultWrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareUserData(sourceArtifactNotation: String, taskName: String, sourcesLocationFilePath: String): UserDataHolderBase {
|
private fun prepareUserData(sourceArtifactNotation: String, taskName: String, sourcesLocationFilePath: String, projectPath: String)
|
||||||
|
: UserDataHolderBase {
|
||||||
val legacyInitScript = LazyVersionSpecificInitScript(
|
val legacyInitScript = LazyVersionSpecificInitScript(
|
||||||
scriptSupplier = { loadLegacyDownloadSourcesInitScript(sourceArtifactNotation, taskName, sourcesLocationFilePath) },
|
scriptSupplier = { loadLegacyDownloadSourcesInitScript(sourceArtifactNotation, taskName, sourcesLocationFilePath, projectPath) },
|
||||||
filePrefix = INIT_SCRIPT_FILE_PREFIX,
|
filePrefix = INIT_SCRIPT_FILE_PREFIX,
|
||||||
isApplicable = { GRADLE_5_6 > it }
|
isApplicable = { GRADLE_5_6 > it }
|
||||||
)
|
)
|
||||||
val initScript = LazyVersionSpecificInitScript(
|
val initScript = LazyVersionSpecificInitScript(
|
||||||
scriptSupplier = { loadDownloadSourcesInitScript(sourceArtifactNotation, taskName, sourcesLocationFilePath) },
|
scriptSupplier = { loadDownloadSourcesInitScript(sourceArtifactNotation, taskName, sourcesLocationFilePath, projectPath) },
|
||||||
filePrefix = INIT_SCRIPT_FILE_PREFIX,
|
filePrefix = INIT_SCRIPT_FILE_PREFIX,
|
||||||
isApplicable = { GRADLE_5_6 <= it }
|
isApplicable = { GRADLE_5_6 <= it }
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,16 +38,13 @@ fun createIdeaPluginConfiguratorInitScript() : Path {
|
|||||||
return createInitScript(IDEA_PLUGIN_CONFIGURATOR_SCRIPT_NAME, initScript)
|
return createInitScript(IDEA_PLUGIN_CONFIGURATOR_SCRIPT_NAME, initScript)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadDownloadSourcesInitScript(dependencyNotation: String,
|
fun loadDownloadSourcesInitScript(dependencyNotation: String, taskName: String, downloadTarget: String, projectPath: String): String =
|
||||||
taskName: String,
|
loadDownloadSourcesInitScript("/org/jetbrains/plugins/gradle/tooling/internal/init/downloadSources.gradle", dependencyNotation,
|
||||||
downloadTarget: String): String = loadDownloadSourcesInitScript(
|
taskName, downloadTarget, projectPath)
|
||||||
"/org/jetbrains/plugins/gradle/tooling/internal/init/downloadSources.gradle", dependencyNotation, taskName, downloadTarget)
|
|
||||||
|
|
||||||
fun loadLegacyDownloadSourcesInitScript(dependencyNotation: String,
|
fun loadLegacyDownloadSourcesInitScript(dependencyNotation: String, taskName: String, downloadTarget: String, projectPath: String): String =
|
||||||
taskName: String,
|
loadDownloadSourcesInitScript("/org/jetbrains/plugins/gradle/tooling/internal/init/legacyDownloadSources.gradle", dependencyNotation,
|
||||||
downloadTarget: String): String = loadDownloadSourcesInitScript(
|
taskName, downloadTarget, projectPath)
|
||||||
"/org/jetbrains/plugins/gradle/tooling/internal/init/legacyDownloadSources.gradle", dependencyNotation,
|
|
||||||
taskName, downloadTarget)
|
|
||||||
|
|
||||||
fun loadTaskInitScript(
|
fun loadTaskInitScript(
|
||||||
projectPath: String,
|
projectPath: String,
|
||||||
@@ -204,10 +201,13 @@ private fun isContentEquals(path: Path, content: ByteArray): Boolean {
|
|||||||
content.contentEquals(path.readBytes())
|
content.contentEquals(path.readBytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadDownloadSourcesInitScript(path: String, dependencyNotation: String, taskName: String, downloadTarget: String): String {
|
private fun loadDownloadSourcesInitScript(
|
||||||
|
path: String, dependencyNotation: String, taskName: String, downloadTarget: String, projectPath: String
|
||||||
|
): String {
|
||||||
return loadInitScript(path, mapOf(
|
return loadInitScript(path, mapOf(
|
||||||
"DEPENDENCY_NOTATION" to dependencyNotation.toGroovyStringLiteral(),
|
"DEPENDENCY_NOTATION" to dependencyNotation.toGroovyStringLiteral(),
|
||||||
"TARGET_PATH" to downloadTarget.toGroovyStringLiteral(),
|
"TARGET_PATH" to downloadTarget.toGroovyStringLiteral(),
|
||||||
"GRADLE_TASK_NAME" to taskName.toGroovyStringLiteral()
|
"GRADLE_TASK_NAME" to taskName.toGroovyStringLiteral(),
|
||||||
|
"GRADLE_PROJECT_PATH" to projectPath.toGroovyStringLiteral(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ interface Properties {
|
|||||||
public static final String targetPath = TARGET_PATH
|
public static final String targetPath = TARGET_PATH
|
||||||
//noinspection GrUnresolvedAccess
|
//noinspection GrUnresolvedAccess
|
||||||
public static final String gradleTaskName = GRADLE_TASK_NAME
|
public static final String gradleTaskName = GRADLE_TASK_NAME
|
||||||
|
//noinspection GrUnresolvedAccess
|
||||||
|
public static final String projectPath = GRADLE_PROJECT_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
// Requires Gradle 5.6+
|
// Requires Gradle 5.6+
|
||||||
@@ -40,22 +42,8 @@ abstract class IjDownloadTask extends DefaultTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<? extends ArtifactRepository> projectRepositories() {
|
|
||||||
def target = new HashSet()
|
|
||||||
allprojects {
|
|
||||||
target.addAll(it.repositories)
|
|
||||||
}
|
|
||||||
return target
|
|
||||||
}
|
|
||||||
|
|
||||||
gradle.projectsEvaluated {
|
|
||||||
rootProject
|
|
||||||
.repositories
|
|
||||||
.addAll(projectRepositories())
|
|
||||||
}
|
|
||||||
|
|
||||||
afterProject {
|
afterProject {
|
||||||
if (it.name == rootProject.name) {
|
if (it.projectDir.path == Properties.projectPath) {
|
||||||
Configuration configuration = it.configurations.create('downloadSources_' + UUID.randomUUID())
|
Configuration configuration = it.configurations.create('downloadSources_' + UUID.randomUUID())
|
||||||
configuration.transitive = false
|
configuration.transitive = false
|
||||||
it.dependencies.add(configuration.name, Properties.dependencyNotation)
|
it.dependencies.add(configuration.name, Properties.dependencyNotation)
|
||||||
|
|||||||
@@ -7,32 +7,31 @@ interface Properties {
|
|||||||
public static final String targetPath = TARGET_PATH
|
public static final String targetPath = TARGET_PATH
|
||||||
//noinspection GrUnresolvedAccess
|
//noinspection GrUnresolvedAccess
|
||||||
public static final String gradleTaskName = GRADLE_TASK_NAME
|
public static final String gradleTaskName = GRADLE_TASK_NAME
|
||||||
|
//noinspection GrUnresolvedAccess
|
||||||
|
public static final String projectPath = GRADLE_PROJECT_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solution for Gradle 3.0...5.5
|
allprojects {
|
||||||
Set<? extends ArtifactRepository> projectRepositories() {
|
afterEvaluate {
|
||||||
def target = new HashSet()
|
if (it.projectDir.path == Properties.projectPath) {
|
||||||
allprojects {
|
configureProject(it)
|
||||||
target.addAll(it.repositories)
|
}
|
||||||
}
|
}
|
||||||
return target
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gradle.projectsEvaluated {
|
private static void configureProject(Project project) {
|
||||||
rootProject
|
project
|
||||||
.repositories
|
.tasks
|
||||||
.addAll(projectRepositories())
|
|
||||||
rootProject.tasks
|
|
||||||
.create(Properties.gradleTaskName) {
|
.create(Properties.gradleTaskName) {
|
||||||
doLast {
|
doLast {
|
||||||
def configuration
|
def configuration
|
||||||
def repository = rootProject.repositories.toList().find {
|
def repository = project.repositories.toList().find {
|
||||||
logger.lifecycle('Attempt to download sources from ' + it.name)
|
logger.lifecycle('Attempt to download sources from ' + it.name)
|
||||||
project.repositories.clear()
|
project.repositories.clear()
|
||||||
project.repositories.add(it)
|
project.repositories.add(it)
|
||||||
configuration = rootProject.configurations.create('downloadSourcesFrom_' + UUID.randomUUID())
|
configuration = project.configurations.create('downloadSourcesFrom_' + UUID.randomUUID())
|
||||||
configuration.transitive = false
|
configuration.transitive = false
|
||||||
rootProject.dependencies.add(configuration.name, Properties.dependencyNotation)
|
project.dependencies.add(configuration.name, Properties.dependencyNotation)
|
||||||
def files = null
|
def files = null
|
||||||
try {
|
try {
|
||||||
files = configuration.resolvedConfiguration.lenientConfiguration.getFiles()
|
files = configuration.resolvedConfiguration.lenientConfiguration.getFiles()
|
||||||
@@ -42,9 +41,9 @@ gradle.projectsEvaluated {
|
|||||||
return files && !files.isEmpty()
|
return files && !files.isEmpty()
|
||||||
}
|
}
|
||||||
if (!repository) {
|
if (!repository) {
|
||||||
configuration = rootProject.configurations.create('downloadSources_' + UUID.randomUUID())
|
configuration = project.configurations.create('downloadSources_' + UUID.randomUUID())
|
||||||
configuration.transitive = false
|
configuration.transitive = false
|
||||||
rootProject.dependencies.add(configuration.name, Properties.dependencyNotation)
|
project.dependencies.add(configuration.name, Properties.dependencyNotation)
|
||||||
configuration.resolve()
|
configuration.resolve()
|
||||||
}
|
}
|
||||||
def sourcesPath = configuration?.singleFile?.path
|
def sourcesPath = configuration?.singleFile?.path
|
||||||
|
|||||||
Reference in New Issue
Block a user