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.Arrays;
19 import java.util.List;
20 import java.util.Properties;
21
22 import org.apache.maven.plugin.AbstractMojo;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.project.MavenProject;
25 import org.jasypt.util.text.BasicTextEncryptor;
26 import org.kuali.common.util.PropertyUtils;
27
28
29
30
31
32
33 public class EncryptPropertiesMojo extends AbstractMojo {
34
35
36
37
38
39
40 private MavenProject project;
41
42
43
44
45
46
47
48 private String[] properties;
49
50
51
52
53
54
55
56
57 private String password;
58
59 @Override
60 public void execute() throws MojoExecutionException {
61
62
63 BasicTextEncryptor encryptor = new BasicTextEncryptor();
64 encryptor.setPassword(password);
65
66
67 Properties p = PropertyUtils.getGlobalProperties(project.getProperties());
68
69
70 List<String> includes = PropertyUtils.getSortedKeys(project.getProperties());
71 if (properties != null) {
72 includes = Arrays.asList(properties);
73 }
74
75
76 PropertyUtils.trim(p, includes, null);
77
78
79 PropertyUtils.encrypt(p, encryptor);
80
81
82 project.getProperties().putAll(p);
83 }
84
85 public String[] getProperties() {
86 return properties;
87 }
88
89 public void setProperties(String[] properties) {
90 this.properties = properties;
91 }
92
93 public String getPassword() {
94 return password;
95 }
96
97 public void setPassword(String password) {
98 this.password = password;
99 }
100
101 public MavenProject getProject() {
102 return project;
103 }
104 }