Skip to content

Commit f1861fb

Browse files
authored
Merge pull request #119 from yumaoka/rfe-118-regexpath
Supports <pathToBundleMapper> and <sourcePathToTargetMapper>
2 parents cc5026a + 80ade08 commit f1861fb

12 files changed

Lines changed: 481 additions & 162 deletions

File tree

gp-maven-plugin/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,32 @@ If this parameter is not specified, `upload` goal creates a new Globalization Pi
450450
with all available machine translation target languages, and `download` goal exports all
451451
target languages currently available in the Globalization Pipeline bundle.
452452

453+
#### `<pathToBundleMapper>`
454+
455+
Specifies a mapping rule for converting source bundle file path to Globalization Pipeline bundle
456+
ID. To specify a mapping rule, use one or more `<regexMapper>` elements with pattern and replacement.
457+
A source resource file path relative to the base source directory (`<directory>` value in `<sourceFiles>` element) is used as the input of target path conversion specified by this setting.
458+
For each `<regexMapper>` element, substring matching a Java regular expression pattern specified by
459+
`<pattern>` value will be replaced with the value specified by `<replacement>` value.
460+
461+
The example below will remove `.properties` from a given path, then replace `/` with `.`.
462+
For example, an input path `com/ibm/g11n/example/MyStrings.properties` will produce
463+
a fully qualified Java class name `com.ibm.g11n.example.MyStrings`, which will be used as the
464+
Globalization Pipeline bundle ID for the resource file.
465+
466+
```
467+
<pathToBundleMapper>
468+
<regexMapper>
469+
<pattern>(.+).properties</pattern>
470+
<replacement>$1</replacement>
471+
</regexMapper>
472+
<regexMapper>
473+
<pattern>/</pattern>
474+
<replacement>\.</replacement>
475+
</regexMapper>
476+
</pathToBundleMapper>
477+
```
478+
453479
#### `<languageMap>`
454480

