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.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Properties;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.maven.plugin.AbstractMojo;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.project.MavenProject;
27 import org.jasypt.util.text.BasicTextEncryptor;
28 import org.kuali.common.util.PropertyUtils;
29
30
31
32
33
34
35
36
37 public class DecryptAllPropertiesMojo extends AbstractMojo {
38
39
40
41
42
43
44 private MavenProject project;
45
46
47
48
49
50
51 private boolean includeSystemProperties;
52
53
54
55
56
57
58 private boolean includeEnvironmentVariables;
59
60
61
62
63
64
65
66 private boolean quiet;
67
68
69
70
71
72
73
74 private String endsWith;
75
76
77
78
79
80
81
82 private boolean show;
83
84
85
86
87
88
89
90 private String password;
91
92 @Override
93 public void execute() throws MojoExecutionException {
94 BasicTextEncryptor encryptor = new BasicTextEncryptor();
95 encryptor.setPassword(password);
96 Properties props = new Properties();
97 props.putAll(project.getProperties());
98 if (includeEnvironmentVariables) {
99 props.putAll(PropertyUtils.getEnvAsProperties());
100 }
101 if (includeSystemProperties) {
102 props.putAll(System.getProperties());
103 }
104 List<String> keys = new ArrayList<String>(props.stringPropertyNames());
105 Collections.sort(keys);
106 for (String key : keys) {
107 boolean decrypt = key.endsWith(endsWith);
108 if (!decrypt) {
109 continue;
110 }
111 String value = props.getProperty(key);
112 if (StringUtils.isBlank(value) && !quiet) {
113 getLog().info("Skipping blank property " + key);
114 continue;
115 }
116 String newValue = encryptor.decrypt(value);
117 int length = endsWith.length();
118 String newKey = key.substring(0, key.length() - length);
119 project.getProperties().setProperty(newKey, newValue);
120 if (quiet) {
121 continue;
122 }
123 if (show) {
124 getLog().info("Setting " + newKey + "=" + newValue + " - " + value);
125 } else {
126 getLog().info("Setting " + newKey);
127 }
128 }
129 }
130
131 public boolean isQuiet() {
132 return quiet;
133 }
134
135 public void setQuiet(boolean quiet) {
136 this.quiet = quiet;
137 }
138
139 public String getEndsWith() {
140 return endsWith;
141 }
142
143 public void setEndsWith(String endsWith) {
144 this.endsWith = endsWith;
145 }
146
147 public boolean isShow() {
148 return show;
149 }
150
151 public void setShow(boolean show) {
152 this.show = show;
153 }
154
155 public String getPassword() {
156 return password;
157 }
158
159 public void setPassword(String password) {
160 this.password = password;
161 }
162
163 public MavenProject getProject() {
164 return project;
165 }
166
167 public boolean isIncludeSystemProperties() {
168 return includeSystemProperties;
169 }
170
171 public void setIncludeSystemProperties(boolean includeSystemProperties) {
172 this.includeSystemProperties = includeSystemProperties;
173 }
174
175 public boolean isIncludeEnvironmentVariables() {
176 return includeEnvironmentVariables;
177 }
178
179 public void setIncludeEnvironmentVariables(boolean includeEnvironmentVariables) {
180 this.includeEnvironmentVariables = includeEnvironmentVariables;
181 }
182 }