damianszczepanik / maven-cucumber-reporting

maven mojo for cucumber reporting
GNU Lesser General Public License v2.1
122 stars 111 forks source link

Support for multiple json output files #4

Closed petmar closed 8 years ago

petmar commented 11 years ago

Hello,

First of all, thank you very much for the excellent work on the cucumber-reporting. I have just set up a project that uses the mojo, and it works very well. Do you intend to also add support for multiple json output files in the mojo?

kingsleyh commented 11 years ago

Hi

Yes I can add that :)

--K

On 10 Apr 2013, at 14:13, petmar notifications@github.com wrote:

Hello,

First of all, thank you very much for the excellent work on the cucumber-reporting. I have just set up a project that uses the mojo, and it works very well. Do you intend to also add support for multiple json output files in the mojo?

— Reply to this email directly or view it on GitHub.

petmar commented 11 years ago

Hi, yes, that would be very helpful! Background here is that I am running several tests in parallel, and each test reports results out to its own json file. The call to ReportBuilder in class CucumberReportGeneratorMojo already takes a list of output files as an argument, but the overall configuration of the mojo as is doesn't yet seem to make use of that capability. I hope it's not too difficult to add.

mkhare75 commented 11 years ago

Hello

Thanks for providing a wonderful reporting tool. Works great. I do have a similar experience and need as of petmar, wherein my builds are running integration tests in parallel and generating multiple json output files which needs to be fed into mojo pom.xml config to create a single consolidated report in verify phase. Having this capability available would be great.

petmar commented 11 years ago

Hi,

We at Magentys have modified the plugin to accept a directory to indicate the location of the .json files.

It is only compatible with cucumber-reporting versions 0.0.21 and onwards. This is due to a backwards incompatible change to the ReportBuilder.class constructor signature.

You will therefore need the maven dependency:

    <dependency>
        <groupid>net.masterthought</groupid>
        <artifactid>cucumber-reporting</artifactid>
        <version>0.0.21</version>
    </dependency>

You will need to download the source, then replace CucumberReportGeneratorMojo code with the custom one below:

    package net.masterthought.cucumber;

    import java.io.File;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.List;

    import org.apache.commons.io.FileUtils;
    import org.apache.commons.io.filefilter.FileFileFilter;
    import org.apache.commons.io.filefilter.RegexFileFilter;
    import org.apache.maven.plugin.AbstractMojo;
    import org.apache.maven.plugin.MojoExecutionException;

    /**
     * Goal which generates a Cucumber Report.
     * 
     * @goal generate
     * @phase post-integration-test
     */
    public class CucumberReportGeneratorMojo extends AbstractMojo {

        /**
         * Name of the project.
         * 
         * @parameter expression="${project.name}"
         * @required
         */
        private String projectName;

        /**
         * Location of the file.
         * 
         * @parameter expression="${project.build.directory}/cucumber-reports"
         * @required
         */
        private File outputDirectory;

        /**
         * Location of the file, or directory. If a directory is specified then
         * recursively look for files with an extension of json.
         * 
         * @parameter expression="${project.build.directory}/cucumber.json"
         * @required
         */
        private File cucumberOutput;

        /**
         * Enable Flash Charts.
         * 
         * @parameter expression="true"
         * @required
         */
        private Boolean enableFlashCharts;

        public void execute() throws MojoExecutionException {
            if (!outputDirectory.exists()) {
                outputDirectory.mkdirs();
            }

            List<String> list = buildFileList();

            ReportBuilder reportBuilder;

            try {
                System.out.println("About to generate");
                reportBuilder = new ReportBuilder(list, outputDirectory, "", "1",
                        projectName, false, false, enableFlashCharts, false, false,
                        "", false);
                reportBuilder.generateReports();

                boolean buildResult = reportBuilder.getBuildStatus();
                if (!buildResult) {
                    throw new MojoExecutionException(
                            "BUILD FAILED - Check Report For Details");
                }
            } catch (Exception e) {
                throw new MojoExecutionException("Error Found:", e);
            }
        }

        private List<String> buildFileList() throws MojoExecutionException {
            List<String> list = new ArrayList<String>();
            if (!cucumberOutput.exists()) {
                throw new MojoExecutionException("The file or directory ["
                        + cucumberOutput + "] does not exist.");
            }
            if (cucumberOutput.isDirectory()) {
                Collection<File> files = FileUtils.listFiles(cucumberOutput, new RegexFileFilter(
                        "^(.*)?\\.json$"), FileFileFilter.FILE);
                for (File file : files) {
                    list.add(file.getAbsolutePath());
                }
                return list;
            }
            list.add(cucumberOutput.getAbsolutePath());
            return list;
        }
    }
crankydillo commented 10 years ago

Petmar, if this change works, why don't you submit a pull request?

kingsleyh commented 10 years ago

if you submit a pull request I will release it in the next release

crankydillo commented 10 years ago