455481
Specifies custom language mappings. Each nested element name is a [BCP 47 language tag](https://tools.ietf.org/html/bcp47)
@@ -527,6 +553,31 @@ then the French version will be `com/ibm/g11n/fr/MyMessages.properties`.
527553

528554
The default value is **LANGUAGE_SUFFIX**.
529555

556+
*Note: This element is ignored when `<sourcePathToTargetMapper>` is specified.*
557+
558+
#### `<sourcePathToTargetMapper>`
559+
560+
Specifies mapping rule(s) to control output file path in `download` goal. To specify a mapping rule, use one or more `<regexMapper>` elements with pattern and replacement. A source resource file path
561+
relative to the base source directory (`<directory>` value in `<sourceFiles>` element) is used as
562+
the input of target path conversion specified by this setting. For each `<regexMapper>` element,
563+
substring matching a Java regular expression pattern specified by `<pattern>` value will be replaced
564+
with the value specified by `<replacement>` value. The final output path must contain a special
565+
place holder token `%LANG%`, which will be replaced with a target language code.
566+
567+
The example below will replace a folder `en` with `%LANG%`. For example, when a source file path
568+
is `nls/comp1/en/Help.json`, the path will be converted to `nls/comp1/%LANG%/Help.json`. Then,
569+
`%LANG%` will be replaced with language ID (configured by `<languageIdStyle>` and `<languageMap>`).
570+
571+
```
572+
<sourcePathToTargetMapper>
573+
<regexMapper>
574+
<pattern>(.+)/en/([^/]+).json</pattern>
575+
<replacement>$1/%LANG%/$2.json</replacement>
576+
</regexMapper>
577+
</sourcePathToTargetMapper>
578+
```
579+
580+
530581

531582
### Default Configuration
532583

Lines changed: 104 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,107 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project
3-
xmlns="http://maven.apache.org/POM/4.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
6-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
75

8-
<groupId>@project.groupId@</groupId>
9-
<artifactId>download-layout</artifactId>
10-
<version>@project.version@</version>
11-
<packaging>jar</packaging>
12-
<name>gp-maven-plugin integration test - download-layout</name>
13-
<build>
14-
<plugins>
15-
<plugin>
16-
<groupId>@project.groupId@</groupId>
17-
<artifactId>@project.artifactId@</artifactId>
18-
<version>@project.version@</version>
19-
<executions>
20-
<execution>
21-
<goals>
22-
<goal>download</goal>
23-
</goals>
24-
</execution>
25-
</executions>
26-
<configuration>
27-
<bundleSets>
28-
<bundleSet>
29-
<sourceFiles>
30-
<directory>src/main/resources</directory>
31-
<includes>
32-
<include>lang_suffix/*.json</include>
33-
</includes>
34-
</sourceFiles>
35-
<targetLanguages>
36-
<param>fr</param>
37-
<param>zh-Hans</param>
38-
</targetLanguages>
39-
<type>JSON</type>
40-
<bundleLayout>LANGUAGE_SUFFIX</bundleLayout>
41-
</bundleSet>
42-
<bundleSet>
43-
<sourceFiles>
44-
<directory>src/main/resources</directory>
45-
<includes>
46-
<include>lang_only/en.json</include>
47-
</includes>
48-
</sourceFiles>
49-
<targetLanguages>
50-
<param>fr</param>
51-
<param>zh-Hans</param>
52-
</targetLanguages>
53-
<type>JSON</type>
54-
<bundleLayout>LANGUAGE_ONLY</bundleLayout>
55-
</bundleSet>
56-
<bundleSet>
57-
<sourceFiles>
58-
<directory>src/main/resources</directory>
59-
<includes>
60-
<include>lang_dir/en/*.json</include>
61-
</includes>
62-
</sourceFiles>
63-
<targetLanguages>
64-
<param>fr</param>
65-
<param>zh-Hans</param>
66-
</targetLanguages>
67-
<type>JSON</type>
68-
<bundleLayout>LANGUAGE_DIR</bundleLayout>
69-
</bundleSet>
70-
<bundleSet>
71-
<sourceFiles>
72-
<directory>src/main/resources</directory>
73-
<includes>
74-
<include>lang_subdir/*.json</include>
75-
</includes>
76-
</sourceFiles>
77-
<targetLanguages>
78-
<param>fr</param>
79-
<param>zh-Hans</param>
80-
</targetLanguages>
81-
<type>JSON</type>
82-
<bundleLayout>LANGUAGE_SUBDIR</bundleLayout>
83-
</bundleSet>
84-
</bundleSets>
85-
</configuration>
86-
</plugin>
87-
</plugins>
88-
</build>
6+
<groupId>@project.groupId@</groupId>
7+
<artifactId>download-layout</artifactId>
8+
<version>@project.version@</version>
9+
<packaging>jar</packaging>
10+
<name>gp-maven-plugin integration test - download-layout</name>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>@project.groupId@</groupId>
15+
<artifactId>@project.artifactId@</artifactId>
16+
<version>@project.version@</version>
17+
<executions>
18+
<execution>
19+
<goals>
20+
<goal>download</goal>
21+
</goals>
22+
</execution>
23+
</executions>
24+
<configuration>
25+
<bundleSets>
26+
<bundleSet>
27+
<sourceFiles>
28+
<directory>src/main/resources</directory>
29+
<includes>
30+
<include>lang_suffix/*.json</include>
31+
</includes>
32+
</sourceFiles>
33+
<targetLanguages>
34+
<param>fr</param>
35+
<param>zh-Hans</param>
36+
</targetLanguages>
37+
<type>JSON</type>
38+
<bundleLayout>LANGUAGE_SUFFIX</bundleLayout>
39+
</bundleSet>
40+
<bundleSet>
41+
<sourceFiles>
42+
<directory>src/main/resources</directory>
43+
<includes>
44+
<include>lang_only/en.json</include>
45+
</includes>
46+
</sourceFiles>
47+
<targetLanguages>
48+
<param>fr</param>
49+
<param>zh-Hans</param>
50+
</targetLanguages>
51+
<type>JSON</type>
52+
<bundleLayout>LANGUAGE_ONLY</bundleLayout>
53+
</bundleSet>
54+
<bundleSet>
55+
<sourceFiles>
56+
<directory>src/main/resources</directory>
57+
<includes>
58+
<include>lang_dir/en/*.json</include>
59+
</includes>
60+
</sourceFiles>
61+
<targetLanguages>
62+
<param>fr</param>
63+
<param>zh-Hans</param>
64+
</targetLanguages>
65+
<type>JSON</type>
66+
<bundleLayout>LANGUAGE_DIR</bundleLayout>
67+
</bundleSet>
68+
<bundleSet>
69+
<sourceFiles>
70+
<directory>src/main/resources</directory>
71+
<includes>
72+
<include>lang_subdir/*.json</include>
73+
</includes>
74+
</sourceFiles>
75+
<targetLanguages>
76+
<param>fr</param>
77+
<param>zh-Hans</param>
78+
</targetLanguages>
79+
<type>JSON</type>
80+
<bundleLayout>LANGUAGE_SUBDIR</bundleLayout>
81+
</bundleSet>
82+
<bundleSet>
83+
<sourceFiles>
84+
<directory>src/main/resources</directory>
85+
<includes>
86+
<include>mapper/**/*.json</include>
87+
</includes>
88+
</sourceFiles>
89+
<targetLanguages>
90+
<param>fr</param>
91+
<param>zh-Hans</param>
92+
</targetLanguages>
93+
<type>JSON</type>
94+
<sourcePathToTargetMapper>
95+
<regexMapper>
96+
<pattern>(.+)/en_(.+).json</pattern>
97+
<replacement>$1/translated/%LANG%_$2.json</replacement>
98+
</regexMapper>
99+
</sourcePathToTargetMapper>
100+
<languageIdStyle>BCP47</languageIdStyle>
101+
</bundleSet>
102+
</bundleSets>
103+
</configuration>
104+
</plugin>
105+
</plugins>
106+
</build>
89107
</project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"key1": "val1"
3+
}

