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 private String[] properties;
48
49
50
51
52
53 private String suffix;
54
55 protected String getProperty(String key) {
56 String sys = System.getProperty(key);
57 String proj = project.getProperties().getProperty(key);
58 if (!StringUtils.isBlank(sys)) {
59 return sys;
60 } else {
61 return proj;
62 }
63
64 }
65
66 @Override
67 public void execute() throws MojoExecutionException {
68 Properties props = project.getProperties();
69 for (String key : properties) {
70 String value = getProperty(key);
71 if (StringUtils.isBlank(value)) {
72 continue;
73 } else {
74 String newValue = value.replace(".", "/");
75 String newKey = key + suffix;
76 getLog().info("Setting " + newKey + "=" + newValue);
77 props.setProperty(newKey, newValue);
78 }
79 }
80 }
81
82 public String[] getProperties() {
83 return properties;
84 }
85
86 public void setProperties(String[] properties) {
87 this.properties = properties;
88 }
89 }