1 package org.codehaus.mojo.rmic;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.HashSet;
28 import java.util.Set;
29
30
31
32
33 public class Source
34 {
35
36 private static final String INCLUDE_ALL = "**/*";
37
38
39
40
41 protected Set<String> includes;
42
43
44
45
46 protected Set<String> excludes;
47
48
49
50
51
52
53 private String version;
54
55
56
57
58 private Boolean iiop;
59
60
61
62
63 private Boolean noLocalStubs;
64
65
66
67
68 private Boolean idl;
69
70
71
72
73 private Boolean noValueMethods;
74
75
76
77
78 private Boolean keep;
79
80
81
82
83 private Boolean nowarn;
84
85
86
87
88 private Boolean poa;
89
90
91
92
93 private Boolean verbose;
94
95
96 public boolean isIiop()
97 {
98 return isSetOrDefault( iiop, false );
99 }
100
101 public boolean isNoLocalStubs()
102 {
103 return isSetOrDefault( noLocalStubs, false );
104 }
105
106 public boolean isIdl()
107 {
108 return isSetOrDefault( idl, false );
109 }
110
111 public boolean isNoValueMethods()
112 {
113 return isSetOrDefault( noValueMethods, false );
114 }
115
116 public boolean isKeep()
117 {
118 return isSetOrDefault( keep, false );
119 }
120
121 public boolean isNowarn()
122 {
123 return isSetOrDefault( nowarn, false );
124 }
125
126 public boolean isPoa()
127 {
128 return isSetOrDefault( poa, false );
129 }
130
131 public boolean isVerbose()
132 {
133 return isSetOrDefault( verbose, false );
134 }
135
136 public String getVersion()
137 {
138 return version;
139 }
140
141 private static boolean isSetOrDefault( Boolean field, boolean defaultValue )
142 {
143 return field != null ? field.booleanValue() : defaultValue;
144 }
145
146 Set<String> getIncludes()
147 {
148 return !isEmpty( includes ) ? includes : Collections.singleton( INCLUDE_ALL );
149 }
150
151 Set<String> getExcludes()
152 {
153 return !isEmpty( excludes ) ? excludes : new HashSet<String>();
154 }
155
156 private static boolean isEmpty( Collection collection )
157 {
158 return collection == null || collection.isEmpty();
159 }
160
161 public String toString()
162 {
163 StringBuffer sb = new StringBuffer();
164 sb.append( "Including " ).append( getIncludes() ).append( "; excluding " ).append( getExcludes() );
165 sb.append( "\nwith options: " );
166 appendIfTrue( sb, isIiop(), "-iiop" );
167 appendIfTrue( sb, isIiop() && isNoLocalStubs(), "-noLocalStubs" );
168 appendIfTrue( sb, isIdl(), "-idl" );
169 appendIfTrue( sb, isIdl() && isNoValueMethods(), "-noValueMethods" );
170 appendIfTrue( sb, isKeep(), "-keep" );
171 appendIfTrue( sb, isNowarn(), "-nowarn" );
172 appendIfTrue( sb, isPoa(), "-poa" );
173
174 if ( getVersion() != null )
175 {
176 sb.append( "-v" ).append( getVersion() );
177 }
178 return sb.toString();
179 }
180
181 private void appendIfTrue( StringBuffer sb, boolean condition, String option )
182 {
183 if ( condition )
184 {
185 sb.append( option ).append( ' ' );
186 }
187 }
188
189 String getConfiguredOptions()
190 {
191 StringBuffer sb = new StringBuffer();
192 appendIfNotEmpty( sb, includes, "includes" );
193 appendIfNotEmpty( sb, excludes, "excludes" );
194 appendOptionIfTrue( sb, isIiop(), "iiop" );
195 appendOptionIfTrue( sb, isIiop() && isNoLocalStubs(), "noLocalStubs" );
196 appendOptionIfTrue( sb, isIdl(), "idl" );
197 appendOptionIfTrue( sb, isIdl() && isNoValueMethods(), "noValueMethods" );
198 appendOptionIfTrue( sb, isKeep(), "keep" );
199 appendOptionIfTrue( sb, isNowarn(), "nowarn" );
200 appendOptionIfTrue( sb, isPoa(), "poa" );
201 return sb.toString();
202 }
203
204 private void appendIfNotEmpty( StringBuffer sb, Set<String> set, String text )
205 {
206 if ( !isEmpty( set ) )
207 {
208 appendOption( sb, text );
209 }
210 }
211
212 private StringBuffer appendOption( StringBuffer sb, String text )
213 {
214 if ( sb.length() != 0 )
215 {
216 sb.append( ", " );
217 }
218 return sb.append( text );
219 }
220
221 private void appendOptionIfTrue( StringBuffer sb, boolean condition, String option )
222 {
223 if ( condition )
224 {
225 appendOption( sb, option );
226 }
227 }
228
229 public void setIncludes( Set<String> includes )
230 {
231 this.includes = includes;
232 }
233
234 public void setExcludes( Set<String> excludes )
235 {
236 this.excludes = excludes;
237 }
238
239 public void setVersion( String version )
240 {
241 this.version = version;
242 }
243
244 public void setIiop( Boolean iiop )
245 {
246 this.iiop = iiop;
247 }
248
249 public void setNoLocalStubs( Boolean noLocalStubs )
250 {
251 this.noLocalStubs = noLocalStubs;
252 }
253
254 public void setIdl( Boolean idl )
255 {
256 this.idl = idl;
257 }
258
259 public void setNoValueMethods( Boolean noValueMethods )
260 {
261 this.noValueMethods = noValueMethods;
262 }
263
264 public void setKeep( Boolean keep )
265 {
266 this.keep = keep;
267 }
268
269 public void setNowarn( Boolean nowarn )
270 {
271 this.nowarn = nowarn;
272 }
273
274 public void setPoa( Boolean poa )
275 {
276 this.poa = poa;
277 }
278
279 public void setVerbose( Boolean verbose )
280 {
281 this.verbose = verbose;
282 }
283
284
285
286 }