[Gradle, JS] Use FileSystemOperations only when it's available
FileSystemOperations is available since Gradle 6.0. ArchiveOperations usage is also refactored. Integration tests Gradle version requirements are reverted.
This commit is contained in:
-3
@@ -12,9 +12,6 @@ import org.junit.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class DukatIntegrationIT : BaseGradleIT() {
|
||||
override val defaultGradleVersion: GradleVersionRequired
|
||||
get() = GradleVersionRequired.AtLeast("6.0")
|
||||
|
||||
@Test
|
||||
fun testSeparateDukatKotlinDslRootDependencies() {
|
||||
testSeparateDukat(
|
||||
|
||||
-3
@@ -305,9 +305,6 @@ abstract class AbstractKotlin2JsGradlePluginIT(val irBackend: Boolean) : BaseGra
|
||||
jsCompilerType = if (irBackend) KotlinJsCompilerType.IR else KotlinJsCompilerType.LEGACY
|
||||
)
|
||||
|
||||
override val defaultGradleVersion: GradleVersionRequired
|
||||
get() = GradleVersionRequired.AtLeast("6.0")
|
||||
|
||||
protected fun CompiledProject.checkIrCompilationMessage() {
|
||||
if (irBackend) {
|
||||
assertContains(USING_JS_IR_BACKEND_MESSAGE)
|
||||
|
||||
-3
@@ -16,9 +16,6 @@ class KotlinJsIrLibraryGradlePluginIT : BaseGradleIT() {
|
||||
jsCompilerType = KotlinJsCompilerType.IR
|
||||
)
|
||||
|
||||
override val defaultGradleVersion: GradleVersionRequired
|
||||
get() = GradleVersionRequired.AtLeast("6.0")
|
||||
|
||||
@Test
|
||||
fun testSimpleJsBinaryLibrary() {
|
||||
val project = Project("simple-js-library")
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import org.junit.Test
|
||||
class CleanDataTaskIT : BaseGradleIT() {
|
||||
|
||||
override val defaultGradleVersion: GradleVersionRequired
|
||||
get() = GradleVersionRequired.AtLeast("6.0")
|
||||
get() = GradleVersionRequired.AtLeast("5.5.1")
|
||||
|
||||
@Test
|
||||
fun testDownloadedFolderDeletion() {
|
||||
|
||||
+6
-21
@@ -2,12 +2,12 @@ package org.jetbrains.kotlin.gradle.targets.js.nodejs
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.file.ArchiveOperations
|
||||
import org.gradle.api.file.FileSystemOperations
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinInfo
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.utils.ArchiveOperationsCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.FileSystemOperationsCompat
|
||||
import org.jetbrains.kotlin.statistics.metrics.NumericalMetrics
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
@@ -16,13 +16,8 @@ import java.net.URI
|
||||
open class NodeJsSetupTask : DefaultTask() {
|
||||
private val settings = NodeJsRootPlugin.apply(project.rootProject)
|
||||
private val env by lazy { settings.requireConfigured() }
|
||||
private val fs = services.get(FileSystemOperations::class.java)
|
||||
private val archives: Any? = try {
|
||||
services.get(ArchiveOperations::class.java)
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
// Gradle version < 6.6
|
||||
null
|
||||
}
|
||||
private val fs = FileSystemOperationsCompat(project)
|
||||
private val archiveOperations = ArchiveOperationsCompat(project)
|
||||
|
||||
val ivyDependency: String
|
||||
@Input get() = env.ivyDependency
|
||||
@@ -89,22 +84,12 @@ open class NodeJsSetupTask : DefaultTask() {
|
||||
|
||||
when {
|
||||
archive.name.endsWith("zip") -> fs.copy {
|
||||
val from = if (archives != null) {
|
||||
(archives as ArchiveOperations).zipTree(archive)
|
||||
} else {
|
||||
project.zipTree(archive)
|
||||
}
|
||||
it.from(from)
|
||||
it.from(archiveOperations.zipTree(archive))
|
||||
it.into(destination)
|
||||
}
|
||||
else -> {
|
||||
fs.copy {
|
||||
val from = if (archives != null) {
|
||||
(archives as ArchiveOperations).tarTree(archive)
|
||||
} else {
|
||||
project.tarTree(archive)
|
||||
}
|
||||
it.from(from)
|
||||
it.from(archiveOperations.tarTree(archive))
|
||||
it.into(destination)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-11
@@ -6,21 +6,20 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.npm
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.ArchiveOperations
|
||||
import org.gradle.api.file.FileSystemOperations
|
||||
import org.jetbrains.kotlin.gradle.targets.js.JS
|
||||
import org.jetbrains.kotlin.gradle.targets.js.JS_MAP
|
||||
import org.jetbrains.kotlin.gradle.targets.js.META_JS
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KLIB_TYPE
|
||||
import org.jetbrains.kotlin.gradle.utils.ArchiveOperationsCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.FileSystemOperationsCompat
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Creates fake NodeJS module directory from given gradle [dependency].
|
||||
*/
|
||||
internal class GradleNodeModuleBuilder(
|
||||
val project: Project,
|
||||
val fs: FileSystemOperations,
|
||||
val archiveOperations: Any?,
|
||||
val fs: FileSystemOperationsCompat,
|
||||
val archiveOperations: ArchiveOperationsCompat,
|
||||
val moduleName: String,
|
||||
val moduleVersion: String,
|
||||
val srcFiles: Collection<File>,
|
||||
@@ -34,12 +33,7 @@ internal class GradleNodeModuleBuilder(
|
||||
when {
|
||||
isKotlinJsRuntimeFile(srcFile) -> files.add(srcFile)
|
||||
srcFile.isCompatibleArchive -> {
|
||||
val archiveFiles = if (archiveOperations != null) {
|
||||
(archiveOperations as ArchiveOperations).zipTree(srcFile)
|
||||
} else {
|
||||
project.zipTree(srcFile)
|
||||
}
|
||||
archiveFiles.forEach { innerFile ->
|
||||
archiveOperations.zipTree(srcFile).forEach { innerFile ->
|
||||
when {
|
||||
innerFile.name == NpmProject.PACKAGE_JSON -> srcPackageJsonFile = innerFile
|
||||
isKotlinJsRuntimeFile(innerFile) -> files.add(innerFile)
|
||||
|
||||
+5
-11
@@ -5,10 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.npm
|
||||
|
||||
import org.gradle.api.file.ArchiveOperations
|
||||
import org.gradle.api.file.FileSystemOperations
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
||||
import org.jetbrains.kotlin.gradle.utils.ArchiveOperationsCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.FileSystemOperationsCompat
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
@@ -18,20 +17,15 @@ internal class GradleNodeModulesCache(nodeJs: NodeJsRootExtension) : AbstractNod
|
||||
@Transient
|
||||
private val project = nodeJs.rootProject
|
||||
|
||||
private val fs = (project as ProjectInternal).services.get(FileSystemOperations::class.java)
|
||||
private val archiveOperations: Any? = try {
|
||||
(project as ProjectInternal).services.get(ArchiveOperations::class.java)
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
// Gradle version < 6.6
|
||||
null
|
||||
}
|
||||
private val fs = FileSystemOperationsCompat(project)
|
||||
private val archiveOperations = ArchiveOperationsCompat(project)
|
||||
|
||||
override fun buildImportedPackage(
|
||||
name: String,
|
||||
version: String,
|
||||
file: File
|
||||
): File? {
|
||||
val module = GradleNodeModuleBuilder(project, fs, archiveOperations, name, version, listOf(file), dir)
|
||||
val module = GradleNodeModuleBuilder(fs, archiveOperations, name, version, listOf(file), dir)
|
||||
module.visitArtifacts()
|
||||
return module.rebuild()
|
||||
}
|
||||
|
||||
+47
-1
@@ -17,9 +17,16 @@
|
||||
package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.ArchiveOperations
|
||||
import org.gradle.api.file.CopySpec
|
||||
import org.gradle.api.file.FileSystemOperations
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.api.tasks.TaskInputs
|
||||
import org.gradle.api.tasks.TaskOutputs
|
||||
import org.gradle.api.tasks.WorkResult
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
||||
import org.gradle.util.GradleVersion
|
||||
import java.io.File
|
||||
@@ -64,4 +71,43 @@ internal fun checkGradleCompatibility(
|
||||
}
|
||||
|
||||
internal val AbstractArchiveTask.archivePathCompatible: File
|
||||
get() = archiveFile.get().asFile
|
||||
get() = archiveFile.get().asFile
|
||||
|
||||
internal class ArchiveOperationsCompat(@Transient private val project: Project) {
|
||||
private val archiveOperations: Any? = try {
|
||||
(project as ProjectInternal).services.get(ArchiveOperations::class.java)
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
// Gradle version < 6.6
|
||||
null
|
||||
}
|
||||
|
||||
fun zipTree(obj: Any): FileTree {
|
||||
return when (archiveOperations) {
|
||||
is ArchiveOperations -> archiveOperations.zipTree(obj)
|
||||
else -> project.zipTree(obj)
|
||||
}
|
||||
}
|
||||
|
||||
fun tarTree(obj: Any): FileTree {
|
||||
return when (archiveOperations) {
|
||||
is ArchiveOperations -> archiveOperations.tarTree(obj)
|
||||
else -> project.tarTree(obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class FileSystemOperationsCompat(@Transient private val project: Project) {
|
||||
private val fileSystemOperations: Any? = try {
|
||||
(project as ProjectInternal).services.get(FileSystemOperations::class.java)
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
// Gradle version < 6.0
|
||||
null
|
||||
}
|
||||
|
||||
fun copy(action: (CopySpec) -> Unit): WorkResult? {
|
||||
return when (fileSystemOperations) {
|
||||
is FileSystemOperations -> fileSystemOperations.copy(action)
|
||||
else -> project.copy(action)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user