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