openclover / clover

This repository contains source code of OpenClover Core as well as its integrations: Clover-for-Ant, Clover-for-Eclipse and Clover-for-IDEA plugins. Sources are licensed under Apache 2.0 license.
Other
63 stars 16 forks source link

OC-22 Clover:aggregate failed: String index out of range #22

Open marek-parfianowicz opened 4 years ago

marek-parfianowicz commented 4 years ago

I am running mvn build on a multimodule project with clover plugin.

The command ran is mvn clover:setup test clover:aggregate clover:clover No goal in the pom defined.

The pluging fails with

[ERROR] Failed to execute goal org.openclover:clover-maven-plugin:4.2.0:aggregate (default-cli) on project parent: Execution default-cli of goal org.openclover:clover-maven-plugin:4.2.0:aggregate failed: String index out of range: -25 -> [Help 1]

Note that it runs in docker. against the image maven:3-jdk-8

After looking at the plugin source code i found the problem to originate in com.atlassian.maven.plugin.clover.CloverAggregateMojo


private List<String> getChildrenCloverDatabases() {
    // Ideally we'd need to find out where each module stores its Clover
    // database. However that's not
    // currently possible in m2 (see
    // http://jira.codehaus.org/browse/MNG-2180). Thus we'll assume for now
    // that all modules use the cloverDatabase configuration from the top
    // level module.

    // Find out the location of the clover DB relative to the root module.
    // Note: This is a pretty buggy algorithm and we really need a proper
    // solution (see MNG-2180)
    final String resolvedCloverDb = resolveCloverDatabase();
    final String projectBaseDir = getProject().getBasedir().getPath();
    getLog().debug("Calculating relative database path of '" + resolvedCloverDb
            + "' against the project base directory '" + projectBaseDir + "'");
    final String relativeCloverDatabasePath = resolvedCloverDb.substring(projectBaseDir.length());
More specifically when i run it with debug info

[DEBUG] Calculating relative database path of '/var/folders/cc/l8sxh9z54cq8t1fxqx928g2w0000gn/T//clover.db' against the project base directory '/Users/NyName/code/company/myproject/MySecret-service/builds/0/project-0'```

Project base dir has length 72 ResolvedCloverDb dir has length 59 Which then of course results in the index out of range exception on substring.

(The log message says relative but the variable resolvedCloverDB is not relative. Deprecated log message?)

The value of ResolvedCloverDB running in a docker image obviously goes wrong.

I solved it by configuring the plugin that it uses one single clover db.

              ```<plugin>
                    <groupId>org.openclover</groupId>
                    <artifactId>clover-maven-plugin</artifactId>
                    <version>${clover-maven-plugin.version}</version>
                    <configuration>
                        <singleCloverDatabase>true</singleCloverDatabase>
                        <debug>true</debug>
                    </configuration>
                </plugin>```

But if found the error very cryptic and hard to find. Took me some debugging.
marek-parfianowicz commented 4 years ago

Original report: https://bitbucket.org/openclover/clover/issues/22