From 1be968219de1abbca1dfea584c3a7b0ba13030aa Mon Sep 17 00:00:00 2001 From: Sean Flanigan Date: Thu, 14 Apr 2016 17:56:36 +1000 Subject: [PATCH] Implement push --list-file-types --- .../commands/init/SourceConfigPrompt.java | 3 +- .../client/commands/push/PushCommand.java | 7 ++++ .../client/commands/push/PushOptions.java | 2 + .../client/commands/push/PushOptionsImpl.java | 41 +++++++++++-------- .../client/commands/push/RawPushCommand.java | 22 ++++++++-- .../org/zanata/maven/AbstractPushMojo.java | 7 ++++ 6 files changed, 60 insertions(+), 22 deletions(-) diff --git a/zanata-client-commands/src/main/java/org/zanata/client/commands/init/SourceConfigPrompt.java b/zanata-client-commands/src/main/java/org/zanata/client/commands/init/SourceConfigPrompt.java index b063fa83..dc83004f 100644 --- a/zanata-client-commands/src/main/java/org/zanata/client/commands/init/SourceConfigPrompt.java +++ b/zanata-client-commands/src/main/java/org/zanata/client/commands/init/SourceConfigPrompt.java @@ -132,10 +132,11 @@ SourceConfigPrompt promptUser() throws Exception { console.blankLine(); console.printfln(Question, get("project.file.type.question")); - // this answer is not persisted in zanata.xml so user will still need to type it when they do the actual push + // FIXME invoke listFileTypes console.printfln(Hint, PushOptionsImpl.fileTypeHelp); console.printf(Question, get("file.type.prompt")); String answer = console.expectAnyNotBlankAnswer(); + // TODO this answer is not persisted in zanata.xml so user will still need to type it when they do the actual push ((PushOptionsImpl) pushOptions).setFileTypes(answer); } diff --git a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java index 18f85dd6..c8b04942 100644 --- a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java +++ b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushCommand.java @@ -111,6 +111,12 @@ public AbstractPushStrategy getStrategy(PushOptions pushOptions) { return strat; } + private void checkOptions() { + if (getOpts().getListFileTypes()) { + throw new RuntimeException("\"List file types\" is only supported for project type FILE"); + } + } + public static void logOptions(Logger logger, PushOptions opts) { if (!logger.isInfoEnabled()) { return; @@ -208,6 +214,7 @@ private boolean pushTrans() { @Override public void run() throws Exception { + checkOptions(); logOptions(log, getOpts()); pushCurrentModule(); diff --git a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptions.java b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptions.java index 34b24edd..67b6a37b 100644 --- a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptions.java +++ b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptions.java @@ -50,6 +50,8 @@ public interface PushOptions extends PushPullOptions { // raw file push public int getChunkSize(); + boolean getListFileTypes(); + public ImmutableList getFileTypes(); public String getValidate(); diff --git a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptionsImpl.java b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptionsImpl.java index bc0a0b20..9c46f997 100644 --- a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptionsImpl.java +++ b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/PushOptionsImpl.java @@ -49,6 +49,7 @@ public class PushOptionsImpl extends AbstractPushPullOptionsImpl private ImmutableList includes = ImmutableList.of(); private ImmutableList excludes = ImmutableList.of(); private ImmutableList fileTypes = ImmutableList.of(); + private boolean listFileTypes = false; private boolean defaultExcludes = DEF_EXCLUDES; private String mergeType = DEF_MERGE_TYPE; private boolean caseSensitive = DEF_CASE_SENSITIVE; @@ -189,24 +190,17 @@ public ImmutableList getFileTypes() { return fileTypes; } - public static final String fileTypeHelp = "File types to locate and transmit to the server. \n" + - "Default file extension will be used unless it is being specified. \n" + - "Pattern: TYPE[extension;extension],TYPE[extension] \n" + - "Supported types: \n" + - "\t XML_DOCUMENT_TYPE_DEFINITION[xml] \n" + - "\t PLAIN_TEXT[txt] \n" + - "\t IDML[idml] \n" + - "\t HTML[html;htm] \n" + - "\t OPEN_DOCUMENT_TEXT[odt] \n" + - "\t OPEN_DOCUMENT_PRESENTATION[odp] \n" + - "\t OPEN_DOCUMENT_GRAPHICS[odg] \n" + - "\t OPEN_DOCUMENT_SPREADSHEET[ods] \n" + - "\t SUBTITLE[srt;sbt;sub;vtt] \n" + - "\t GETTEXT[pot] \n" + - "\t PROPERTIES[properties] \n" + - "\t PROPERTIES_UTF8[properties] \n" + - "\t XLIFF[xml] \n" + - "Usage --file-types \"XML_DOCUMENT_TYPE_DEFINITION,PLAIN_TEXT[md;txt]\""; + public static final String fileTypeHelp = "File types to locate and transmit to the server.\n" + + "Pattern: TYPE[extension;extension],TYPE[extension] \n" + + "The default file extension(s) for each TYPE will be used unless\n" + + "'extension' is specified in square brackets. If overriding extensions,\n" + + "please note that most shells require quotes around square brackets unless\n" + + "they are escaped.\n" + + "The special type \"DEFAULTS\" can be used to inherit the default file types\n" + + "when setting this parameter. If this parameter is set without using\n" + + "\"DEFAULTS\", only the file types specified here will be used.\n" + + "Use --list-file-types to see supported types and their default extensions. \n" + + "Usage: --file-types \"DEFAULTS,PROPERTIES,PLAIN_TEXT[md;txt]\""; @Option(name = "--file-types", metaVar = "TYPES", usage = fileTypeHelp) @@ -214,6 +208,17 @@ public void setFileTypes(String fileTypes) { this.fileTypes = ImmutableList.copyOf(StringUtil.split(fileTypes, ",")); } + @Override + public boolean getListFileTypes() { + return this.listFileTypes; + } + + @Option(name = "--list-file-types", + usage = "List file types supported by the configured server") + public void setListFileTypes(boolean listFileTypes) { + this.listFileTypes = listFileTypes; + } + @Override public boolean getCaseSensitive() { return caseSensitive; diff --git a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/RawPushCommand.java b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/RawPushCommand.java index 971da529..e39c6033 100644 --- a/zanata-client-commands/src/main/java/org/zanata/client/commands/push/RawPushCommand.java +++ b/zanata-client-commands/src/main/java/org/zanata/client/commands/push/RawPushCommand.java @@ -30,8 +30,10 @@ import java.security.DigestInputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -46,6 +48,7 @@ import javax.annotation.Nullable; +import com.google.common.base.Joiner; import org.apache.commons.codec.binary.Hex; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; @@ -251,6 +254,22 @@ public void run() throws IOException { consoleInteractor.printfln(DisplayMode.Warning, "Using EXPERIMENTAL project type 'file'."); + List serverAcceptedTypes = client.acceptedFileTypes(); + + if (getOpts().getListFileTypes()) { + consoleInteractor.printfln(DisplayMode.Information, "Listing supported file types [with extensions]:"); + List types = new ArrayList<>(serverAcceptedTypes); + Collections.sort(types); + for (DocumentType docType : types) { + List sourceExtensions = new ArrayList<>(docType.getSourceExtensions()); + Collections.sort(sourceExtensions); + String exts = Joiner.on(';').join(sourceExtensions); + consoleInteractor.printfln(DisplayMode.Information, " %s[%s]", docType.name(), exts); + } + log.info("Listed file types: no files were pushed"); + return; + } + // only supporting single module for now File sourceDir = getOpts().getSrcDir(); @@ -271,9 +290,6 @@ public void run() throws IOException { RawPushStrategy strat = new RawPushStrategy(); strat.setPushOptions(getOpts()); - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") - List serverAcceptedTypes = client.acceptedFileTypes(); - Map> filteredDocTypes = validateFileTypes(serverAcceptedTypes, getOpts().getFileTypes()); diff --git a/zanata-maven-plugin/src/main/java/org/zanata/maven/AbstractPushMojo.java b/zanata-maven-plugin/src/main/java/org/zanata/maven/AbstractPushMojo.java index c06e6965..29f49aca 100644 --- a/zanata-maven-plugin/src/main/java/org/zanata/maven/AbstractPushMojo.java +++ b/zanata-maven-plugin/src/main/java/org/zanata/maven/AbstractPushMojo.java @@ -115,6 +115,8 @@ public PushPullCommand initCommand() { private String[] fileTypes = "txt,dtd,odt,fodt,odp,fodp,ods,fods,odg,fodg,odf,odb".split(","); + private boolean listFileTypes = false; + /** * Case sensitive for includes and excludes options. * @@ -195,6 +197,11 @@ public ImmutableList getFileTypes() { return ImmutableList.copyOf(fileTypes); } + @Override + public boolean getListFileTypes() { + return false; + } + @Override public String getCommandName() { return "push";