Fixed some major sonar issues in yang-validation-tool
[yangtools.git] / yang-validation-tool / src / main / java / org / opendaylight / yangtools / yang / validation / tool / Params.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.validation.tool;
9
10 import java.io.File;
11 import java.net.URISyntaxException;
12 import net.sourceforge.argparse4j.ArgumentParsers;
13 import net.sourceforge.argparse4j.annotation.Arg;
14 import net.sourceforge.argparse4j.inf.ArgumentParser;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 final class Params {
19
20     private static final Logger LOGGER = LoggerFactory.getLogger(Params.class);
21     @Arg(dest = "yang-source-dir")
22     private File yangSourceDir;
23
24     static ArgumentParser getParser() throws URISyntaxException {
25         final ArgumentParser parser = ArgumentParsers.newArgumentParser("jar_file_name");
26         parser.description("Validation Tool for Yang Models")
27             .formatUsage();
28
29         parser.addArgumentGroup("Required arguments")
30             .addArgument("--yang-source-dir")
31             .type(File.class)
32             .required(true)
33             .help("directory containing yang models which will be parsed")
34             .dest("yang-source-dir")
35             .metavar("");
36
37         return parser;
38     }
39
40     public boolean isValid() {
41         if (yangSourceDir == null) {
42             return false;
43         }
44         if (!yangSourceDir.exists()) {
45             LOGGER.error("Yang source directory has to exist");
46             return false;
47         }
48         if (!yangSourceDir.canRead()) {
49             LOGGER.error("Yang source directory has to be readable");
50             return false;
51         }
52         if (yangSourceDir.list().length == 0) {
53             LOGGER.error("Yang source directory {} doesn't contain any model", yangSourceDir.getPath());
54             return false;
55         }
56
57         return true;
58     }
59
60     public File getYangSourceDir() {
61         return yangSourceDir;
62     }
63 }