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.List;
19 import java.util.Properties;
20
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.apache.maven.plugin.MojoFailureException;
23 import org.kuali.common.util.CollectionUtils;
24 import org.kuali.common.util.PropertyUtils;
25
26
27
28
29
30
31
32
33 public class WriteProjectProperties extends AbstractWritePropertiesMojo {
34
35
36
37
38
39
40
41 private boolean includeSystemProperties;
42
43
44
45
46
47
48
49 private boolean includeEnvironmentVariables;
50
51
52
53
54
55
56 private String exclude;
57
58
59
60
61
62
63 private String include;
64
65
66
67
68
69
70 private List<String> includes;
71
72
73
74
75
76
77 private List<String> excludes;
78
79
80
81
82
83
84 private boolean resolvePlaceholders;
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 private boolean includeStandardMavenProperties;
100
101 @Override
102 public void execute() throws MojoExecutionException, MojoFailureException {
103 Properties properties = new Properties();
104
105
106 properties.putAll(project.getProperties());
107
108 if (includeStandardMavenProperties) {
109 properties.putAll(MavenUtils.getInternalMavenProperties(project));
110 }
111
112
113 if (includeEnvironmentVariables) {
114 properties.putAll(PropertyUtils.getEnvAsProperties());
115 }
116
117
118 if (includeSystemProperties) {
119 properties.putAll(System.getProperties());
120 }
121
122
123 List<String> includeList = CollectionUtils.sortedMerge(includes, include);
124 List<String> excludeList = CollectionUtils.sortedMerge(excludes, exclude);
125
126
127 override(properties, includeList);
128
129
130 if (resolvePlaceholders) {
131 Properties resolved = PropertyUtils.getResolvedProperties(properties);
132 getLog().info("Resolved " + resolved.size() + " properties");
133 properties.putAll(resolved);
134 }
135
136
137 PropertyUtils.trim(properties, includeList, excludeList);
138
139
140 writeProperties(outputFile, properties, outputStyle, prefix, encoding, comment);
141 }
142
143 protected void override(Properties properties, List<String> includes) {
144 List<String> keys = PropertyUtils.getSortedKeys(properties, includes, null);
145 Properties global = PropertyUtils.getGlobalProperties(properties);
146 properties.clear();
147 for (String key : keys) {
148 String value = global.getProperty(key);
149 if (value != null) {
150 properties.setProperty(key, value);
151 }
152 }
153 }
154
155 public boolean isIncludeSystemProperties() {
156 return includeSystemProperties;
157 }
158
159 public void setIncludeSystemProperties(boolean includeSystemProperties) {
160 this.includeSystemProperties = includeSystemProperties;
161 }
162
163 public boolean isIncludeEnvironmentVariables() {
164 return includeEnvironmentVariables;
165 }
166
167 public void setIncludeEnvironmentVariables(boolean includeEnvironmentVariables) {
168 this.includeEnvironmentVariables = includeEnvironmentVariables;
169 }
170
171 public String getExclude() {
172 return exclude;
173 }
174
175 public void setExclude(String exclude) {
176 this.exclude = exclude;
177 }
178
179 public String getInclude() {
180 return include;
181 }
182
183 public void setInclude(String include) {
184 this.include = include;
185 }
186
187 public boolean isResolvePlaceholders() {
188 return resolvePlaceholders;
189 }
190
191 public void setResolvePlaceholders(boolean resolvePlaceholders) {
192 this.resolvePlaceholders = resolvePlaceholders;
193 }
194
195 public boolean isIncludeStandardMavenProperties() {
196 return includeStandardMavenProperties;
197 }
198
199 public void setIncludeStandardMavenProperties(boolean includeStandardMavenProperties) {
200 this.includeStandardMavenProperties = includeStandardMavenProperties;
201 }
202
203 public List<String> getIncludes() {
204 return includes;
205 }
206
207 public void setIncludes(List<String> includes) {
208 this.includes = includes;
209 }
210
211 public List<String> getExcludes() {
212 return excludes;
213 }
214
215 public void setExcludes(List<String> excludes) {
216 this.excludes = excludes;
217 }
218
219 }