blob: eb554866ed86dced9819bf771f64705e6ced7b59 [file] [log] [blame]
/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
import org.gradle.api.artifacts.transform.*
import java.nio.file.Files
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
ext.tasks_version = '16.0.1'
def artifactType = Attribute.of("artifactType", String)
def unpackedAar = Attribute.of("unpackedAar", Boolean)
configurations.all {
afterEvaluate {
if (canBeResolved) {
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
}
}
}
dependencies {
attributesSchema {
attribute(unpackedAar)
}
artifactTypes {
aar {
attributes.attribute(unpackedAar, false)
}
}
registerTransform(UnpackAar) {
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
}
api("com.google.android.gms:play-services-tasks:$tasks_version") {
exclude group: 'com.android.support'
}
}
tasks.withType(dokka.getClass()) {
externalDocumentationLink {
url = new URL("https://developers.google.com/android/reference/")
// This is workaround for missing package list in Google API
packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL()
}
}
abstract class UnpackAar implements TransformAction<TransformParameters.None> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
@Override
void transform(TransformOutputs outputs) {
ZipFile zip = new ZipFile(inputArtifact.get().asFile)
try {
for (entry in zip.entries()) {
if (!entry.isDirectory() && entry.name.endsWith(".jar")) {
unzipEntryTo(zip, entry, outputs.file(entry.name))
}
}
} finally {
zip.close()
}
}
private static void unzipEntryTo(ZipFile zip, ZipEntry entry, File output) {
InputStream stream = zip.getInputStream(entry)
try {
Files.copy(stream, output.toPath())
} finally {
stream.close()
}
}
}