Java Code Examples for org.gradle.api.tasks.TaskProvider#get()

The following examples show how to use org.gradle.api.tasks.TaskProvider#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void Cpd_shouldAllowConfigurationOfDefaultTaskProperties(Project project, TaskProvider<Cpd> cpdCheck) {
    // Given:
    Task dependantTask = project.getTasks().create("dependant");

    // When:
    cpdCheck.configure(task -> {
        task.setDependsOn(singleton(dependantTask));
        task.setDescription("Execute me!");
        task.setEnabled(false);
        task.setExcludes(asList("*.kt", "*.txt"));
        task.setGroup("check");
    });

    // Then:
    Cpd actual = cpdCheck.get();
    assertThat(actual.getDependsOn()).containsOnly(dependantTask);
    assertThat(actual.getDescription()).isEqualTo("Execute me!");
    assertThat(actual.getEnabled()).isFalse();
    assertThat(actual.getExcludes()).containsOnly("*.kt", "*.txt");
    assertThat(actual.getGroup()).isEqualTo("check");
}
 
Example 2
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void Cpd_shouldAllowConfigurationOfSourceTaskProperties(TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> {
        task.exclude("**/literal/*");
        task.exclude("**/*z*.java");
        task.include("**/*2.java");
        task.source(testFile(JAVA, "."));
    });
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThat(actual.getExcludes()).containsOnly("**/literal/*", "**/*z*.java");
    assertThat(actual.getIncludes()).containsOnly("**/*2.java");
    assertThat(actual.getSource()).containsOnly(testFile(JAVA, "de/aaschmid/identifier/Identifier2.java"));
}
 
Example 3
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void Cpd_shouldHaveCorrectTaskInputs(Project project, TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> {
        task.reports(report -> {
            report.getText().setDestination(project.file(project.getBuildDir() + "/cpdCheck.text"));
            report.getText().setEnabled(true);
        });
        task.source(testFile(JAVA, "de/aaschmid/clazz/"));
    });
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThat(actual.getInputs().getProperties()).hasSize(50);
    assertThat(actual.getInputs().getSourceFiles()).containsExactlyInAnyOrderElementsOf(testFilesRecurseIn(JAVA, "de/aaschmid/clazz"));
}
 
Example 4
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void Cpd_shouldHaveCorrectTaskOutputs(Project project, TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> {
        task.reports(report -> {
            report.getCsv().setDestination(project.file(project.getBuildDir() + "/cpd.csv"));
            report.getCsv().setEnabled(false);
            report.getText().setDestination(project.file("cpdCheck.txt"));
            report.getText().setEnabled(true);
            report.getVs().setDestination(project.file("cpd.vs"));
        });
        task.source(testFile(JAVA, "."));
    });
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThat(actual.getOutputs().getFiles()).containsExactlyInAnyOrder(
            project.file(project.getBuildDir() + "/cpd.csv"),
            project.file("cpdCheck.txt"),
            project.file("cpd.vs"),
            project.file(project.getBuildDir() + "/reports/cpd/cpdCheck.xml")
    );
}
 
Example 5
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void Cpd_shouldThrowInvalidUserDataExceptionIfTwoReportsAreEnabled(TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> task.reports(report -> {
        report.getCsv().setEnabled(false);
        report.getText().setEnabled(false);
        report.getVs().setEnabled(false);
        report.getXml().setEnabled(false);
    }));
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThatThrownBy(() -> actual.getActions().forEach(a -> a.execute(actual)))
            .isInstanceOf(InvalidUserDataException.class)
            .hasMessage("Task 'cpdCheck' requires at least one enabled report.");
}
 
