Skip to content

Commit 4569ae8

Browse files
author
Yoshito Umaoka
committed
Configuration for handling existing translated files
Updated the default exclusion filter for uplading files to exclude existing translated properties files (**/*_*.properties will be excluded as bundle source). Added plugin configuration <overwrite> true/false to control download goal to overwrite existing translation files with the ones exported from a GP instance. The default value is true. Updated resource filter implementation not to throw UnsupportedOperationException in merge() method. It does not make sense to catch UnsupportedOperationException on caller side, because we eventually implement the method. The implementation of a couple of resource filters was updated and fallback to write() method. Removed inore annotation from some resource filter test cases. We still want to run the test code to make sure they don't cause any crash, although the output might be what we expect at this point.
1 parent ae790b9 commit 4569ae8

9 files changed

Lines changed: 75 additions & 45 deletions

File tree

gp-maven-plugin/src/main/java/com/ibm/g11n/pipeline/maven/GPBaseMojo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import com.ibm.g11n.pipeline.resfilter.ResourceType;
4242

4343
/**
44-
* Base class of GP import/export Mojo.
44+
* Base class of GP download/upload Mojo.
4545
*
4646
* @author Yoshito Umaoka
4747
*/
@@ -184,6 +184,8 @@ protected synchronized List<BundleSet> getBundleSets() {
184184
FileSet fs = new FileSet();
185185
fs.setDirectory("src/main/resources");
186186
fs.addInclude("**/*.properties");
187+
// Note: This exclusion pattern might be too aggressive...
188+
fs.addExclude("**/*_*.properties");
187189
bundleSets = Collections.singletonList(new BundleSet(fs));
188190
}
189191
return bundleSets;

gp-maven-plugin/src/main/java/com/ibm/g11n/pipeline/maven/GPDownloadMojo.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.FileOutputStream;
2121
import java.io.IOException;
2222
import java.util.Collection;
23-
import java.util.EnumSet;
2423
import java.util.HashSet;
2524
import java.util.LinkedList;
2625
import java.util.List;
@@ -60,12 +59,19 @@ public class GPDownloadMojo extends GPBaseMojo {
6059
@Parameter(defaultValue = "${project.build.directory}/classes")
6160
private File outputDir;
6261

62+
/**
63+
* Whether this goal overwrites existing bundle file in output directory
64+
* or not. The default value is true.
65+
*/
66+
@Parameter(defaultValue = "true")
67+
private boolean overwrite;
68+
6369
/* (non-Javadoc)
6470
* @see org.apache.maven.plugin.Mojo#execute()
6571
*/
6672
@Override
6773
public void execute() throws MojoExecutionException, MojoFailureException {
68-
getLog().debug("Entering GPExportMojo#execute()");
74+
getLog().debug("Entering GPDownloadMojo#execute()");
6975

7076
ServiceClient client = getServiceClient();
7177

@@ -186,6 +192,18 @@ private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, S
186192
getLog().info("Exporting bundle:" + bf.getBundleId() + " language:" + language + " to "
187193
+ outputFile.getAbsolutePath());
188194

195+
if (outputFile.exists()) {
196+
if (overwrite) {
197+
getLog().info("The output bundle file:" + outputFile.getAbsolutePath()
198+
+ " already exists - overwriting");
199+
} else {
200+
getLog().info("The output bundle file:" + outputFile.getAbsolutePath()
201+
+ " already exists - skipping");
202+
// When overwrite is false, do nothing
203+
return;
204+
}
205+
}
206+
189207
if (!outputFile.getParentFile().exists()) {
190208
outputFile.getParentFile().mkdirs();
191209
}
@@ -223,27 +241,8 @@ private String getLanguageId(String gpLanguageTag, LanguageIdStyle langIdStyle,
223241
return languageId;
224242
}
225243

226-
// TODO: Some resource filter types do not support 'merge' method
227-
// and throwing UnsupportedOperationException at runtime. For now,
228-
// this implementation has hardcoded types that support 'merge' operation.
229-
// The resource filter API should provide a method returning if the filter
230-
// implementation supports the operation or not.
231-
private static final EnumSet<ResourceType> MERGE_AVAIL_TYPES =
232-
EnumSet.of(
233-
ResourceType.AMDJS,
234-
ResourceType.ANDROID,
235-
ResourceType.IOS,
236-
ResourceType.JAVA,
237-
ResourceType.PO,
238-
ResourceType.POT);
239-
240244
private void mergeTranslation(ServiceClient client, String bundleId, String language,
241245
ResourceType type, File srcFile, File outFile) throws MojoFailureException {
242-
if (!MERGE_AVAIL_TYPES.contains(type)) {
243-
exportTranslation(client, bundleId, language, type, outFile, true);
244-
return;
245-
}
246-
247246
Bundle resBundle = null;
248247
try {
249248
resBundle = getBundle(client, bundleId, language, false);

gp-maven-plugin/src/main/java/com/ibm/g11n/pipeline/maven/GPUploadMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class GPUploadMojo extends GPBaseMojo {
5151
*/
5252
@Override
5353
public void execute() throws MojoExecutionException, MojoFailureException {
54-
getLog().debug("Entering GPImportMojo#execute()");
54+
getLog().debug("Entering GPUploadMojo#execute()");
5555

5656
ServiceClient client = getServiceClient();
5757

gp-res-filter/.settings/org.eclipse.jdt.core.prefs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
66
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
77
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
88
org.eclipse.jdt.core.compiler.source=1.7
9+
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
910
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
1011
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
1112
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
@@ -19,8 +20,10 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
1920
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
2021
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
2122
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
23+
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
2224
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
2325
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
26+
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
2427
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
2528
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
2629
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
@@ -30,6 +33,8 @@ org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration
3033
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
3134
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
3235
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
36+
org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
37+
org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
3338
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
3439
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
3540
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
@@ -88,6 +93,7 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
8893
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
8994
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
9095
org.eclipse.jdt.core.formatter.indentation.size=4
96+
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
9197
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
9298
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
9399
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
@@ -282,12 +288,24 @@ org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
282288
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
283289
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
284290
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
291+
org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
292+
org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
293+
org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
294+
org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
295+
org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
296+
org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
297+
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
298+
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
299+
org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
300+
org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
285301
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
286302
org.eclipse.jdt.core.formatter.tabulation.char=space
287303
org.eclipse.jdt.core.formatter.tabulation.size=4
288304
org.eclipse.jdt.core.formatter.use_on_off_tags=false
289305
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
306+
org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
290307
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
308+
org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
291309
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
292310
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
293311
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/JsonResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void write(OutputStream outStream, String language, Bundle bundle) throws
8181
@Override
8282
public void merge(InputStream base, OutputStream outStream, String language, Bundle bundle)
8383
throws IOException {
84-
throw new UnsupportedOperationException("Merging JSON resource is not supported.");
84+
//TODO: Add merge implementation here. For now, fallback to write() operation.
85+
write(outStream, language, bundle);
8586
}
8687
}

gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/YMLResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ private void writeFile(OutputStream writer, Map<String, Object> map, int depth)
166166
@Override
167167
public void merge(InputStream base, OutputStream outStream, String language, Bundle bundle)
168168
throws IOException {
169-
throw new UnsupportedOperationException("Merging YML resource is not supported.");
169+
//TODO: Add merge implementation here. For now, fallback to write() operation.
170+
write(outStream, language, bundle);
170171
}
171172
}

gp-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/JsonResourceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.LinkedList;
3131
import java.util.List;
3232

33+
import org.junit.Ignore;
3334
import org.junit.Test;
3435

3536
import com.ibm.g11n.pipeline.resfilter.ResourceString.ResourceStringComparator;
@@ -92,15 +93,16 @@ public void testWrite() throws IOException {
9293
}
9394
}
9495

95-
@Test(expected = UnsupportedOperationException.class)
96+
@Test
9697
public void testMerge() throws IOException {
9798
File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".json");
9899
tempFile.deleteOnExit();
99100

100101
try (OutputStream os = new FileOutputStream(tempFile); InputStream is = new FileInputStream(INPUT_FILE)) {
101102
res.merge(is, os, null, WRITE_BUNDLE);
102103
os.flush();
103-
assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_FILE, tempFile));
104+
// TODO: Not ready yet
105+
// assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_FILE, tempFile));
104106
}
105107
}
106108
}

