Skip to content

Commit cdae01a

Browse files
committed
Upgrade tested Android Studio to Ladybug
1 parent d8bb6ab commit cdae01a

File tree

4 files changed

+110
-31
lines changed

4 files changed

+110
-31
lines changed

buildSrc/src/main/kotlin/profiler.android-studio-setup.gradle.kts

+21-27
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ import extensions.AndroidStudioTestExtension
22
import tasks.InstallAndroidSdkTask
33
import providers.AndroidStudioInstallation
44
import providers.AndroidStudioSystemProperties
5+
import tasks.ExtractAndroidStudioTask
56

67
repositories {
7-
ivy {
8-
// Url of Android Studio archive
9-
url = uri("https://redirector.gvt1.com/edgedl/android/studio/ide-zips")
10-
patternLayout {
11-
artifact("[revision]/[artifact]-[revision]-[ext]")
12-
}
13-
metadataSources { artifact() }
14-
content {
15-
includeGroup("android-studio")
8+
listOf(
9+
// Urls of Android Studio archive
10+
"https://redirector.gvt1.com/edgedl/android/studio/ide-zips",
11+
"https://redirector.gvt1.com/edgedl/android/studio/install"
12+
).forEach {
13+
ivy {
14+
url = uri(it)
15+
patternLayout {
16+
artifact("[revision]/[artifact]-[revision]-[ext]")
17+
}
18+
metadataSources { artifact() }
19+
content {
20+
includeGroup("android-studio")
21+
}
1622
}
1723
}
1824
}
@@ -35,29 +41,17 @@ val androidStudioRuntime by configurations.creating
3541
dependencies {
3642
val fileExtension = when {
3743
isWindows() -> "windows.zip"
38-
isMacOS() && isIntel() -> "mac.zip"
39-
isMacOS() && !isIntel() -> "mac_arm.zip"
44+
isMacOS() && isIntel() -> "mac.dmg"
45+
isMacOS() && !isIntel() -> "mac_arm.dmg"
4046
isLinux() -> "linux.tar.gz"
4147
else -> throw IllegalStateException("Unsupported OS: $os")
4248
}
4349
androidStudioRuntime(extension.testAndroidStudioVersion.map { version -> "android-studio:android-studio:$version@$fileExtension" })
4450
}
4551

46-
val unpackAndroidStudio = tasks.register<Copy>("unpackAndroidStudio") {
47-
from(Callable {
48-
val singleFile = androidStudioRuntime.singleFile
49-
when {
50-
singleFile.name.endsWith(".tar.gz") -> tarTree(singleFile)
51-
else -> zipTree(singleFile)
52-
}
53-
}) {
54-
eachFile {
55-
// Remove top folder when unzipping, that way we get rid of Android Studio.app folder that can cause issues on Mac
56-
// where MacOS would kill the Android Studio process right after start, issue: https://github.com/gradle/gradle-profiler/issues/469
57-
relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray())
58-
}
59-
}
60-
into(layout.buildDirectory.dir("android-studio"))
52+
val unpackAndroidStudio = tasks.register<ExtractAndroidStudioTask>("unpackAndroidStudio") {
53+
androidStudioLocation = androidStudioRuntime
54+
outputDir = layout.buildDirectory.dir("android-studio")
6155
}
6256

6357
val installAndroidSdk = tasks.register<InstallAndroidSdkTask>("installAndroidSdk") {
@@ -68,7 +62,7 @@ val installAndroidSdk = tasks.register<InstallAndroidSdkTask>("installAndroidSdk
6862
}
6963

7064
val androidStudioInstallation = objects.newInstance<AndroidStudioInstallation>().apply {
71-
studioInstallLocation.fileProvider(unpackAndroidStudio.map { it.destinationDir })
65+
studioInstallLocation = unpackAndroidStudio.flatMap { it.outputDir }
7266
}
7367

7468
tasks.withType<Test>().configureEach {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package tasks
2+
3+
import org.gradle.api.DefaultTask
4+
import org.gradle.api.file.ConfigurableFileCollection
5+
import org.gradle.api.file.DirectoryProperty
6+
import org.gradle.api.file.FileSystemOperations
7+
import org.gradle.api.file.RelativePath
8+
import org.gradle.api.internal.file.FileOperations
9+
import org.gradle.api.tasks.*
10+
import org.gradle.process.ExecOperations
11+
import org.gradle.work.DisableCachingByDefault
12+
import java.io.File
13+
import javax.inject.Inject
14+
15+
16+
@DisableCachingByDefault(because = "Not worth caching")
17+
abstract class ExtractAndroidStudioTask @Inject constructor(
18+
private val execOps: ExecOperations,
19+
private val fsOps: FileSystemOperations,
20+
private val fileOps: FileOperations
21+
) : DefaultTask() {
22+
23+
companion object {
24+
private const val VOLUME_NAME = "AndroidStudioForGradle"
25+
}
26+
27+
@get:InputFiles
28+
@get:PathSensitive(PathSensitivity.NONE)
29+
abstract val androidStudioLocation: ConfigurableFileCollection
30+
31+
@get:OutputDirectory
32+
abstract val outputDir: DirectoryProperty
33+
34+
@TaskAction
35+
fun extract() {
36+
val androidStudioDistribution = androidStudioLocation.singleFile
37+
when {
38+
androidStudioDistribution.name.endsWith(".dmg") -> extractDmg(androidStudioDistribution)
39+
else -> extractZipOrTar(androidStudioDistribution)
40+
}
41+
}
42+
43+
fun extractZipOrTar(androidStudioDistribution: File) {
44+
fsOps.copy {
45+
val src = when {
46+
androidStudioDistribution.name.endsWith(".tar.gz") -> fileOps.tarTree(androidStudioDistribution)
47+
else -> fileOps.zipTree(androidStudioDistribution)
48+
}
49+
50+
from(src) {
51+
eachFile {
52+
// Remove top folder when unzipping, that way we get rid of Android Studio.app folder that can cause issues on Mac
53+
// where MacOS would kill the Android Studio process right after start, issue: https://github.com/gradle/gradle-profiler/issues/469
54+
@Suppress("SpreadOperator")
55+
relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray())
56+
}
57+
}
58+
59+
into(outputDir)
60+
}
61+
}
62+
63+
fun extractDmg(androidStudioDistribution: File) {
64+
val volumeDir = "/Volumes/$VOLUME_NAME"
65+
val srcDir = "/Volumes/$VOLUME_NAME/Android Studio.app"
66+
require(!File(srcDir).exists()) {
67+
"The directory $srcDir already exists. Please unmount it via `hdiutil detach $volumeDir`."
68+
}
69+
70+
try {
71+
execOps.exec {
72+
commandLine("hdiutil", "attach", androidStudioDistribution.absolutePath, "-mountpoint", volumeDir)
73+
}
74+
75+
outputDir.get().asFile.mkdirs()
76+
execOps.exec {
77+
commandLine("cp", "-r", "$volumeDir/Android Studio.app/Contents", outputDir.get().asFile.absolutePath)
78+
}
79+
} finally {
80+
execOps.exec {
81+
commandLine("hdiutil", "detach", volumeDir)
82+
}
83+
}
84+
}
85+
}

gradle/libs.versions.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[versions]
22
groovy = "3.0.15"
33
spock = "2.1-groovy-3.0"
4-
# Iguana (2023.2.1.7) Canary 7
5-
testAndroidStudioVersion = "2023.2.1.7"
4+
# Ladybug Patch 1 (2024.2.1.10)
5+
testAndroidStudioVersion = "2024.2.1.10"
66
testAndroidSdkVersion = "7.3.0"
77

88
[libraries]

src/test/groovy/org/gradle/profiler/AndroidStudioIntegrationTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import spock.lang.Requires
1313
import static org.gradle.profiler.studio.AndroidStudioTestSupport.setupLocalProperties
1414

1515
/**
16-
* If running this tests with Android Studio Giraffe (2022.3) or later you need ANDROID_HOME or ANDROID_SDK_ROOT set or
17-
* having Android sdk installed in <user.home>/Library/Android/sdk (e.g. on Mac /Users/<username>/Library/Android/sdk)
16+
* You need ANDROID_HOME or ANDROID_SDK_ROOT set or
17+
* Android sdk installed in <user.home>/Library/Android/sdk (e.g. on Mac /Users/<username>/Library/Android/sdk)
1818
*/
1919
@ShowAndroidStudioLogsOnFailure
2020
@Requires({ StudioFinder.findStudioHome() })

0 commit comments

Comments
 (0)