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.io.File;
19 import java.util.Properties;
20
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.project.MavenProject;
23 import org.kuali.common.util.PropertyUtils;
24
25
26
27
28
29 public abstract class AbstractWritePropertiesMojo extends AbstractMojo {
30
31
32
33
34
35
36 MavenProject project;
37
38
39
40
41
42
43
44 File outputFile;
45
46
47
48
49
50
51
52
53 OutputStyle outputStyle;
54
55
56
57
58
59
60 String prefix;
61
62
63
64
65
66
67 String encoding;
68
69
70
71
72
73
74 String comment;
75
76 protected void writeProperties(File file, Properties properties, OutputStyle outputStyle, String prefix, String encoding, String comment) {
77 Properties prefixed = PropertyUtils.getPrefixedProperties(properties, prefix);
78 Properties formatted = getFormattedProperties(prefixed, outputStyle);
79 PropertyUtils.store(formatted, file, encoding, comment);
80 }
81
82 protected Properties getFormattedProperties(Properties properties, OutputStyle style) {
83 switch (style) {
84 case NORMAL:
85 return properties;
86 case ENVIRONMENT_VARIABLE:
87 return PropertyUtils.reformatKeysAsEnvVars(properties);
88 default:
89 throw new IllegalArgumentException(outputStyle + " is unknown");
90 }
91 }
92
93 public MavenProject getProject() {
94 return project;
95 }
96
97 public File getOutputFile() {
98 return outputFile;
99 }
100
101 public void setOutputFile(File outputFile) {
102 this.outputFile = outputFile;
103 }
104
105 public OutputStyle getOutputStyle() {
106 return outputStyle;
107 }
108
109 public void setOutputStyle(OutputStyle outputStyle) {
110 this.outputStyle = outputStyle;
111 }
112
113 public String getPrefix() {
114 return prefix;
115 }
116
117 public void setPrefix(String prefix) {
118 this.prefix = prefix;
119 }
120
121 public String getEncoding() {
122 return encoding;
123 }
124
125 public void setEncoding(String encoding) {
126 this.encoding = encoding;
127 }
128
129 public String getComment() {
130 return comment;
131 }
132
133 public void setComment(String comment) {
134 this.comment = comment;
135 }
136 }