Search in sources :

Example 1 with DirectoryReport

use of org.gradle.api.reporting.DirectoryReport in project gradle by gradle.

the class Test method executeTests.

@TaskAction
public void executeTests() {
    LogLevel currentLevel = determineCurrentLogLevel();
    TestLogging levelLogging = testLogging.get(currentLevel);
    TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
    TestEventLogger eventLogger = new TestEventLogger(getTextOutputFactory(), currentLevel, levelLogging, exceptionFormatter);
    addTestListener(eventLogger);
    addTestOutputListener(eventLogger);
    if (getFilter().isFailOnNoMatchingTests() && !getFilter().getIncludePatterns().isEmpty()) {
        addTestListener(new NoMatchingTestsReporter("No tests found for given includes: " + getFilter().getIncludePatterns()));
    }
    File binaryResultsDir = getBinResultsDir();
    getProject().delete(binaryResultsDir);
    getProject().mkdir(binaryResultsDir);
    Map<String, TestClassResult> results = new HashMap<String, TestClassResult>();
    TestOutputStore testOutputStore = new TestOutputStore(binaryResultsDir);
    TestOutputStore.Writer outputWriter = testOutputStore.writer();
    TestReportDataCollector testReportDataCollector = new TestReportDataCollector(results, outputWriter);
    addTestListener(testReportDataCollector);
    addTestOutputListener(testReportDataCollector);
    TestCountLogger testCountLogger = new TestCountLogger(getProgressLoggerFactory());
    addTestListener(testCountLogger);
    testListenerInternalBroadcaster.add(new TestListenerAdapter(testListenerBroadcaster.getSource(), testOutputListenerBroadcaster.getSource()));
    TestResultProcessor resultProcessor = new StateTrackingTestResultProcessor(testListenerInternalBroadcaster.getSource());
    if (testExecuter == null) {
        testExecuter = new DefaultTestExecuter(getProcessBuilderFactory(), getActorFactory(), getModuleRegistry(), getServices().get(BuildOperationWorkerRegistry.class), getServices().get(BuildOperationExecutor.class), getServices().get(StartParameter.class).getMaxWorkerCount());
    }
    JavaVersion javaVersion = getJavaVersion();
    if (!javaVersion.isJava6Compatible()) {
        throw new UnsupportedJavaRuntimeException("Support for test execution using Java 5 or earlier was removed in Gradle 3.0.");
    }
    try {
        testExecuter.execute(this, resultProcessor);
    } finally {
        testExecuter = null;
        testListenerBroadcaster.removeAll();
        testOutputListenerBroadcaster.removeAll();
        testListenerInternalBroadcaster.removeAll();
        outputWriter.close();
    }
    new TestResultSerializer(binaryResultsDir).write(results.values());
    TestResultsProvider testResultsProvider = new InMemoryTestResultsProvider(results.values(), testOutputStore);
    try {
        if (testReporter == null) {
            testReporter = new DefaultTestReport(getBuildOperationProcessor());
        }
        JUnitXmlReport junitXml = reports.getJunitXml();
        if (junitXml.isEnabled()) {
            TestOutputAssociation outputAssociation = junitXml.isOutputPerTestCase() ? TestOutputAssociation.WITH_TESTCASE : TestOutputAssociation.WITH_SUITE;
            Binary2JUnitXmlReportGenerator binary2JUnitXmlReportGenerator = new Binary2JUnitXmlReportGenerator(junitXml.getDestination(), testResultsProvider, outputAssociation, getBuildOperationProcessor(), getInetAddressFactory().getHostname());
            binary2JUnitXmlReportGenerator.generate();
        }
        DirectoryReport html = reports.getHtml();
        if (!html.isEnabled()) {
            getLogger().info("Test report disabled, omitting generation of the HTML test report.");
        } else {
            testReporter.generateReport(testResultsProvider, html.getDestination());
        }
    } finally {
        CompositeStoppable.stoppable(testResultsProvider).stop();
        testReporter = null;
        testFramework = null;
    }
    if (testCountLogger.hadFailures()) {
        handleTestFailures();
    }
}
Also used : TestResultSerializer(org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer) InMemoryTestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider) TestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.TestResultsProvider) InMemoryTestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider) HashMap(java.util.HashMap) TestResultProcessor(org.gradle.api.internal.tasks.testing.TestResultProcessor) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestClassResult(org.gradle.api.internal.tasks.testing.junit.result.TestClassResult) TestCountLogger(org.gradle.api.internal.tasks.testing.logging.TestCountLogger) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) JavaVersion(org.gradle.api.JavaVersion) LogLevel(org.gradle.api.logging.LogLevel) TestEventLogger(org.gradle.api.internal.tasks.testing.logging.TestEventLogger) TestReportDataCollector(org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector) StartParameter(org.gradle.StartParameter) TestOutputAssociation(org.gradle.api.internal.tasks.testing.junit.result.TestOutputAssociation) TestLogging(org.gradle.api.tasks.testing.logging.TestLogging) NoMatchingTestsReporter(org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter) UnsupportedJavaRuntimeException(org.gradle.internal.jvm.UnsupportedJavaRuntimeException) TestListenerAdapter(org.gradle.api.internal.tasks.testing.results.TestListenerAdapter) DefaultTestExecuter(org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter) Binary2JUnitXmlReportGenerator(org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator) TestOutputStore(org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore) TestExceptionFormatter(org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter) File(java.io.File) DefaultTestReport(org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport) DirectoryReport(org.gradle.api.reporting.DirectoryReport) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with DirectoryReport

