1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.mojo.properties;
17
18 import java.util.Properties;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.project.MavenProject;
24
25
26
27
28
29
30
31
32
33
34 public class TranslatePropertiesMojo extends AbstractMojo {
35
36
37
38
39
40
41 private MavenProject project;
42
43
44
45
46
47
48
49 private String[] properties;
50
51
52
53
54
55
56
57 private String suffix;
58
59 protected String getProperty(String key) {
60 String sys = System.getProperty(key);
61 String proj = project.getProperties().getProperty(key);
62 if (!StringUtils.isBlank(sys)) {
63 return sys;
64 } else {
65 return proj;
66 }
67
68 }
69
70 @Override
71 public void execute() throws MojoExecutionException {
72 Properties props = project.getProperties();
73 for (String key : properties) {
74 String value = getProperty(key);
75 if (StringUtils.isBlank(value)) {
76 continue;
77 } else {
78 String newValue = value.replace(".", "/");
79 String newKey = key + suffix;
80 getLog().info("Setting " + newKey + "=" + newValue);
81 props.setProperty(newKey, newValue);
82 }
83 }
84 }
85
86 public String[] getProperties() {
87 return properties;
88 }
89
90 public void setProperties(String[] properties) {
91 this.properties = properties;
92 }
93 }