Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release/1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
igordmn committed Oct 11, 2022
2 parents a1a3cdc + d5af962 commit 89a334e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSIONING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Features
## Compatability and versioning overview

### Supported platforms
* macOS (x86-64, arm64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ abstract class ProguardSettings @Inject constructor(
val maxHeapSize: Property<String?> = objects.nullableProperty()
val configurationFiles: ConfigurableFileCollection = objects.fileCollection()
val isEnabled: Property<Boolean> = objects.notNullProperty(false)
val obfuscate: Property<Boolean> = objects.notNullProperty(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ private fun JvmApplicationContext.configureProguardTask(
mainClass.set(app.mainClass)
proguardVersion.set(settings.version)
configurationFiles.from(settings.configurationFiles)
// ProGuard uses -dontobfuscate option to turn off obfuscation, which is enabled by default
// We want to disable obfuscation by default, because often
// it is not needed, but makes troubleshooting much harder.
// If obfuscation is turned off by default,
// enabling (`isObfuscationEnabled.set(true)`) seems much better,
// than disabling obfuscation disabling (`dontObfuscate.set(false)`).
// That's why a task property is follows ProGuard design,
// when our DSL does the opposite.
dontobfuscate.set(settings.obfuscate.map { !it })

dependsOn(unpackDefaultResources)
defaultComposeRulesFile.set(unpackDefaultResources.flatMap { it.resources.defaultComposeProguardRules })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() {
@get:InputFiles
val configurationFiles: ConfigurableFileCollection = objects.fileCollection()

@get:Optional
@get:Input
val dontobfuscate: Property<Boolean?> = objects.nullableProperty()

// todo: DSL for excluding default rules
// also consider pulling coroutines rules from coroutines artifact
// https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/resources/META-INF/proguard/coroutines.pro
Expand Down Expand Up @@ -107,6 +111,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() {
}

rootConfigurationFile.ioFile.bufferedWriter().use { writer ->
if (dontobfuscate.orNull == true) {
writer.writeLn("-dontobfuscate")
}

writer.writeLn("""
-keep public class ${mainClass.get()} {
public static void main(java.lang.String[]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import java.util.*
import java.util.jar.JarFile
import kotlin.collections.HashSet
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.Test

Expand Down Expand Up @@ -77,17 +78,43 @@ class DesktopApplicationTest : GradlePluginTestBase() {

@Test
fun proguard(): Unit = with(testProject(TestProjects.proguard)) {
gradle(":runReleaseDistributable").build().checks { check ->
check.taskOutcome(":proguardReleaseJars", TaskOutcome.SUCCESS)
val enableObfuscation = """
compose.desktop {
application {
buildTypes.release.proguard {
obfuscate.set(true)
}
}
}
""".trimIndent()

assertEqualTextFiles(file("main-methods.actual.txt"), file("main-methods.expected.txt"))
val actualMainImage = file("main-image.actual.png")
val expectedMainImage = file("main-image.expected.png")

val actualMainImage = file("main-image.actual.png")
val expectedMainImage = file("main-image.expected.png")
fun checkImageBeforeBuild() {
assertFalse(actualMainImage.exists(), "'$actualMainImage' exists")
}
fun checkImageAfterBuild() {
assert(actualMainImage.readBytes().contentEquals(expectedMainImage.readBytes())) {
"The actual image '$actualMainImage' does not match the expected image '$expectedMainImage'"
}
}

checkImageBeforeBuild()
gradle(":runReleaseDistributable").build().checks { check ->
check.taskOutcome(":proguardReleaseJars", TaskOutcome.SUCCESS)
checkImageAfterBuild()
assertEqualTextFiles(file("main-methods.actual.txt"), file("main-methods.expected.txt"))
}

file("build.gradle").modify { "$it\n$enableObfuscation" }
actualMainImage.delete()
checkImageBeforeBuild()
gradle(":runReleaseDistributable").build().checks { check ->
check.taskOutcome(":proguardReleaseJars", TaskOutcome.SUCCESS)
checkImageAfterBuild()
assertNotEqualTextFiles(file("main-methods.actual.txt"), file("main-methods.expected.txt"))
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ internal fun String.checkContains(substring: String) {
}

internal fun assertEqualTextFiles(actual: File, expected: File) {
fun File.normalizedText() = readLines().joinToString("\n") { it.trim() }

val actualText = actual.normalizedText()
val expectedText = expected.normalizedText()
Assertions.assertEquals(
expectedText,
actualText,
"Expected file '$expected' differs from actual file '$actual'"
expected.normalizedText(),
actual.normalizedText(),
"Content of '$expected' is not equal to content of '$actual'"
)
}

internal fun assertNotEqualTextFiles(actual: File, expected: File) {
Assertions.assertNotEquals(
expected.normalizedText(),
actual.normalizedText(),
"Content of '$expected' is equal to content of '$actual'"
)
}
}

private fun File.normalizedText() =
readLines().joinToString("\n") { it.trim() }
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
-keep public class Main {
public void keptByKeepRule(...);
}

-keepclassmembernames public class Main {
*;
}
4 changes: 2 additions & 2 deletions idea-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ deploy.version=0.1-SNAPSHOT

plugin.channels=snapshots
plugin.since.build=203
plugin.until.build=222.*
plugin.until.build=233.*
## See https://jb.gg/intellij-platform-builds-list for available build versions.
plugin.verifier.ide.versions=2020.3.2, 2021.1, 2022.1
plugin.verifier.ide.versions=2021.1, 2022.1, 2022.2

platform.type=IC
platform.version=2021.1
Expand Down

0 comments on commit 89a334e

Please sign in to comment.