Do not declare URISyntaxException as thrown
[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 net.sourceforge.argparse4j.ArgumentParsers;
12 import net.sourceforge.argparse4j.annotation.Arg;
13 import net.sourceforge.argparse4j.inf.ArgumentParser;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 final class Params {
18
19     private static final Logger LOG = LoggerFactory.getLogger(Params.class);
20     @Arg(dest = "yang-source-dir")
21     private File yangSourceDir;
22
23     static ArgumentParser getParser() {
24         final ArgumentParser parser = ArgumentParsers.newArgumentParser("jar_file_name");
25         parser.description("Validation Tool for Yang Models")
26             .formatUsage();
27
28         parser.addArgumentGroup("Required arguments")
29             .addArgument("--yang-source-dir")
30             .type(File.class)
31             .required(true)
32             .help("directory containing yang models which will be parsed")
33             .dest("yang-source-dir")
34             .metavar("");
35
36         return parser;
37     }
38
39     public boolean isValid() {
40         if (yangSourceDir == null) {
41             return false;
42         }
43         if (!yangSourceDir.exists()) {
44             LOG.error("Yang source directory has to exist");
45             return false;
46         }
47         if (!yangSourceDir.canRead()) {
48             LOG.error("Yang source directory has to be readable");
49             return false;
50         }
51         if (yangSourceDir.list().length == 0) {
52             LOG.error("Yang source directory {} doesn't contain any model", yangSourceDir.getPath());
53             return false;
54         }
55
56         return true;
57     }
58
59     public File getYangSourceDir() {
60         return yangSourceDir;
61     }
62 }