View Javadoc
1   package org.codehaus.mojo.rmic;
2   
3   /*
4    * Copyright (c) 2012, Codehaus.org
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
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   * Represents a group of class files to be processed by rmic, along with the desired options.
32   */
33  public class Source
34  {
35  
36      private static final String INCLUDE_ALL = "**/*";
37  
38      /**
39       * A list of inclusions when searching for classes to compile.
40       */
41      protected Set<String> includes;
42  
43      /**
44       * A list of exclusions when searching for classes to compile.
45       */
46      protected Set<String> excludes;
47  
48      /**
49       * The version of the rmi protocol to which the stubs should be compiled. Valid values include 1.1, 1.2, compat. See
50       * the rmic documentation for more information. If nothing is specified the underlying rmi compiler will
51       * choose the default value.  For example, in sun jdk 1.5 the default is 1.2.
52       */
53      private String version;
54  
55      /**
56       * Create stubs for IIOP.
57       */
58      private Boolean iiop;
59  
60      /**
61       * Do not create stubs optimized for same process.
62       */
63      private Boolean noLocalStubs;
64  
65      /**
66       * Create IDL.
67       */
68      private Boolean idl;
69  
70      /**
71       * Do not generate methods for valuetypes.
72       */
73      private Boolean noValueMethods;
74  
75      /**
76       * Do not delete intermediate generated source files.
77       */
78      private Boolean keep;
79  
80      /**
81       * Turn off rmic warnings.
82       */
83      private Boolean nowarn;
84  
85      /**
86       * Enable poa generation.
87       */
88      private Boolean poa;
89  
90      /**
91       * Enable verbose output.
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 }