-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jars flattening as a separate task to fix packageUberJarForCurrentOS.
- Loading branch information
1 parent
95603ce
commit 80bcfc8
Showing
3 changed files
with
75 additions
and
19 deletions.
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
45 changes: 45 additions & 0 deletions
45
...ns/compose/src/main/kotlin/org/jetbrains/compose/desktop/tasks/AbstractJarsFlattenTask.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,45 @@ | ||
/* | ||
* Copyright 2020-2024 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.compose.desktop.tasks | ||
|
||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.DuplicatesStrategy | ||
import org.gradle.api.file.FileCollection | ||
import org.gradle.api.tasks.InputFiles | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
import org.jetbrains.compose.internal.utils.clearDirs | ||
import java.io.File | ||
|
||
abstract class AbstractJarsFlattenTask : AbstractComposeDesktopTask() { | ||
|
||
@get:InputFiles | ||
val inputFiles: ConfigurableFileCollection = objects.fileCollection() | ||
|
||
@get:OutputDirectory | ||
val destinationDir: DirectoryProperty = objects.directoryProperty() | ||
|
||
@TaskAction | ||
fun execute() { | ||
fileOperations.clearDirs(destinationDir) | ||
|
||
fileOperations.copy { | ||
it.duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
it.from(flattenJars(inputFiles)) | ||
it.into(destinationDir) | ||
} | ||
} | ||
|
||
private fun flattenJars(files: FileCollection) = files.map { | ||
when { | ||
it.isZipOrJar() -> this.archiveOperations.zipTree(it) | ||
else -> it | ||
} | ||
} | ||
|
||
private fun File.isZipOrJar() = name.endsWith(".jar", ignoreCase = true) || name.endsWith(".zip", ignoreCase = true) | ||
} |