Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added text file creation #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.numberfour.maven.plugins.jscoverage;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
Expand All @@ -25,7 +26,7 @@
*
* @goal list
* @requiresDependencyResolution compile
* @description Creates a JSON-formatted list of files
* @description Creates a list of files. The supported types are JSON, text, or JUnit test suite.
*/
public class ListMojo extends AbstractMojo {

Expand Down Expand Up @@ -70,6 +71,8 @@ public class ListMojo extends AbstractMojo {
public String[] excludes;

/**
* Supported types are "json", "text", and "junit".
*
* @parameter default-value="json"
*/
public String type;
Expand All @@ -81,6 +84,13 @@ public class ListMojo extends AbstractMojo {
*/
public boolean caseSensitive;

/**
* Whether to prefix the file with a '/'
*
* @parameter
*/
public boolean includeSlashPrefix;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
FileWriter fileWriter = null;
Expand All @@ -94,6 +104,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
log.info("Includes: " + Arrays.toString(this.includes));
log.info("Exludes: " + Arrays.toString(this.excludes));
log.info("Type: " + this.type);
log.info("Include /: " + this.includeSlashPrefix);

DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(this.baseDir);
Expand All @@ -106,12 +117,26 @@ public void execute() throws MojoExecutionException, MojoFailureException {

log.info("File list contains " + includedFiles.length + " files");

// Create the directories for the file
new File(this.outputFile).getParentFile().mkdirs();

fileWriter = new FileWriter(this.outputFile);

if (this.includeSlashPrefix) {
for (int i = 0; i < includedFiles.length; ++i) {
includedFiles[i] = "/" + includedFiles[i];
}
}

if ("json".equals(this.type)) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(includedFiles);
fileWriter.write(json);
} else if ("text".equals(this.type)) {
for (String f : includedFiles) {
fileWriter.write(f);
fileWriter.write(NEW_LINE);
}
} else if ("junit".equals(this.type)) {
StringBuilder suiteContent = new StringBuilder();
suiteContent.append("package n4.quat.selenium.acceptancetest.suites;");
Expand Down