The Unified and Autonomous Development Platform
midwork
robin shine230b8ee0658d
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.javaindex 8945252b70..f88073b231 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java@@ -1,124 +1,124 @@-package com.pmease.commons.git.command;--import java.io.File;-import java.util.concurrent.atomic.AtomicBoolean;--import org.slf4j.Logger;-import org.slf4j.LoggerFactory;--import com.google.common.base.Preconditions;-import com.pmease.commons.git.Git;-import com.pmease.commons.util.execution.Commandline;-import com.pmease.commons.util.execution.ExecuteResult;-import com.pmease.commons.util.execution.LineConsumer;--public class MergeCommand extends GitCommand<String> {-- private static final Logger logger = LoggerFactory.getLogger(MergeCommand.class);-- public enum FastForwardMode {FF_ONLY, NO_FF, FF};-- private String revision;-- private FastForwardMode fastForwardMode;-- private boolean squash;-- private String strategy;-- private String strategyOption;-- private String message;-- public MergeCommand(final File repoDir) {- super(repoDir);- }-- public MergeCommand revision(String revision) {- this.revision = revision;- return this;- }-- public MergeCommand fastForwardMode(FastForwardMode fastForwardMode) {- this.fastForwardMode = fastForwardMode;- return this;- }-- public MergeCommand strategy(String strategy) {- this.strategy = strategy;- return this;- }-- public MergeCommand strategyOption(String strategyOption) {- this.strategyOption = strategyOption;- return this;- }-- public MergeCommand squash(boolean squash) {- this.squash = squash;- return this;- }-- public MergeCommand message(String message) {- this.message = message;- return this;- }-- @Override- public String call() {- Preconditions.checkNotNull(revision, "revision has to be specified.");-- Commandline cmd = cmd().addArgs("merge");-- cmd.addArgs("--no-edit", "--quiet");-- if (fastForwardMode == FastForwardMode.FF_ONLY)- cmd.addArgs("--ff-only");- else if (fastForwardMode == FastForwardMode.NO_FF)- cmd.addArgs("--no-ff");- else- cmd.addArgs("--ff");-- if (strategy != null)- cmd.addArgs("--strategy=" + strategy);- if (strategyOption != null)- cmd.addArgs("--strategy-option=" + strategyOption);-- if (squash)- cmd.addArgs("--squash");- else if (message != null)- cmd.addArgs("-m", message);-- cmd.addArgs(revision);-- final AtomicBoolean conflict = new AtomicBoolean(false);-- ExecuteResult result = cmd.execute(new LineConsumer() {-- @Override- public void consume(String line) {- if (line.startsWith("CONFLICT") || line.startsWith("fatal: Not possible to fast-forward"))- conflict.set(true);- }-- }, new LineConsumer() {-- @Override- public void consume(String line) {- logger.error(line);- }-- });-- if (conflict.get())- return null;-- result.checkReturnCode();-- Git git = new Git(repoDir);- if (squash)- git.commit(message, false, false);- return git.parseRevision("HEAD", true);- }--}+package com.pmease.commons.git.command;++import java.io.File;+import java.util.concurrent.atomic.AtomicBoolean;++import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++import com.google.common.base.Preconditions;+import com.pmease.commons.git.Git;+import com.pmease.commons.util.execution.Commandline;+import com.pmease.commons.util.execution.ExecuteResult;+import com.pmease.commons.util.execution.LineConsumer;++public class MergeCommand extends GitCommand<String> {++ private static final Logger logger = LoggerFactory.getLogger(MergeCommand.class);++ public enum FastForwardMode {FF_ONLY, NO_FF, FF};++ private String revision;++ private FastForwardMode fastForwardMode;++ private boolean squash;++ private String strategy;++ private String strategyOption;++ private String message;++ public MergeCommand(final File repoDir) {+ super(repoDir);+ }++ public MergeCommand revision(String revision) {+ this.revision = revision;+ return this;+ }++ public MergeCommand fastForwardMode(FastForwardMode fastForwardMode) {+ this.fastForwardMode = fastForwardMode;+ return this;+ }++ public MergeCommand strategy(String strategy) {+ this.strategy = strategy;+ return this;+ }++ public MergeCommand strategyOption(String strategyOption) {+ this.strategyOption = strategyOption;+ return this;+ }++ public MergeCommand squash(boolean squash) {+ this.squash = squash;+ return this;+ }++ public MergeCommand message(String message) {+ this.message = message;+ return this;+ }++ @Override+ public String call() {+ Preconditions.checkNotNull(revision, "revision has to be specified.");++ Commandline cmd = cmd().addArgs("merge");++ cmd.addArgs("--no-edit", "--quiet");++ if (fastForwardMode == FastForwardMode.FF_ONLY)+ cmd.addArgs("--ff-only");+ else if (fastForwardMode == FastForwardMode.NO_FF)+ cmd.addArgs("--no-ff");+ else+ cmd.addArgs("--ff");++ if (strategy != null)+ cmd.addArgs("--strategy=" + strategy);+ if (strategyOption != null)+ cmd.addArgs("--strategy-option=" + strategyOption);++ if (squash)+ cmd.addArgs("--squash");+ else if (message != null)+ cmd.addArgs("-m", message);++ cmd.addArgs(revision);++ final AtomicBoolean conflict = new AtomicBoolean(false);++ ExecuteResult result = cmd.execute(new LineConsumer() {++ @Override+ public void consume(String line) {+ if (line.startsWith("CONFLICT") || line.startsWith("fatal: Not possible to fast-forward"))+ conflict.set(true);+ }++ }, new LineConsumer() {++ @Override+ public void consume(String line) {+ logger.error(line);+ }++ });++ if (conflict.get())+ return null;++ result.checkReturnCode();++ Git git = new Git(repoDir);+ if (squash)+ git.commit(message, false, false);+ return git.parseRevision("HEAD", true);+ }++}diff --git a/commons.util/src/main/java/com/pmease/commons/util/StringUtils.java b/commons.util/src/main/java/com/pmease/commons/util/StringUtils.javaindex c4f3e39e3a..4d72a7c7d1 100644--- a/commons.util/src/main/java/com/pmease/commons/util/StringUtils.java+++ b/commons.util/src/main/java/com/pmease/commons/util/StringUtils.java@@ -1,329 +1,329 @@-package com.pmease.commons.util;--import java.io.BufferedReader;-import java.io.IOException;-import java.io.StreamTokenizer;-import java.io.StringReader;-import java.util.ArrayList;-import java.util.Collection;-import java.util.List;-import java.util.StringTokenizer;--import javax.annotation.Nullable;--import com.google.common.base.CaseFormat;--public class StringUtils extends org.apache.commons.lang3.StringUtils {-- /**- * Split specified string with specified separator and trim the result fields.- *- * @param str- * @param separator- * @return- * modifiable collection of split fields. Leading and trailing white spaces will be trimmed- * from these fields. Element of the resulting collection will never be null or- * empty string- */- public static List<String> splitAndTrim(String str, String separator) {- List<String> fields = new ArrayList<String>();- for (String each: StringUtils.split(str, separator)) {- if (each != null && each.trim().length() != 0)- fields.add(each.trim());- }- return fields;- }-- /**- * Split specified string with comma and line separator.- *- * @param str- * string to be split- * @return- * modifiable collection of split fields. Leading and trailing white spaces will be trimmed- * from these fields. Element of resulting collection will never be null or empty string- */- public static List<String> splitAndTrim(String str) {- return splitAndTrim(str, ",\n");- }-- public static String trimStart(String str) {- return StringUtils.stripStart(str, " \r\n\t");- }-- public static String trimEnd(String str) {- return StringUtils.stripEnd(str, " \r\n\t");- }-- /**- * Parse specified string into tokens. Content surrounded with " character- * is considered as a single token. For example: echo "hello world" will be parsed- * into two tokens, respectively [echo], and [hello world]. The quote character- * itself can be quoted and escaped in order to return as ordinary character. For- * example: echo "hello \" world" will be parsed into two tokens: [echo] and- * [hello " world].- * @param string- * @return- */- public static String[] parseQuoteTokens(String string) {- List<String> commandTokens = new ArrayList<String>();-- StreamTokenizer st = new StreamTokenizer(- new BufferedReader(new StringReader(string)));- st.resetSyntax();- st.wordChars(0, 255);- st.ordinaryChar(' ');- st.ordinaryChar('\n');- st.ordinaryChar('\t');- st.ordinaryChar('\r');- st.quoteChar('"');-- try {- String token = null;- while (st.nextToken() != StreamTokenizer.TT_EOF) {- if (st.ttype == '"' || st.ttype == StreamTokenizer.TT_WORD) {- if (token == null)- token = st.sval;- else- token += st.sval;- } else if (token != null) {- commandTokens.add(token);- token = null;- }- }- if (token != null)- commandTokens.add(token);- } catch (IOException e) {- throw new RuntimeException(e);- }-- return commandTokens.toArray(new String[commandTokens.size()]);- }-- /**- * Tokenize the given String into a String array via a StringTokenizer.- * Trims tokens and omits empty tokens.- * <p>The given delimiters string is supposed to consist of any number of- * delimiter characters. Each of those characters can be used to separate- * tokens. A delimiter is always a single character; for multi-character- * delimiters, consider using <code>delimitedListToStringArray</code>- * <p/>- * <p>Copied from the Spring Framework while retaining all license, copyright and author information.- *- * @param str the String to tokenize- * @param delimiters the delimiter characters, assembled as String- * (each of those characters is individually considered as delimiter).- * @return an array of the tokens- * @see java.util.StringTokenizer- * @see java.lang.String#trim()- */- public static String[] tokenizeToStringArray(String str, String delimiters) {- return tokenizeToStringArray(str, delimiters, true, true);- }-- /**- * Tokenize the given String into a String array via a StringTokenizer.- * <p>The given delimiters string is supposed to consist of any number of- * delimiter characters. Each of those characters can be used to separate- * tokens. A delimiter is always a single character; for multi-character- * delimiters, consider using <code>delimitedListToStringArray</code>- * <p/>- * <p>Copied from the Spring Framework while retaining all license, copyright and author information.- *- * @param str the String to tokenize- * @param delimiters the delimiter characters, assembled as String- * (each of those characters is individually considered as delimiter)- * @param trimTokens trim the tokens via String's <code>trim</code>- * @param ignoreEmptyTokens omit empty tokens from the result array- * (only applies to tokens that are empty after trimming; StringTokenizer- * will not consider subsequent delimiters as token in the first place).- * @return an array of the tokens (<code>null</code> if the input String- * was <code>null</code>)- * @see java.util.StringTokenizer- * @see java.lang.String#trim()- */- public static String[] tokenizeToStringArray(- String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {-- if (str == null) {- return null;- }- StringTokenizer st = new StringTokenizer(str, delimiters);- List<String> tokens = new ArrayList<String>();- while (st.hasMoreTokens()) {- String token = st.nextToken();- if (trimTokens) {- token = token.trim();- }- if (!ignoreEmptyTokens || token.length() > 0) {- tokens.add(token);- }- }- return toStringArray(tokens);- }-- /**- * Copy the given Collection into a String array.- * The Collection must contain String elements only.- * <p/>- * <p>Copied from the Spring Framework while retaining all license, copyright and author information.- *- * @param collection the Collection to copy- * @return the String array (<code>null</code> if the passed-in- * Collection was <code>null</code>)- */- public static String[] toStringArray(Collection<?> collection) {- if (collection == null) {- return null;- }- return collection.toArray(new String[collection.size()]);- }-- /**- * Convert camel case string into lower case with underscore, for example:- * input: FirstSecondThird- * output: first_second_third- *- * @param input- * @return lower case string with underscore- */- public static @Nullable String camelCaseToLowerCaseWithUnderscore(@Nullable String input) {- if (input == null)- return input;-- return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, input);- }-- /**- * Convert camel case string into lower case with hyphen, for example:- * input: FirstSecondThird- * output: first-second-third- *- * @param input- * @return lower case string with hyphen- */- public static @Nullable String camelCaseToLowerCaseWithHyphen(@Nullable String input) {- if (input == null)- return input;-- return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, input);- }-- public static String camelCaseToLowerCaseWithConnector(String input, char connector) {- if (input == null) return input; // garbage in, garbage out- int length = input.length();- StringBuilder result = new StringBuilder(length * 2);- int resultLength = 0;- boolean wasPrevTranslated = false;- for (int i = 0; i < length; i++)- {- char c = input.charAt(i);- if (i > 0 || c != connector) // skip first starting underscore- {- if (Character.isUpperCase(c))- {- if (!wasPrevTranslated && resultLength > 0 && result.charAt(resultLength - 1) != connector)- {- result.append(connector);- resultLength++;- }- c = Character.toLowerCase(c);- wasPrevTranslated = true;- }- else- {- wasPrevTranslated = false;- }- result.append(c);- resultLength++;- }- }- return resultLength > 0 ? result.toString() : input;- }-- private static final String SINGLE_QUOTE = "\'";- private static final String DOUBLE_QUOTE = "\"";- /**- * Put quotes around the given String if necessary.- * <p>- * If the argument doesn't include spaces or quotes, return it as is. If it- * contains double quotes, use single quotes - else surround the argument by- * double quotes.- * </p>- *- * @param argument the argument to be quoted- * @return the quoted argument- * @throws IllegalArgumentException If argument contains both types of quotes- */- public static String quoteArgument(final String argument) {-- String cleanedArgument = argument.trim();-- // strip the quotes from both ends- while(cleanedArgument.startsWith(SINGLE_QUOTE) || cleanedArgument.startsWith(DOUBLE_QUOTE)) {- cleanedArgument = cleanedArgument.substring(1);- }-- while(cleanedArgument.endsWith(SINGLE_QUOTE) || cleanedArgument.endsWith(DOUBLE_QUOTE)) {- cleanedArgument = cleanedArgument.substring(0, cleanedArgument.length() - 1);- }-- final StringBuffer buf = new StringBuffer();- if (cleanedArgument.indexOf(DOUBLE_QUOTE) > -1) {- if (cleanedArgument.indexOf(SINGLE_QUOTE) > -1) {- throw new IllegalArgumentException(- "Can't handle single and double quotes in same argument");- } else {- return buf.append(SINGLE_QUOTE).append(cleanedArgument).append(- SINGLE_QUOTE).toString();- }- } else if (cleanedArgument.indexOf(SINGLE_QUOTE) > -1- || cleanedArgument.indexOf(" ") > -1) {- return buf.append(DOUBLE_QUOTE).append(cleanedArgument).append(- DOUBLE_QUOTE).toString();- } else {- return cleanedArgument;- }- }-- public static int calcLevenshteinDistance(String str1, String str2) {- int len0 = str1.length() + 1;- int len1 = str2.length() + 1;-- // the array of distances- int[] cost = new int[len0];- int[] newcost = new int[len0];-- // initial cost of skipping prefix in String s0- for (int i = 0; i < len0; i++) cost[i] = i;-- // dynamically computing the array of distances-- // transformation cost for each letter in s1- for (int j = 1; j < len1; j++) {- // initial cost of skipping prefix in String s1- newcost[0] = j;-- // transformation cost for each letter in s0- for(int i = 1; i < len0; i++) {- // matching current letters in both strings- int match = (str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0 : 1;-- // computing cost for each transformation- int cost_replace = cost[i - 1] + match;- int cost_insert = cost[i] + 1;- int cost_delete = newcost[i - 1] + 1;-- // keep minimum cost- newcost[i] = Math.min(Math.min(cost_insert, cost_delete), cost_replace);- }-- // swap cost/newcost arrays- int[] swap = cost; cost = newcost; newcost = swap;- }-- // the distance is the cost for transforming all letters in both strings- return cost[len0 - 1];- }--}+package com.pmease.commons.util;++import java.io.BufferedReader;+import java.io.IOException;+import java.io.StreamTokenizer;+import java.io.StringReader;+import java.util.ArrayList;+import java.util.Collection;+import java.util.List;+import java.util.StringTokenizer;++import javax.annotation.Nullable;++import com.google.common.base.CaseFormat;++public class StringUtils extends org.apache.commons.lang3.StringUtils {++ /**+ * Split specified string with specified separator and trim the result fields.+ *+ * @param str+ * @param separator+ * @return+ * modifiable collection of split fields. Leading and trailing white spaces will be trimmed+ * from these fields. Element of the resulting collection will never be null or+ * empty string+ */+ public static List<String> splitAndTrim(String str, String separator) {+ List<String> fields = new ArrayList<String>();+ for (String each: StringUtils.split(str, separator)) {+ if (each != null && each.trim().length() != 0)+ fields.add(each.trim());+ }+ return fields;+ }++ /**+ * Split specified string with comma and line separator.+ *+ * @param str+ * string to be split+ * @return+ * modifiable collection of split fields. Leading and trailing white spaces will be trimmed+ * from these fields. Element of resulting collection will never be null or empty string+ */+ public static List<String> splitAndTrim(String str) {+ return splitAndTrim(str, ",\n");+ }++ public static String trimStart(String str) {+ return StringUtils.stripStart(str, " \r\n\t");+ }++ public static String trimEnd(String str) {+ return StringUtils.stripEnd(str, " \r\n\t");+ }++ /**+ * Parse specified string into tokens. Content surrounded with " character+ * is considered as a single token. For example: echo "hello world" will be parsed+ * into two tokens, respectively [echo], and [hello world]. The quote character+ * itself can be quoted and escaped in order to return as ordinary character. For+ * example: echo "hello \" world" will be parsed into two tokens: [echo] and+ * [hello " world].+ * @param string+ * @return+ */+ public static String[] parseQuoteTokens(String string) {+ List<String> commandTokens = new ArrayList<String>();++ StreamTokenizer st = new StreamTokenizer(+ new BufferedReader(new StringReader(string)));+ st.resetSyntax();+ st.wordChars(0, 255);+ st.ordinaryChar(' ');+ st.ordinaryChar('\n');+ st.ordinaryChar('\t');+ st.ordinaryChar('\r');+ st.quoteChar('"');++ try {+ String token = null;+ while (st.nextToken() != StreamTokenizer.TT_EOF) {+ if (st.ttype == '"' || st.ttype == StreamTokenizer.TT_WORD) {+ if (token == null)+ token = st.sval;+ else+ token += st.sval;+ } else if (token != null) {+ commandTokens.add(token);+ token = null;+ }+ }+ if (token != null)+ commandTokens.add(token);+ } catch (IOException e) {+ throw new RuntimeException(e);+ }++ return commandTokens.toArray(new String[commandTokens.size()]);+ }++ /**+ * Tokenize the given String into a String array via a StringTokenizer.+ * Trims tokens and omits empty tokens.+ * <p>The given delimiters string is supposed to consist of any number of+ * delimiter characters. Each of those characters can be used to separate+ * tokens. A delimiter is always a single character; for multi-character+ * delimiters, consider using <code>delimitedListToStringArray</code>+ * <p/>+ * <p>Copied from the Spring Framework while retaining all license, copyright and author information.+ *+ * @param str the String to tokenize+ * @param delimiters the delimiter characters, assembled as String+ * (each of those characters is individually considered as delimiter).+ * @return an array of the tokens+ * @see java.util.StringTokenizer+ * @see java.lang.String#trim()+ */+ public static String[] tokenizeToStringArray(String str, String delimiters) {+ return tokenizeToStringArray(str, delimiters, true, true);+ }++ /**+ * Tokenize the given String into a String array via a StringTokenizer.+ * <p>The given delimiters string is supposed to consist of any number of+ * delimiter characters. Each of those characters can be used to separate+ * tokens. A delimiter is always a single character; for multi-character+ * delimiters, consider using <code>delimitedListToStringArray</code>+ * <p/>+ * <p>Copied from the Spring Framework while retaining all license, copyright and author information.+ *+ * @param str the String to tokenize+ * @param delimiters the delimiter characters, assembled as String+ * (each of those characters is individually considered as delimiter)+ * @param trimTokens trim the tokens via String's <code>trim</code>+ * @param ignoreEmptyTokens omit empty tokens from the result array+ * (only applies to tokens that are empty after trimming; StringTokenizer+ * will not consider subsequent delimiters as token in the first place).+ * @return an array of the tokens (<code>null</code> if the input String+ * was <code>null</code>)+ * @see java.util.StringTokenizer+ * @see java.lang.String#trim()+ */+ public static String[] tokenizeToStringArray(+ String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {++ if (str == null) {+ return null;+ }+ StringTokenizer st = new StringTokenizer(str, delimiters);+ List<String> tokens = new ArrayList<String>();+ while (st.hasMoreTokens()) {+ String token = st.nextToken();+ if (trimTokens) {+ token = token.trim();+ }+ if (!ignoreEmptyTokens || token.length() > 0) {+ tokens.add(token);+ }+ }+ return toStringArray(tokens);+ }++ /**+ * Copy the given Collection into a String array.+ * The Collection must contain String elements only.+ * <p/>+ * <p>Copied from the Spring Framework while retaining all license, copyright and author information.+ *+ * @param collection the Collection to copy+ * @return the String array (<code>null</code> if the passed-in+ * Collection was <code>null</code>)+ */+ public static String[] toStringArray(Collection<?> collection) {+ if (collection == null) {+ return null;+ }+ return collection.toArray(new String[collection.size()]);+ }++ /**+ * Convert camel case string into lower case with underscore, for example:+ * input: FirstSecondThird+ * output: first_second_third+ *+ * @param input+ * @return lower case string with underscore+ */+ public static @Nullable String camelCaseToLowerCaseWithUnderscore(@Nullable String input) {+ if (input == null)+ return input;++ return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, input);+ }++ /**+ * Convert camel case string into lower case with hyphen, for example:+ * input: FirstSecondThird+ * output: first-second-third+ *+ * @param input+ * @return lower case string with hyphen+ */+ public static @Nullable String camelCaseToLowerCaseWithHyphen(@Nullable String input) {+ if (input == null)+ return input;++ return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, input);+ }++ public static String camelCaseToLowerCaseWithConnector(String input, char connector) {+ if (input == null) return input; // garbage in, garbage out+ int length = input.length();+ StringBuilder result = new StringBuilder(length * 2);+ int resultLength = 0;+ boolean wasPrevTranslated = false;+ for (int i = 0; i < length; i++)+ {+ char c = input.charAt(i);+ if (i > 0 || c != connector) // skip first starting underscore+ {+ if (Character.isUpperCase(c))+ {+ if (!wasPrevTranslated && resultLength > 0 && result.charAt(resultLength - 1) != connector)+ {+ result.append(connector);+ resultLength++;+ }+ c = Character.toLowerCase(c);+ wasPrevTranslated = true;+ }+ else+ {+ wasPrevTranslated = false;+ }+ result.append(c);+ resultLength++;+ }+ }+ return resultLength > 0 ? result.toString() : input;+ }++ private static final String SINGLE_QUOTE = "\'";+ private static final String DOUBLE_QUOTE = "\"";+ /**+ * Put quotes around the given String if necessary.+ * <p>+ * If the argument doesn't include spaces or quotes, return it as is. If it+ * contains double quotes, use single quotes - else surround the argument by+ * double quotes.+ * </p>+ *+ * @param argument the argument to be quoted+ * @return the quoted argument+ * @throws IllegalArgumentException If argument contains both types of quotes+ */+ public static String quoteArgument(final String argument) {++ String cleanedArgument = argument.trim();++ // strip the quotes from both ends+ while(cleanedArgument.startsWith(SINGLE_QUOTE) || cleanedArgument.startsWith(DOUBLE_QUOTE)) {+ cleanedArgument = cleanedArgument.substring(1);+ }++ while(cleanedArgument.endsWith(SINGLE_QUOTE) || cleanedArgument.endsWith(DOUBLE_QUOTE)) {+ cleanedArgument = cleanedArgument.substring(0, cleanedArgument.length() - 1);+ }++ final StringBuffer buf = new StringBuffer();+ if (cleanedArgument.indexOf(DOUBLE_QUOTE) > -1) {+ if (cleanedArgument.indexOf(SINGLE_QUOTE) > -1) {+ throw new IllegalArgumentException(+ "Can't handle single and double quotes in same argument");+ } else {+ return buf.append(SINGLE_QUOTE).append(cleanedArgument).append(+ SINGLE_QUOTE).toString();+ }+ } else if (cleanedArgument.indexOf(SINGLE_QUOTE) > -1+ || cleanedArgument.indexOf(" ") > -1) {+ return buf.append(DOUBLE_QUOTE).append(cleanedArgument).append(+ DOUBLE_QUOTE).toString();+ } else {+ return cleanedArgument;+ }+ }++ public static int calcLevenshteinDistance(String str1, String str2) {+ int len0 = str1.length() + 1;+ int len1 = str2.length() + 1;++ // the array of distances+ int[] cost = new int[len0];+ int[] newcost = new int[len0];++ // initial cost of skipping prefix in String s0+ for (int i = 0; i < len0; i++) cost[i] = i;++ // dynamically computing the array of distances++ // transformation cost for each letter in s1+ for (int j = 1; j < len1; j++) {+ // initial cost of skipping prefix in String s1+ newcost[0] = j;++ // transformation cost for each letter in s0+ for(int i = 1; i < len0; i++) {+ // matching current letters in both strings+ int match = (str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0 : 1;++ // computing cost for each transformation+ int cost_replace = cost[i - 1] + match;+ int cost_insert = cost[i] + 1;+ int cost_delete = newcost[i - 1] + 1;++ // keep minimum cost+ newcost[i] = Math.min(Math.min(cost_insert, cost_delete), cost_replace);+ }++ // swap cost/newcost arrays+ int[] swap = cost; cost = newcost; newcost = swap;+ }++ // the distance is the cost for transforming all letters in both strings+ return cost[len0 - 1];+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/AlignResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/AlignResourceReference.javaindex 050fa3e2db..e2a1861c82 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/AlignResourceReference.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/AlignResourceReference.java@@ -1,29 +1,29 @@-package com.pmease.commons.wicket.assets.align;--import java.util.ArrayList;-import java.util.List;--import org.apache.wicket.markup.head.HeaderItem;-import org.apache.wicket.markup.head.JavaScriptHeaderItem;-import org.apache.wicket.request.resource.JavaScriptResourceReference;--import com.pmease.commons.wicket.assets.textareacaretposition.TextareaCaretPositionResourceReference;--public class AlignResourceReference extends JavaScriptResourceReference {-- private static final long serialVersionUID = 1L;-- public static final AlignResourceReference INSTANCE = new AlignResourceReference();-- private AlignResourceReference() {- super(AlignResourceReference.class, "jquery.align.js");- }-- @Override- public Iterable<? extends HeaderItem> getDependencies() {- List<HeaderItem> dependencies = new ArrayList<>();- dependencies.add(JavaScriptHeaderItem.forReference(TextareaCaretPositionResourceReference.INSTANCE));- return dependencies;- }--}+package com.pmease.commons.wicket.assets.align;++import java.util.ArrayList;+import java.util.List;++import org.apache.wicket.markup.head.HeaderItem;+import org.apache.wicket.markup.head.JavaScriptHeaderItem;+import org.apache.wicket.request.resource.JavaScriptResourceReference;++import com.pmease.commons.wicket.assets.textareacaretposition.TextareaCaretPositionResourceReference;++public class AlignResourceReference extends JavaScriptResourceReference {++ private static final long serialVersionUID = 1L;++ public static final AlignResourceReference INSTANCE = new AlignResourceReference();++ private AlignResourceReference() {+ super(AlignResourceReference.class, "jquery.align.js");+ }++ @Override+ public Iterable<? extends HeaderItem> getDependencies() {+ List<HeaderItem> dependencies = new ArrayList<>();+ dependencies.add(JavaScriptHeaderItem.forReference(TextareaCaretPositionResourceReference.INSTANCE));+ return dependencies;+ }++}diff --git a/gitplex.product/pom.xml b/gitplex.product/pom.xmlindex 2b2bcebc7e..ca5c17c81f 100644--- a/gitplex.product/pom.xml+++ b/gitplex.product/pom.xml@@ -1,168 +1,168 @@-<?xml version="1.0" encoding="UTF-8"?>--<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/xsd/maven-4.0.0.xsd">- <modelVersion>4.0.0</modelVersion>- <artifactId>gitplex</artifactId>- <name>GitPlex</name>- <parent>- <groupId>com.pmease</groupId>- <artifactId>parent.general</artifactId>- <version>1.0.31</version>- </parent>- <build>- <plugins>- <plugin>- <artifactId>maven-archetype-plugin</artifactId>- </plugin>- <plugin>- <artifactId>maven-source-plugin</artifactId>- </plugin>- <plugin>- <artifactId>maven-javadoc-plugin</artifactId>- </plugin>- <plugin>- <groupId>com.pmease</groupId>- <artifactId>plugin.maven</artifactId>- <executions>- <execution>- <id>copy-product-resources</id>- <phase>compile</phase>- <goals>- <goal>run-ant</goal>- </goals>- <configuration>- <target>- <copy todir="${project.build.directory}/sandbox">- <fileset dir="system"- excludes="site/images/**, site/avatars/**, **/*.keystore" />- <filterset>- <filter token="dbName" value="${project.artifactId}" />- <filter token="productName" value="${project.name}" />- </filterset>- </copy>- <copy todir="${project.build.directory}/sandbox">- <fileset dir="system"- includes="site/images/**, site/avatars/**, **/*.keystore" />- </copy>- </target>- </configuration>- </execution>- </executions>- </plugin>- <plugin>- <artifactId>maven-antrun-plugin</artifactId>- <executions>- <execution>- <id>prepare-package</id>- <phase>prepare-package</phase>- <goals>- <goal>run</goal>- </goals>- <configuration>- <target>- <taskdef name="gant" classname="org.codehaus.gant.ant.Gant" />- <gant file="build/prepare_package.gant">- <definition name="buildDirectory" value="${project.build.directory}" />- <definition name="outputDirectory" value="${project.build.outputDirectory}" />- <definition name="jswPath" value="${com.pmease:commons.jsw:jar}" />- <definition name="productId" value="${project.artifactId}" />- <definition name="productName" value="${project.name}" />- <definition name="bootstrapClass" value="${bootstrapClass}" />- </gant>- </target>- </configuration>- </execution>- <execution>- <id>package</id>- <phase>package</phase>- <goals>- <goal>run</goal>- </goals>- <configuration>- <target>- <taskdef name="gant" classname="org.codehaus.gant.ant.Gant" />- <gant file="build/package.gant">- <definition name="buildDirectory" value="${project.build.directory}" />- <definition name="executables" value="${executables}" />- <definition name="packageName"- value="${project.artifactId}-${project.version}" />- </gant>- </target>- </configuration>- </execution>- </executions>- </plugin>- </plugins>- </build>- <dependencies>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>commons.jsw</artifactId>- <version>1.0.31</version>- <scope>provided</scope>- </dependency>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>gitplex.core</artifactId>- <version>1.0.31</version>- </dependency>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>gitplex.web</artifactId>- <version>1.0.0</version>- </dependency>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>commons.loader</artifactId>- <version>1.0.31</version>- <type>test-jar</type>- <scope>test</scope>- </dependency>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>commons.git</artifactId>- <version>1.0.0</version>- <type>test-jar</type>- <scope>test</scope>- </dependency>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>gitplex.rest</artifactId>- <version>1.0.0</version>- </dependency>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>gitplex.http</artifactId>- <version>1.0.0</version>- </dependency>- <dependency>- <groupId>com.pmease</groupId>- <artifactId>gitplex.search</artifactId>- <version>1.0.0</version>- </dependency>- </dependencies>- <repositories>- <repository>- <id>pmeaseRepo</id>- <name>PMEase Repository</name>- <releases>- <enabled>true</enabled>- <updatePolicy>never</updatePolicy>- <checksumPolicy>fail</checksumPolicy>- </releases>- <snapshots>- <enabled>true</enabled>- <updatePolicy>always</updatePolicy>- <checksumPolicy>fail</checksumPolicy>- </snapshots>- <url>http://artifact.pmease.com/</url>- </repository>- </repositories>- <properties>- <executables>bin/*.sh, bin/wrapper-*</executables>- <bootstrapClass>com.pmease.commons.bootstrap.Bootstrap</bootstrapClass>- <moduleClass>com.pmease.gitplex.product.ProductModule</moduleClass>- <aggregation>true</aggregation>- </properties>-</project>+<?xml version="1.0" encoding="UTF-8"?>++<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/xsd/maven-4.0.0.xsd">+ <modelVersion>4.0.0</modelVersion>+ <artifactId>gitplex</artifactId>+ <name>GitPlex</name>+ <parent>+ <groupId>com.pmease</groupId>+ <artifactId>parent.general</artifactId>+ <version>1.0.31</version>+ </parent>+ <build>+ <plugins>+ <plugin>+ <artifactId>maven-archetype-plugin</artifactId>+ </plugin>+ <plugin>+ <artifactId>maven-source-plugin</artifactId>+ </plugin>+ <plugin>+ <artifactId>maven-javadoc-plugin</artifactId>+ </plugin>+ <plugin>+ <groupId>com.pmease</groupId>+ <artifactId>plugin.maven</artifactId>+ <executions>+ <execution>+ <id>copy-product-resources</id>+ <phase>compile</phase>+ <goals>+ <goal>run-ant</goal>+ </goals>+ <configuration>+ <target>+ <copy todir="${project.build.directory}/sandbox">+ <fileset dir="system"+ excludes="site/images/**, site/avatars/**, **/*.keystore" />+ <filterset>+ <filter token="dbName" value="${project.artifactId}" />+ <filter token="productName" value="${project.name}" />+ </filterset>+ </copy>+ <copy todir="${project.build.directory}/sandbox">+ <fileset dir="system"+ includes="site/images/**, site/avatars/**, **/*.keystore" />+ </copy>+ </target>+ </configuration>+ </execution>+ </executions>+ </plugin>+ <plugin>+ <artifactId>maven-antrun-plugin</artifactId>+ <executions>+ <execution>+ <id>prepare-package</id>+ <phase>prepare-package</phase>+ <goals>+ <goal>run</goal>+ </goals>+ <configuration>+ <target>+ <taskdef name="gant" classname="org.codehaus.gant.ant.Gant" />+ <gant file="build/prepare_package.gant">+ <definition name="buildDirectory" value="${project.build.directory}" />+ <definition name="outputDirectory" value="${project.build.outputDirectory}" />+ <definition name="jswPath" value="${com.pmease:commons.jsw:jar}" />+ <definition name="productId" value="${project.artifactId}" />+ <definition name="productName" value="${project.name}" />+ <definition name="bootstrapClass" value="${bootstrapClass}" />+ </gant>+ </target>+ </configuration>+ </execution>+ <execution>+ <id>package</id>+ <phase>package</phase>+ <goals>+ <goal>run</goal>+ </goals>+ <configuration>+ <target>+ <taskdef name="gant" classname="org.codehaus.gant.ant.Gant" />+ <gant file="build/package.gant">+ <definition name="buildDirectory" value="${project.build.directory}" />+ <definition name="executables" value="${executables}" />+ <definition name="packageName"+ value="${project.artifactId}-${project.version}" />+ </gant>+ </target>+ </configuration>+ </execution>+ </executions>+ </plugin>+ </plugins>+ </build>+ <dependencies>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>commons.jsw</artifactId>+ <version>1.0.31</version>+ <scope>provided</scope>+ </dependency>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>gitplex.core</artifactId>+ <version>1.0.31</version>+ </dependency>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>gitplex.web</artifactId>+ <version>1.0.0</version>+ </dependency>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>commons.loader</artifactId>+ <version>1.0.31</version>+ <type>test-jar</type>+ <scope>test</scope>+ </dependency>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>commons.git</artifactId>+ <version>1.0.0</version>+ <type>test-jar</type>+ <scope>test</scope>+ </dependency>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>gitplex.rest</artifactId>+ <version>1.0.0</version>+ </dependency>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>gitplex.http</artifactId>+ <version>1.0.0</version>+ </dependency>+ <dependency>+ <groupId>com.pmease</groupId>+ <artifactId>gitplex.search</artifactId>+ <version>1.0.0</version>+ </dependency>+ </dependencies>+ <repositories>+ <repository>+ <id>pmeaseRepo</id>+ <name>PMEase Repository</name>+ <releases>+ <enabled>true</enabled>+ <updatePolicy>never</updatePolicy>+ <checksumPolicy>fail</checksumPolicy>+ </releases>+ <snapshots>+ <enabled>true</enabled>+ <updatePolicy>always</updatePolicy>+ <checksumPolicy>fail</checksumPolicy>+ </snapshots>+ <url>http://artifact.pmease.com/</url>+ </repository>+ </repositories>+ <properties>+ <executables>bin/*.sh, bin/wrapper-*</executables>+ <bootstrapClass>com.pmease.commons.bootstrap.Bootstrap</bootstrapClass>+ <moduleClass>com.pmease.gitplex.product.ProductModule</moduleClass>+ <aggregation>true</aggregation>+ </properties>+</project>diff --git a/gitplex.product/src/test/java/gitplex/product/Test.java b/gitplex.product/src/test/java/gitplex/product/Test.javaindex b10dd53b80..aa23c287ac 100644--- a/gitplex.product/src/test/java/gitplex/product/Test.java+++ b/gitplex.product/src/test/java/gitplex/product/Test.java@@ -1,11 +1,11 @@-package gitplex.product;--import java.io.IOException;--public class Test {-- @org.junit.Test- public void test() throws IOException {- }-+package gitplex.product;++import java.io.IOException;++public class Test {++ @org.junit.Test+ public void test() throws IOException {+ }+}\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/CommitQuery.g4 b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/CommitQuery.g4index c1537195a6..1439c2429f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/CommitQuery.g4+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/CommitQuery.g4@@ -1,44 +1,44 @@-grammar CommitQuery;--query: criteria+ EOF;--criteria: revisionCriteria | before | after | committer | author | path | message;--revisionCriteria- : revision # SingleRevision- | EXCLUDE revision # RevisionExclusion- | revision Range revision # RevisionRange- ;--revision: (BRANCH|TAG|ID) Value;--before: BEFORE Value;--after: AFTER Value;--committer: COMMITTER Value;--author: AUTHOR Value;--path: PATH Value;--message: MESSAGE Value;--BRANCH: 'branch';-TAG: 'tag';-ID: 'id';-BEFORE: 'before';-AFTER: 'after';-MESSAGE: 'message';-COMMITTER: 'committer';-AUTHOR: 'author';-PATH: 'path';-EXCLUDE: '^';--Range: '..' | '...';-Value: '(' (ESCAPE|~[()\\])+? ')';--fragment-ESCAPE: '\\'[()\\];-+grammar CommitQuery;++query: criteria+ EOF;++criteria: revisionCriteria | before | after | committer | author | path | message;++revisionCriteria+ : revision # SingleRevision+ | EXCLUDE revision # RevisionExclusion+ | revision Range revision # RevisionRange+ ;++revision: (BRANCH|TAG|ID) Value;++before: BEFORE Value;++after: AFTER Value;++committer: COMMITTER Value;++author: AUTHOR Value;++path: PATH Value;++message: MESSAGE Value;++BRANCH: 'branch';+TAG: 'tag';+ID: 'id';+BEFORE: 'before';+AFTER: 'after';+MESSAGE: 'message';+COMMITTER: 'committer';+AUTHOR: 'author';+PATH: 'path';+EXCLUDE: '^';++Range: '..' | '...';+Value: '(' (ESCAPE|~[()\\])+? ')';++fragment+ESCAPE: '\\'[()\\];+WS: [ \t\r\n]+ -> skip;\ No newline at end of file