-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #579 from gradle/asodja/upgrade-profiler
Make gradle-profiler work with Android Studio Koala and Ladybug
- Loading branch information
Showing
20 changed files
with
252 additions
and
180 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
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
85 changes: 85 additions & 0 deletions
85
buildSrc/src/main/kotlin/tasks/ExtractAndroidStudioTask.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,85 @@ | ||
package tasks | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.FileSystemOperations | ||
import org.gradle.api.file.RelativePath | ||
import org.gradle.api.internal.file.FileOperations | ||
import org.gradle.api.tasks.* | ||
import org.gradle.process.ExecOperations | ||
import org.gradle.work.DisableCachingByDefault | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
|
||
@DisableCachingByDefault(because = "Not worth caching") | ||
abstract class ExtractAndroidStudioTask @Inject constructor( | ||
private val execOps: ExecOperations, | ||
private val fsOps: FileSystemOperations, | ||
private val fileOps: FileOperations | ||
) : DefaultTask() { | ||
|
||
companion object { | ||
private const val VOLUME_NAME = "AndroidStudioForGradle" | ||
} | ||
|
||
@get:InputFiles | ||
@get:PathSensitive(PathSensitivity.NONE) | ||
abstract val androidStudioLocation: ConfigurableFileCollection | ||
|
||
@get:OutputDirectory | ||
abstract val outputDir: DirectoryProperty | ||
|
||
@TaskAction | ||
fun extract() { | ||
val androidStudioDistribution = androidStudioLocation.singleFile | ||
when { | ||
androidStudioDistribution.name.endsWith(".dmg") -> extractDmg(androidStudioDistribution) | ||
else -> extractZipOrTar(androidStudioDistribution) | ||
} | ||
} | ||
|
||
fun extractZipOrTar(androidStudioDistribution: File) { | ||
fsOps.copy { | ||
val src = when { | ||
androidStudioDistribution.name.endsWith(".tar.gz") -> fileOps.tarTree(androidStudioDistribution) | ||
else -> fileOps.zipTree(androidStudioDistribution) | ||
} | ||
|
||
from(src) { | ||
eachFile { | ||
// Remove top folder when unzipping, that way we get rid of Android Studio.app folder that can cause issues on Mac | ||
// where MacOS would kill the Android Studio process right after start, issue: https://github.com/gradle/gradle-profiler/issues/469 | ||
@Suppress("SpreadOperator") | ||
relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray()) | ||
} | ||
} | ||
|
||
into(outputDir) | ||
} | ||
} | ||
|
||
fun extractDmg(androidStudioDistribution: File) { | ||
val volumeDir = "/Volumes/$VOLUME_NAME" | ||
val srcDir = "/Volumes/$VOLUME_NAME/Android Studio.app" | ||
require(!File(srcDir).exists()) { | ||
"The directory $srcDir already exists. Please unmount it via `hdiutil detach $volumeDir`." | ||
} | ||
|
||
try { | ||
execOps.exec { | ||
commandLine("hdiutil", "attach", androidStudioDistribution.absolutePath, "-mountpoint", volumeDir) | ||
} | ||
|
||
outputDir.get().asFile.mkdirs() | ||
execOps.exec { | ||
commandLine("cp", "-r", "$volumeDir/Android Studio.app/Contents", outputDir.get().asFile.absolutePath) | ||
} | ||
} finally { | ||
execOps.exec { | ||
commandLine("hdiutil", "detach", volumeDir) | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.