Skip to content

Commit

Permalink
Feature/enchance directory (#4)
Browse files Browse the repository at this point in the history
* Adding enchanced directory concatenation to specify a starting file

* update README

* README update

* Test updates

* test formatter

* test formatter

* removing formatting shell script
  • Loading branch information
Darren Forsythe authored Feb 8, 2018
1 parent 6218baf commit f11e704
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 26 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Will concat all files in the directory to the output file.
* For selecting different types of concatentation implementations. Defaults to requiring a list of files as specified in the basic example.
* `directory`
* When using `ConcatenationType.DIRECTORY` specify the directory from which to get all files. Natural ordering of the file name is used to sort the files.
* `startingFile`
* When using directory this file will be used as the starting file for concatenation.

## Change Log ##

Expand Down Expand Up @@ -122,4 +124,9 @@ Will concat all files in the directory to the output file.

* Make `concatenationType` required.
* Add debug logger for the parmas if enable.
* Move verification to CI profile
* Move verification to CI profile

### 1.3.0 ###

* Add `startingFile` param used in `DIRECTORY` concatenation.
* If specified this file will be the first file to be concatenated to with the rest following with natural ordering.
2 changes: 0 additions & 2 deletions format.sh

This file was deleted.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.flaw101</groupId>
<artifactId>concat-maven-plugin</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<packaging>maven-plugin</packaging>
<name>Concat Maven Plugin</name>
<description>Maven plugin that can concatenate several files into one new file.</description>
Expand Down Expand Up @@ -218,7 +218,7 @@
<excludedMethod>hashCode</excludedMethod>
</excludedMethods>
<threads>4</threads>
<coverageThreshold>68</coverageThreshold>
<coverageThreshold>66</coverageThreshold>
<mutationThreshold>88</mutationThreshold>
</configuration>
</execution>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/io/github/flaw101/concat/ConcatMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public class ConcatMojo extends AbstractMojo {
*/
private boolean deleteTargetFile;

/**
* If using {@link ConcantenationType#DIRECTORY} you can specify the file you wish to
* start, the rest will follow in natural order.
*
* @parameter
*/
private File startingFile;

/*
* (non-Javadoc)
*
Expand All @@ -104,7 +112,7 @@ public class ConcatMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {
final ConcatParams params = new ConcatParams(directory, concatFiles, outputFile,
deleteTargetFile, appendNewline, concatenationType);
deleteTargetFile, appendNewline, concatenationType, startingFile);
if (getLog().isDebugEnabled()) {
getLog().debug("Concatenating with params" + params.toString());
}
Expand Down
60 changes: 40 additions & 20 deletions src/main/java/io/github/flaw101/concat/ConcatParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
package io.github.flaw101.concat;

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

import io.github.flaw101.concat.service.ConcantenationType;

Expand All @@ -44,20 +43,22 @@ public class ConcatParams {
private final File outputFile;
private final boolean deleteTargetFile;
private final boolean appendNewline;
private final Collection<File> files = new ArrayList<File>();
private final Collection<File> files = new LinkedList<File>();
private final ConcantenationType concatenationType;
private final File startingFile;

public ConcatParams(final String directory, final List<File> files,
final File outputFile, final boolean deleteTargetFile,
final boolean appendNewline, final ConcantenationType concatentationType) {
public ConcatParams(String directory, Collection<File> files, File outputFile,
boolean deleteTargetFile, boolean appendNewline,
ConcantenationType concatenationType, File startingFile) {
this.directory = directory;
if (files != null) {
this.files.addAll(files);
}
this.concatenationType = concatentationType;
this.concatenationType = concatenationType;
this.outputFile = outputFile;
this.deleteTargetFile = deleteTargetFile;
this.appendNewline = appendNewline;
this.startingFile = startingFile;
}

public boolean isAppendNewline() {
Expand All @@ -84,10 +85,30 @@ public void addAll(final Collection<File> files) {
this.files.addAll(files);
}

public void add(final File file) {
this.files.add(file);
}

public String getDirectory() {
return directory;
}

public File getStartingFile() {
return startingFile;
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("ConcatParams [directory=").append(directory)
.append(", outputFile=").append(outputFile).append(", deleteTargetFile=")
.append(deleteTargetFile).append(", appendNewline=").append(appendNewline)
.append(", files=").append(files).append(", concatenationType=")
.append(concatenationType).append(", startingFile=").append(startingFile)
.append("]");
return builder.toString();
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -97,13 +118,14 @@ public int hashCode() {
+ ((concatenationType == null) ? 0 : concatenationType.hashCode());
result = prime * result + (deleteTargetFile ? 1231 : 1237);
result = prime * result + ((directory == null) ? 0 : directory.hashCode());
result = prime * result + (files.hashCode());
result = prime * result + ((files == null) ? 0 : files.hashCode());
result = prime * result + ((outputFile == null) ? 0 : outputFile.hashCode());
result = prime * result + ((startingFile == null) ? 0 : startingFile.hashCode());
return result;
}

@Override
public boolean equals(Object obj) { // NOSONAR
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
Expand Down Expand Up @@ -133,6 +155,7 @@ else if (!directory.equals(other.directory)) {
}
if (other.files != null) {
return false;

}
else if (!files.equals(other.files)) {
return false;
Expand All @@ -145,17 +168,14 @@ else if (!files.equals(other.files)) {
else if (!outputFile.equals(other.outputFile)) {
return false;
}
if (startingFile == null) {
if (other.startingFile != null) {
return false;
}
}
else if (!startingFile.equals(other.startingFile)) {
return false;
}
return true;
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("ConcatParams [directory=").append(directory)
.append(", outputFile=").append(outputFile).append(", deleteTargetFile=")
.append(deleteTargetFile).append(", appendNewline=").append(appendNewline)
.append(", files=").append(files).append(", concatenationType=")
.append(concatenationType).append("]");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class DirectorySetup implements OutputSetup {
@Override
public void setup(final ConcatParams params) {
final File directory = new File(params.getDirectory());
if (params.getStartingFile() != null) {
params.add(params.getStartingFile());
}
final List<File> listFiles = (List<File>) FileUtils.listFiles(directory,
FileFilterUtils.fileFileFilter(), null);
Collections.sort(listFiles, new Comparator<File>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ else if (StringUtils.isNotEmpty(concatParams.getDirectory())) {
throw new ValidationFailedException(
"Directory param is set, when File List conccat type is set. These are mutually exclusive");
}
else if (concatParams.getStartingFile() != null) {
throw new ValidationFailedException(
"Starting file is set. This is not used/required for this type of concatentation");
}

for (final File file : concatParams.getFiles()) {
if (!file.exists()) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/io/github/flaw101/concat/ConcatMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public void testConcat_Directory() throws Exception {
"target/concatfile.output", "file1file2file3");
}

@Test
public void testConcat_Directory_StartingFile() throws Exception {
execute("src/test/resources/test-pom-directory-with-starting-file.xml", "concat",
"target/concatfile.output", "startfile1file2file3");
}

@Test
public void testConcatShouldNotDeleteTarget() throws Exception {
FileUtils.copyFile(new File("src/test/resources/testfiles/file_1.input"),
Expand Down Expand Up @@ -124,6 +130,18 @@ public void testDirectoryCompetingArgs() throws Exception {
}
}

@Test
public void testListCompetingArgs() throws Exception {
try {
execute("src/test/resources/test-pom-competing-arguments.xml", "concat",
"bla", "nothing");
}
catch (final Exception e) {
ExceptionUtils.printRootCauseStackTrace(e);
assertEquals(MojoExecutionException.class, e.getClass());
}
}

@Test
public void testDirectoryMissingDirectory() throws Exception {
try {
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/startingFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
start
37 changes: 37 additions & 0 deletions src/test/resources/test-pom-competing-arguments.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>io.github.flaw101</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test ConcatMojo</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>concat-maven-plugin</artifactId>
<configuration>
<outputFile>target/concatfile.output</outputFile>
<concatenationType>FILE_LIST</concatenationType>
<concatFiles>
<concatFile>src/test/resources/testfiles/file_1.input</concatFile>
<concatFile>src/test/resources/testfiles/file_2.input</concatFile>
<concatFile>src/test/resources/testfiles/file_3.input</concatFile>
</concatFiles>
<startingFile>src/test/resources/startingFile</startingFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
36 changes: 36 additions & 0 deletions src/test/resources/test-pom-directory-with-starting-file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>io.github.flaw101</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test ConcatMojo</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.flawless101</groupId>
<artifactId>concat-maven-plugin</artifactId>
<configuration>
<outputFile>target/concatfile.output</outputFile>
<directory>src/test/resources/testfiles/</directory>
<concatenationType>
DIRECTORY
</concatenationType>
<startingFile>src/test/resources/startingFile</startingFile>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit f11e704

Please sign in to comment.