001package org.galaxyproject.gxformat2;
002
003import java.util.Map;
004
005public class Lint {
006  public static int EXIT_CODE_SUCCESS = 0;
007  public static int EXIT_CODE_LINT_FAILED = 1;
008  public static int EXIT_CODE_FORMAT_ERROR = 2;
009  public static int EXIT_CODE_FILE_PARSE_FAILED = 3;
010
011  public static LintContext lint(final Map<String, Object> workflow) {
012    final String wfClass = (String) workflow.get("class");
013    GalaxyWorkflowLinter linter;
014    if (wfClass != null && wfClass.equals("GalaxyWorkflow")) {
015      linter = new Format2Linter();
016    } else {
017      linter = new NativeLinter();
018    }
019    final LintContext lintContext = new LintContext();
020    linter.lint(lintContext, workflow);
021    return lintContext;
022  }
023
024  public static void main(String[] args) throws Exception {
025    final int exitCode = lint(args);
026    System.exit(exitCode);
027  }
028
029  public static int lint(final String[] args) throws Exception {
030    final Map<String, Object> object = (Map<String, Object>) IoUtils.readYamlFromPath(args[0]);
031    final LintContext lintContext = lint(object);
032    lintContext.printMessages();
033    int exitCode;
034    if (lintContext.getFoundErrors()) {
035      exitCode = EXIT_CODE_FORMAT_ERROR;
036    } else if (lintContext.getFoundWarns()) {
037      exitCode = EXIT_CODE_LINT_FAILED;
038    } else {
039      exitCode = EXIT_CODE_SUCCESS;
040    }
041    return exitCode;
042  }
043}