EMMA Coverage Report (generated Fri Jun 19 09:16:10 CEST 2009)
[all classes][org.ktc.rbutils.rb.generation]

COVERAGE SUMMARY FOR SOURCE FILE [RbGeneratorUtility.java]

nameclass, %method, %block, %line, %
RbGeneratorUtility.java100% (1/1)100% (5/5)96%  (137/142)100% (38,9/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RbGeneratorUtility100% (1/1)100% (5/5)96%  (137/142)100% (38,9/39)
mainNoExit (String [], PrintWriter): int 100% (1/1)91%  (50/55)99%  (11,9/12)
<static initializer> 100% (1/1)100% (18/18)100% (5/5)
RbGeneratorUtility (String []): void 100% (1/1)100% (13/13)100% (5/5)
getGenDir (): File 100% (1/1)100% (7/7)100% (2/2)
process (): int 100% (1/1)100% (49/49)100% (15/15)

1/*
2 * Copyright  2005-2006 The RbUtils Project
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *  Unless required by applicable law or agreed to in writing, software
11 *  distributed under the License is distributed on an "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *  See the License for the specific language governing permissions and
14 *  limitations under the License.
15 *
16 */
17 
18// $Id: RbGeneratorUtility.java,v 1.7 2008/07/02 11:30:39 moishi Exp $
19 
20package org.ktc.rbutils.rb.generation;
21 
22import java.io.File;
23import java.io.FileNotFoundException;
24import java.io.PrintWriter;
25import java.util.Collection;
26import java.util.List;
27 
28import org.apache.commons.cli.Option;
29import org.apache.commons.cli.Options;
30import org.ktc.rbutils.api.RbUtilsException;
31import org.ktc.rbutils.api.audit.MainProcessor;
32import org.ktc.rbutils.rb.AbstractUtility;
33import org.ktc.rbutils.rb.CommonProps;
34import org.ktc.rbutils.rb.TaskType;
35 
36/**
37 * Command line utility for ResourceBundle generation.
38 * @since RbUtils 0.8.1
39 * @version $Revision: 1.7 $
40 * @author ktcguru
41 */
42public class RbGeneratorUtility extends AbstractUtility implements GeneratorUtility {
43    // TODO need a refactoring with RbGeneratorUtility
44    // A lot of thing can be done in AbstractUtility as it is done with Ant Task
45 
46    /** The options to the command line. */
47    private static final Options GENERATOR_OPTS;
48 
49    /** The g option (for target generation directory). */
50    protected static final String OPTION_GEN = "g";
51 
52    /** Error mesage when more than on target generation directory is specified. */
53    public static final String ERROR_MSG_GEN_NBR = "Must specify one "
54        + "and only one target generation directory";
55 
56    static {
57        GENERATOR_OPTS = getCommonOptions();
58        final Option genDirOption = new Option(OPTION_GEN, "gendir", true, REQUIRED_HEADER
59            + "the directory where the java resourcebundle source files will be generated.");
60        genDirOption.setRequired(true);
61        GENERATOR_OPTS.addOption(genDirOption);
62    }
63 
64    /**
65      * Number of files that have been checked by the utility.
66      * @since RbUtils 0.11
67      */
68    // TODO variable duplication with RbCheckerUtility, should be move to super class as protected
69    private int processedFilesCount;
70 
71    /**
72     * Creates a new instance of RbGeneratorUtility.
73     * @param args the arguments to be passed to the utility.
74     */
75    protected RbGeneratorUtility(final String[] args) {
76        taskName = CommonProps.RBGENERATOR_TASKNAME;
77        internalArgs = args;
78        options = clone(GENERATOR_OPTS);
79    }
80 
81    /**
82     * {@inheritDoc}
83     */
84    public File getGenDir() throws RbUtilsException, FileNotFoundException {
85        final File uniqueDir = getUniqueDir(OPTION_GEN, ERROR_MSG_GEN_NBR);
86        return uniqueDir;
87    }
88 
89    /**
90     * Launches the utility. Do not display anything. Call method should catch parse exceptions and
91     * display messages to user.
92     * @return the number of errors that occur during the generation (this does not count arguments
93     *         parse error).
94     * @throws Exception the arguments to be passed to the utility.
95     */
96    protected int process() throws Exception {
97        parseParameters();
98        final File rootDir = getRootDir();
99        final File genDir = getGenDir();
100        final List files = getFilesToBeProcessed();
101        final Collection loggers = getLoggers();
102        final String extension = getExtension();
103 
104        final MainProcessor generator = new MainGenerator(rootDir, genDir);
105        generator.addLoggers(loggers);
106        generator.setExtension(extension);
107 
108        if (!files.isEmpty()) {
109            generator.addFiles(files);
110            generator.setFilesAlreadyAdded(true);
111        }
112 
113        final int errorsNumber = generator.process();
114        processedFilesCount = generator.getProcessedFilesCount();
115        return errorsNumber;
116    }
117 
118    /**
119     * Launches the utility. Acts like the main method but does not exit.
120     * @param args the arguments to be passed to the utility.
121     * @param pw the Writer to be used to print messages.
122     * @return the number of error detected during generation.
123     */
124    protected static int mainNoExit(final String[] args, final PrintWriter pw) {
125        // RFE add outputstream where log error output
126        pw.println(CommonProps.getRunningTask(TaskType.RBGENERATOR));
127        int errorsNumber = -1;
128 
129        RbGeneratorUtility util = null;
130        try {
131            util = new RbGeneratorUtility(args);
132            errorsNumber = util.process();
133            // RBUTILS-028: Display the number of processed files
134            pw.println("Processed Files: " + util.processedFilesCount);
135            pw.println("Errors: " + errorsNumber);
136        }
137        catch (final Exception exception) {
138            util.parse(exception, pw);
139        }
140        finally {
141            // TODO see how the defaultLogger flush to be sure it is done sometimes
142            pw.flush();
143        }
144 
145        return errorsNumber;
146    }
147 
148}

[all classes][org.ktc.rbutils.rb.generation]
EMMA 2.0.5312 (C) Vladimir Roubtsov