package org.eobjects.build;

import java.io.File;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

public abstract class AbstractDotnetTestMojo extends AbstractDotnetMojo {

    @Parameter(property = "dotnet.test.outputxml", required = false, defaultValue = "TestResults.xml")
    private String outputXml;

    private final ObjectMapper objectMapper = new ObjectMapper();

    public void executeInternal() throws MojoFailureException {
        final PluginHelper helper = getPluginHelper();
        for (File subDirectory : helper.getProjectDirectories()) {
            if (isTestRunnable(subDirectory)) {
                helper.executeCommand(subDirectory, "dotnet", "test", "-c", helper.getBuildConfiguration(), "-xml", outputXml);
            }
        }
    }

    private boolean isTestRunnable(File subDirectory) {
        // check if there is a 'testRunner' attribute defined in project.json
        final File projectJsonFile = new File(subDirectory, "project.json");
        final ObjectNode root;
        try {
            root = (ObjectNode) objectMapper.readTree(projectJsonFile);
        } catch (Exception e) {
            getLog().warn("Failed to parse '" + projectJsonFile
                    + "' in order to determine if a 'testRunner' attribute is set.");
            return false;
        }
        final JsonNode testRunnerNode = root.get("testRunner");
        return testRunnerNode != null && !testRunnerNode.isMissingNode();
    }
}

@@ -42,16 +42,69 @@
 io.File;
+%0Aimport java.util.Arrays;%0Aimport java.util.ArrayList;
 %0A%0Aimport
@@ -508,42 +508,8 @@
 alse
-, defaultValue = %22TestResults.xml%22
 )%0A  
@@ -522,14 +522,12 @@
 ate 
-String
+File
  out
@@ -717,24 +717,326 @@
 inHelper();%0A
+        ArrayList%3CString%3E argsList = new ArrayList%3CString%3E(Arrays.asList(%22dotnet%22, %22test%22, %22-c%22, helper.getBuildConfiguration()));%0A        if(outputXml != null) %7B%0A            outputXml.getParentFile().mkdirs();%0A            argsList.add(%22-xml%22);%0A            argsList.add(outputXml.getPath());%0A        %7D%0A
         for 
@@ -1194,81 +1194,53 @@
 ry, 
-%22dotnet%22, %22test%22, %22-c%22, helper.getBuildConfiguration(), %22-xml%22, outputXml
+argsList.toArray(new String%5BargsList.size()%5D)
 );%0A 

Remove default value for dotnet.test.outputxml