This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
PushOptionsImpl.java
245 lines (213 loc) · 8.24 KB
/
PushOptionsImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Copyright 2011, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.zanata.client.commands.push;
import com.google.common.collect.ImmutableList;
import org.kohsuke.args4j.Option;
import org.zanata.client.commands.AbstractPushPullOptionsImpl;
import org.zanata.client.commands.BooleanValueHandler;
import org.zanata.client.commands.PushPullType;
import org.zanata.client.commands.ZanataCommand;
import org.zanata.util.StringUtil;
/**
* @author Sean Flanigan <a
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
public class PushOptionsImpl extends AbstractPushPullOptionsImpl<PushOptions>
implements PushOptions {
private static final boolean DEF_EXCLUDES = true;
private static final boolean DEF_CASE_SENSITIVE = true;
private static final boolean DEF_EXCLUDE_LOCALES = true;
private static final boolean DEF_COPYTRANS = true;
private static final int DEF_CHUNK_SIZE = 1024 * 1024;
/** @see org.zanata.common.MergeType for options */
private static final String DEF_MERGE_TYPE = "AUTO";
private static final String DEF_PUSH_TYPE = "source";
private ImmutableList<String> includes = ImmutableList.of();
private ImmutableList<String> excludes = ImmutableList.of();
private ImmutableList<String> fileTypes = ImmutableList.of();
private boolean defaultExcludes = DEF_EXCLUDES;
private String mergeType = DEF_MERGE_TYPE;
private boolean caseSensitive = DEF_CASE_SENSITIVE;
private int chunkSize = DEF_CHUNK_SIZE;
private boolean excludeLocaleFilenames = DEF_EXCLUDE_LOCALES;
private boolean copyTrans = DEF_COPYTRANS;
private String pushType = DEF_PUSH_TYPE;
private String sourceLang = "en-US";
private String validate;
@Override
public ZanataCommand initCommand() {
if (PROJECT_TYPE_FILE.equalsIgnoreCase(getProjectType())) {
return new RawPushCommand(this);
} else {
return new PushCommand(this);
}
}
@Override
public String getCommandName() {
return "push";
}
@Override
public String getCommandDescription() {
return "Pushes source text to a Zanata project version so that it can be translated.";
}
@Override
public String getSourceLang() {
return sourceLang;
}
@Option(name = "--src-lang",
usage = "Language of source documents (defaults to en-US)")
public void setSourceLang(String sourceLang) {
this.sourceLang = sourceLang;
}
@Option(aliases = { "-l" }, name = "--locales",
metaVar = "LOCALE1,LOCALE2,...",
usage = "Locales to push to the server.\n"
+ "By default all locales in zanata.xml will be pushed.")
public void setLocales(String locales) {
this.locales = locales.split(",");
}
@Override
public boolean getCopyTrans() {
return copyTrans;
}
public boolean isCopyTrans() {
return copyTrans;
}
@Option(
name = "--copy-trans",
handler = BooleanValueHandler.class,
usage = "Copy latest translations from equivalent messages/documents in the database (default: "
+ DEF_COPYTRANS + ")")
public
void setCopyTrans(boolean copyTrans) {
this.copyTrans = copyTrans;
}
@Override
public String getMergeType() {
return mergeType;
}
@Option(name = "--merge-type", metaVar = "TYPE",
usage = "Merge type: \"auto\" (default) or \"import\" (DANGER!).")
public void setMergeType(String mergeType) {
this.mergeType = mergeType;
}
@Override
public PushPullType getPushType() {
return PushPullType.fromString(pushType);
}
@Option(
name = "--push-type",
metaVar = "TYPE",
required = false,
usage = "Type of push to perform on the server:\n"
+ " \"source\" (default) pushes source documents only.\n"
+ " \"trans\" pushes translation documents only.\n"
+ " \"both\" pushes both source and translation documents.")
public
void setPushType(String pushType) {
this.pushType = pushType;
}
@Override
public boolean getDefaultExcludes() {
return defaultExcludes;
}
@Option(
name = "--default-excludes",
handler = BooleanValueHandler.class,
usage = "Add the default excludes (.svn, .git, etc) to the excludes list (default: "
+ DEF_EXCLUDES + ")")
public
void setDefaultExcludes(boolean defaultExcludes) {
this.defaultExcludes = defaultExcludes;
}
@Override
public boolean getDeleteObsoleteModules() {
// modules are currently only supported by Maven Mojos:
return false;
}
@Override
public int getChunkSize() {
return chunkSize;
}
@Option(
name = "--chunk-size",
metaVar = "SIZE",
usage = "Maximum size, in bytes, of document chunks to transmit. Documents smaller\n"
+ "than this size will be transmitted in a single request, larger documents\n"
+ "will be sent over multiple requests.")
public
void setChunkSize(int chunkSize) {
this.chunkSize = chunkSize;
}
@Override
public ImmutableList<String> getFileTypes() {
return fileTypes;
}
@Option(name = "--file-types", metaVar = "TYPES",
usage = "File types to locate and transmit to the server.")
public void setFileTypes(String fileTypes) {
this.fileTypes = ImmutableList.copyOf(StringUtil.split(fileTypes, ","));
}
@Override
public boolean getCaseSensitive() {
return caseSensitive;
}
@Option(
name = "--case-sensitive",
handler = BooleanValueHandler.class,
usage = "Consider case of filenames in includes and excludes options. (default: "
+ DEF_CASE_SENSITIVE + ")")
public
void setCaseSensitive(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}
@Override
public boolean getExcludeLocaleFilenames() {
return excludeLocaleFilenames;
}
@Option(
name = "--exclude-locale-filenames",
handler = BooleanValueHandler.class,
usage = "Exclude filenames which match locales in zanata.xml (other than the\n"
+ "source locale). For instance, if zanata.xml includes de and fr,\n"
+ "then the files messages_de.properties and messages_fr.properties\n"
+ "will not be treated as source files.\n"
+ "NB: This parameter will be ignored for some project types which use\n"
+ "different file naming conventions (eg podir, gettext).\n"
+ "(default: " + DEF_EXCLUDE_LOCALES + ")")
public
void setExcludeLocaleFilenames(boolean excludeLocaleFilenames) {
this.excludeLocaleFilenames = excludeLocaleFilenames;
}
@Override
public String getValidate() {
return validate;
}
@Option(
name = "--validate",
metaVar = "TYPE",
usage = "Type of validation for XLIFF files. (values: XSD, CONTENT (default))")
public
void setValidate(String validate) {
this.validate = validate;
}
}