gp-maven-plugin/src/it/download-layout/verify.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def outFiles = [
2727
"target/classes/lang_dir/fr/Strings.json",
2828
"target/classes/lang_dir/zh_Hans/Strings.json",
2929
"target/classes/lang_subdir/fr/Strings.json",
30-
"target/classes/lang_subdir/zh_hans/Strings.json"
30+
"target/classes/lang_subdir/zh_hans/Strings.json",
31+
"target/classes/mapper/res/translated/fr_resource.json",
32+
"target/classes/mapper/res/translated/zh-Hans_resource.json"
3133
]
3234

3335
def missing = []

gp-maven-plugin/src/it/upload-basic/pom.xml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project
3-
xmlns="http://maven.apache.org/POM/4.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
53
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
64
<modelVersion>4.0.0</modelVersion>
75

@@ -16,7 +14,39 @@
1614
<groupId>@project.groupId@</groupId>
1715
<artifactId>@project.artifactId@</artifactId>
1816
<version>@pom.version@</version>
17+
18+
<configuration>
19+
<bundleSets>
20+
<bundleSet>
21+
<sourceFiles>
22+
<directory>src/main/resources</directory>
23+
<includes>
24+
<include>**/*.properties</include>
25+
</includes>
26+
</sourceFiles>
27+
</bundleSet>
28+
<bundleSet>
29+
<sourceFiles>
30+
<directory>src/main/resources</directory>
31+
<includes>
32+
<include>**/*_en.json</include>
33+
</includes>
34+
</sourceFiles>
35+
<type>JSON</type>
36+
<pathToBundleMapper>
37+
<regexMapper>
38+
<pattern>(.+)_en.json</pattern>
39+
<replacement>JSON-$1</replacement>
40+
</regexMapper>
41+
<regexMapper>
42+
<pattern>/</pattern>
43+
<replacement>_</replacement>
44+
</regexMapper>
45+
</pathToBundleMapper>
46+
</bundleSet>
47+
</bundleSets>
48+
</configuration>
1949
</plugin>
2050
</plugins>
21-
</build>
51+
</build>
2252
</project>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
broker-url=https://gp-fakebroker-unsubscribed-ceriman.au-syd.mybluemix.net/newInstance
22
credentials=credentials.json
3-
createdbundles=com.bundle1.ResourceBundle,com.bundle2.ResourceBundle,com.bundle3.Bundle_with_spaces
3+
createdbundles=com.bundle1.ResourceBundle,com.bundle2.ResourceBundle,com.bundle3.Bundle_with_spaces,JSON-com_bundle4_Strings
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"key1": "val1"
3+
}

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.ibm.g11n.pipeline.maven;
1717

1818
import java.io.File;
19+
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Set;
2122

@@ -62,6 +63,11 @@ public class BundleSet {
6263
@Parameter(defaultValue = "LANGUAGE_SUFFIX")
6364
private BundleLayout bundleLayout = BundleLayout.LANGUAGE_SUFFIX;
6465

66+
@Parameter
67+
private List<RegexMapper> pathToBundleMapper;
68+
69+
@Parameter
70+
private List<RegexMapper> sourcePathToTargetMapper;
6571

6672
public BundleSet() {
6773
}
@@ -206,7 +212,35 @@ public BundleLayout getBundleLayout() {
206212
/**
207213
* @param bundleLayout the bundle layout to set
208214
*/
209-
public void setOutputPathOption(BundleLayout bundleLayout) {
215+
public void setBundleLayout(BundleLayout bundleLayout) {
210216
this.bundleLayout = bundleLayout;
211217
}
218+
219+
/**
220+
* @return the pathToBundleMapper
221+
*/
222+
public List<RegexMapper> getPathToBundleMapper() {
223+
return pathToBundleMapper;
224+
}
225+
226+
/**
227+
* @param pathToBundleMapper the pathToBundleMapper to set
228+
*/
229+
public void setPathToBundleMapper(List<RegexMapper> pathToBundleMapper) {
230+
this.pathToBundleMapper = pathToBundleMapper;
231+
}
232+
233+
/**
234+
* @return the sourcePathToTargetMapper
235+
*/
236+
public List<RegexMapper> getSourcePathToTargetMapper() {
237+
return sourcePathToTargetMapper;
238+
}
239+
240+
/**
241+
* @param sourcePathToTargetMapper the sourcePathToTargetMapper to set
242+
*/
243+
public void setSourcePathToTargetMapper(List<RegexMapper> sourcePathToTargetMapper) {
244+
this.sourcePathToTargetMapper = sourcePathToTargetMapper;
245+
}
212246
}

0 commit comments

Comments
 (0)