Skip to content

Commit 6eb138f

Browse files
author
Yoshito Umaoka
committed
Updated the resource filter implementation. Integrated new GP java client APIs to keep resource ordering. Many other changes.
1 parent defea58 commit 6eb138f

65 files changed

Lines changed: 2735 additions & 552 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gp-cli/.classpath

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<attribute name="maven.pomderived" value="true"/>
1212
</attributes>
1313
</classpathentry>
14-
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
14+
<classpathentry combineaccessrules="false" kind="src" path="/gaas-java-client"/>
1515
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
1616
<attributes>
1717
<attribute name="maven.pomderived" value="true"/>
@@ -23,5 +23,7 @@
2323
<attribute name="maven.pomderived" value="true"/>
2424
</attributes>
2525
</classpathentry>
26+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
27+
<classpathentry combineaccessrules="false" kind="src" path="/gp-res-filter"/>
2628
<classpathentry kind="output" path="target/classes"/>
2729
</classpath>

gp-cli/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<artifactId>gp-java-tools</artifactId>
55
<groupId>com.ibm.g11n.pipeline</groupId>
6-
<version>1.0.0-SNAPSHOT</version>
6+
<version>1.1.0-SNAPSHOT</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>gp-cli</artifactId>

gp-cli/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.ibm.g11n.pipeline</groupId>
88
<artifactId>gp-java-tools</artifactId>
9-
<version>1.0.0-SNAPSHOT</version>
9+
<version>1.1.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>gp-cli</artifactId>
1212
<name>gp-cli</name>
@@ -61,16 +61,22 @@
6161
<version>1.48</version>
6262
</dependency>
6363

64+
<dependency>
65+
<groupId>com.google.code.gson</groupId>
66+
<artifactId>gson</artifactId>
67+
<version>2.6.1</version>
68+
</dependency>
69+
6470
<dependency>
6571
<groupId>com.ibm.g11n.pipeline</groupId>
6672
<artifactId>gp-java-client</artifactId>
67-
<version>1.0.0</version>
73+
<version>1.1.0</version>
6874
</dependency>
6975

7076
<dependency>
7177
<groupId>com.ibm.g11n.pipeline</groupId>
7278
<artifactId>gp-res-filter</artifactId>
73-
<version>1.0.0-SNAPSHOT</version>
79+
<version>1.1.0-SNAPSHOT</version>
7480
</dependency>
7581
</dependencies>
7682
</project>

gp-cli/src/main/java/com/ibm/g11n/pipeline/tools/cli/ExportCmd.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
package com.ibm.g11n.pipeline.tools.cli;
1717

1818
import java.io.File;
19-
import java.io.FileOutputStream;
2019
import java.io.FileInputStream;
20+
import java.io.FileOutputStream;
2121
import java.io.IOException;
22+
import java.util.Collection;
23+
import java.util.LinkedList;
2224
import java.util.Map;
25+
import java.util.Map.Entry;
2326

2427
import com.beust.jcommander.Parameter;
2528
import com.beust.jcommander.Parameters;
29+
import com.ibm.g11n.pipeline.client.ResourceEntryData;
2630
import com.ibm.g11n.pipeline.client.ServiceException;
2731
import com.ibm.g11n.pipeline.resfilter.ResourceFilter;
2832
import com.ibm.g11n.pipeline.resfilter.ResourceFilterFactory;
33+
import com.ibm.g11n.pipeline.resfilter.ResourceString;
2934
import com.ibm.g11n.pipeline.resfilter.ResourceType;
3035

