KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > Initializer


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.verifier;
24
25 import java.io.File JavaDoc;
26 import java.util.logging.Handler JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import java.util.logging.ConsoleHandler JavaDoc;
30
31 import com.sun.enterprise.logging.LogDomains;
32 import com.sun.enterprise.logging.VerifierFormatter;
33 import com.sun.enterprise.tools.verifier.util.VerifierConstants;
34 import com.sun.enterprise.util.LocalStringManagerImpl;
35
36 /**
37  * Initialization of arguments and other temporary variables is done here. This
38  * class is responsible for creating the framework context and setting proper
39  * argument values to it.
40  *
41  * @author Vikas Awasthi
42  */

43 public class Initializer {
44
45     private LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
46     private Logger JavaDoc logger = LogDomains.getLogger(
47             LogDomains.AVK_VERIFIER_LOGGER);
48
49     private FrameworkContext frameworkContext = null;
50     private String JavaDoc _FOStr = "Failures only"; // NOI18N
51
private String JavaDoc _WFOStr = "Warning and Failures only"; // NOI18N
52
private String JavaDoc _AOStr = "All"; // NOI18N
53

54     /**
55      * Constructor for creating the intitializer object.
56      * @param args
57      */

58     public Initializer(String JavaDoc[] args) {
59         this.frameworkContext = new FrameworkContext();
60         parseArgs(args);
61     }
62
63     /**
64      *
65      * @return returns the initialized FrameworkContext object
66      */

67     public FrameworkContext getFrameworkContext() {
68         return frameworkContext;
69     }
70
71     /**
72      * parses the arguments passed to verifier and sets the framework context
73      * object.
74      * @param argv
75      */

76     private void parseArgs(String JavaDoc[] argv) {
77         int c;
78         String JavaDoc arg;
79         boolean isVerboseSet = false;
80         LongOption[] longopts = new LongOption[20];
81         // The set of valid long options for verifier
82
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
83         longopts[0] = new LongOption("help", false, null, 'h'); // NOI18N
84
longopts[1] = new LongOption("timestamp", false, null, 't'); // NOI18N
85
longopts[2] = new LongOption("verbose", false, null, 'v'); // NOI18N
86
longopts[3] = new LongOption("version", false, null, 'V'); // NOI18N
87
longopts[4] = new LongOption("destdir", true, sb, 'd'); // NOI18N
88
longopts[5] = new LongOption("reportlevel", true, sb, 'r'); // NOI18N
89
longopts[6] = new LongOption("gui", false, null, 'u'); // NOI18N
90
longopts[7] = new LongOption("app", false, null, 'a'); // NOI18N
91
longopts[8] = new LongOption("appclient", false, null, 'A'); // NOI18N
92
longopts[9] = new LongOption("connector", false, null, 'c'); // NOI18N
93
longopts[10] = new LongOption("ejb", false, null, 'e'); // NOI18N
94
longopts[11] = new LongOption("web", false, null, 'w'); // NOI18N
95
longopts[12] = new LongOption("webservices", false, null, 's'); // NOI18N
96
longopts[13] = new LongOption("webservicesclient", false, null, 'l'); // NOI18N
97
longopts[14] = new LongOption("persistence", false, null, 'P'); // NOI18N
98
longopts[15] = new LongOption("configdir", true, null, 'C'); // NOI18N
99
longopts[16] = new LongOption("portability", false, null, 'p'); // NOI18N
100
longopts[17] = new LongOption("domain", true, null, 'D'); // NOI18N
101
longopts[18] = new LongOption("extDir", true, null, 'E'); // NOI18N
102
longopts[19] = new LongOption("mode", true, null, 'm'); // NOI18N
103

104         //The set of valid reportlevel arguments
105
String JavaDoc[] levels = new String JavaDoc[6];
106         levels[0] = "a"; // NOI18N
107
levels[1] = "w"; // NOI18N
108
levels[2] = "f"; // NOI18N
109
levels[3] = "all"; // NOI18N
110
levels[4] = "warnings"; // NOI18N
111
levels[5] = "failures"; // NOI18N
112

113
114         CLIPParser parser = null;
115         parser =
116                 new CLIPParser("verifier", argv, "-:vtVhud:r:aAcewslC:pPm:D:E:", // NOI18N
117
longopts);
118
119         while ((c = parser.getopt()) != -1)
120             switch (c) {
121                 case 0:
122                     arg = parser.getOptarg();
123                     processValidLongOpt(
124                             (char) (new Integer JavaDoc(sb.toString())).intValue(),
125                             arg, levels);
126                     break;
127                 case 'v':
128                     logger.setLevel(Level.FINEST);
129                     isVerboseSet = true;
130                     Handler JavaDoc[] handler = Logger.getLogger("").getHandlers();
131                     for (int i = 0; i < handler.length; i++) {
132                         handler[i].setLevel(Level.FINEST);
133                     }
134                     logger.log(Level.FINE,
135                             getClass().getName() + ".debug.verboseFlag"); // NOI18N
136
break;
137
138                 case 't':
139                     frameworkContext.setUseTimeStamp(true);
140                     break;
141
142                 case 'h':
143                     logger.log(Level.FINE,
144                             getClass().getName() + ".debug.helpMessage"); // NOI18N
145
usage();
146                     break;
147
148                 case 'V':
149                     logger.log(Level.INFO, getClass().getName() + ".Version");
150                     System.exit(0);
151                     break;
152
153                 case 'u':
154                     logger.log(Level.FINE,
155                             getClass().getName() + ".debug.startGUI"); // NOI18N
156
frameworkContext.setUsingGui(true);
157                     break;
158
159                 case 'r':
160                     arg = parser.getOptarg();
161                     if (arg == null) {
162                         logger.log(Level.SEVERE,
163                                 getClass().getName() + ".reqargs", // NOI18N
164
new Object JavaDoc[]{"verifier", "-r"}); // NOI18N
165
usage();
166
167                     } else {
168                         boolean validLevel = false;
169                         for (int i = 0; i < levels.length; i++) {
170                             if (arg.equals(levels[i])) {
171                                 validLevel = true;
172                                 break;
173                             }
174                         }
175                         if (!validLevel) {
176                             logger.log(Level.SEVERE, getClass().getName() +
177                                     ".invalidreplevel", // NOI18N
178
new Object JavaDoc[]{"verifier", arg}); // NOI18N
179
usage();
180                         } else {
181                             setReportingLevel(arg.charAt(0));
182                         }
183                     }
184                     break;
185
186                 case 'd':
187                     arg = parser.getOptarg();
188                     if (arg == null) {
189                         logger.log(Level.SEVERE, getClass().getName() +
190                                 ".reqargs", // NOI18N
191
new Object JavaDoc[]{"verifier", "-d"}); // NOI18N
192
usage();
193                     } else if (!verifyAndSetResultDir(arg)) {
194                         usage();
195                     }
196                     break;
197
198                 case ':':
199                     // probably it will never come here
200
logger.log(Level.SEVERE, getClass().getName() + ".reqsarg",
201                             new Object JavaDoc[]{"verifier", // NOI18N
202
new Character JavaDoc(
203                                                  (char) parser.getOptopt()).toString()});
204                     usage();
205                     break;
206                 case 'a':
207                     logger.log(Level.FINE, getClass().getName() + ".debug.app");
208                     frameworkContext.setApp(true);
209                     frameworkContext.setPartition(true);
210                     break;
211
212                 case 'A':
213                     logger.log(Level.FINE,
214                             getClass().getName() + ".debug.appclient"); // NOI18N
215
frameworkContext.setAppClient(true);
216                     frameworkContext.setPartition(true);
217                     break;
218
219                 case 'c':
220                     logger.log(Level.FINE,
221                             getClass().getName() + ".debug.connector"); // NOI18N
222
frameworkContext.setConnector(true);
223                     frameworkContext.setPartition(true);
224                     break;
225
226                 case 'e':
227                     logger.log(Level.FINE, getClass().getName() + ".debug.ejb");
228                     frameworkContext.setEjb(true);
229                     frameworkContext.setPartition(true);
230                     break;
231
232                 case 'w':
233                     logger.log(Level.FINE, getClass().getName() + ".debug.web");
234                     frameworkContext.setWeb(true);
235                     frameworkContext.setPartition(true);
236                     break;
237
238                 case 's':
239                     logger.log(Level.FINE,
240                             getClass().getName() + ".debug.webservices"); // NOI18N
241
frameworkContext.setWebServices(true);
242                     frameworkContext.setPartition(true);
243                     break;
244
245                 case 'l':
246                     logger.log(Level.FINE,
247                             getClass().getName() + ".debug.webservicesclient"); // NOI18N
248
frameworkContext.setWebServicesClient(true);
249                     frameworkContext.setPartition(true);
250                     break;
251
252                 case 'P':
253                     frameworkContext.setPersistenceUnits(true);
254                     frameworkContext.setPartition(true);
255                     break;
256
257                 case '?':
258                     char x = (char) parser.getOptopt();
259                     if (x == '?') {
260                         usage();
261                     }
262                     logger.log(Level.SEVERE,
263                             getClass().getName() + ".invalidarg", // NOI18N
264
new Object JavaDoc[]{"verifier", // NOI18N
265
new Character JavaDoc(x).toString()});
266                     usage();
267                     break;
268
269                 case 'C':
270                     arg = parser.getOptarg();
271                     if (arg == null || !(new File JavaDoc(arg).exists())) {
272                         logger.log(Level.SEVERE, getClass().getName() +
273                                 ".reqargs", // NOI18N
274
new Object JavaDoc[]{"verifier", "-C"}); // NOI18N
275
usage();
276                     }
277                     frameworkContext.setConfigDirStr(arg);
278                     break;
279
280                 case 'p':
281                     frameworkContext.setPortabilityMode(true);
282                     break;
283
284                 case 'm':
285                     arg = parser.getOptarg();
286                     if (arg != null &&
287                         (arg.equals(SpecVersionMapper.JavaEEVersion_1_2) ||
288                             arg.equals(SpecVersionMapper.JavaEEVersion_1_3) ||
289                             arg.equals(SpecVersionMapper.JavaEEVersion_1_4) ||
290                             arg.equals(SpecVersionMapper.JavaEEVersion_5))) {
291                         frameworkContext.setJavaEEVersion(arg);
292                     } else {
293                         logger.log(Level.SEVERE,
294                                 getClass().getName() + ".invalidjavaeeversion", // NOI18N
295
new Object JavaDoc[]{"verifier", arg}); // NOI18N
296
usage();
297                     }
298                     logger.log(Level.INFO, getClass().getName() + ".specversion",
299                             new Object JavaDoc[]{frameworkContext.getJavaEEVersion()});
300                     break;
301
302                 case 'D':
303                     arg = parser.getOptarg();
304                     if (arg == null) {
305                         logger.log(Level.SEVERE, getClass().getName() +
306                                 ".reqargs", // NOI18N
307
new Object JavaDoc[]{"verifier", "-D"}); // NOI18N
308
usage();
309                     }
310                     if(!new File JavaDoc(arg).exists()) {
311                         logger.log(Level.SEVERE, getClass().getName() +
312                                 ".log.noDirExists", // NOI18N
313
new Object JavaDoc[]{arg});
314                         usage();
315                     }
316                     frameworkContext.setDomainDir(arg);
317                     break;
318
319                 case 'E':
320                     arg = parser.getOptarg();
321                     if (arg == null) {
322                         logger.log(Level.SEVERE, getClass().getName() +
323                                 ".reqargs", // NOI18N
324
new Object JavaDoc[]{"verifier", "-E"}); // NOI18N
325
usage();
326                     }
327                     frameworkContext.setExtDir(arg);
328                     break;
329
330                 default:
331                     logger.log(Level.SEVERE,
332                             getClass().getName() + ".invalidarg", // NOI18N
333
new Object JavaDoc[]{"verifier", // NOI18N
334
new Character JavaDoc((char) c).toString()});
335                     usage();
336                     break;
337             }
338
339         int i = parser.getOptind();
340         if (i < argv.length) {
341             File JavaDoc jarFile = new File JavaDoc(argv[i]);
342             if (!jarFile.exists()) {
343                 logger.log(Level.SEVERE,
344                         getClass().getName() + ".invalidArchive", // NOI18N
345
new Object JavaDoc[]{argv[i]});
346                 usage();
347             }
348             frameworkContext.setJarFileName(jarFile.getPath());
349             logger.log(Level.FINE, getClass().getName() + ".debug.jarFileName",
350                     new Object JavaDoc[]{frameworkContext.getJarFileName()});
351
352             i++;
353             for (; i < argv.length; i++)
354                 logger.log(Level.INFO, getClass().getName() + ".extraargs",
355                         new Object JavaDoc[]{"verifier", argv[i]}); // NOI18N
356

357         } else {
358             if (!frameworkContext.isUsingGui()) {
359                 logger.log(Level.SEVERE, getClass().getName() + ".jarmissing",
360                         new Object JavaDoc[]{"verifier"}); // NOI18N
361
usage();
362             }
363         }
364         if(!isVerboseSet)
365             setFormatter();
366         logger.log(Level.FINE, getClass().getName() + ".debug.endParseArgs");
367
368     }
369
370     /**
371      * validates long cli options
372      * @param c
373      * @param arg
374      * @param levels
375      */

376     private void processValidLongOpt(int c, String JavaDoc arg, String JavaDoc[] levels) {
377
378         switch (c) {
379             case 'v':
380                 logger.setLevel(Level.FINEST);
381                 Handler JavaDoc[] handler = Logger.getLogger("").getHandlers();
382                 for (int i = 0; i < handler.length; i++) {
383                     handler[i].setLevel(Level.FINEST);
384                 }
385                 logger.log(Level.FINE,
386                         getClass().getName() + ".debug.verboseFlag"); // NOI18N
387
break;
388
389             case 't':
390                 frameworkContext.setUseTimeStamp(true);
391                 break;
392
393             case 'h':
394                 logger.log(Level.FINE,
395                         getClass().getName() + ".debug.helpMessage"); // NOI18N
396
usage();
397                 break;
398
399             case 'V':
400                 logger.log(Level.INFO, getClass().getName() + ".Version");
401                 System.exit(0);
402                 break;
403
404             case 'u':
405                 logger.log(Level.FINE,
406                         getClass().getName() + ".debug.startGUI"); // NOI18N
407
frameworkContext.setUsingGui(true);
408                 break;
409
410             case 'r':
411                 if (arg == null) {
412                     logger.log(Level.SEVERE, getClass().getName() + ".reqargs",
413                             new Object JavaDoc[]{"verifier", "-r"}); // NOI18N
414
usage();
415                 } else {
416                     boolean validLevel = false;
417                     for (int i = 0; i < levels.length; i++) {
418                         if (arg.equals(levels[i])) {
419                             validLevel = true;
420                             break;
421                         }
422                     }
423                     if (!validLevel) {
424                         logger.log(Level.SEVERE, getClass().getName() +
425                                 ".invalidreplevel", // NOI18N
426
new Object JavaDoc[]{"verifier", arg}); // NOI18N
427
usage();
428                     } else {
429                         setReportingLevel(arg.charAt(0));
430                     }
431                 }
432                 break;
433
434             case 'd':
435                 if (arg == null) {
436                     logger.log(Level.SEVERE, getClass().getName() + ".reqargs",
437                             new Object JavaDoc[]{"verifier", "-d"}); // NOI18N
438
usage();
439                 } else if (!verifyAndSetResultDir(arg)) {
440                     usage();
441                 }
442                 break;
443
444             default:
445                 // should never come here
446
logger.log(Level.SEVERE, getClass().getName() + ".invalidarg",
447                         new Object JavaDoc[]{"verifier", // NOI18N
448
new Character JavaDoc((char) c).toString()});
449                 usage();
450                 break;
451         }
452     }
453
454     /**
455      * set the reporting level of verifier based on the option used while
456      * invoking verifier.
457      * @param c
458      */

459     private void setReportingLevel(char c) {
460
461         boolean setWarningLevelOnce = false;
462         switch (c) {
463             case 'w':
464                 if (!setWarningLevelOnce) {
465                     logger.log(Level.FINE,
466                             getClass().getName() +
467                             ".debug.displayWarningFailures"); // NOI18N
468
frameworkContext.setReportLevel(VerifierConstants.WARN);
469                     setWarningLevelOnce = true;
470                 } else {
471                     logger.log(Level.FINE,
472                             getClass().getName() + ".debug.reportLevel", // NOI18N
473
new Object JavaDoc[]{
474                                 getReportLevelString(
475                                         frameworkContext.getReportLevel())});
476                 }
477                 break;
478
479             case 'f':
480                 if (!setWarningLevelOnce) {
481                     logger.log(Level.FINE,
482                             getClass().getName() + ".debug.displayFailures"); // NOI18N
483
frameworkContext.setReportLevel(VerifierConstants.FAIL);
484                     setWarningLevelOnce = true;
485                 } else {
486                     logger.log(Level.FINE,
487                             getClass().getName() + ".debug.reportLevel", // NOI18N
488
new Object JavaDoc[]{
489                                 getReportLevelString(
490                                         frameworkContext.getReportLevel())});
491                 }
492                 break;
493
494             case 'a':
495                 if (!setWarningLevelOnce) {
496                     logger.log(Level.FINE,
497                             getClass().getName() + ".debug.displayAll"); // NOI18N
498
frameworkContext.setReportLevel(VerifierConstants.ALL);
499                     setWarningLevelOnce = true;
500                 } else {
501                     logger.log(Level.FINE,
502                             getClass().getName() + ".debug.reportLevel", // NOI18N
503
new Object JavaDoc[]{
504                                 getReportLevelString(
505                                         frameworkContext.getReportLevel())});
506                 }
507                 break;
508
509             default:
510                 // should never come here
511
logger.log(Level.SEVERE,
512                         getClass().getName() + ".invalidreplevel", // NOI18N
513
new Object JavaDoc[]{"verifier", new Character JavaDoc(c).toString()}); // NOI18N
514
usage();
515         }
516     }
517
518     /**
519      * Display usage message to user upon encountering invalid option
520      */

521     private void usage() {
522         if (!frameworkContext.isUsingGui()) {
523             logger.log(Level.INFO, getUsageString());
524             //If any argument is found invalid then Veriifer will bail out.
525
System.exit(1);
526         }
527     }
528
529     /**
530      *
531      * @return string
532      */

533     private String JavaDoc getUsageString() {
534         String JavaDoc usage = "\n" + // NOI18N
535
(smh.getLocalString
536                 (getClass().getName() + ".usageLine1", // NOI18N
537
"usage: VERIFIER [optional_params] <jarFile>")) // NOI18N
538
+ "\n\n" + // NOI18N
539
(smh.getLocalString
540                 (getClass().getName() + ".usageLine2", // NOI18N
541
"where :")) // NOI18N
542
+ "\n\n" + // NOI18N
543
(smh.getLocalString
544                 (getClass().getName() + ".usageLine3", // NOI18N
545
" [optional_params]: Must be: ")) // NOI18N
546
+ "\n\n" + // NOI18N
547
(smh.getLocalString
548                 (getClass().getName() + ".usageLine5", // NOI18N
549
" -d|--destdir <destination dir> : Verifier " + // NOI18N
550
"results are put in the specified existing directory")) // NOI18N
551
+ "\n" + // NOI18N
552
(smh.getLocalString
553                 (getClass().getName() + ".usageLine35", // NOI18N
554
" -D|--domain : Absolute path of the domain directory. Domain directory will be ignored if verifier is run with -p option. The default domain directory is <AS_INSTALL_DIR>/domains/domain1")) // NOI18N
555
+ "\n" + // NOI18N
556
(smh.getLocalString
557                 (getClass().getName() + ".usageLine36", // NOI18N
558
" -p|--portability : Verifier will be run in portability mode with this option. Verifier runs in appserver mode by default. In the default mode verifier additionally checks correct usage of Sun application server features.")) // NOI18N
559
+ "\n" + // NOI18N
560
(smh.getLocalString
561                 (getClass().getName() + ".usageLine16", // NOI18N
562
" -h|--help|-? : display verifier help")) // NOI18N
563
+ "\n" + // NOI18N
564
(smh.getLocalString
565                 (getClass().getName() + ".usageLine34", // NOI18N
566
" -t|--timestamp : verifer results are generated with timestamp appended to it")) // NOI18N
567
+ "\n\n" + // NOI18N
568
(smh.getLocalString
569                 (getClass().getName() + ".usageLine7", // NOI18N
570
" -u|--gui : use Verifier GUI")) // NOI18N
571
+ "\n\n" + // NOI18N
572
(smh.getLocalString
573                 (getClass().getName() + ".usageLine4", // NOI18N
574
" -v|--verbose : Display more execution information ")) // NOI18N
575
+ "\n" + // NOI18N
576
(smh.getLocalString
577                 (getClass().getName() + ".usageLine17", // NOI18N
578
" -V|--version : display verifier tool version")) // NOI18N
579
+ "\n" + // NOI18N
580
(smh.getLocalString
581                 (getClass().getName() + ".usageLine8", // NOI18N
582
" (Note: Overrides default behavior, ")) // NOI18N
583
+ "\n" + // NOI18N
584
(smh.getLocalString
585                 (getClass().getName() + ".usageLine9", // NOI18N
586
" required jarFile not needed)")) // NOI18N
587
+ "\n\n" + // NOI18N
588
(smh.getLocalString
589                 (getClass().getName() + ".usageLine10", // NOI18N
590
" -r|--reportlevel : result reporting level")) // NOI18N
591
+ "\n" + // NOI18N
592
(smh.getLocalString
593                 (getClass().getName() + ".usageLine11", // NOI18N
594
" level= a|all : set output report level to " + // NOI18N
595
"display all results")) // NOI18N
596
+ "\n" + // NOI18N
597
(smh.getLocalString
598                 (getClass().getName() + ".usageLine14", // NOI18N
599
" f|failures : set output report level " + // NOI18N
600
"to display only failure")) // NOI18N
601
+ "\n" + // NOI18N
602
(smh.getLocalString
603                 (getClass().getName() + ".usageLine15", // NOI18N
604
" results")) // NOI18N
605
+ "\n" + // NOI18N
606
(smh.getLocalString
607                 (getClass().getName() + ".usageLine12", // NOI18N
608
" w|warnings : set output report level " + // NOI18N
609
"to display only warning and")) // NOI18N
610
+ "\n" + // NOI18N
611
(smh.getLocalString
612                 (getClass().getName() + ".usageLine13", // NOI18N
613
" failure results")) // NOI18N
614
+ "\n" + // NOI18N
615
(smh.getLocalString
616                 (getClass().getName() + ".usageLine27", // NOI18N
617
" -a|--app : run only the Application tests")) // NOI18N
618
+ "\n" + // NOI18N
619
(smh.getLocalString
620                 (getClass().getName() + ".usageLine28", // NOI18N
621
" -A|--appclient : run only the Application Client tests")) // NOI18N
622
+ "\n" + // NOI18N
623
(smh.getLocalString
624                 (getClass().getName() + ".usageLine29", // NOI18N
625
" -c|--connector : run only the Connector tests")) // NOI18N
626
+ "\n" + // NOI18N
627
(smh.getLocalString
628                 (getClass().getName() + ".usageLine30", // NOI18N
629
" -e|--ejb : run only the EJB tests")) // NOI18N
630
+ "\n" + // NOI18N
631
(smh.getLocalString
632                 (getClass().getName() + ".usageLine31", // NOI18N
633
" -w|--web : run only the Web tests")) // NOI18N
634
+ "\n" + // NOI18N
635
(smh.getLocalString
636                 (getClass().getName() + ".usageLine32", // NOI18N
637
" -s|--webservices : run only the WebServices tests")) // NOI18N
638
+ "\n" + // NOI18N
639
(smh.getLocalString
640                 (getClass().getName() + ".usageLine33", // NOI18N
641
" -l|--webservicesclient : run only the WebServicesClient tests")) // NOI18N
642
+ "\n" + // NOI18N
643
(smh.getLocalString
644                 (getClass().getName() + ".usageLine37", // NOI18N
645
" -P|--persistence : run only the EJB 3.0 persistence tests")) // NOI18N
646
+ "\n\n\n" + // NOI18N
647
(smh.getLocalString
648                 (getClass().getName() + ".usageLine19", // NOI18N
649
"Note: The default mode is non-verbose mode and the " + // NOI18N
650
"default reportlevel is to display only warning and failure results.\n")) // NOI18N
651
//*****
652
+ "\n\n" +
653                 (smh.getLocalString
654                 (getClass().getName() + ".usageLine20",
655                         "<jarFile>: ear/war/jar/rar file to perform static " +
656                 "verification on "))
657                 + "\n\n" +
658                 (smh.getLocalString
659                 (getClass().getName() + ".usageLine21",
660                         "Below is an example which runs verifier in verbose mode"))
661                 + "\n" +
662                 (smh.getLocalString
663                 (getClass().getName() + ".usageLine22",
664                         "and writes all the results of static verification of "))
665                 + "\n" +
666                 (smh.getLocalString
667                 (getClass().getName() + ".usageLine23",
668                         "file sample.ear to the destination directory /verifierresults"))
669                 + "\n\n" +
670                 (smh.getLocalString
671                 (getClass().getName() + ".usageLine24",
672                         " verifier -v -ra -d /verifierresults sample.ear"))
673                 + "\n\n" +
674                 (smh.getLocalString
675                 (getClass().getName() + ".usageLine25",
676                         " The results get generated in both text and xml format."))
677                 + "\n" +
678                 (smh.getLocalString
679                 (getClass().getName() + ".usageLine26",
680                         " Two result files, sample.ear.txt and sample.ear.xml, " +
681                 "will be created."))
682                 + "\n\n";
683
684         return usage;
685     }
686
687     /**
688      * verifies and sets the output directory for keeping the result files.
689      * @param name The output directory to keep the result files
690      * @return true if output directory is writable, otherwise false.
691      */

692     private boolean verifyAndSetResultDir(String JavaDoc name) {
693
694         File JavaDoc outputDir = new File JavaDoc(name);
695         if (outputDir.exists()) {
696             if (outputDir.isDirectory()) {
697                 if (outputDir.canWrite()) {
698                     frameworkContext.setOutputDirName(name);
699                     return true;
700                 } else {
701                     logger.log(Level.SEVERE, getClass().getName() +
702                             ".log.noPermissions", new Object JavaDoc[]{name}); // NOI18N
703
return false;
704                 }
705             } else {
706                 logger.log(Level.SEVERE, getClass().getName() +
707                         ".log.notADir", new Object JavaDoc[]{name}); // NOI18N
708
return false;
709
710             }
711         } else {
712             logger.log(Level.SEVERE, getClass().getName() +
713                     ".log.noDirExists", new Object JavaDoc[]{name}); // NOI18N
714
return false;
715         }
716     }
717     
718     /**
719      * This method is only used in standalone invocation. For backend
720      * invocations this method should not be called. The logger should continue
721      * to use the default formatter when verifier is invoked from backend.
722      */

723     private void setFormatter() {
724         Handler JavaDoc[] handlers = logger.getParent().getHandlers();
725         for (int i = 0; i < handlers.length; i++)
726             if(handlers[i] instanceof ConsoleHandler JavaDoc)
727                 handlers[i].setFormatter(new VerifierFormatter());
728     }
729
730     /**
731      * @param rl
732      * @return reporting level string.
733      */

734     private String JavaDoc getReportLevelString(int rl) {
735         String JavaDoc rls = "";
736         if (rl == VerifierConstants.FAIL) {
737             rls = _FOStr;
738         } else if (rl == VerifierConstants.WARN) {
739             rls = _WFOStr;
740         } else if (rl == VerifierConstants.ALL) {
741             rls = _AOStr;
742         }
743         return rls;
744     }
745
746 }
747
Popular Tags