Example 6
Source File: CpdPluginTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void CpdPlugin_shouldCreateAndConfigureCpdCheckTaskWithCorrectDefaultValues(Project project, Configuration cpdConfiguration, TaskProvider<Cpd> cpdCheck) {
    Cpd t = cpdCheck.get();

    assertThat(t).isInstanceOf(Cpd.class);
    assertThat(t.getDescription()).isEqualTo("Run CPD analysis for all sources");
    assertThat(t.getGroup()).isNull();

    assertThat(t.getEncoding()).isEqualTo(System.getProperty("file.encoding"));
    assertThat(t.getIgnoreAnnotations()).isFalse();
    assertThat(t.getIgnoreFailures()).isFalse();
    assertThat(t.getIgnoreIdentifiers()).isFalse();
    assertThat(t.getIgnoreLiterals()).isFalse();
    assertThat(t.getLanguage()).isEqualTo("java");
    assertThat(t.getMinimumTokenCount()).isEqualTo(50);

    assertThat(t.getPmdClasspath()).isEqualTo(cpdConfiguration);

    assertThat(t.getReports().getCsv().getDestination()).isEqualTo(project.file("build/reports/cpd/cpdCheck.csv"));
    assertThat(t.getReports().getCsv().isEnabled()).isFalse();
    assertThat(t.getReports().getText().getDestination()).isEqualTo(project.file("build/reports/cpd/cpdCheck.text"));
    assertThat(t.getReports().getText().isEnabled()).isFalse();
    assertThat(t.getReports().getVs().getDestination()).isEqualTo(project.file("build/reports/cpd/cpdCheck.vs"));
    assertThat(t.getReports().getVs().isEnabled()).isFalse();
    assertThat(t.getReports().getXml().getDestination()).isEqualTo(project.file("build/reports/cpd/cpdCheck.xml"));
    assertThat(t.getReports().getXml().isEnabled()).isTrue();

    assertThat(t.getSkipDuplicateFiles()).isFalse();
    assertThat(t.getSkipLexicalErrors()).isFalse();
    assertThat(t.getSkipBlocks()).isTrue();
    assertThat(t.getSkipBlocksPattern()).isEqualTo(Tokenizer.DEFAULT_SKIP_BLOCKS_PATTERN);

    assertThat(t.getSource()).isEmpty();
}
 