3136
/**
@@ -68,11 +73,27 @@ final class ExportCmd extends BundleCmd {
6873

6974
@Override
7075
protected void _execute() {
71-
Map<String, String> resStrings = null;
76+
Map<String, ResourceEntryData> resEntries = null;
77+
Collection<ResourceString> resStrings = new LinkedList<>();
7278
try {
73-
resStrings =
74-
getClient().getResourceStrings(bundleId, languageId, fallback);
75-
79+
resEntries =
80+
getClient().getResourceEntries(bundleId, languageId);
81+
for (Entry<String, ResourceEntryData> entry : resEntries.entrySet()) {
82+
String key = entry.getKey();
83+
ResourceEntryData data = entry.getValue();
84+
String resVal = data.getValue();
85+
Integer seqNum = data.getSequenceNumber();
86+
if (resVal == null && fallback) {
87+
resVal = data.getSourceValue();
88+
}
89+
if (resVal != null) {
90+
ResourceString resString = new ResourceString(key, resVal);
91+
if (seqNum != null) {
92+
resString.setSequenceNumber(seqNum.intValue());
93+
}
94+
resStrings.add(resString);
95+
}
96+
}
7697
} catch (ServiceException e) {
7798
throw new RuntimeException(e);
7899
}

gp-cli/src/main/java/com/ibm/g11n/pipeline/tools/cli/GPCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ public static void main(String[] args) {
3838

3939
jc.addCommand("help", new HelpCmd());
4040

41-
jc.addCommand("list-bundle", new ListBundleCmd(), "list");
41+
jc.addCommand("list-bundle", new ListBundlesCmd(), "list");
4242
jc.addCommand("show-bundle", new ShowBundleCmd(), "show");
4343
jc.addCommand("create-bundle", new CreateBundleCmd(), "create");
4444
jc.addCommand("delete-bundle", new DeleteBundleCmd(), "delete");
4545
jc.addCommand("export", new ExportCmd());
4646
jc.addCommand("import", new ImportCmd());
47+
jc.addCommand("list-mt-languages", new ListMTLanguagesCmd());
4748

4849
//users
4950
jc.addCommand("list-users", new ListUsersCmd());

gp-cli/src/main/java/com/ibm/g11n/pipeline/tools/cli/ImportCmd.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
import java.io.File;
1919
import java.io.FileInputStream;
2020
import java.io.IOException;
21+
import java.util.Collection;
22+
import java.util.HashMap;
2123
import java.util.Map;
2224

2325
import com.beust.jcommander.Parameter;
2426
import com.beust.jcommander.Parameters;
27+
import com.ibm.g11n.pipeline.client.NewResourceEntryData;
2528
import com.ibm.g11n.pipeline.client.ServiceException;
2629
import com.ibm.g11n.pipeline.resfilter.ResourceFilter;
2730
import com.ibm.g11n.pipeline.resfilter.ResourceFilterFactory;
31+
import com.ibm.g11n.pipeline.resfilter.ResourceString;
2832
import com.ibm.g11n.pipeline.resfilter.ResourceType;
2933

3034
/**
@@ -55,18 +59,27 @@ final class ImportCmd extends BundleCmd {
5559

5660
@Override
5761
protected void _execute() {
58-
Map<String, String> resStrings = null;
62+
Map<String, NewResourceEntryData> resEntries = null;
5963
ResourceFilter filter = ResourceFilterFactory.get(type);
6064
File f = new File(fileName);
6165
try (FileInputStream fis = new FileInputStream(f)) {
62-
resStrings = filter.parse(fis);
66+
Collection<ResourceString> resStrings = filter.parse(fis);
67+
resEntries = new HashMap<>(resStrings.size());
68+
for (ResourceString resString : resStrings) {
69+
NewResourceEntryData resEntryData = new NewResourceEntryData(resString.getValue());
70+
int seqNum = resString.getSequenceNumber();
71+
if (seqNum >= 0) {
72+
resEntryData.setSequenceNumber(Integer.valueOf(seqNum));
73+
}
74+
resEntries.put(resString.getKey(), resEntryData);
75+
}
6376
} catch (IOException e) {
6477
throw new RuntimeException("Failed to read the resoruce data from "
6578
+ fileName + ": " + e.getMessage(), e);
6679
}
6780

6881
try {
69-
getClient().uploadResourceStrings(bundleId, languageId, resStrings);
82+
getClient().uploadResourceEntries(bundleId, languageId, resEntries);
7083
} catch (ServiceException e) {
7184
throw new RuntimeException(e);
7285
}

gp-cli/src/main/java/com/ibm/g11n/pipeline/tools/cli/ListBundleCmd.java renamed to gp-cli/src/main/java/com/ibm/g11n/pipeline/tools/cli/ListBundlesCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @author Yoshito Umaoka
2727
*/
2828
@Parameters(commandDescription = "Prints out translation bundle IDs.")
29-
final class ListBundleCmd extends ServiceInstanceCmd {
29+
final class ListBundlesCmd extends ServiceInstanceCmd {
3030
@Override
3131
protected void _execute() {
3232
try {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.ibm.g11n.pipeline.tools.cli;
2+
3+
import java.util.Collections;
4+
import java.util.Map;
5+
import java.util.Set;
6+
7+
import com.beust.jcommander.Parameter;
8+
import com.beust.jcommander.Parameters;
9+
import com.google.gson.Gson;
10+
import com.ibm.g11n.pipeline.client.ServiceException;
11+
12+
/**
13+
* Prints out a list of active machine translation languages for the given
14+
* source language.
15+
*
16+
* @author Yoshito Umaoka
17+
*/
18+
@Parameters(commandDescription = "Prints out active machine translation languages.")
19+
public class ListMTLanguagesCmd extends ServiceInstanceCmd {
20+
21+
@Parameter(
22+
names = {"-f", "--fromLanguage"},
23+
description = "Language ID of the translation source language",
24+
required = true)
25+
private String fromLanguage;
26+
27+
@Override
28+
protected void _execute() {
29+
Set<String> resultLanguages = null;
30+
try {
31+
Map<String, Set<String>> mtLanguages = getClient().getConfiguredMTLanguages();
32+
resultLanguages = mtLanguages.get(fromLanguage);
33+
} catch (ServiceException e) {
34+
throw new RuntimeException(e);
35+
}
36+
37+
if (resultLanguages == null) {
38+
resultLanguages = Collections.emptySet();
39+
}
40+
41+
Gson gson = new Gson();
42+
String outStr = gson.toJson(resultLanguages);
43+
System.out.println(outStr);
44+
}
45+
}

gp-res-filter/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<attribute name="maven.pomderived" value="true"/>
1212
</attributes>
1313
</classpathentry>
14-
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
1514
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
1615
<attributes>
1716
<attribute name="maven.pomderived" value="true"/>
@@ -23,5 +22,6 @@
2322
<attribute name="maven.pomderived" value="true"/>
2423
</attributes>
2524
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
2626
<classpathentry kind="output" path="target/classes"/>
2727
</classpath>

gp-res-filter/pom.xml

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,35 @@
66
<parent>
77
<groupId>com.ibm.g11n.pipeline</groupId>
88
<artifactId>gp-java-tools</artifactId>
9-
<version>1.0.0-SNAPSHOT</version>
9+
<version>1.1.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>gp-res-filter</artifactId>
1212
<name>gp-res-filter</name>
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<maven.compiler.target>1.8</maven.compiler.target>
1618
</properties>
1719

1820
<build>
1921
<plugins>
2022
<plugin>
2123
<groupId>org.apache.maven.plugins</groupId>
22-
<artifactId>maven-compiler-plugin</artifactId>
23-
<version>3.3</version>
24-
<configuration>
25-
<source>1.7</source>
26-
<target>1.7</target>
27-
</configuration>
24+
<artifactId>maven-dependency-plugin</artifactId>
25+
<version>2.10</version>
26+
<executions>
27+
<execution>
28+
<id>analyze</id>
29+
<goals>
30+
<goal>analyze-only</goal>
31+
</goals>
32+
<configuration>
33+
<ignoreNonCompile>true</ignoreNonCompile>
34+
<failOnWarning>true</failOnWarning>
35+
</configuration>
36+
</execution>
37+
</executions>
2838
</plugin>
2939
</plugins>
3040
</build>
@@ -33,7 +43,7 @@
3343
<dependency>
3444
<groupId>com.google.code.gson</groupId>
3545
<artifactId>gson</artifactId>
36-
<version>2.3.1</version>
46+
<version>2.6.1</version>
3747
</dependency>
3848

3949
<!-- For parsing AMD js -->
@@ -47,7 +57,25 @@
4757
<dependency>
4858
<groupId>com.fasterxml.jackson.dataformat</groupId>
4959
<artifactId>jackson-dataformat-yaml</artifactId>
50-
<version>2.5.4</version>
60+
<version>2.6.3</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>com.fasterxml.jackson.core</groupId>
64+
<artifactId>jackson-core</artifactId>
65+
<version>2.6.3</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.fasterxml.jackson.core</groupId>
69+
<artifactId>jackson-databind</artifactId>
70+
<version>2.6.3</version>
71+
</dependency>
72+
73+
<!-- JUnit -->
74+
<dependency>
75+
<groupId>junit</groupId>
76+
<artifactId>junit</artifactId>
77+
<version>4.12</version>
78+
<scope>test</scope>
5179
</dependency>
5280
</dependencies>
5381
</project>

0 commit comments

Comments
 (0)