Coder Social home page Coder Social logo

[BUG]: Ant + Jacoco: 'Failed to enable code coverage: TypeError: Cannot read properties of undefined (reading 'split')' about azure-pipelines-tasks HOT 2 CLOSED

ataverascrespo avatar ataverascrespo commented on May 28, 2024
[BUG]: Ant + Jacoco: 'Failed to enable code coverage: TypeError: Cannot read properties of undefined (reading 'split')'

from azure-pipelines-tasks.

Comments (2)

ataverascrespo avatar ataverascrespo commented on May 28, 2024

Adding this as a comment, as to not make the description too long.

I looked into the JaCoCo code coverage functions and believe I found the root cause of the issue in the enableCodeCoverage() function in the jacoco.ant.cc.enabler class.

In enableCodeCoverage(), the global sourceDirs variable is set to the value of ccProps["sourcedirectories"], which contains the value of the INPUT_SRCDIRECTORIES environment variable passed from the Ant task.

From there, addCodeCoverageData() is called, which then calls getSourceFilter().

    protected getSourceFilter(): string {
        let srcData = "";
        let srcDirs = this.sourceDirs === null ? "" : this.sourceDirs;
        srcDirs.split(",").forEach(dir => {
            if (!util.isNullOrWhitespace(dir)) {
                srcData += `<fileset dir="${dir}"/>`;
                srcData += os.EOL;
            }
        });
        if (util.isNullOrWhitespace(srcData)) {
            srcData = `<fileset dir="."/>`;
            srcData += os.EOL;
        }
        return srcData;
    }

If the codeCoverageSourceDirectories YAML input is not given a value, then INPUT_SRCDIRECTORIES is undefined, meaning the value of global var sourceDirs is set to undefined. Thus, calling split() on an undefined value generates the error and causes JaCoCo code coverage to fail on the pipeline.

This is a simple fix. The issue is the azure-pipelines-tasks-coverage-tools repo (which contains those JaCoCo code coverage functions) is archived, so I can't open any new issues or create any PRs. I'm opening the bug here, hoping that a contributor with access to the private repo will see it.

A minimum recreation of a possible fix would look something like:

    let srcData = "";
    let srcDirs = sourceDirs === null ? "" : sourceDirs;
    if (srcDirs) {
        srcDirs.split(",").forEach(dir => {
               // continues if srcDirs != undefined
        });
    }
    else {
        // continues if srcDirs == undefined
    }
    

After a brief search, this error might also occur for JaCoCo code coverage on Maven and Gradle tasks.

@vmapetr I see you were a contributor on the azure-pipelines-tasks-coverage-tools repo. Any chance this could help or be used at all?

from azure-pipelines-tasks.

ataverascrespo avatar ataverascrespo commented on May 28, 2024

Closing this as I see the azure-pipelines-tasks-coverage-tools repo has been moved to azure-pipelines-tasks-common-packages, so I'll open a new issue ticket there

from azure-pipelines-tasks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.