Skip to content

Commit

Permalink
#244 Merge branch 'dev_textmerger'
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeec committed Dec 14, 2016
2 parents a0685d4 + b29feec commit ecec9a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cobigen/cobigen-textmerger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.capgemini</groupId>
<artifactId>cobigen-textmerger</artifactId>
<packaging>jar</packaging>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
<name>CobiGen - Text Merger</name>
<parent>
<groupId>com.capgemini</groupId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>com.capgemini</groupId>
<artifactId>cobigen-core</artifactId>
<version>1.0.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.capgemini.cobigen.textmerger;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import com.capgemini.cobigen.extension.IMerger;
import com.capgemini.cobigen.api.exception.MergeException;
import com.capgemini.cobigen.api.extension.Merger;

/**
* The {@link TextAppender} allows appending the patch to the base file
* @author mbrunnli (03.06.2014)
*/
public class TextAppender implements IMerger {
public class TextAppender implements Merger {

/**
* Type (or name) of the instance
Expand Down Expand Up @@ -39,22 +41,19 @@ public TextAppender(String type, boolean withNewLineBeforehand) {
this.withNewLineBeforehand = withNewLineBeforehand;
}

/**
* {@inheritDoc}
* @author mbrunnli (03.06.2014)
*/
@Override
public String getType() {
return type;
}

/**
* {@inheritDoc}
* @author mbrunnli (03.06.2014)
*/
@Override
public String merge(File base, String patch, String targetCharset) throws Exception {
String mergedString = FileUtils.readFileToString(base, targetCharset);
public String merge(File base, String patch, String targetCharset) throws MergeException {
String mergedString;
try {
mergedString = FileUtils.readFileToString(base, targetCharset);
} catch (IOException e) {
throw new MergeException(base, "Could not read base file.", e);
}
if (withNewLineBeforehand && StringUtils.isNotEmpty(patch)) {
mergedString += System.lineSeparator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,27 @@

import java.util.List;

import com.capgemini.cobigen.extension.IGeneratorPluginActivator;
import com.capgemini.cobigen.extension.IMerger;
import com.capgemini.cobigen.extension.ITriggerInterpreter;
import com.capgemini.cobigen.api.extension.GeneratorPluginActivator;
import com.capgemini.cobigen.api.extension.Merger;
import com.capgemini.cobigen.api.extension.TriggerInterpreter;
import com.google.common.collect.Lists;

/**
* This Plugin Activator registers a merger, which only appends the patch text to the original existing file
* @author mbrunnli (06.04.2014)
*/
public class TextMergerPluginActivator implements IGeneratorPluginActivator {
public class TextMergerPluginActivator implements GeneratorPluginActivator {

/**
* {@inheritDoc}
* @author mbrunnli (06.04.2014)
*/
@Override
public List<IMerger> bindMerger() {
List<IMerger> merger = Lists.newLinkedList();
public List<Merger> bindMerger() {
List<Merger> merger = Lists.newLinkedList();
merger.add(new TextAppender("textmerge_append", false));
merger.add(new TextAppender("textmerge_appendWithNewLine", true));
return merger;
}

/**
* {@inheritDoc}
* @author mbrunnli (08.04.2014)
*/
@Override
public List<ITriggerInterpreter> bindTriggerInterpreter() {
public List<TriggerInterpreter> bindTriggerInterpreter() {
return null;
}

Expand Down

0 comments on commit ecec9a2

Please sign in to comment.