fun generateGradleW()

in aspoet/src/main/kotlin/com/google/androidstudiopoet/generators/project/GradlewGenerator.kt [31:70]


    fun generateGradleW(root: String, projectBlueprint: ProjectBlueprint) {

        val gradlew = "gradlew"
        val gradlewbat = "gradlew.bat"

        if (!File(getAssetsFolderPath()).exists() ||
                !File(getAssetsFolderPath(), gradlew).exists() ||
                !File(getAssetsFolderPath(), gradlewbat).exists() ||
                !File(getAssetsFolderPath(), "gradle/wrapper").exists()
                ) {

            println("AS Poet needs network access to download gradle files from Github " +
                    "\nhttps://github.com/android/android-studio-poet/tree/master/resources/gradle-assets?ref=$ref " +
                    "\nplease copy/paste the gradle folder directly to the generated root folder")
            return
        }

        val gradleWFile = File(root, gradlew).toPath()
        Files.copy(FileInputStream(File(getAssetsFolderPath(), gradlew)), gradleWFile, StandardCopyOption.REPLACE_EXISTING)
        Files.copy(FileInputStream(File(getAssetsFolderPath(), gradlewbat)), File(root, gradlewbat).toPath(), StandardCopyOption.REPLACE_EXISTING)

        Runtime.getRuntime().exec("chmod u+x " + gradleWFile)

        val gradleFolder = File(root, "gradle")
        gradleFolder.mkdir()
        val gradleWrapperFolder = File(gradleFolder, "wrapper")
        gradleWrapperFolder.mkdir()

        val sourceFolder = File(getAssetsFolderPath(), "gradle/wrapper")

        val gradleWrapperJar = "gradle-wrapper.jar"
        val gradleWrapperProperties = "gradle-wrapper.properties"

        Files.copy(FileInputStream(File(sourceFolder, gradleWrapperJar)),
                File(gradleWrapperFolder, gradleWrapperJar).toPath(),
                StandardCopyOption.REPLACE_EXISTING)

        File(gradleWrapperFolder, gradleWrapperProperties).
                writeText(gradleWrapper(projectBlueprint.gradleVersion))
    }