Search in sources :

Example 1 with ParseArgumentsMissingException

use of com.github.rvesse.airline.parser.errors.ParseArgumentsMissingException in project webofneeds by researchstudio-sat.

the class Shacl2JavaSrcGenCommand method main.

public static void main(String[] args) {
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.WARN);
    System.out.println(String.format("running %s %s", MethodHandles.lookup().lookupClass().getName(), Stream.of(args).collect(Collectors.joining(" "))));
    SingleCommand<Shacl2JavaSrcGenCommand> parser;
    Shacl2JavaSrcGenCommand cmd = null;
    parser = SingleCommand.singleCommand(Shacl2JavaSrcGenCommand.class);
    try {
        cmd = parser.parse(args);
    } catch (ParseArgumentsMissingException e) {
        System.err.println(e.getMessage());
        CliCommandUsageGenerator usageMessageGenerator = new CliCommandUsageGenerator();
        printUsage(parser, usageMessageGenerator);
        System.exit(3);
    }
    SourceGenerator generator = new SourceGenerator();
    Shacl2JavaConfig config = Shacl2JavaConfig.builder().abbreviateTypeIndicators(cmd.abbreviateFieldTypeIndicators).alwaysAddTypeIndicator(cmd.alwaysAddFieldTypeIndicator).outputDir(cmd.outputDir).classNameRegexReplace(cmd.classnameRegexReplace.get(0), cmd.classnameRegexReplace.get(1)).packageName(cmd.packageName).addVisitorClassesString(cmd.visitorClasses).interfacesForRdfTypes(cmd.interfacesForRdfTypes).build();
    String currentFile = null;
    try {
        for (String shapesFile : cmd.shapesFiles) {
            currentFile = shapesFile;
            SourceGeneratorStats stats = generator.generate(new File(shapesFile), config);
            if (!cmd.quiet) {
                System.out.println(String.format("Shacl2Java source generation stats for %s", shapesFile));
                System.out.println(stats.formatted());
                System.out.println(String.format("(run with option '-q' to suppress this output)", shapesFile));
            }
        }
    } catch (IOException e) {
        System.err.println(String.format("Cannot generate classes into %s from shapes file %s - %s: %s", config.getOutputDir(), currentFile, e.getClass().getSimpleName(), e.getMessage()));
        if (!cmd.quiet) {
            e.printStackTrace(System.err);
        }
        System.exit(1);
    }
}
Also used : SourceGeneratorStats(won.shacl2java.sourcegen.SourceGeneratorStats) CliCommandUsageGenerator(com.github.rvesse.airline.help.cli.CliCommandUsageGenerator) ParseArgumentsMissingException(com.github.rvesse.airline.parser.errors.ParseArgumentsMissingException) SourceGenerator(won.shacl2java.sourcegen.SourceGenerator) IOException(java.io.IOException) Logger(ch.qos.logback.classic.Logger) File(java.io.File)

Aggregations

Logger (ch.qos.logback.classic.Logger)1 CliCommandUsageGenerator (com.github.rvesse.airline.help.cli.CliCommandUsageGenerator)1 ParseArgumentsMissingException (com.github.rvesse.airline.parser.errors.ParseArgumentsMissingException)1 File (java.io.File)1 IOException (java.io.IOException)1 SourceGenerator (won.shacl2java.sourcegen.SourceGenerator)1 SourceGeneratorStats (won.shacl2java.sourcegen.SourceGeneratorStats)1