Example 7
Source File: CpdPluginTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void CpdPlugin_shouldAllowConfigureCpdCheckTaskViaCpdExtension(Project project, CpdExtension cpd, TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpd.setEncoding("UTF-8");
    cpd.setIgnoreAnnotations(true);
    cpd.setIgnoreFailures(true);
    cpd.setIgnoreIdentifiers(true);
    cpd.setIgnoreLiterals(true);
    cpd.setLanguage("ruby");
    cpd.setMinimumTokenCount(25);
    cpd.setReportsDir(project.file("cpd-reports"));
    cpd.setSkipDuplicateFiles(true);
    cpd.setSkipLexicalErrors(true);
    cpd.setSkipBlocks(false);
    cpd.setSkipBlocksPattern("<|>");

    // When:
    Cpd task = cpdCheck.get();

    // Then:
    assertThat(task.getEncoding()).isEqualTo("UTF-8");
    assertThat(task.getIgnoreAnnotations()).isTrue();
    assertThat(task.getIgnoreFailures()).isTrue();
    assertThat(task.getIgnoreIdentifiers()).isTrue();
    assertThat(task.getIgnoreLiterals()).isTrue();
    assertThat(task.getLanguage()).isEqualTo("ruby");
    assertThat(task.getMinimumTokenCount()).isEqualTo(25);
    assertThat(task.getReports().getCsv().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.csv"));
    assertThat(task.getReports().getText().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.text"));
    assertThat(task.getReports().getVs().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.vs"));
    assertThat(task.getReports().getXml().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.xml"));
    assertThat(task.getSkipDuplicateFiles()).isTrue();
    assertThat(task.getSkipLexicalErrors()).isTrue();
    assertThat(task.getSkipBlocks()).isFalse();
    assertThat(task.getSkipBlocksPattern()).isEqualTo("<|>");
}
 
Example 8
Source File: CpdVsFileReportImplTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void CpdVsFileReportImpl_shouldHaveNullAsDefaultEncoding(TaskProvider<Cpd> cpdCheck) {
    // When:
    CpdVsFileReportImpl result = new CpdVsFileReportImpl("vs", cpdCheck.get());

    // Then:
    assertThat(result).isNotNull();
}
 
Example 9
Source File: CpdTextFileReportImplTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void CpdTextFileReportImpl_shouldHaveDefaultLineSeparatorAndTrimLeadingCommonSourceWhitespaces(TaskProvider<Cpd> cpdCheck) {
    // When:
    CpdTextFileReportImpl result = new CpdTextFileReportImpl("text", cpdCheck.get());

    // Then:
    assertThat(result.getLineSeparator()).isEqualTo(CpdTextFileReport.DEFAULT_LINE_SEPARATOR);
    assertThat(result.getTrimLeadingCommonSourceWhitespaces()).isEqualTo(CpdTextFileReport.DEFAULT_TRIM_LEADING_COMMON_SOURCE_WHITESPACE);
}
 
Example 10
Source File: CpdXmlFileReportImplTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void CpdXmlFileReportImpl_shouldHaveNullAsDefaultEncoding(TaskProvider<Cpd> cpdCheck) {
    // When:
    CpdXmlFileReportImpl result = new CpdXmlFileReportImpl("csv", cpdCheck.get());

    // Then:
    assertThat(result.getEncoding()).isNull();
}
 
Example 11
Source File: CpdCsvFileReportImplTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void CpdCsvFileReportImpl_shouldHaveDefaults(TaskProvider<Cpd> cpdCheck) {
    // When:
    CpdCsvFileReportImpl result = new CpdCsvFileReportImpl("csv", cpdCheck.get());

    // Then:
    assertThat(result.getSeparator()).isEqualTo(CpdCsvFileReport.DEFAULT_SEPARATOR);
    assertThat(result.isIncludeLineCount()).isEqualTo(CpdCsvFileReport.DEFAULT_INCLUDE_LINE_COUNT);
}
 
Example 12
Source File: CpdCsvFileReportImplTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void setSeparator_shouldThrowInvalidUserDataExceptionIfSeparatorIsSetToNull(TaskProvider<Cpd> cpdCheck) {
    // Given:
    CpdCsvFileReportImpl underTest = new CpdCsvFileReportImpl("csv", cpdCheck.get());

    // Expect:
    assertThatThrownBy(() -> underTest.setSeparator(null))
            .isInstanceOf(InvalidUserDataException.class)
            .hasMessage("CSV report 'separator' must not be null.");
}
 
Example 13
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void Cpd_shouldAllowConfigurationOfCpdTaskProperties(Project project, TaskProvider<Cpd> cpdCheck) {
    // Given:
    List<File> expectedPmdClasspath = createProjectFiles(project, "libs/pmd-classpath/");

    // When:
    cpdCheck.configure(task -> {
        task.setDescription("Execute me!");
        task.setGroup("check");

        task.setEncoding("ISO-8859-1");
        task.setIgnoreAnnotations(true);
        task.setIgnoreFailures(true);
        task.setIgnoreIdentifiers(true);
        task.setIgnoreLiterals(true);
        task.setLanguage("cpp");
        task.setMinimumTokenCount(10);
        task.setPmdClasspath(project.files(expectedPmdClasspath));
        task.setSkipDuplicateFiles(true);
        task.setSkipLexicalErrors(true);
        task.setSkipBlocks(false);
        task.setSkipBlocksPattern("<template|>");
    });

    // Then:
    Cpd actual = cpdCheck.get();
    assertThat(actual.getEncoding()).isEqualTo("ISO-8859-1");
    assertThat(actual.getIgnoreAnnotations()).isTrue();
    assertThat(actual.getIgnoreFailures()).isTrue();
    assertThat(actual.getIgnoreIdentifiers()).isTrue();
    assertThat(actual.getIgnoreLiterals()).isTrue();
    assertThat(actual.getLanguage()).isEqualTo("cpp");
    assertThat(actual.getMinimumTokenCount()).isEqualTo(10);
    assertThat(actual.getPmdClasspath()).containsExactlyInAnyOrderElementsOf(expectedPmdClasspath);
    assertThat(actual.getSkipDuplicateFiles()).isTrue();
    assertThat(actual.getSkipLexicalErrors()).isTrue();
    assertThat(actual.getSkipBlocks()).isFalse();
    assertThat(actual.getSkipBlocksPattern()).isEqualTo("<template|>");
}
 
Example 14
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void Cpd_shouldThrowInvalidUserDataExceptionIfEncodingIsNull(TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> task.setEncoding(null));
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThatThrownBy(() -> actual.getActions().forEach(a -> a.execute(actual)))
            .isInstanceOf(InvalidUserDataException.class)
            .hasMessage("Task 'cpdCheck' requires 'encoding' but was: null.");
}
 
Example 15
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void Cpd_shouldThrowInvalidUserDataExceptionIfMinimumTokenCountIsMinusOne(TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> task.setMinimumTokenCount(-1));
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThatThrownBy(() -> actual.getActions().forEach(a -> a.execute(actual)))
            .isInstanceOf(InvalidUserDataException.class)
            .hasMessageMatching("Task 'cpdCheck' requires 'minimumTokenCount' to be greater than zero.");
}
 
Example 16
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource
void getXmlRendererEncoding(String taskEncoding, String reportEncoding, String expected, TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> task.setEncoding(taskEncoding));

    CpdXmlFileReportImpl report = new CpdXmlFileReportImpl("xml", cpdCheck.get());
    report.setEncoding(reportEncoding);

    // Expect:
    assertThat(cpdCheck.get().getXmlRendererEncoding(report)).isEqualTo(expected);
}