aboutsummaryrefslogtreecommitdiffstats
path: root/integration/kotlinx-coroutines-play-services/build.gradle
blob: 61201faeb797fad28654989ab03941d57bea4131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.nio.file.Files
import java.nio.file.NoSuchFileException
import java.util.zip.ZipEntry
import java.util.zip.ZipFile

/*
 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

ext.tasks_version = '16.0.1'

def attr = Attribute.of("artifactType", String.class)
configurations {
    aar {
        attributes { attribute(attr, ArtifactTypeDefinition.JAR_TYPE) }
        sourceSets.main.compileClasspath += it
        sourceSets.test.compileClasspath += it
        sourceSets.test.runtimeClasspath += it
    }
}

dependencies {
    registerTransform {
        from.attribute(attr, "aar")
        to.attribute(attr, "jar")
        artifactTransform(ExtractJars.class)
    }

    aar("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()
    }

    afterEvaluate {
        classpath += project.configurations.aar.files
    }
}

class ExtractJars extends ArtifactTransform {
    @Override
    List<File> transform(File input) {
        unzip(input)

        List<File> jars = new ArrayList<>()
        outputDirectory.traverse(nameFilter: ~/.*\.jar/) { jars += it }

        return jars
    }

    private void unzip(File zipFile) {
        ZipFile zip
        try {
            zip = new ZipFile(zipFile)
            for (entry in zip.entries()) {
                unzipEntryTo(zip, entry)
            }
        } finally {
            if (zip != null) zip.close()
        }
    }

    private void unzipEntryTo(ZipFile zip, ZipEntry entry) {
        File output = new File(outputDirectory, entry.name)
        if (entry.isDirectory()) {
            output.mkdirs()
        } else {
            InputStream stream
            try {
                stream = zip.getInputStream(entry)
                Files.copy(stream, output.toPath())
            } catch (NoSuchFileException ignored) {
            } finally {
                if (stream != null) stream.close()
            }
        }
    }
}