<commit_before>/*
 * Copyright 2015 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.launcher.continuous.jdk7

import org.gradle.launcher.continuous.Java7RequiringContinuousIntegrationTest
import org.gradle.util.Requires
import org.gradle.util.TestPrecondition

import java.nio.file.Files
import java.nio.file.Paths

@Requires(TestPrecondition.NOT_WINDOWS)
class SymlinkContinuousIntegrationTest extends Java7RequiringContinuousIntegrationTest {
    def "can use symlink for input"() {
        given:
        def baseDir = file("src").createDir()
        def sourceFile = baseDir.file("A")
        sourceFile.text = "original"
        def symlink = baseDir.file("link")
        buildFile << """
    task echo {
        def symlink = file("${symlink.toURI()}")
        inputs.files symlink
        doLast {
            println "text: " + (symlink.exists() ? symlink.text:"missing")
        }
    }
"""
        when: "symlink is used as input and exists"
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(sourceFile.toURI()))
        then:
        succeeds("echo")
        executedAndNotSkipped(":echo")
        output.contains("text: original")
        when: "symlink is deleted"
        symlink.delete()
        then:
        succeeds()
        executedAndNotSkipped(":echo")
        output.contains("text: missing")
        when: "symlink is created"
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(sourceFile.toURI()))
        then:
        succeeds()
        executedAndNotSkipped(":echo")
        output.contains("text: original")
        when: "changes made to target of symlink"
        sourceFile.text = "changed"
        then:
        noBuildTriggered()

        cleanup:
        assert symlink.delete()
    }

    def "can use symlinked directory for input"() {
        given:
        def baseDir = file("src").createDir()
        def targetDir = baseDir.file("target").createDir()
        targetDir.files("A", "B")*.createFile()

        def symlink = baseDir.file("link")
        buildFile << """
    task echo {
        def symlink = files("${symlink.toURI()}")
        inputs.files symlink
        doLast {
            println "isEmpty: " + symlink.isEmpty()
        }
    }
"""
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(targetDir.toURI()))
        expect:
        succeeds("echo")
        executedAndNotSkipped(":echo")
        output.contains("isEmpty: false")
        when: "symlink is deleted"
        symlink.delete()
        then:
        noBuildTriggered()
// TODO: This behavior seems inconsistent with symlinked files
//        succeeds()
//        executedAndNotSkipped(":echo")
//        output.contains("isEmpty: true")
//        when: "symlink is created"
//        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(targetDir.toURI()))
//        then:
//        succeeds()
//        executedAndNotSkipped(":echo")
//        output.contains("isEmpty: false")
        when: "changes made to target of symlink"
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(targetDir.toURI()))
        targetDir.file("C").createFile()
        then:
        noBuildTriggered()
        when: "target directory is removed"
        targetDir.deleteDir()
        then:
        noBuildTriggered()
    }
}
<commit_msg>Symlinks are followed so it's expected that changes are watched<commit_after>/*
 * Copyright 2015 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.launcher.continuous.jdk7

import org.gradle.launcher.continuous.Java7RequiringContinuousIntegrationTest
import org.gradle.util.Requires
import org.gradle.util.TestPrecondition

import java.nio.file.Files
import java.nio.file.Paths

@Requires(TestPrecondition.NOT_WINDOWS)
class SymlinkContinuousIntegrationTest extends Java7RequiringContinuousIntegrationTest {
    def "can use symlink for input"() {
        given:
        def baseDir = file("src").createDir()
        def sourceFile = baseDir.file("A")
        sourceFile.text = "original"
        def symlink = baseDir.createDir("linkdir").file("link")
        buildFile << """
    task echo {
        def symlink = file("${symlink.toURI()}")
        inputs.files symlink
        doLast {
            println "text: " + (symlink.exists() ? symlink.text:"missing")
        }
    }
"""
        when: "symlink is used as input and exists"
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(sourceFile.toURI()))
        then:
        succeeds("echo")
        executedAndNotSkipped(":echo")
        output.contains("text: original")
        when: "symlink is deleted"
        symlink.delete()
        then:
        succeeds()
        executedAndNotSkipped(":echo")
        output.contains("text: missing")
        when: "symlink is created"
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(sourceFile.toURI()))
        then:
        succeeds()
        executedAndNotSkipped(":echo")
        output.contains("text: original")
        when: "changes made to target of symlink"
        sourceFile.text = "changed"
        then:
        noBuildTriggered()

        cleanup:
        assert symlink.delete()
    }

    def "can use symlinked directory for input"() {
        given:
        def baseDir = file("src").createDir()
        def targetDir = baseDir.file("target").createDir()
        targetDir.files("A", "B")*.createFile()

        def symlink = baseDir.createDir("linkdir").file("link")
        buildFile << """
    task echo {
        def symlink = files("${symlink.toURI()}")
        inputs.files symlink
        doLast {
            println "isEmpty: " + symlink.isEmpty()
        }
    }
"""
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(targetDir.toURI()))
        expect:
        succeeds("echo")
        executedAndNotSkipped(":echo")
        output.contains("isEmpty: false")
        when: "symlink is deleted"
        symlink.delete()
        then:
        noBuildTriggered()
        when: "changes made to target of symlink"
        Files.createSymbolicLink(Paths.get(symlink.toURI()), Paths.get(targetDir.toURI()))
        targetDir.file("C").createFile()
        then:
        succeeds("echo")
        executedAndNotSkipped(":echo")
        output.contains("isEmpty: false")
    }
}

{'fraction_non_alphanumeric': 0.11745689655172414, 'fraction_numerical': 0.002963362068965517, 'mean_word_length': 2.650442477876106, 'pattern_counts': {'":': 11, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1470556', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2152, 'n_words': 525}