use of org.gradle.api.reporting.DirectoryReport in project gradle by gradle.

the class Test method handleTestFailures.

private void handleTestFailures() {
    String message = "There were failing tests";
    DirectoryReport htmlReport = reports.getHtml();
    if (htmlReport.isEnabled()) {
        String reportUrl = new ConsoleRenderer().asClickableFileUrl(htmlReport.getEntryPoint());
        message = message.concat(". See the report at: " + reportUrl);
    } else {
        DirectoryReport junitXmlReport = reports.getJunitXml();
        if (junitXmlReport.isEnabled()) {
            String resultsUrl = new ConsoleRenderer().asClickableFileUrl(junitXmlReport.getEntryPoint());
            message = message.concat(". See the results at: " + resultsUrl);
        }
    }
    if (getIgnoreFailures()) {
        getLogger().warn(message);
    } else {
        throw new GradleException(message);
    }
}
Also used : GradleException(org.gradle.api.GradleException) ConsoleRenderer(org.gradle.internal.logging.ConsoleRenderer) DirectoryReport(org.gradle.api.reporting.DirectoryReport)

Example 3 with DirectoryReport

use of org.gradle.api.reporting.DirectoryReport in project gradle by gradle.

the class BuildDashboardPlugin method apply.

public void apply(final Project project) {
    project.getPluginManager().apply(ReportingBasePlugin.class);
    final GenerateBuildDashboard buildDashboardTask = project.getTasks().create(BUILD_DASHBOARD_TASK_NAME, GenerateBuildDashboard.class);
    buildDashboardTask.setDescription("Generates a dashboard of all the reports produced by this build.");
    buildDashboardTask.setGroup("reporting");
    DirectoryReport htmlReport = buildDashboardTask.getReports().getHtml();
    ConventionMapping htmlReportConventionMapping = new DslObject(htmlReport).getConventionMapping();
    htmlReportConventionMapping.map("destination", new Callable<Object>() {

        public Object call() throws Exception {
            return project.getExtensions().getByType(ReportingExtension.class).file("buildDashboard");
        }
    });
    Action<Task> captureReportingTasks = new Action<Task>() {

        public void execute(Task task) {
            if (!(task instanceof Reporting)) {
                return;
            }
            Reporting reporting = (Reporting) task;
            buildDashboardTask.aggregate(reporting);
            if (!task.equals(buildDashboardTask)) {
                task.finalizedBy(buildDashboardTask);
            }
        }
    };
    for (Project aProject : project.getAllprojects()) {
        aProject.getTasks().all(captureReportingTasks);
    }
}
Also used : DslObject(org.gradle.api.internal.plugins.DslObject) DslObject(org.gradle.api.internal.plugins.DslObject) Reporting(org.gradle.api.reporting.Reporting) DirectoryReport(org.gradle.api.reporting.DirectoryReport) ConventionMapping(org.gradle.api.internal.ConventionMapping) GenerateBuildDashboard(org.gradle.api.reporting.GenerateBuildDashboard)

Aggregations

DirectoryReport (org.gradle.api.reporting.DirectoryReport)3 File (java.io.File)1 HashMap (java.util.HashMap)1 StartParameter (org.gradle.StartParameter)1 GradleException (org.gradle.api.GradleException)1 JavaVersion (org.gradle.api.JavaVersion)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 DslObject (org.gradle.api.internal.plugins.DslObject)1 NoMatchingTestsReporter (org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter)1 TestResultProcessor (org.gradle.api.internal.tasks.testing.TestResultProcessor)1 DefaultTestExecuter (org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter)1 DefaultTestReport (org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport)1 Binary2JUnitXmlReportGenerator (org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator)1 InMemoryTestResultsProvider (org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider)1 TestClassResult (org.gradle.api.internal.tasks.testing.junit.result.TestClassResult)1 TestOutputAssociation (org.gradle.api.internal.tasks.testing.junit.result.TestOutputAssociation)1 TestOutputStore (org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore)1 TestReportDataCollector (org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector)1 TestResultSerializer (org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer)1 TestResultsProvider (org.gradle.api.internal.tasks.testing.junit.result.TestResultsProvider)1