Example usage for org.apache.commons.cli MissingArgumentException getClass

List of usage examples for org.apache.commons.cli MissingArgumentException getClass

Introduction

In this page you can find the example usage for org.apache.commons.cli MissingArgumentException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.coprtools.core.CopyrightToolsEngine.java

@Override
public void run() {
    LOGGER.setLevel(Level.SEVERE);
    try {/*ww  w.  ja v a  2s. c  o  m*/
        this.cli.parse();

        if (cli.hasOption(OptionConstants.HELP_SHORT)) {
            cli.showUsage();
        } else if (cli.getArguments().length == 0) {
            throw new MissingArgumentException("Missing command!");
        } else {
            String textConsoleCommand = cli.getArguments()[0];

            String rootFolderPath = cli.getOptionValue(OptionConstants.ROOT_SHORT);
            String noticePath = cli.getOptionValue(OptionConstants.NOTICE_SHORT);
            String[] extensions = cli.getOptionValues(OptionConstants.EXTENSION_SHORT);
            String newNotice = null;

            if (cli.hasOption(OptionConstants.NEW_NOTICE_SHORT)
                    && !cli.hasOption(OptionConstants.STRING_SHORT)) {
                String newNoticePath = cli.getOptionValue(OptionConstants.NEW_NOTICE_SHORT);
                File newNoticeFile = new File(newNoticePath);
                newNotice = this.manipulator.readFromFile(newNoticeFile);
            }

            File rootDir = new File(rootFolderPath);
            File destinationFolder = null;

            if (cli.hasOption(OptionConstants.OUTPUT_SHORT)) {
                String destinationPath = cli.getOptionValue(OptionConstants.OUTPUT_SHORT);
                destinationFolder = new File(destinationPath);
                this.manipulator.copyFolder(rootDir, destinationFolder);
                rootDir = destinationFolder;
            }

            // Enables logging and creates a log file in the root path
            if (cli.hasOption(OptionConstants.INFO_LONG)) {
                this.enableLogging(rootDir.getAbsolutePath());
            }

            String notice = null;
            if (cli.hasOption(OptionConstants.STRING_SHORT)) {
                notice = cli.getOptionValue(OptionConstants.NOTICE_SHORT);
                newNotice = cli.getOptionValue(OptionConstants.NEW_NOTICE_SHORT);
            } else {
                File noticeFile = new File(noticePath);
                notice = this.manipulator.readFromFile(noticeFile);
                if (cli.hasOption(OptionConstants.BLANK_SHORT)) {
                    notice = insertBlankSpace(notice);
                }
            }

            CommandType commandType = resolveCommandType(textConsoleCommand);

            AbstractCommand command = commandFactory.create(commandType, notice, extensions, this.manipulator,
                    newNotice);

            command.executeRecursively(rootDir);

            if (!command.isHasError()) {
                writer.writeLine(UserMessagesConstants.SUCCESFULL_OPERATION_MESSAGE);
            } else {
                writer.writeLine(UserMessagesConstants.FAILD_OPERTION_MESSAGE,
                        rootDir.getAbsolutePath() + File.separator + InserterConstants.LOG_FILENAME);
            }
            if (this.fileHandler != null) {
                this.fileHandler.close();
                LOGGER.removeHandler(this.fileHandler);
            }
        }

    } catch (MissingArgumentException e) {
        LOGGER.log(Level.SEVERE, e.getMessage());
    } catch (ArgumentParseException e) {
        LOGGER.log(Level.SEVERE, "Error while parsing arguments: " + e.getMessage());
    } catch (FileNotFoundException e) {
        LOGGER.log(Level.SEVERE, e.getMessage());
    } catch (SecurityException e) {
        LOGGER.log(Level.SEVERE, "Security violation has occurred: " + e.getMessage());
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage());
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Unknown exception: " + e.getClass().getName() + " " + e.getMessage());
    }
}