[NO ISSUE] Don't break lines without whitespace by default Add a new boolean indent parameter "strict" to denote when lines should be force-wrapped even when there are no word breaks.
Change-Id: I716caf020466f30e469531d0bd8498d0c781c2af Reviewed-on: https://asterix-gerrit.ics.uci.edu/2574 Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Murtadha Hubail <mhub...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/fa52d7c0 Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/fa52d7c0 Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/fa52d7c0 Branch: refs/heads/release-0.9.4-pre-rc Commit: fa52d7c09f4f4bd7b9aef6728efbe0235bbfe713 Parents: 3f4cb46 Author: Michael Blow <mb...@apache.org> Authored: Sat Apr 7 03:05:30 2018 -0400 Committer: Michael Blow <mb...@apache.org> Committed: Sat Apr 7 17:20:30 2018 -0700 ---------------------------------------------------------------------- .../apache/hyracks/maven/license/LicenseUtil.java | 16 ++++++++++------ .../maven/license/freemarker/IndentDirective.java | 12 +++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fa52d7c0/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java index a80dc1d..5ea768e 100644 --- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java +++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java @@ -56,11 +56,11 @@ public class LicenseUtil { } } - public static String process(String input, boolean unpad, boolean wrap) throws IOException { + public static String process(String input, boolean unpad, boolean wrap, boolean strict) throws IOException { try (BufferedReader reader = new BufferedReader(new StringReader(input))) { reader.mark(input.length() + 1); StringWriter sw = new StringWriter(); - trim(sw, reader, unpad, wrap); + trim(sw, reader, unpad, wrap, strict); sw.append('\n'); return sw.toString(); } @@ -75,20 +75,22 @@ public class LicenseUtil { } private static void trim(Writer out, BufferedReader reader) throws IOException { - trim(out, reader, true, true); + trim(out, reader, true, true, false); } - private static void trim(Writer out, BufferedReader reader, boolean unpad, boolean wrap) throws IOException { + private static void trim(Writer out, BufferedReader reader, boolean unpad, boolean wrap, boolean strict) + throws IOException { Pair<Integer, Integer> result = null; if (unpad || wrap) { result = analyze(reader); reader.reset(); } doTrim(out, reader, unpad ? result.getLeft() : 0, - wrap && (result.getRight() > wrapThreshold) ? wrapLength : Integer.MAX_VALUE); + wrap && (result.getRight() > wrapThreshold) ? wrapLength : Integer.MAX_VALUE, strict); } - private static void doTrim(Writer out, BufferedReader reader, int extraPadding, int wrapLength) throws IOException { + private static void doTrim(Writer out, BufferedReader reader, int extraPadding, int wrapLength, boolean strict) + throws IOException { boolean head = true; int empty = 0; for (String line = reader.readLine(); line != null; line = reader.readLine()) { @@ -110,6 +112,8 @@ public class LicenseUtil { out.append(trimmed.substring(0, cut)); out.append('\n'); trimmed = trimmed.substring(cut + 1); + } else if (!strict) { + break; } else { out.append(trimmed.substring(0, wrapLength)); out.append('\n'); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fa52d7c0/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/IndentDirective.java ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/IndentDirective.java b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/IndentDirective.java index f58b419..9237dde 100644 --- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/IndentDirective.java +++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/IndentDirective.java @@ -25,6 +25,9 @@ import java.io.Writer; import java.util.Arrays; import java.util.Map; +import org.apache.commons.io.IOUtils; +import org.apache.hyracks.maven.license.LicenseUtil; + import freemarker.core.Environment; import freemarker.template.TemplateBooleanModel; import freemarker.template.TemplateDirectiveBody; @@ -33,14 +36,13 @@ import freemarker.template.TemplateException; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; import freemarker.template.TemplateNumberModel; -import org.apache.commons.io.IOUtils; -import org.apache.hyracks.maven.license.LicenseUtil; public class IndentDirective implements TemplateDirectiveModel { private static final String PARAM_NAME_SPACES = "spaces"; private static final String PARAM_NAME_UNPAD = "unpad"; private static final String PARAM_NAME_WRAP = "wrap"; + private static final String PARAM_NAME_STRICT = "strict"; @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) @@ -49,6 +51,7 @@ public class IndentDirective implements TemplateDirectiveModel { int numSpaces = -1; boolean unpad = false; boolean wrap = false; + boolean strict = false; for (Object o : params.entrySet()) { Map.Entry ent = (Map.Entry) o; @@ -66,6 +69,9 @@ public class IndentDirective implements TemplateDirectiveModel { case PARAM_NAME_WRAP: wrap = getBooleanParam(paramName, paramValue); break; + case PARAM_NAME_STRICT: + strict = getBooleanParam(paramName, paramValue); + break; default: throw new TemplateModelException("Unsupported parameter: " + paramName); } @@ -81,7 +87,7 @@ public class IndentDirective implements TemplateDirectiveModel { // case we don't provide a special writer as the parameter: StringWriter sw = new StringWriter(); body.render(sw); - String fixedup = LicenseUtil.process(sw.toString(), unpad, wrap); + String fixedup = LicenseUtil.process(sw.toString(), unpad, wrap, strict); IOUtils.copy(new StringReader(fixedup), new IndentingWriter(env.getOut(), numSpaces)); } }