<commit_before>/*
 * Copyright 2016 <NAME>
 *
 * 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 com.github.rodm.teamcity

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.junit.Before
import org.junit.Ignore
import org.junit.Test

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
import static org.junit.Assert.assertEquals

class SamplesTest {

    private File samplesDir

    @Before
    public void setup() throws IOException {
        samplesDir = new File('samples')
    }

    @Test
    public void serverPlugin() {
        File projectDir = new File(samplesDir, 'server-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void serverPluginWithAlternativeBuildFile() {
        File projectDir = new File(samplesDir, 'server-plugin')
        BuildResult result = executeBuild(projectDir, '-b', 'build-alt.gradle', 'clean', 'build')

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void agentServerPlugin() {
        File projectDir = new File(samplesDir, 'agent-server-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void agentToolPlugin() {
        File projectDir = new File(samplesDir, 'agent-tool-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void multiProjectPlugin() {
        File projectDir = new File(samplesDir, 'multi-project-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':server:build').getOutcome(), SUCCESS)
    }

    @Test @Ignore("currently failing to download the kotlin-gradle-plugin")
    public void 'build kotlin plugin'() {
        File projectDir = new File(samplesDir, 'kotlin-plugin')
        BuildResult result = executeBuildWithVersion(projectDir, '3.3')

        assertEquals(result.task(':server:build').getOutcome(), SUCCESS)
    }

    private BuildResult executeBuild(File projectDir, String... args = ['clean', 'build']) {
        BuildResult result = GradleRunner.create()
                .withProjectDir(projectDir)
                .withArguments(args)
                .withPluginClasspath()
                .forwardOutput()
                .build()
        return result
    }

    private BuildResult executeBuildWithVersion(File projectDir, String version, String... args = ['clean', 'build']) {
        BuildResult result = GradleRunner.create()
                .withProjectDir(projectDir)
                .withArguments(args)
                .withPluginClasspath()<commit_msg>Re-enable Kotlin plugin test<commit_after>/*
 * Copyright 2016 <NAME>
 *
 * 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 com.github.rodm.teamcity

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.junit.Before
import org.junit.Test

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
import static org.junit.Assert.assertEquals

class SamplesTest {

    private File samplesDir

    @Before
    public void setup() throws IOException {
        samplesDir = new File('samples')
    }

    @Test
    public void serverPlugin() {
        File projectDir = new File(samplesDir, 'server-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void serverPluginWithAlternativeBuildFile() {
        File projectDir = new File(samplesDir, 'server-plugin')
        BuildResult result = executeBuild(projectDir, '-b', 'build-alt.gradle', 'clean', 'build')

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void agentServerPlugin() {
        File projectDir = new File(samplesDir, 'agent-server-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void agentToolPlugin() {
        File projectDir = new File(samplesDir, 'agent-tool-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':build').getOutcome(), SUCCESS)
    }

    @Test
    public void multiProjectPlugin() {
        File projectDir = new File(samplesDir, 'multi-project-plugin')
        BuildResult result = executeBuild(projectDir)

        assertEquals(result.task(':server:build').getOutcome(), SUCCESS)
    }

    @Test
    public void 'build kotlin plugin'() {
        File projectDir = new File(samplesDir, 'kotlin-plugin')
        BuildResult result = executeBuildWithVersion(projectDir, '3.3')

        assertEquals(result.task(':server:build').getOutcome(), SUCCESS)
    }

    private BuildResult executeBuild(File projectDir, String... args = ['clean', 'build']) {
        BuildResult result = GradleRunner.create()
                .withProjectDir(projectDir)
                .withArguments(args)
                .withPluginClasspath()
                .forwardOutput()
                .build()
        return result
    }

    private BuildResult executeBuildWithVersion(File projectDir, String version, String... args = ['clean', 'build']) {
        BuildResult result = GradleRunner.create()
                .withProjectDir(projectDir)
                .withArguments(args)
                .withPluginClasspath()
{'fraction_non_alphanumeric': 0.1023538344722855, 'fraction_numerical': 0.0030372057706909645, 'mean_word_length': 3.052923076923077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2891253', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1693, 'n_words': 484}