<commit_before>/*
 * Copyright 2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.caching.internal.packaging


import org.gradle.integtests.fixtures.DirectoryBuildCacheFixture
import org.gradle.integtests.fixtures.daemon.DaemonIntegrationSpec
import spock.lang.Issue
import spock.lang.Unroll

class BuildCacheEntryPackingIntegrationTest extends DaemonIntegrationSpec implements DirectoryBuildCacheFixture {
    @Issue("https://github.com/gradle/gradle/issues/9877")
    @Unroll
    def "can store and load files having #type characters in name (default file encoding #fileEncoding)"() {
        def outputFile = file(fileName)

        buildFile << """
            println "> File encoding: \${System.getProperty("file.encoding")}"
            println "> Default charset: \${java.nio.charset.Charset.defaultCharset()}"

            task createFile {
                outputs.file("$fileName")
                outputs.cacheIf { true }
                doLast {
                    file("$fileName").text = "output"
                }
            }
        """

        when:
        withBuildCache().run"createFile", "-Dfile.encoding=$fileEncoding", "--info"
        then:
        output.contains("> Default charset: $fileEncoding")
        executedAndNotSkipped(":createFile")

        when:
        assert outputFile.delete()
        withBuildCache().run"createFile", "-Dfile.encoding=$fileEncoding", "--info"
        skipped(":createFile")

        then:
        output.contains("> Default charset: $fileEncoding")
        outputFile.text == "output"

        where:
        [type, fileName, fileEncoding] << [
            [
                "ascii-only": "input-file.txt",
                "chinese-simplified": "敏捷的棕色狐狸跳过了懒狗.txt",
                "chinese-traditional": "敏捷的棕色狐狸跳過了懶狗.txt",
                "cyrillic": "здравствуйте.txt",
                "hungarian": "Dezső.txt",
                "space": "input file.txt",
                "zwnj": "input\u200cfile.txt",
                "url-quoted": "input%<file>#2.txt",
            ].entrySet(),
            [
                "UTF-8",
                "ISO-8859-1",
                "ISO-8859-2",
                "ISO-8859-5",
            ]
        ].combinations { text, encoding -> [text.key, text.value, encoding] }
    }
}
<commit_msg>Try breaking things with Windows-1251<commit_after>/*
 * Copyright 2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.caching.internal.packaging


import org.gradle.integtests.fixtures.DirectoryBuildCacheFixture
import org.gradle.integtests.fixtures.daemon.DaemonIntegrationSpec
import spock.lang.Issue
import spock.lang.Unroll

class BuildCacheEntryPackingIntegrationTest extends DaemonIntegrationSpec implements DirectoryBuildCacheFixture {
    @Issue("https://github.com/gradle/gradle/issues/9877")
    @Unroll
    def "can store and load files having #type characters in name (default file encoding #fileEncoding)"() {
        def outputFile = file(fileName)

        buildFile << """
            println "> File encoding: \${System.getProperty("file.encoding")}"
            println "> Default charset: \${java.nio.charset.Charset.defaultCharset()}"

            task createFile {
                outputs.file("$fileName")
                outputs.cacheIf { true }
                doLast {
                    file("$fileName").text = "output"
                }
            }
        """

        when:
        withBuildCache().run("createFile", "-Dfile.encoding=$fileEncoding", "--info")
        then:
        output.contains("> Default charset: $fileEncoding")
        executedAndNotSkipped(":createFile")

        when:
        assert outputFile.delete()
        withBuildCache().run("createFile", "-Dfile.encoding=$fileEncoding", "--info")
        skipped(":createFile")

        then:
        output.contains("> Default charset: $fileEncoding")
        outputFile.text == "output"

        where:
        [type, fileName, fileEncoding] << [
            [
                "ascii-only": "input-file.txt",
                "chinese-simplified": "敏捷的棕色狐狸跳过了懒狗.txt",
                "chinese-traditional": "敏捷的棕色狐狸跳過了懶狗.txt",
                "cyrillic": "АдрМНИн.txt",
                "hungarian": "Dezső.txt",
                "space": "input file.txt",
                "zwnj": "input\u200cfile.txt",
                "url-quoted": "input%<file>#2.txt",
            ].entrySet(),
            [
                "UTF-8",
                "ISO-8859-1",
                "ISO-8859-2",
                "windows-1251",
            ]
        ].combinations { text, encoding -> [text.key, text.value, encoding] }
    }
}

{'fraction_non_alphanumeric': 0.11744206307719114, 'fraction_numerical': 0.011674507753964105, 'mean_word_length': 2.2301631963984243, 'pattern_counts': {'":': 20, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4370936', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1606, 'n_words': 394}