When do you expect the next release?

kingsleyh commented 10 years ago

Im not sure - I'm still very busy so not had any time to work on this project. I still have lots of ideas and things I want to improve - but probably wont get around to that until after the summer. But I could just release the multiple json files thing for the maven mojo. You could even grab the code from Petmar youself and submit a pull request. I sadly don't any time to do it right now.

--K

On 2 Jun 2014, at 21:38, crankydillo notifications@github.com wrote:

When do you expect the next release?

— Reply to this email directly or view it on GitHub.

crankydillo commented 10 years ago

I'm doing that now. I'll give due credit to Petmar in the comments, but I really need this feature:)

LinusHuesler commented 10 years ago

Great feature, exactly what we need! Please provide a new release as soon as possible.

FaiMal commented 10 years ago

I have multiple json files for test results. I tried specifying the directory (JsonResults: The folder was generated by running the tests. ) for the json files as

<cucumberOutput>${project.build.directory}/JsonResults</cucumberOutput>

But I am getting the following error when I try to generate html reports

java.io.FileNotFoundException: \target\JsonResults (Access is denied)

How do I specify multiple json files or the directory containing mutiple json files in config? If I specify one file from this folder it works

kingsleyh commented 10 years ago

Read the bottom of this page: https://github.com/masterthought/jenkins-cucumber-jvm-reports-plugin-java/wiki/Detailed-Configuration

Sent from my iPhone

On 6 Nov 2014, at 22:29, FaiMal notifications@github.com wrote:

I have multiple json files for test results. I tried specifying the directory (JsonResults) for the json files as

${project.build.directory}/JsonResults

But I am getting the following error when I try to generate html reports

java.io.FileNotFoundException: \target\JsonResults (Access is denied)

How do I specify multiple json files or the directory containing mutiple json files in config?

— Reply to this email directly or view it on GitHub.

kingsleyh commented 10 years ago

Ah not sure if it's been released yet with multiple file support

FaiMal commented 10 years ago

There was a commit related to this so I thought it is in the released version. How can I get the unreleased version of code that has this commit merged? Do I have to add it to my project as a jar? (I am new to GitHub and Maven)

kingsleyh commented 10 years ago

Yes

Sent from my iPhone

On 6 Nov 2014, at 22:48, FaiMal notifications@github.com wrote:

There was a commit related to this so I thought it is in the released version. How can I get the unreleased version of code that has this commit merged? Do I have to add it to my project as a jar?

— Reply to this email directly or view it on GitHub.

FaiMal commented 10 years ago

I downloaded the code and added the following dependency in pom

<dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
</dependency>

Then I created a jar file and added it to my local m2 repo. I am getting the following error when I do mvn verify

[ERROR] Failed to execute goal net.masterthought:maven-cucumber-reporting:0.0.7-SNAPSHOT:generate (execution) on project platform-aat: Execution execution of goal net.masterthought:maven-cucumber-reporting:0.0.7-SNAPSHOT:generate failed: A required class was missing while executing net.masterthought:maven-cucumber-reporting:0.0.7-SNAPSHOT:generate: org/apache/commons/io/FileUtils

I have added this dependency to my project's pom as well but I am still getting the same error. How can I fix this?

kingsleyh commented 10 years ago

I think You need to clone the mojo repo and the cucumber-reporting repo and then build cucumber reporting locally and put the version as a dependency in the mojo Pom - then build the mojo.

Then add the mojo to your project

--k

Sent from my iPhone

On 7 Nov 2014, at 17:13, FaiMal notifications@github.com wrote:

I downloaded the code and added the following dependency in pom

org.apache.commons commons-io 1.3.2

Then I created a jar file and added it to my local m2 repo. I am getting the following error when I do mvn verify

[ERROR] Failed to execute goal net.masterthought:maven-cucumber-reporting:0.0.7-SNAPSHOT:generate (execution) on project platform-aat: Execution execution of goal net.masterthought:maven-cucumber-reporting:0.0.7-SNAPSHOT:generate failed: A required class was missing while executing net.masterthought:maven-cucumber-reporting:0.0.7-SNAPSHOT:generate: org/apache/commons/io/FileUtils I have added this dependency to my project's pom as well but I am still getting the same error. How can I fix this?

— Reply to this email directly or view it on GitHub.

cjbooms commented 9 years ago

Will this be released any time soon? I'm very interested in the updated functionality.

kingsleyh commented 9 years ago

I’ve been swamped with other stuff recently but I’ll try to release this soon.

—K

On 13 Jan 2015, at 00:21, Conor Gallagher notifications@github.com wrote:

Will this be released any time soon? I'm very interested in the updated functionality.

— Reply to this email directly or view it on GitHub https://github.com/masterthought/maven-cucumber-reporting-mojo/issues/4#issuecomment-69673824.

patelakhil commented 9 years ago

We are also interested in this fix as it will be very helpful for multiple and parallel execution enviornment