gp-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/XLIFFResourceTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.ibm.g11n.pipeline.resfilter;
1717

18-
import static org.junit.Assert.assertEquals;
1918
import static org.junit.Assert.assertTrue;
2019

2120
import java.io.File;
@@ -27,7 +26,6 @@
2726
import java.util.Collection;
2827
import java.util.LinkedList;
2928

30-
import org.junit.Ignore;
3129
import org.junit.Test;
3230

3331
/**
@@ -37,11 +35,14 @@
3735
public class XLIFFResourceTest {
3836
private static final File INPUT_FILE = new File("src/test/resource/resfilter/xliff/input.xlf");
3937

38+
@SuppressWarnings("unused")
4039
private static final File EXPECTED_WRITE_FILE = new File("src/test/resource/resfilter/xliff/write-output.xlf");
4140

4241
private static final File MERGE_INPUT_1_FILE = new File("src/test/resource/resfilter/xliff/merge-input-1.xlf");
4342
private static final File MERGE_INPUT_2_FILE = new File("src/test/resource/resfilter/xliff/merge-input-2.xlf");
43+
@SuppressWarnings("unused")
4444
private static final File EXPECTED_MERGE_1_FILE = new File("src/test/resource/resfilter/xliff/merge-output-1.xlf");
45+
@SuppressWarnings("unused")
4546
private static final File EXPECTED_MERGE_2_FILE = new File("src/test/resource/resfilter/xliff/merge-output-2.xlf");
4647

4748
private static Collection<ResourceString> EXPECTED_INPUT_RES_LIST;
@@ -76,18 +77,19 @@ public class XLIFFResourceTest {
7677

7778
private static final XLIFFResource res = new XLIFFResource();
7879

79-
@Ignore("not ready yet")
8080
@Test
8181
public void testParse() throws IOException {
8282
assertTrue("The input test file <" + INPUT_FILE + "> does not exist.", INPUT_FILE.exists());
8383

8484
try (InputStream is = new FileInputStream(INPUT_FILE)) {
85+
@SuppressWarnings("unused")
8586
Bundle bundle = res.parse(is);
86-
assertEquals("ResourceStrings did not match.", EXPECTED_INPUT_RES_LIST, bundle.getResourceStrings());
87+
// TODO: Not ready yet
88+
// assertEquals("ResourceStrings did not match.", EXPECTED_INPUT_RES_LIST, bundle.getResourceStrings());
8789
}
8890
}
8991

90-
@Ignore("not ready yet")
92+
@SuppressWarnings("deprecation")
9193
@Test
9294
public void testWrite() throws IOException {
9395
File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".xlf");
@@ -96,12 +98,12 @@ public void testWrite() throws IOException {
9698
try (OutputStream os = new FileOutputStream(tempFile)) {
9799
res.write(os, null, WRITE_BUNDLE);
98100
os.flush();
99-
100-
assertTrue(ResourceTestUtil.compareFiles(EXPECTED_WRITE_FILE, tempFile));
101+
// TODO: Not ready yet
102+
// assertTrue(ResourceTestUtil.compareFiles(EXPECTED_WRITE_FILE, tempFile));
101103
}
102104
}
103105

104-
@Ignore("not ready yet")
106+
@SuppressWarnings("deprecation")
105107
@Test
106108
public void testMerge() throws IOException {
107109
File tempFile;
@@ -113,7 +115,8 @@ public void testMerge() throws IOException {
113115
InputStream is = new FileInputStream(MERGE_INPUT_1_FILE)) {
114116
res.merge(is, os, "en", MERGE_BUNDLE);
115117
os.flush();
116-
assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_1_FILE, tempFile));
118+
// TODO: Not ready yet
119+
// assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_1_FILE, tempFile));
117120
}
118121

119122
tempFile = File.createTempFile(this.getClass().getSimpleName(), ".xlf");
@@ -123,7 +126,8 @@ public void testMerge() throws IOException {
123126
InputStream is = new FileInputStream(MERGE_INPUT_2_FILE)) {
124127
res.merge(is, os, "en", MERGE_BUNDLE);
125128
os.flush();
126-
assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_2_FILE, tempFile));
129+
// TODO: Not ready yet
130+
// assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_2_FILE, tempFile));
127131
}
128132
}
129133
}

gp-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/YMLResourceTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
public class YMLResourceTest {
3838
private static final File INPUT_FILE = new File("src/test/resource/resfilter/yml/input.yml");
3939

40+
@SuppressWarnings("unused")
4041
private static final File EXPECTED_WRITE_FILE = new File("src/test/resource/resfilter/yml/write-output.yml");
4142

43+
@SuppressWarnings("unused")
4244
private static final File EXPECTED_MERGE_FILE = new File("src/test/resource/resfilter/yml/merge-output.yml");
4345

4446
private static Collection<ResourceString> EXPECTED_INPUT_RES_LIST;
@@ -67,18 +69,18 @@ public class YMLResourceTest {
6769

6870
private static final YMLResource res = new YMLResource();
6971

70-
@Ignore("not ready yet")
7172
@Test
7273
public void testParse() throws IOException {
7374
assertTrue("The input test file <" + INPUT_FILE + "> does not exist.", INPUT_FILE.exists());
7475

7576
try (InputStream is = new FileInputStream(INPUT_FILE)) {
76-
Bundle bundle = res.parse(is);
77-
assertEquals("ResourceStrings did not match.", EXPECTED_INPUT_RES_LIST, bundle.getResourceStrings());
77+
@SuppressWarnings("unused")
78+
Bundle bundle = res.parse(is);
79+
// TODO: Not ready yet
80+
// assertEquals("ResourceStrings did not match.", EXPECTED_INPUT_RES_LIST, bundle.getResourceStrings());
7881
}
7982
}
8083

81-
@Ignore("not ready yet")
8284
@Test
8385
public void testWrite() throws IOException {
8486
File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".yml");
@@ -87,20 +89,21 @@ public void testWrite() throws IOException {
8789
try (OutputStream os = new FileOutputStream(tempFile)) {
8890
res.write(os, null, WRITE_BUNDLE);
8991
os.flush();
90-
91-
assertTrue(ResourceTestUtil.compareFiles(EXPECTED_WRITE_FILE, tempFile));
92+
// TODO: Not ready yet
93+
// assertTrue(ResourceTestUtil.compareFiles(EXPECTED_WRITE_FILE, tempFile));
9294
}
9395
}
9496

95-
@Test(expected = UnsupportedOperationException.class)
97+
@Test
9698
public void testMerge() throws IOException {
9799
File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".yml");
98100
tempFile.deleteOnExit();
99101

100102
try (OutputStream os = new FileOutputStream(tempFile); InputStream is = new FileInputStream(INPUT_FILE)) {
101103
res.merge(is, os, null, WRITE_BUNDLE);
102104
os.flush();
103-
assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_FILE, tempFile));
105+
// TODO: Not ready yet
106+
// assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_FILE, tempFile));
104107
}
105108
}
106109
}

0 commit comments

Comments
 (0)