Example usage for java.io File isFile

List of usage examples for java.io File isFile

Introduction

In this page you can find the example usage for java.io File isFile.

Prototype

public boolean isFile() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a normal file.

Usage

From source file:com.msd.gin.halyard.tools.HalyardExport.java

/**
 * Main of the HalyardExport//from w ww . j a va 2s .  c o m
 * @param args String command line arguments
 * @throws Exception throws Exception in case of any problem
 */
public static void main(final String args[]) throws Exception {
    if (conf == null)
        conf = new Configuration();
    Options options = new Options();
    options.addOption(newOption("h", null, "Prints this help"));
    options.addOption(newOption("v", null, "Prints version"));
    options.addOption(newOption("s", "source_htable", "Source HBase table with Halyard RDF store"));
    options.addOption(
            newOption("q", "sparql_query", "SPARQL tuple or graph query executed to export the data"));
    options.addOption(newOption("t", "target_url",
            "file://<path>/<file_name>.<ext> or hdfs://<path>/<file_name>.<ext> or jdbc:<jdbc_connection>/<table_name>"));
    options.addOption(newOption("p", "property=value", "JDBC connection properties"));
    options.addOption(newOption("l", "driver_classpath", "JDBC driver classpath delimited by ':'"));
    options.addOption(newOption("c", "driver_class", "JDBC driver class name"));
    options.addOption(newOption("r", null, "Trim target table before export (apply for JDBC only)"));
    try {
        CommandLine cmd = new PosixParser().parse(options, args);
        if (args.length == 0 || cmd.hasOption('h')) {
            printHelp(options);
            return;
        }
        if (cmd.hasOption('v')) {
            Properties p = new Properties();
            try (InputStream in = HalyardExport.class
                    .getResourceAsStream("/META-INF/maven/com.msd.gin.halyard/hbasesail/pom.properties")) {
                if (in != null)
                    p.load(in);
            }
            System.out.println("Halyard Export version " + p.getProperty("version", "unknown"));
            return;
        }
        if (!cmd.getArgList().isEmpty())
            throw new ExportException("Unknown arguments: " + cmd.getArgList().toString());
        for (char c : "sqt".toCharArray()) {
            if (!cmd.hasOption(c))
                throw new ExportException("Missing mandatory option: " + c);
        }
        for (char c : "sqtlc".toCharArray()) {
            String s[] = cmd.getOptionValues(c);
            if (s != null && s.length > 1)
                throw new ExportException("Multiple values for option: " + c);
        }
        StatusLog log = new StatusLog() {
            private final Logger l = Logger.getLogger(HalyardExport.class.getName());

            @Override
            public void tick() {
            }

            @Override
            public void logStatus(String status) {
                l.info(status);
            }
        };
        String driverClasspath = cmd.getOptionValue('l');
        URL driverCP[] = null;
        if (driverClasspath != null) {
            String jars[] = driverClasspath.split(":");
            driverCP = new URL[jars.length];
            for (int j = 0; j < jars.length; j++) {
                File f = new File(jars[j]);
                if (!f.isFile())
                    throw new ExportException("Invalid JDBC driver classpath element: " + jars[j]);
                driverCP[j] = f.toURI().toURL();
            }
        }
        export(conf, log, cmd.getOptionValue('s'), cmd.getOptionValue('q'), cmd.getOptionValue('t'),
                cmd.getOptionValue('c'), driverCP, cmd.getOptionValues('p'), cmd.hasOption('r'));
    } catch (RuntimeException exp) {
        System.out.println(exp.getMessage());
        printHelp(options);
        throw exp;
    }
}

From source file:com.bericotech.clavin.index.IndexDirectoryBuilder.java

/**
 * Turns a GeoNames gazetteer file into a Lucene index, and adds
 * some supplementary gazetteer records at the end.
 *
 * @param args              not used//from   ww  w.j a  v  a 2s. c om
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    Options options = getOptions();
    CommandLine cmd = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        LOG.error(pe.getMessage());
        printHelp(options);
        System.exit(-1);
    }

    if (cmd.hasOption(HELP_OPTION)) {
        printHelp(options);
        System.exit(0);
    }

    String indexPath = cmd.getOptionValue(INDEX_PATH_OPTION, DEFAULT_INDEX_DIRECTORY);
    String[] gazetteerPaths = cmd.getOptionValues(GAZETTEER_FILES_OPTION);
    if (gazetteerPaths == null || gazetteerPaths.length == 0) {
        gazetteerPaths = DEFAULT_GAZETTEER_FILES;
    }
    boolean replaceIndex = cmd.hasOption(REPLACE_INDEX_OPTION);
    boolean fullAncestry = cmd.hasOption(FULL_ANCESTRY_OPTION);

    File idir = new File(indexPath);
    // if the index directory exists, delete it if we are replacing, otherwise
    // exit gracefully
    if (idir.exists()) {
        if (replaceIndex) {
            LOG.info("Replacing index: {}", idir.getAbsolutePath());
            FileUtils.deleteDirectory(idir);
        } else {
            LOG.info("{} exists. Remove the directory and try again.", idir.getAbsolutePath());
            System.exit(-1);
        }
    }

    List<File> gazetteerFiles = new ArrayList<File>();
    for (String gp : gazetteerPaths) {
        File gf = new File(gp);
        if (gf.isFile() && gf.canRead()) {
            gazetteerFiles.add(gf);
        } else {
            LOG.info("Unable to read Gazetteer file: {}", gf.getAbsolutePath());
        }
    }
    if (gazetteerFiles.isEmpty()) {
        LOG.error("No Gazetteer files found.");
        System.exit(-1);
    }

    String altNamesPath = cmd.getOptionValue(ALTERNATE_NAMES_OPTION);
    File altNamesFile = altNamesPath != null ? new File(altNamesPath) : null;
    if (altNamesFile != null && !(altNamesFile.isFile() && altNamesFile.canRead())) {
        LOG.error("Unable to read alternate names file: {}", altNamesPath);
        System.exit(-1);
    }

    new IndexDirectoryBuilder(fullAncestry).buildIndex(idir, gazetteerFiles, altNamesFile);
}

From source file:io.apicurio.studio.tools.release.ReleaseTool.java

/**
 * Main method.//from  www.  jav a 2 s  . c o  m
 * @param args
 */
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("n", "release-name", true, "The name of the new release.");
    options.addOption("p", "prerelease", false, "Indicate that this is a pre-release.");
    options.addOption("t", "release-tag", true, "The tag name of the new release.");
    options.addOption("o", "previous-tag", true, "The tag name of the previous release.");
    options.addOption("g", "github-pat", true, "The GitHub PAT (for authentication/authorization).");
    options.addOption("a", "artifact", true, "The binary release artifact (full path).");
    options.addOption("d", "output-directory", true, "Where to store output file(s).");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (!cmd.hasOption("n") || !cmd.hasOption("t") || !cmd.hasOption("o") || !cmd.hasOption("g")
            || !cmd.hasOption("a")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("release-studio", options);
        System.exit(1);
    }

    // Arguments (command line)
    String releaseName = cmd.getOptionValue("n");
    boolean isPrerelease = cmd.hasOption("p");
    String releaseTag = cmd.getOptionValue("t");
    String oldReleaseTag = cmd.getOptionValue("o");
    String githubPAT = cmd.getOptionValue("g");
    String artifact = cmd.getOptionValue("a");
    File outputDir = new File("");
    if (cmd.hasOption("d")) {
        outputDir = new File(cmd.getOptionValue("d"));
        if (!outputDir.exists()) {
            outputDir.mkdirs();
        }
    }

    File releaseArtifactFile = new File(artifact);
    File releaseArtifactSigFile = new File(artifact + ".asc");

    String releaseArtifact = releaseArtifactFile.getName();
    String releaseArtifactSig = releaseArtifactSigFile.getName();

    if (!releaseArtifactFile.isFile()) {
        System.err.println("Missing file: " + releaseArtifactFile.getAbsolutePath());
        System.exit(1);
    }
    if (!releaseArtifactSigFile.isFile()) {
        System.err.println("Missing file: " + releaseArtifactSigFile.getAbsolutePath());
        System.exit(1);
    }

    System.out.println("=========================================");
    System.out.println("Creating Release: " + releaseTag);
    System.out.println("Previous Release: " + oldReleaseTag);
    System.out.println("            Name: " + releaseName);
    System.out.println("        Artifact: " + releaseArtifact);
    System.out.println("     Pre-Release: " + isPrerelease);
    System.out.println("=========================================");

    String releaseNotes = "";

    // Step #1 - Generate Release Notes
    //   * Grab info about the previous release (extract publish date)
    //   * Query all Issues for ones closed since that date
    //   * Generate Release Notes from the resulting Issues
    try {
        System.out.println("Getting info about release " + oldReleaseTag);
        HttpResponse<JsonNode> response = Unirest
                .get("https://api.github.com/repos/apicurio/apicurio-studio/releases/tags/v" + oldReleaseTag)
                .header("Accept", "application/json").header("Authorization", "token " + githubPAT).asJson();
        if (response.getStatus() != 200) {
            throw new Exception("Failed to get old release info: " + response.getStatusText());
        }
        JsonNode body = response.getBody();
        String publishedDate = body.getObject().getString("published_at");
        if (publishedDate == null) {
            throw new Exception("Could not find Published Date for previous release " + oldReleaseTag);
        }
        System.out.println("Release " + oldReleaseTag + " was published on " + publishedDate);

        List<JSONObject> issues = getIssuesForRelease(publishedDate, githubPAT);
        System.out.println("Found " + issues.size() + " issues closed in release " + releaseTag);
        System.out.println("Generating Release Notes");

        releaseNotes = generateReleaseNotes(releaseName, releaseTag, issues);
        System.out.println("------------ Release Notes --------------");
        System.out.println(releaseNotes);
        System.out.println("-----------------------------------------");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    String assetUploadUrl = null;

    // Step #2 - Create a GitHub Release
    try {
        System.out.println("\nCreating GitHub Release " + releaseTag);
        JSONObject body = new JSONObject();
        body.put("tag_name", "v" + releaseTag);
        body.put("name", releaseName);
        body.put("body", releaseNotes);
        body.put("prerelease", isPrerelease);

        HttpResponse<JsonNode> response = Unirest
                .post("https://api.github.com/repos/apicurio/apicurio-studio/releases")
                .header("Accept", "application/json").header("Content-Type", "application/json")
                .header("Authorization", "token " + githubPAT).body(body).asJson();
        if (response.getStatus() != 201) {
            throw new Exception("Failed to create release in GitHub: " + response.getStatusText());
        }

        assetUploadUrl = response.getBody().getObject().getString("upload_url");
        if (assetUploadUrl == null || assetUploadUrl.trim().isEmpty()) {
            throw new Exception("Failed to get Asset Upload URL for newly created release!");
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    // Step #3 - Upload Release Artifact (zip file)
    System.out.println("\nUploading Quickstart Artifact: " + releaseArtifact);
    try {
        String artifactUploadUrl = createUploadUrl(assetUploadUrl, releaseArtifact);
        byte[] artifactData = loadArtifactData(releaseArtifactFile);
        System.out.println("Uploading artifact asset: " + artifactUploadUrl);
        HttpResponse<JsonNode> response = Unirest.post(artifactUploadUrl).header("Accept", "application/json")
                .header("Content-Type", "application/zip").header("Authorization", "token " + githubPAT)
                .body(artifactData).asJson();
        if (response.getStatus() != 201) {
            throw new Exception("Failed to upload asset: " + releaseArtifact,
                    new Exception(response.getStatus() + "::" + response.getStatusText()));
        }

        Thread.sleep(1000);

        artifactUploadUrl = createUploadUrl(assetUploadUrl, releaseArtifactSig);
        artifactData = loadArtifactData(releaseArtifactSigFile);
        System.out.println("Uploading artifact asset: " + artifactUploadUrl);
        response = Unirest.post(artifactUploadUrl).header("Accept", "application/json")
                .header("Content-Type", "text/plain").header("Authorization", "token " + githubPAT)
                .body(artifactData).asJson();
        if (response.getStatus() != 201) {
            throw new Exception("Failed to upload asset: " + releaseArtifactSig,
                    new Exception(response.getStatus() + "::" + response.getStatusText()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    Thread.sleep(1000);

    // Step #4 - Download Latest Release JSON for inclusion in the project web site
    try {
        System.out.println("Getting info about the release.");
        HttpResponse<JsonNode> response = Unirest
                .get("https://api.github.com/repos/apicurio/apicurio-studio/releases/latest")
                .header("Accept", "application/json").asJson();
        if (response.getStatus() != 200) {
            throw new Exception("Failed to get release info: " + response.getStatusText());
        }
        JsonNode body = response.getBody();
        String publishedDate = body.getObject().getString("published_at");
        if (publishedDate == null) {
            throw new Exception("Could not find Published Date for release.");
        }
        String fname = publishedDate.replace(':', '-');
        File outFile = new File(outputDir, fname + ".json");

        System.out.println("Writing latest release info to: " + outFile.getAbsolutePath());

        String output = body.getObject().toString(4);
        try (FileOutputStream fos = new FileOutputStream(outFile)) {
            fos.write(output.getBytes("UTF-8"));
            fos.flush();
        }

        System.out.println("Release info successfully written.");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    System.out.println("=========================================");
    System.out.println("All Done!");
    System.out.println("=========================================");
}

From source file:at.ac.tuwien.inso.subcat.postprocessor.PostProcessor.java

public static void main(String[] args) {
    Map<String, PostProcessorTask> steps = new HashMap<String, PostProcessorTask>();
    PostProcessorTask _step = new ClassificationTask();
    steps.put(_step.getName(), _step);// ww w . j a  va2  s .c  om
    CommentAnalyserTask commentAnalysisStep = new CommentAnalyserTask();
    steps.put(commentAnalysisStep.getName(), commentAnalysisStep);
    AccountInterlinkingTask interlinkingTask = new AccountInterlinkingTask();
    steps.put(interlinkingTask.getName(), interlinkingTask);
    _step = new CommitBugInterlinkingTask();
    steps.put(_step.getName(), _step);

    Options options = new Options();
    options.addOption("h", "help", false, "Show this options");
    options.addOption("d", "db", true, "The database to process (required)");
    options.addOption("v", "verbose", false, "Show details");
    options.addOption("p", "project", true, "The project ID to process");
    options.addOption("P", "list-projects", false, "List all registered projects");
    options.addOption("S", "list-processor-steps", false, "List all registered processor steps");
    options.addOption("s", "processor-step", true, "A processor step name");
    options.addOption("c", "commit-dictionary", true,
            "Path to a classification dictionary for commit message classification");
    options.addOption("b", "bug-dictionary", true,
            "Path to a classification dictionary for bug classification");
    options.addOption("m", "smart-matching", true,
            "Smart user matching configuration. Syntax: <method>:<distance>");
    options.addOption("M", "list-matching-methods", false, "List smart matching methods");

    final Reporter reporter = new Reporter(true);
    reporter.startTimer();

    Settings settings = new Settings();
    ModelPool pool = null;

    boolean printTraces = false;
    CommandLineParser parser = new PosixParser();

    try {
        CommandLine cmd = parser.parse(options, args);
        printTraces = cmd.hasOption("verbose");

        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("postprocessor", options);
            return;
        }

        if (cmd.hasOption("list-processor-steps")) {
            for (String proj : steps.keySet()) {
                System.out.println("  " + proj);
            }
            return;
        }

        if (cmd.hasOption("list-matching-methods")) {
            for (String method : HashFunc.getHashFuncNames()) {
                System.out.println("  " + method);
            }
            return;
        }

        if (cmd.hasOption("db") == false) {
            reporter.error("post-processor", "Option --db is required");
            reporter.printSummary();
            return;
        }

        File dbf = new File(cmd.getOptionValue("db"));
        if (dbf.exists() == false || dbf.isFile() == false) {
            reporter.error("post-processor", "Invalid database file path");
            reporter.printSummary();
            return;
        }

        pool = new ModelPool(cmd.getOptionValue("db"), 2);

        if (cmd.hasOption("list-projects")) {
            Model model = pool.getModel();

            for (Project proj : model.getProjects()) {
                System.out.println("  " + proj.getId() + ": " + proj.getDate());
            }

            model.close();
            return;
        }

        Integer projId = null;
        if (cmd.hasOption("project") == false) {
            reporter.error("post-processor", "Option --project is required");
            reporter.printSummary();
            return;
        } else {
            try {
                projId = Integer.parseInt(cmd.getOptionValue("project"));
            } catch (NumberFormatException e) {
                reporter.error("post-processor", "Invalid project ID");
                reporter.printSummary();
                return;
            }
        }

        Model model = pool.getModel();
        Project project = model.getProject(projId);
        model.close();

        if (project == null) {
            reporter.error("post-processor", "Invalid project ID");
            reporter.printSummary();
            return;
        }

        if (cmd.hasOption("bug-dictionary")) {
            DictionaryParser dp = new DictionaryParser();

            for (String path : cmd.getOptionValues("bug-dictionary")) {
                try {
                    Dictionary dict = dp.parseFile(path);
                    settings.bugDictionaries.add(dict);
                } catch (FileNotFoundException e) {
                    reporter.error("post-processor", "File  not found: " + path + ": " + e.getMessage());
                    reporter.printSummary();
                    return;
                } catch (XmlReaderException e) {
                    reporter.error("post-processor", "XML Error: " + path + ": " + e.getMessage());
                    reporter.printSummary();
                    return;
                }
            }
        }

        if (cmd.hasOption("commit-dictionary")) {
            DictionaryParser dp = new DictionaryParser();

            for (String path : cmd.getOptionValues("commit-dictionary")) {
                try {
                    Dictionary dict = dp.parseFile(path);
                    settings.srcDictionaries.add(dict);
                } catch (FileNotFoundException e) {
                    reporter.error("post-processor", "File  not found: " + path + ": " + e.getMessage());
                    reporter.printSummary();
                    return;
                } catch (XmlReaderException e) {
                    reporter.error("post-processor", "XML Error: " + path + ": " + e.getMessage());
                    reporter.printSummary();
                    return;
                }
            }
        }

        if (cmd.hasOption("smart-matching")) {
            String str = cmd.getOptionValue("smart-matching");
            String[] parts = str.split(":");
            if (parts.length != 2) {
                reporter.error("post-processor", "Unexpected smart-matching format");
                reporter.printSummary();
                return;
            }

            HashFunc func = HashFunc.getHashFunc(parts[0]);
            if (func == null) {
                reporter.error("post-processor", "Unknown smart matching hash function");
                reporter.printSummary();
                return;
            }

            int dist = -1;
            try {
                dist = Integer.parseInt(parts[1]);
            } catch (NumberFormatException e) {
                dist = -1;
            }

            if (dist < 0) {
                reporter.error("post-processor", "Invalid smart matching edist distance");
                reporter.printSummary();
                return;
            }

            interlinkingTask.setDistance(dist);
            interlinkingTask.setHashFunc(func);
        }

        PostProcessor processor = new PostProcessor(project, pool, settings);
        if (cmd.hasOption("processor-step")) {
            for (String stepName : cmd.getOptionValues("processor-step")) {
                PostProcessorTask step = steps.get(stepName);
                if (step == null) {
                    reporter.error("post-processor", "Unknown processor step: '" + stepName + "'");
                    reporter.printSummary();
                    return;
                }

                processor.register(step);
            }
        } else {
            processor.register(steps.values());
        }

        if (printTraces == true) {
            model = pool.getModel();
            final Stats stats = model.getStats(project);
            model.close();

            processor.addListener(new PostProcessorListener() {
                private int commitCount = 0;
                private int bugCount = 0;

                @Override
                public void commit(PostProcessor proc) {
                    commitCount++;
                    reporter.note("post-processor", "status: Commit " + commitCount + "/" + stats.commitCount);
                }

                @Override
                public void bug(PostProcessor proc) {
                    bugCount++;
                    reporter.note("post-processor", "status: Bug " + bugCount + "/" + stats.bugCount);
                }
            });
        }

        processor.process();
    } catch (ParseException e) {
        reporter.error("post-processor", "Parsing failed: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } catch (ClassNotFoundException e) {
        reporter.error("post-processor", "Failed to create a database connection: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } catch (SQLException e) {
        reporter.error("post-processor", "Failed to create a database connection: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } catch (PostProcessorException e) {
        reporter.error("post-processor", "Post-Processor Error: " + e.getMessage());
        if (printTraces == true) {
            e.printStackTrace();
        }
    } finally {
        if (pool != null) {
            pool.close();
        }
    }

    reporter.printSummary(true);
}

From source file:at.ac.tuwien.inso.subcat.reporter.Reporter.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("h", "help", false, "Show this options");
    options.addOption("d", "db", true, "The database to process (required)");
    options.addOption("p", "project", true, "The project ID to process");
    options.addOption("P", "list-projects", false, "List all registered projects");
    options.addOption("C", "config", true, "A configuration file including reports");
    options.addOption("F", "list-formats", false, "List all supported output formats");
    options.addOption("f", "format", true, "Output format");
    options.addOption("R", "list-reports", false, "List all report types");
    options.addOption("r", "report", true, "Report type");
    options.addOption("o", "output", true, "Output path");
    options.addOption("c", "commit-dictionary", true, "The commit dictionary ID to use");
    options.addOption("b", "bug-dictionary", true, "The bug dictionary ID to use");
    options.addOption("D", "list-dictionaries", false, "List all dictionaries");
    options.addOption("v", "verbose", false, "Show details");

    at.ac.tuwien.inso.subcat.utility.Reporter errReporter = new at.ac.tuwien.inso.subcat.utility.Reporter(
            false);/*from w  w  w. ja  va  2 s. com*/
    Settings settings = new Settings();
    boolean verbose = false;
    ModelPool pool = null;
    Model model = null;

    CommandLineParser parser = new PosixParser();

    try {
        CommandLine cmd = parser.parse(options, args);
        verbose = cmd.hasOption("verbose");

        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("postprocessor", options);
            return;
        }

        if (cmd.hasOption("db") == false) {
            errReporter.error("reporter", "Option --db is required");
            errReporter.printSummary();
            return;
        }

        if (cmd.hasOption("config") == false) {
            errReporter.error("reporter", "Option --config is required");
            errReporter.printSummary();
            return;
        }

        Configuration config = new Configuration();
        Parser configParser = new Parser();
        try {
            configParser.parse(config, new File(cmd.getOptionValue("config")));
        } catch (IOException e) {
            errReporter.error("reporter", "Could not read configuration file: " + e.getMessage());
            errReporter.printSummary();
            return;
        } catch (ParserException e) {
            errReporter.error("reporter", "Could not parse configuration file: " + e.getMessage());
            errReporter.printSummary();
            return;
        }

        if (cmd.hasOption("list-reports")) {
            int i = 1;

            for (ExporterConfig exconf : config.getExporterConfigs()) {
                System.out.println("  (" + i + ") " + exconf.getName());
                i++;
            }

            return;
        }

        File dbf = new File(cmd.getOptionValue("db"));
        if (dbf.exists() == false || dbf.isFile() == false) {
            errReporter.error("reporter", "Invalid database file path");
            errReporter.printSummary();
            return;
        }

        pool = new ModelPool(cmd.getOptionValue("db"), 2);
        pool.setPrintTemplates(verbose);
        model = pool.getModel();

        if (cmd.hasOption("list-formats")) {
            Reporter exporter = new Reporter(model);
            int i = 1;

            for (ReportWriter formatter : exporter.getWriters()) {
                System.out.println("  (" + i + ") " + formatter.getLabel());
                i++;
            }

            return;
        }

        if (cmd.hasOption("list-projects")) {
            for (Project proj : model.getProjects()) {
                System.out.println("  " + proj.getId() + ": " + proj.getDate());
            }

            return;
        }

        Integer projId = null;
        if (cmd.hasOption("project") == false) {
            errReporter.error("reporter", "Option --project is required");
            errReporter.printSummary();
            return;
        } else {
            try {
                projId = Integer.parseInt(cmd.getOptionValue("project"));
            } catch (NumberFormatException e) {
                errReporter.error("reporter", "Invalid project ID");
                errReporter.printSummary();
                return;
            }
        }

        if (cmd.hasOption("output") == false) {
            errReporter.error("reporter", "Option --output is required");
            errReporter.printSummary();
            return;
        }

        String outputPath = cmd.getOptionValue("output");
        model = pool.getModel();
        Project project = model.getProject(projId);

        if (project == null) {
            errReporter.error("reporter", "Invalid project ID");
            errReporter.printSummary();
            return;
        }

        if (cmd.hasOption("list-dictionaries")) {
            List<at.ac.tuwien.inso.subcat.model.Dictionary> dictionaries = model.getDictionaries(project);
            for (at.ac.tuwien.inso.subcat.model.Dictionary dict : dictionaries) {
                System.out
                        .println("  (" + dict.getId() + ") " + " " + dict.getContext() + " " + dict.getName());
            }
            return;
        }

        int bugDictId = -1;
        if (cmd.hasOption("bug-dictionary")) {
            try {
                bugDictId = Integer.parseInt(cmd.getOptionValue("bug-dictionary"));
                List<at.ac.tuwien.inso.subcat.model.Dictionary> dictionaries = model.getDictionaries(project);
                boolean valid = false;

                for (at.ac.tuwien.inso.subcat.model.Dictionary dict : dictionaries) {
                    if (dict.getId() == bugDictId) {
                        valid = true;
                        break;
                    }
                }

                if (valid == false) {
                    errReporter.error("reporter", "Invalid bug dictionary ID");
                    errReporter.printSummary();
                    return;
                }
            } catch (NumberFormatException e) {
                errReporter.error("reporter", "Invalid bug dictionary ID");
                errReporter.printSummary();
                return;
            }
        }

        int commitDictId = -1;
        if (cmd.hasOption("commit-dictionary")) {
            try {
                commitDictId = Integer.parseInt(cmd.getOptionValue("commit-dictionary"));
                List<at.ac.tuwien.inso.subcat.model.Dictionary> dictionaries = model.getDictionaries(project);
                boolean valid = false;

                for (at.ac.tuwien.inso.subcat.model.Dictionary dict : dictionaries) {
                    if (dict.getId() == commitDictId) {
                        valid = true;
                        break;
                    }
                }

                if (valid == false) {
                    errReporter.error("reporter", "Invalid commit dictionary ID");
                    errReporter.printSummary();
                    return;
                }
            } catch (NumberFormatException e) {
                errReporter.error("reporter", "Invalid commit dictionary ID");
                errReporter.printSummary();
                return;
            }
        }

        if (cmd.hasOption("format") == false) {
            errReporter.error("reporter", "Option --format is required");
            errReporter.printSummary();
            return;
        }

        Reporter exporter = new Reporter(model);
        ReportWriter writer = null;
        try {
            int id = Integer.parseInt(cmd.getOptionValue("format"));
            if (id < 1 || id > exporter.getWriters().size()) {
                errReporter.error("reporter", "Invalid output format");
                errReporter.printSummary();
                return;
            }

            writer = exporter.getWriters().get(id - 1);
        } catch (NumberFormatException e) {
            errReporter.error("reporter", "Invalid output format");
            errReporter.printSummary();
            return;
        }

        ExporterConfig exporterConfig = null;
        if (cmd.hasOption("report") == false) {
            errReporter.error("reporter", "Option --report is required");
            errReporter.printSummary();
            return;
        } else {
            try {
                int id = Integer.parseInt(cmd.getOptionValue("report"));
                if (id < 1 || id > config.getExporterConfigs().size()) {
                    errReporter.error("reporter", "Invalid reporter ID");
                    errReporter.printSummary();
                    return;
                }

                exporterConfig = config.getExporterConfigs().get(id - 1);
            } catch (NumberFormatException e) {
                errReporter.error("reporter", "Invalid reporter ID");
                errReporter.printSummary();
                return;
            }
        }

        exporter.export(exporterConfig, project, commitDictId, bugDictId, settings, writer, outputPath);
    } catch (ParseException e) {
        errReporter.error("reporter", "Parsing failed: " + e.getMessage());
        if (verbose == true) {
            e.printStackTrace();
        }
    } catch (ClassNotFoundException e) {
        errReporter.error("reporter", "Failed to create a database connection: " + e.getMessage());
        if (verbose == true) {
            e.printStackTrace();
        }
    } catch (SQLException e) {
        errReporter.error("reporter", "Failed to create a database connection: " + e.getMessage());
        if (verbose == true) {
            e.printStackTrace();
        }
    } catch (ReporterException e) {
        errReporter.error("reporter", "Reporter Error: " + e.getMessage());
        if (verbose == true) {
            e.printStackTrace();
        }
    } finally {
        if (model != null) {
            model.close();
        }
        if (pool != null) {
            pool.close();
        }
    }

    errReporter.printSummary();
}

From source file:GenAppStoreSales.java

/**
 * Starting point for the demonstration application.
 * @throws IOException //from w  w  w .j ava  2s.c o m
 * 
 */
public static void main(String[] args) throws IOException {
    System.out.print("\nRefreshing Apple Store Reports...");

    // Init Calendars
    rollCalendar = Calendar.getInstance();
    updateRollCalendar();
    currentYear = rollCalendar.get(Calendar.YEAR);
    currentMonth = rollCalendar.get(Calendar.MONTH) + 1;
    currentDay = rollCalendar.get(Calendar.DATE);
    Calendar launchCalendar = Calendar.getInstance();
    int launchYear = 2013, launchMonth = 2, launchDay = 28; //Month from 0..11
    launchCalendar.set(launchYear, launchMonth, launchDay);
    /* Report Folders
     */
    currentPath = new File("").getAbsolutePath();
    String sourceName = "/sources";
    File sourceDir = new File(currentPath, sourceName);
    if (!sourceDir.isDirectory()) {
        if (!(new File(currentPath + sourceName)).mkdirs()) {
            System.out.println("[Error] Couldn't create 'source' folder.");
        }
    }
    sourcePath = sourceDir.getAbsolutePath();

    String chartName = "/charts";
    File chartDir = new File(currentPath, chartName);
    if (!chartDir.isDirectory()) {
        if (!(new File(currentPath + chartName)).mkdirs()) {
            System.out.println("[Error] Couldn't create 'chart' folder.");
        }
    }
    chartPath = chartDir.getAbsolutePath();

    String dateCode, reportName;

    // DAILY REPORT
    System.out.println("\n-> Daily reports");
    for (int d = 0; d < 14; d++) {
        rollCalendar.add(Calendar.DATE, -1);
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        reportName = "S_D_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Daily", dateCode);
    }
    printDatePeriod("DAILY", "report");

    // WEEKLY REPORT
    System.out.println("\n-> Weekly reports");
    rollCalendar = Calendar.getInstance();
    rollCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    pursuedDay = currentDay;
    pursuedMonth = currentMonth;
    pursuedYear = currentYear;
    for (int w = 0; w < 13; w++) {
        rollCalendar.add(Calendar.DATE, -7);
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        reportName = "S_W_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Weekly", dateCode);
    }
    printDatePeriod("WEEKLY", "report");

    // MONTHLY REPORTS
    System.out.println("\n-> Monthly reports");
    rollCalendar = Calendar.getInstance();
    pursuedDay = currentDay;
    pursuedMonth = currentMonth - 1;
    pursuedYear = currentYear;
    for (int m = 0; m < 12; m++) {
        rollCalendar.add(Calendar.MONTH, -1);
        rollCalendar.set(Calendar.DATE, rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d%02d", pursuedYear, pursuedMonth);
        reportName = "S_M_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Monthly", dateCode);
    }
    printDatePeriod("MONTHLY", "report");

    // YEARLY REPORTS
    System.out.println("\n-> Yearly reports");
    rollCalendar = Calendar.getInstance();
    rollCalendar.add(Calendar.DATE, -1);
    pursuedDay = currentDay - 1;
    pursuedMonth = currentMonth;
    pursuedYear = currentYear;
    for (int y = 0; y < 100; y++) {
        rollCalendar.add(Calendar.YEAR, -1);
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d", pursuedYear);
        reportName = "S_Y_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Yearly", dateCode);
    }
    printDatePeriod("YEARLY", "report");

    /**
     * Reading Sales.txt & Generating Charts
     */
    // WEEK CHARTS
    String plotName, pursuedPeriodDate;
    System.out.print("\nRestoring charts...\n");
    System.out.println("-> Week charts");
    rollCalendar = Calendar.getInstance();
    rollCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    rollCalendar.add(Calendar.DATE, -7);
    updateRollCalendar();
    while (rollCalendar.compareTo(launchCalendar) > 0) {
        pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        plotName = "S_W_" + appID + "_" + dateCode;
        File plotFile = new File(chartPath + "/" + plotName + ".png");
        if (!plotFile.isFile()) {
            readSales("week", true, true);
            if (countryLabels.size() > 0) {
                genPlot("WEEK", plotName, pursuedPeriodDate, countryLabels, countryUnits);
            }
            if (countryInAppLabels.size() > 0) {
                genPlot("WEEK IN-APP", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels,
                        countryInAppUnits);
            }
        } else
            readSales("week", false, true);// Week already plotted
    }
    printDatePeriod("WEEK", "charts");

    // Incomplete current Week (let the current day be computed)
    rollCalendar = Calendar.getInstance();
    updateRollCalendar();
    readSales("week", false, true);
    // MONTH CHARTS
    System.out.println("\n-> Month charts");
    rollCalendar = Calendar.getInstance();
    rollCalendar.add(Calendar.MONTH, -1);
    rollCalendar.set(Calendar.DATE, rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    updateRollCalendar();
    while (rollCalendar.compareTo(launchCalendar) > 0) {
        pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        plotName = "S_M_" + appID + "_" + dateCode;
        File plotFile = new File(chartPath + "/" + plotName + ".png");
        if (!plotFile.isFile()) {
            readSales("month", true, false);
            if (countryLabels.size() > 0) {
                genPlot("MONTH", plotName, pursuedPeriodDate, countryLabels, countryUnits);
            }
            if (countryInAppLabels.size() > 0) {
                genPlot("MONTH", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits);
            }
        } else {
            readSales("month", false, false);
        }

    }
    printDatePeriod("MONTH", "charts");

    // YEAR CHARTS
    System.out.println("\n-> Year charts");
    rollCalendar = (Calendar) launchCalendar.clone();
    rollCalendar.set(Calendar.DATE, -1);
    rollCalendar.add(Calendar.YEAR, -1);
    updateRollCalendar();
    while (rollCalendar.compareTo(launchCalendar) > 0) {
        pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        plotName = "S_Y_" + appID + "_" + dateCode;
        File plotFile = new File(chartPath + "/" + plotName + ".png");
        if (!plotFile.isFile()) {
            readSales("year", true, false);
            if (countryLabels.size() > 0) {
                genPlot("YEAR", plotName, pursuedPeriodDate, countryLabels, countryUnits);
            }
            if (countryInAppLabels.size() > 0) {
                genPlot("YEAR", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits);
            }
        } else
            readSales("year", false, false);
    }
    printDatePeriod("YEAR", "charts");

    // CUSTOM CHART PERIOD
    System.out.println("\n-> Custom charts");
    customCalendar = (Calendar) launchCalendar.clone(); // begin day
    rollCalendar = Calendar.getInstance(); // end day
    rollCalendar.add(Calendar.DATE, -1);
    updateRollCalendar();
    pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
    dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
    plotName = "S_C_" + appID + "__whole";// + dateCode;
    File plotFile = new File(chartPath + "/" + plotName + ".png");
    if (!plotFile.isFile()) {
        readSales("custom", true, false);
        if (countryLabels.size() > 0) {
            genPlot("CUSTOM", plotName, pursuedPeriodDate, countryLabels, countryUnits);
        }
        if (countryInAppLabels.size() > 0) {
            genPlot("CUSTOM IN-APP", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels,
                    countryInAppUnits);
        }
    }
    printDatePeriod("CUSTOM Period", "charts");

    // Day Sales units
    rollCalendar = Calendar.getInstance();
    rollCalendar.add(Calendar.DATE, -1);
    updateRollCalendar();
    readSales("day", false, false);

    System.out.println("\nTotal units: " + totalUnits + "/" + totalUpdateUnits + "-Up (+" + dayUnits + ")");
    System.out.println("Total IN-APP units: " + totalInAppUnits + " (+" + dayINAPPUnits + ")\n");
    System.exit(0);
}

From source file:DIA_Umpire_Quant.DIA_Umpire_ProtQuant.java

/**
 * @param args the command line arguments
 *//*w w  w  . j  a va  2  s.co  m*/
public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
    System.out.println(
            "=================================================================================================");
    System.out.println(
            "DIA-Umpire protein quantitation module (version: " + UmpireInfo.GetInstance().Version + ")");
    if (args.length != 1) {
        System.out.println(
                "command format error, the correct format should be: java -jar -Xmx10G DIA_Umpire_PortQuant.jar diaumpire_module.params");
        return;
    }
    try {
        ConsoleLogger.SetConsoleLogger(Level.INFO);
        ConsoleLogger.SetFileLogger(Level.DEBUG,
                FilenameUtils.getFullPath(args[0]) + "diaumpire_orotquant.log");
    } catch (Exception e) {
    }

    Logger.getRootLogger().info("Version: " + UmpireInfo.GetInstance().Version);
    Logger.getRootLogger().info("Parameter file:" + args[0]);

    BufferedReader reader = new BufferedReader(new FileReader(args[0]));
    String line = "";
    String WorkFolder = "";
    int NoCPUs = 2;

    String Combined_Prot = "";
    boolean DefaultProtFiltering = true;

    float Freq = 0f;
    int TopNPep = 6;
    int TopNFrag = 6;
    String FilterWeight = "GW";
    float MinWeight = 0.9f;

    TandemParam tandemPara = new TandemParam(DBSearchParam.SearchInstrumentType.TOF5600);
    HashMap<String, File> AssignFiles = new HashMap<>();

    boolean ExportSaint = false;
    boolean SAINT_MS1 = false;
    boolean SAINT_MS2 = true;

    HashMap<String, String[]> BaitList = new HashMap<>();
    HashMap<String, String> BaitName = new HashMap<>();
    HashMap<String, String[]> ControlList = new HashMap<>();
    HashMap<String, String> ControlName = new HashMap<>();

    //<editor-fold defaultstate="collapsed" desc="Reading parameter file">
    while ((line = reader.readLine()) != null) {
        line = line.trim();
        Logger.getRootLogger().info(line);
        if (!"".equals(line) && !line.startsWith("#")) {
            //System.out.println(line);
            if (line.equals("==File list begin")) {
                do {
                    line = reader.readLine();
                    line = line.trim();
                    if (line.equals("==File list end")) {
                        continue;
                    } else if (!"".equals(line)) {
                        File newfile = new File(line);
                        if (newfile.exists()) {
                            AssignFiles.put(newfile.getAbsolutePath(), newfile);
                        } else {
                            Logger.getRootLogger().info("File: " + newfile + " does not exist.");
                        }
                    }
                } while (!line.equals("==File list end"));
            }
            if (line.split("=").length < 2) {
                continue;
            }
            String type = line.split("=")[0].trim();
            String value = line.split("=")[1].trim();
            switch (type) {
            case "Path": {
                WorkFolder = value;
                break;
            }
            case "path": {
                WorkFolder = value;
                break;
            }
            case "Thread": {
                NoCPUs = Integer.parseInt(value);
                break;
            }
            case "Fasta": {
                tandemPara.FastaPath = value;
                break;
            }
            case "Combined_Prot": {
                Combined_Prot = value;
                break;
            }
            case "DefaultProtFiltering": {
                DefaultProtFiltering = Boolean.parseBoolean(value);
                break;
            }
            case "DecoyPrefix": {
                if (!"".equals(value)) {
                    tandemPara.DecoyPrefix = value;
                }
                break;
            }
            case "ProteinFDR": {
                tandemPara.ProtFDR = Float.parseFloat(value);
                break;
            }
            case "FilterWeight": {
                FilterWeight = value;
                break;
            }
            case "MinWeight": {
                MinWeight = Float.parseFloat(value);
                break;
            }
            case "TopNFrag": {
                TopNFrag = Integer.parseInt(value);
                break;
            }
            case "TopNPep": {
                TopNPep = Integer.parseInt(value);
                break;
            }
            case "Freq": {
                Freq = Float.parseFloat(value);
                break;
            }
            //<editor-fold defaultstate="collapsed" desc="SaintOutput">
            case "ExportSaintInput": {
                ExportSaint = Boolean.parseBoolean(value);
                break;
            }
            case "QuantitationType": {
                switch (value) {
                case "MS1": {
                    SAINT_MS1 = true;
                    SAINT_MS2 = false;
                    break;
                }
                case "MS2": {
                    SAINT_MS1 = false;
                    SAINT_MS2 = true;
                    break;
                }
                case "BOTH": {
                    SAINT_MS1 = true;
                    SAINT_MS2 = true;
                    break;
                }
                }
                break;
            }
            //                    case "BaitInputFile": {
            //                        SaintBaitFile = value;
            //                        break;
            //                    }
            //                    case "PreyInputFile": {
            //                        SaintPreyFile = value;
            //                        break;
            //                    }
            //                    case "InterationInputFile": {
            //                        SaintInteractionFile = value;
            //                        break;
            //                    }
            default: {
                if (type.startsWith("BaitName_")) {
                    BaitName.put(type.substring(9), value);
                }
                if (type.startsWith("BaitFile_")) {
                    BaitList.put(type.substring(9), value.split("\t"));
                }
                if (type.startsWith("ControlName_")) {
                    ControlName.put(type.substring(12), value);
                }
                if (type.startsWith("ControlFile_")) {
                    ControlList.put(type.substring(12), value.split("\t"));
                }
                break;
            }
            //</editor-fold>                    
            }
        }
    }
    //</editor-fold>

    //Initialize PTM manager using compomics library
    PTMManager.GetInstance();

    //Check if the fasta file can be found
    if (!new File(tandemPara.FastaPath).exists()) {
        Logger.getRootLogger().info("Fasta file :" + tandemPara.FastaPath
                + " cannot be found, the process will be terminated, please check.");
        System.exit(1);
    }

    //Check if the prot.xml file can be found
    if (!new File(Combined_Prot).exists()) {
        Logger.getRootLogger().info("ProtXML file: " + Combined_Prot
                + " cannot be found, the export protein summary table will be empty.");
    }
    LCMSID protID = null;

    //Parse prot.xml and generate protein master list given an FDR 
    if (Combined_Prot != null && !Combined_Prot.equals("")) {
        protID = LCMSID.ReadLCMSIDSerialization(Combined_Prot);
        if (!"".equals(Combined_Prot) && protID == null) {
            protID = new LCMSID(Combined_Prot, tandemPara.DecoyPrefix, tandemPara.FastaPath);
            ProtXMLParser protxmlparser = new ProtXMLParser(protID, Combined_Prot, 0f);
            //Use DIA-Umpire default protein FDR calculation
            if (DefaultProtFiltering) {
                protID.RemoveLowLocalPWProtein(0.8f);
                protID.RemoveLowMaxIniProbProtein(0.9f);
                protID.FilterByProteinDecoyFDRUsingMaxIniProb(tandemPara.DecoyPrefix, tandemPara.ProtFDR);
            }
            //Get protein FDR calculation without other filtering
            else {
                protID.FilterByProteinDecoyFDRUsingLocalPW(tandemPara.DecoyPrefix, tandemPara.ProtFDR);
            }
            protID.LoadSequence();
            protID.WriteLCMSIDSerialization(Combined_Prot);
        }
        Logger.getRootLogger().info("Protein No.:" + protID.ProteinList.size());
    }
    HashMap<String, HashMap<String, FragmentPeak>> IDSummaryFragments = new HashMap<>();

    //Generate DIA file list
    ArrayList<DIAPack> FileList = new ArrayList<>();
    try {
        File folder = new File(WorkFolder);
        if (!folder.exists()) {
            Logger.getRootLogger().info("The path : " + WorkFolder + " cannot be found.");
            System.exit(1);
        }
        for (final File fileEntry : folder.listFiles()) {
            if (fileEntry.isFile()
                    && (fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                            | fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzml"))
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry);
            }
            if (fileEntry.isDirectory()) {
                for (final File fileEntry2 : fileEntry.listFiles()) {
                    if (fileEntry2.isFile()
                            && (fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                                    | fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzml"))
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                        AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2);
                    }
                }
            }
        }

        Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size());
        for (File fileEntry : AssignFiles.values()) {
            Logger.getRootLogger().info(fileEntry.getAbsolutePath());
        }

        for (File fileEntry : AssignFiles.values()) {
            String mzXMLFile = fileEntry.getAbsolutePath();
            if (mzXMLFile.toLowerCase().endsWith(".mzxml") | mzXMLFile.toLowerCase().endsWith(".mzml")) {
                DIAPack DiaFile = new DIAPack(mzXMLFile, NoCPUs);
                Logger.getRootLogger().info(
                        "=================================================================================================");
                Logger.getRootLogger().info("Processing " + mzXMLFile);
                if (!DiaFile.LoadDIASetting()) {
                    Logger.getRootLogger().info("Loading DIA setting failed, job is incomplete");
                    System.exit(1);
                }
                if (!DiaFile.LoadParams()) {
                    Logger.getRootLogger().info("Loading parameters failed, job is incomplete");
                    System.exit(1);
                }
                Logger.getRootLogger().info("Loading identification results " + mzXMLFile + "....");

                //If the serialization file for ID file existed
                if (DiaFile.ReadSerializedLCMSID()) {
                    DiaFile.IDsummary.ReduceMemoryUsage();
                    DiaFile.IDsummary.ClearAssignPeakCluster();
                    FileList.add(DiaFile);
                    HashMap<String, FragmentPeak> FragMap = new HashMap<>();
                    IDSummaryFragments.put(FilenameUtils.getBaseName(mzXMLFile), FragMap);
                }
            }
        }

        //<editor-fold defaultstate="collapsed" desc="Peptide and fragment selection">

        Logger.getRootLogger().info("Peptide and fragment selection across the whole dataset");
        ArrayList<LCMSID> SummaryList = new ArrayList<>();
        for (DIAPack diafile : FileList) {
            if (protID != null) {
                //Generate protein list according to mapping of peptide ions for each DIA file to the master protein list
                diafile.IDsummary.GenerateProteinByRefIDByPepSeq(protID, true);
                diafile.IDsummary.ReMapProPep();
            }
            if ("GW".equals(FilterWeight)) {
                diafile.IDsummary.SetFilterByGroupWeight();
            } else if ("PepW".equals(FilterWeight)) {
                diafile.IDsummary.SetFilterByWeight();
            }
            SummaryList.add(diafile.IDsummary);
        }
        FragmentSelection fragselection = new FragmentSelection(SummaryList);
        fragselection.freqPercent = Freq;
        fragselection.GeneratePepFragScoreMap();
        fragselection.GenerateTopFragMap(TopNFrag);
        fragselection.GenerateProtPepScoreMap(MinWeight);
        fragselection.GenerateTopPepMap(TopNPep);
        //</editor-fold>

        //<editor-fold defaultstate="collapsed" desc="Writing general reports">                 
        ExportTable export = new ExportTable(WorkFolder, SummaryList, IDSummaryFragments, protID,
                fragselection);
        export.Export(TopNPep, TopNFrag, Freq);
        //</editor-fold>

        //<editor-fold defaultstate="collapsed" desc="//<editor-fold defaultstate="collapsed" desc="Generate SAINT input files">
        if (ExportSaint && protID != null) {
            HashMap<String, DIAPack> Filemap = new HashMap<>();
            for (DIAPack DIAfile : FileList) {
                Filemap.put(DIAfile.GetBaseName(), DIAfile);
            }

            FileWriter baitfile = new FileWriter(WorkFolder + "SAINT_Bait_" + DateTimeTag.GetTag() + ".txt");
            FileWriter preyfile = new FileWriter(WorkFolder + "SAINT_Prey_" + DateTimeTag.GetTag() + ".txt");
            FileWriter interactionfileMS1 = null;
            FileWriter interactionfileMS2 = null;
            if (SAINT_MS1) {
                interactionfileMS1 = new FileWriter(
                        WorkFolder + "SAINT_Interaction_MS1_" + DateTimeTag.GetTag() + ".txt");
            }
            if (SAINT_MS2) {
                interactionfileMS2 = new FileWriter(
                        WorkFolder + "SAINT_Interaction_MS2_" + DateTimeTag.GetTag() + ".txt");
            }
            HashMap<String, String> PreyID = new HashMap<>();

            for (String samplekey : ControlName.keySet()) {
                String name = ControlName.get(samplekey);
                for (String file : ControlList.get(samplekey)) {
                    baitfile.write(FilenameUtils.getBaseName(file) + "\t" + name + "\t" + "C\n");
                    LCMSID IDsummary = Filemap.get(FilenameUtils.getBaseName(file)).IDsummary;
                    if (SAINT_MS1) {
                        SaintOutput(protID, IDsummary, fragselection, interactionfileMS1, file, name, PreyID,
                                1);
                    }
                    if (SAINT_MS2) {
                        SaintOutput(protID, IDsummary, fragselection, interactionfileMS2, file, name, PreyID,
                                2);
                    }
                }
            }
            for (String samplekey : BaitName.keySet()) {
                String name = BaitName.get(samplekey);
                for (String file : BaitList.get(samplekey)) {
                    baitfile.write(FilenameUtils.getBaseName(file) + "\t" + name + "\t" + "T\n");
                    LCMSID IDsummary = Filemap.get(FilenameUtils.getBaseName(file)).IDsummary;
                    if (SAINT_MS1) {
                        SaintOutput(protID, IDsummary, fragselection, interactionfileMS1, file, name, PreyID,
                                1);
                    }
                    if (SAINT_MS2) {
                        SaintOutput(protID, IDsummary, fragselection, interactionfileMS2, file, name, PreyID,
                                2);
                    }
                }
            }
            baitfile.close();
            if (SAINT_MS1) {
                interactionfileMS1.close();
            }
            if (SAINT_MS2) {
                interactionfileMS2.close();
            }
            for (String AccNo : PreyID.keySet()) {
                preyfile.write(AccNo + "\t" + PreyID.get(AccNo) + "\n");
            }
            preyfile.close();
        }

        //</editor-fold>

        Logger.getRootLogger().info("Job done");
        Logger.getRootLogger().info(
                "=================================================================================================");

    } catch (Exception e) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(e));
        throw e;
    }
}

From source file:org.silverpeas.dbbuilder.DBBuilder.java

/**
 * @param args/*from   w  w w .  j  a  va 2  s. c  o m*/
 * @see
 */
public static void main(String[] args) {
    ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext(
            "classpath:/spring-jdbc-datasource.xml");
    try {
        // Ouverture des traces
        Date startDate = new Date();
        System.out.println(
                MessageFormat.format(messages.getString("dbbuilder.start"), DBBuilderAppVersion, startDate));
        console = new Console(DBBuilder.class);
        console.printMessage("*************************************************************");
        console.printMessage(
                MessageFormat.format(messages.getString("dbbuilder.start"), DBBuilderAppVersion, startDate));
        // Lecture des variables d'environnement  partir de dbBuilderSettings
        dbBuilderResources = FileUtil
                .loadResource("/org/silverpeas/dbBuilder/settings/dbBuilderSettings.properties");
        // Lecture des paramtres d'entre
        params = new CommandLineParameters(console, args);

        if (params.isSimulate() && DatabaseType.ORACLE == params.getDbType()) {
            throw new Exception(messages.getString("oracle.simulate.error"));
        }
        console.printMessage(messages.getString("jdbc.connection.configuration"));
        console.printMessage(ConnectionFactory.getConnectionInfo());
        console.printMessage("\tAction        : " + params.getAction());
        console.printMessage("\tVerbose mode  : " + params.isVerbose());
        console.printMessage("\tSimulate mode : " + params.isSimulate());
        if (Action.ACTION_CONNECT == params.getAction()) {
            // un petit message et puis c'est tout
            console.printMessage(messages.getString("connection.success"));
            System.out.println(messages.getString("connection.success"));
        } else {
            // Modules en place sur la BD avant install
            console.printMessage("DB Status before build :");
            List<String> packagesIntoDB = checkDBStatus();
            // initialisation d'un vecteur des instructions SQL  passer en fin d'upgrade
            // pour mettre  niveau les versions de modules en base
            MetaInstructions sqlMetaInstructions = new MetaInstructions();
            File dirXml = new File(params.getDbType().getDBContributionDir());
            DBXmlDocument destXml = loadMasterContribution(dirXml);
            UninstallInformations processesToCacheIntoDB = new UninstallInformations();

            File[] listeFileXml = dirXml.listFiles();
            Arrays.sort(listeFileXml);

            List<DBXmlDocument> listeDBXmlDocument = new ArrayList<DBXmlDocument>(listeFileXml.length);
            int ignoredFiles = 0;
            // Ouverture de tous les fichiers de configurations
            console.printMessage(messages.getString("ignored.contribution"));

            for (File xmlFile : listeFileXml) {
                if (xmlFile.isFile() && "xml".equals(FileUtil.getExtension(xmlFile))
                        && !(FIRST_DBCONTRIBUTION_FILE.equalsIgnoreCase(xmlFile.getName()))
                        && !(MASTER_DBCONTRIBUTION_FILE.equalsIgnoreCase(xmlFile.getName()))) {
                    DBXmlDocument fXml = new DBXmlDocument(dirXml, xmlFile.getName());
                    fXml.load();
                    // vrification des dpendances et prise en compte uniquement si dependences OK
                    if (hasUnresolvedRequirements(listeFileXml, fXml)) {
                        console.printMessage(
                                '\t' + xmlFile.getName() + " (because of unresolved requirements).");
                        ignoredFiles++;
                    } else if (ACTION_ENFORCE_UNINSTALL == params.getAction()) {
                        console.printMessage('\t' + xmlFile.getName() + " (because of "
                                + ACTION_ENFORCE_UNINSTALL + " mode).");
                        ignoredFiles++;
                    } else {
                        listeDBXmlDocument.add(fXml);
                    }
                }
            }
            if (0 == ignoredFiles) {
                console.printMessage("\t(none)");
            }

            // prpare une HashMap des modules prsents en fichiers de contribution
            Map packagesIntoFile = new HashMap();
            int j = 0;
            console.printMessage(messages.getString("merged.contribution"));
            console.printMessage(params.getAction().toString());
            if (ACTION_ENFORCE_UNINSTALL != params.getAction()) {
                console.printMessage('\t' + FIRST_DBCONTRIBUTION_FILE);
                j++;
            }
            for (DBXmlDocument currentDoc : listeDBXmlDocument) {
                console.printMessage('\t' + currentDoc.getName());
                j++;
            }
            if (0 == j) {
                console.printMessage("\t(none)");
            }
            // merge des diffrents fichiers de contribution ligibles :
            console.printMessage("Build decisions are :");
            // d'abord le fichier dbbuilder-contribution ...
            DBXmlDocument fileXml;
            if (ACTION_ENFORCE_UNINSTALL != params.getAction()) {
                try {
                    fileXml = new DBXmlDocument(dirXml, FIRST_DBCONTRIBUTION_FILE);
                    fileXml.load();
                } catch (Exception e) {
                    // contribution de dbbuilder non trouve -> on continue, on est certainement en train
                    // de desinstaller la totale
                    fileXml = null;
                }
                if (null != fileXml) {
                    DBBuilderFileItem dbbuilderItem = new DBBuilderFileItem(fileXml);
                    packagesIntoFile.put(dbbuilderItem.getModule(), null);
                    mergeActionsToDo(dbbuilderItem, destXml, processesToCacheIntoDB, sqlMetaInstructions);
                }
            }

            // ... puis les autres
            for (DBXmlDocument currentDoc : listeDBXmlDocument) {
                DBBuilderFileItem tmpdbbuilderItem = new DBBuilderFileItem(currentDoc);
                packagesIntoFile.put(tmpdbbuilderItem.getModule(), null);
                mergeActionsToDo(tmpdbbuilderItem, destXml, processesToCacheIntoDB, sqlMetaInstructions);
            }

            // ... et enfin les pices BD  dsinstaller
            // ... attention, l'ordonnancement n'tant pas dispo, on les traite dans
            // l'ordre inverse pour faire passer busCore a la fin, de nombreuses contraintes
            // des autres modules referencant les PK de busCore
            List<String> itemsList = new ArrayList<String>();

            boolean foundDBBuilder = false;
            for (String dbPackage : packagesIntoDB) {
                if (!packagesIntoFile.containsKey(dbPackage)) {
                    // Package en base et non en contribution -> candidat  desinstallation
                    if (DBBUILDER_MODULE.equalsIgnoreCase(dbPackage)) {
                        foundDBBuilder = true;
                    } else if (ACTION_ENFORCE_UNINSTALL == params.getAction()) {
                        if (dbPackage.equals(params.getModuleName())) {
                            itemsList.add(0, dbPackage);
                        }
                    } else {
                        itemsList.add(0, dbPackage);
                    }
                }
            }

            if (foundDBBuilder) {
                if (ACTION_ENFORCE_UNINSTALL == params.getAction()) {
                    if (DBBUILDER_MODULE.equals(params.getModuleName())) {
                        itemsList.add(itemsList.size(), DBBUILDER_MODULE);
                    }
                } else {
                    itemsList.add(itemsList.size(), DBBUILDER_MODULE);
                }
            }
            for (String item : itemsList) {
                console.printMessage("**** Treating " + item + " ****");
                DBBuilderDBItem tmpdbbuilderItem = new DBBuilderDBItem(item);
                mergeActionsToDo(tmpdbbuilderItem, destXml, processesToCacheIntoDB, sqlMetaInstructions);
            }
            destXml.setName("res.txt");
            destXml.save();
            console.printMessage("Build parts are :");
            // Traitement des pices slectionnes
            // remarque : durant cette phase, les erreurs sont traites -> on les catche en
            // retour sans les retraiter
            if (ACTION_INSTALL == params.getAction()) {
                processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_INSTALL);
            } else if (ACTION_UNINSTALL == params.getAction()
                    || ACTION_ENFORCE_UNINSTALL == params.getAction()) {
                processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_UNINSTALL);
            } else if (ACTION_OPTIMIZE == params.getAction()) {
                processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_OPTIMIZE);
            } else if (ACTION_ALL == params.getAction()) {
                processDB(destXml, processesToCacheIntoDB, sqlMetaInstructions, TAGS_TO_MERGE_4_ALL);
            }
            // Modules en place sur la BD en final
            console.printMessage("Finally DB Status :");
            checkDBStatus();
        }
        Date endDate = new Date();
        console.printMessage(MessageFormat.format(messages.getString("dbbuilder.success"), endDate));
        System.out.println("*******************************************************************");
        System.out.println(MessageFormat.format(messages.getString("dbbuilder.success"), endDate));
    } catch (Exception e) {
        e.printStackTrace();
        console.printError(e.getMessage(), e);
        Date endDate = new Date();
        console.printError(MessageFormat.format(messages.getString("dbbuilder.failure"), endDate));
        System.out.println("*******************************************************************");
        System.out.println(MessageFormat.format(messages.getString("dbbuilder.failure"), endDate));
        System.exit(1);
    } finally {
        springContext.close();
        console.close();
    }
}

From source file:org.waarp.common.filemonitor.FileMonitor.java

public static void main(String[] args) {
    if (args.length < 3) {
        System.err.println("Need a statusfile, a stopfile and a directory to test");
        return;//  www  .  j  a  v  a2  s . co m
    }
    File file = new File(args[0]);
    if (file.exists() && !file.isFile()) {
        System.err.println("Not a correct status file");
        return;
    }
    File stopfile = new File(args[1]);
    if (file.exists() && !file.isFile()) {
        System.err.println("Not a correct stop file");
        return;
    }
    File dir = new File(args[2]);
    if (!dir.isDirectory()) {
        System.err.println("Not a directory");
        return;
    }
    FileMonitorCommandRunnableFuture filemonitor = new FileMonitorCommandRunnableFuture() {
        public void run(FileItem file) {
            System.out.println("File New: " + file.file.getAbsolutePath());
            finalize(true, 0);
        }
    };
    FileMonitor monitor = new FileMonitor("test", file, stopfile, dir, null, 0,
            new RegexFileFilter(RegexFileFilter.REGEX_XML_EXTENSION), false, filemonitor,
            new FileMonitorCommandRunnableFuture() {
                public void run(FileItem file) {
                    System.err.println("File Del: " + file.file.getAbsolutePath());
                }
            }, new FileMonitorCommandRunnableFuture() {
                public void run(FileItem unused) {
                    System.err.println("Check done");
                }
            });
    filemonitor.setMonitor(monitor);
    monitor.start();
    monitor.waitForStopFile();
}

From source file:de.prozesskraft.pkraft.Startinstance.java

public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException {

    /*----------------------------
      get options from ini-file/*  www . j  a  v a  2  s  .c  o m*/
    ----------------------------*/
    java.io.File inifile = new java.io.File(WhereAmI.getInstallDirectoryAbsolutePath(Startinstance.class) + "/"
            + "../etc/pkraft-startinstance.ini");

    if (inifile.exists()) {
        try {
            ini = new Ini(inifile);
        } catch (InvalidFileFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        System.err.println("ini file does not exist: " + inifile.getAbsolutePath());
        System.exit(1);
    }

    /*----------------------------
      create boolean options
    ----------------------------*/
    Option ohelp = new Option("help", "print this message");
    Option ov = new Option("v", "prints version and build-date");

    /*----------------------------
      create argument options
    ----------------------------*/
    Option obasedir = OptionBuilder.withArgName("DIR").hasArg()
            .withDescription("[optional, default .] base directory where instance shourd run.")
            //            .isRequired()
            .create("basedir");

    Option odefinition = OptionBuilder.withArgName("FILE").hasArg()
            .withDescription("[optional] definition file of the process you want to start an instance from.")
            //            .isRequired()
            .create("definition");

    Option onostart = OptionBuilder.withArgName("")
            //            .hasArg()
            .withDescription(
                    "[optional] oppresses the start of the instance. (only create the process-instance)")
            //            .isRequired()
            .create("nostart");

    Option opdomain = OptionBuilder.withArgName("STRING").hasArg()
            .withDescription("[optional] domain of the process (mandatory if you omit -definition)")
            //            .isRequired()
            .create("pdomain");

    Option opname = OptionBuilder.withArgName("STRING").hasArg().withDescription(
            "[optional] name of the process you want to start an instance from (mandatory if you omit -definition)")
            //            .isRequired()
            .create("pname");

    Option opversion = OptionBuilder.withArgName("STRING").hasArg().withDescription(
            "[optional] version of the process you want to start an instance from (mandatory if you omit -definition)")
            //            .isRequired()
            .create("pversion");

    Option ocommitfile = OptionBuilder.withArgName("KEY=FILE; FILE").hasArg()
            .withDescription("[optional] this file will be committed as file. omit KEY= if KEY==FILENAME.")
            //            .isRequired()
            .create("commitfile");

    Option ocommitvariable = OptionBuilder.withArgName("KEY=VALUE; VALUE").hasArg()
            .withDescription("[optional] this string will be committed as a variable. omit KEY= if KEY==VALUE")
            //            .isRequired()
            .create("commitvariable");

    Option ocommitfiledummy = OptionBuilder.withArgName("KEY=FILE; FILE").hasArg().withDescription(
            "[optional] use this parameter like --commitfile. the file will not be checked against the process interface and therefore allows to commit files which are not expected by the process definition. use this parameter only for test purposes e.g. to commit dummy output files for accelerated tests of complex processes or the like.")
            //            .isRequired()
            .create("commitfiledummy");

    Option ocommitvariabledummy = OptionBuilder.withArgName("KEY=VALUE; VALUE").hasArg().withDescription(
            "[optional] use this parameter like --commitvariable. the variable will not be checked against the process interface and therefore allows to commit variables which are not expected by the process definition. use this parameter only for test purposes e.g. to commit dummy output variables for accelerated tests of complex processes or the like.")
            //            .isRequired()
            .create("commitvariabledummy");

    /*----------------------------
      create options object
    ----------------------------*/
    Options options = new Options();

    options.addOption(ohelp);
    options.addOption(ov);
    options.addOption(obasedir);
    options.addOption(odefinition);
    options.addOption(onostart);
    options.addOption(opname);
    options.addOption(opversion);
    options.addOption(ocommitfile);
    options.addOption(ocommitvariable);
    options.addOption(ocommitfiledummy);
    options.addOption(ocommitvariabledummy);

    /*----------------------------
      create the parser
    ----------------------------*/
    CommandLineParser parser = new GnuParser();
    // parse the command line arguments
    commandline = parser.parse(options, args);

    /*----------------------------
      usage/help
    ----------------------------*/
    if (commandline.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("startinstance", options);
        System.exit(0);
    }

    if (commandline.hasOption("v")) {
        System.out.println("author:  alexander.vogel@caegroup.de");
        System.out.println("version: [% version %]");
        System.out.println("date:    [% date %]");
        System.exit(0);
    }
    /*----------------------------
      ueberpruefen ob eine schlechte kombination von parametern angegeben wurde
    ----------------------------*/
    if (!(commandline.hasOption("definition")) && (!(commandline.hasOption("pname"))
            || !(commandline.hasOption("pversion")) || !(commandline.hasOption("pdomain")))) {
        System.err.println("option -definition or the options -pname & -pversion & -pdomain are mandatory");
        exiter();
    }

    if ((commandline.hasOption("definition") && ((commandline.hasOption("pversion"))
            || (commandline.hasOption("pname")) || (commandline.hasOption("pdomain"))))) {
        System.err.println("you must not use option -definition with -pversion or -pname or -pdomain");
        exiter();
    }

    /*----------------------------
      die lizenz ueberpruefen und ggf abbrechen
    ----------------------------*/

    // check for valid license
    ArrayList<String> allPortAtHost = new ArrayList<String>();
    allPortAtHost.add(ini.get("license-server", "license-server-1"));
    allPortAtHost.add(ini.get("license-server", "license-server-2"));
    allPortAtHost.add(ini.get("license-server", "license-server-3"));

    MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1");

    // lizenz-logging ausgeben
    for (String actLine : (ArrayList<String>) lic.getLog()) {
        System.err.println(actLine);
    }

    // abbruch, wenn lizenz nicht valide
    if (!lic.isValid()) {
        System.exit(1);
    }

    /*----------------------------
      die eigentliche business logic
    ----------------------------*/

    Process p1 = new Process();
    String pathToDefinition = "";

    if (commandline.hasOption("definition")) {
        pathToDefinition = commandline.getOptionValue("definition");
    } else if (commandline.hasOption("pname") && commandline.hasOption("pversion")
            && commandline.hasOption("pdomain")) {
        pathToDefinition.replaceAll("/+$", "");
        pathToDefinition = ini.get("process", "domain-installation-directory") + "/"
                + commandline.getOptionValue("pdomain") + "/" + commandline.getOptionValue("pname") + "/"
                + commandline.getOptionValue("pversion") + "/process.xml";
    } else {
        System.err.println("option -definition or the options -pname & -pversion & -pdomain are mandatory");
        exiter();
    }

    // check ob das ermittelte oder uebergebene xml-file ueberhaupt existiert
    java.io.File xmlDefinition = new java.io.File(pathToDefinition);
    if (!(xmlDefinition.exists()) || !(xmlDefinition.isFile())) {
        System.err.println("process definition does not exist: " + pathToDefinition);
        exiter();
    }

    p1.setInfilexml(xmlDefinition.getCanonicalPath());
    Process p2 = null;

    try {
        p2 = p1.readXml();
    } catch (JAXBException e1) {
        System.err.println(e1.getMessage());
    }

    // das processBinary vorneweg schon mal erstellen, da es sein kann das das committen laenger dauert und ein pradar-attend den neuen prozess schon mal aufnehmen will
    // root-verzeichnis erstellen
    if (commandline.hasOption("basedir")) {
        p2.setBaseDir(commandline.getOptionValue("basedir"));
    }

    p2.makeRootdir();

    // den pfad fuers binary setzen
    p2.setOutfilebinary(p2.getRootdir() + "/process.pmb");

    System.err.println("info: writing process instance " + p2.getOutfilebinary());

    // binary schreiben
    p2.writeBinary();

    // step, an den die commits gehen, soll 'root' sein.
    Step stepRoot = p2.getRootStep();

    // committen von files (ueber einen glob)
    if (commandline.hasOption("commitfile")) {
        for (String actOptionCommitfile : commandline.getOptionValues("commitfile")) {
            String[] parts = actOptionCommitfile.split("=");
            File userFile = new File();

            if (parts.length == 1) {
                userFile.setKey(new java.io.File(parts[0]).getName());
                userFile.setGlob(parts[0]);
            } else if (parts.length == 2) {
                userFile.setKey(parts[0]);
                userFile.setGlob(parts[1]);
            } else {
                System.err.println("error in option -commitfile " + actOptionCommitfile);
                exiter();
            }

            // die auf der kommandozeile uebergebenen Informationen sollen in die vorhandenen commits im rootStep gemappt werden
            // alle vorhandenen commits in step root durchgehen und dem passenden file zuordnen
            for (Commit actCommit : stepRoot.getCommit()) {
                // alle files des aktuellen commits
                for (File actFile : actCommit.getFile()) {
                    if (actFile.getKey().equals(userFile.getKey())) {
                        // wenn actFile schon ein valider eintrag ist, dann soll ein klon befuellt werden
                        if (actFile.getGlob() != null) {
                            // wenn die maximale erlaubte anzahl noch nicht erreicht ist
                            if (actCommit.getFile(actFile.getKey()).size() < actFile.getMaxoccur()) {
                                File newFile = actFile.clone();
                                newFile.setGlob(userFile.getGlob());
                                System.err.println("entering file into commit '" + actCommit.getName() + "' ("
                                        + newFile.getKey() + "=" + newFile.getGlob() + ")");
                                actCommit.addFile(newFile);
                                break;
                            } else {
                                System.err.println("fatal: you only may commit " + actFile.getMaxoccur() + " "
                                        + actFile.getKey() + "-files into commit " + actCommit.getName());
                                exiter();
                            }
                        }
                        // ansonsten das bereits vorhandene file im commit mit den daten befuellen
                        else {
                            actFile.setGlob(userFile.getGlob());
                            actFile.setGlobdir(p2.getBaseDir());
                            System.err.println("entering file into commit '" + actCommit.getName() + "' ("
                                    + actFile.getKey() + "=" + actFile.getGlob() + ")");
                            break;
                        }
                    }
                }
            }
        }
    }

    // committen von files (ueber einen glob)
    if (commandline.hasOption("commitfiledummy")) {
        // diese files werden nicht in bestehende commits der prozessdefinition eingetragen, sondern in ein spezielles commit
        Commit commitFiledummy = new Commit();
        commitFiledummy.setName("fileDummy");
        stepRoot.addCommit(commitFiledummy);

        for (String actOptionCommitfiledummy : commandline.getOptionValues("commitfiledummy")) {
            String[] parts = actOptionCommitfiledummy.split("=");
            File userFile = new File();
            commitFiledummy.addFile(userFile);

            if (parts.length == 1) {
                userFile.setKey(new java.io.File(parts[0]).getName());
                userFile.setGlob(parts[0]);
            } else if (parts.length == 2) {
                userFile.setKey(parts[0]);
                userFile.setGlob(parts[1]);
            } else {
                System.err.println("error in option -commitfiledummy " + actOptionCommitfiledummy);
                exiter();
            }
            userFile.setGlobdir(p2.getBaseDir());
            System.err.println("entering (dummy-)file into commit '" + commitFiledummy.getName() + "' ("
                    + userFile.getKey() + "=" + userFile.getGlob() + ")");
        }
    }

    if (commandline.hasOption("commitvariable")) {
        for (String actOptionCommitvariable : commandline.getOptionValues("commitvariable")) {
            if (actOptionCommitvariable.matches(".+=.+")) {
                String[] parts = actOptionCommitvariable.split("=");
                Variable userVariable = new Variable();

                if (parts.length == 1) {
                    userVariable.setKey("default");
                    userVariable.setValue(parts[0]);
                } else if (parts.length == 2) {
                    userVariable.setKey(parts[0]);
                    userVariable.setValue(parts[1]);
                } else {
                    System.err.println("error in option -commitvariable");
                    exiter();
                }
                //                  commit.addVariable(variable);

                // die auf der kommandozeile uebergebenen Informationen sollen in die vorhandenen commits im rootStep gemappt werden
                // alle vorhandenen commits in step root durchgehen und dem passenden file zuordnen
                for (Commit actCommit : stepRoot.getCommit()) {
                    // alle files des aktuellen commits
                    for (Variable actVariable : actCommit.getVariable()) {
                        if (actVariable.getKey().equals(userVariable.getKey())) {
                            // wenn actFile schon ein valider eintrag ist, dann soll ein klon befuellt werden
                            if (actVariable.getGlob() != null) {
                                // wenn die maximale erlaubte anzahl noch nicht erreicht ist
                                if (actCommit.getVariable(actVariable.getKey()).size() < actVariable
                                        .getMaxoccur()) {
                                    Variable newVariable = actVariable.clone();
                                    newVariable.setValue(userVariable.getValue());
                                    System.err.println("entering variable into commit '" + actCommit.getName()
                                            + "' (" + newVariable.getKey() + "=" + newVariable.getValue()
                                            + ")");
                                    actCommit.addVariable(newVariable);
                                    break;
                                } else {
                                    System.err.println("fatal: you only may commit " + actVariable.getMaxoccur()
                                            + " " + actVariable.getKey() + "-variable(s) into commit "
                                            + actCommit.getName());
                                    exiter();
                                }
                            }
                            // ansonsten das bereits vorhandene file im commit mit den daten befuellen
                            else {
                                actVariable.setValue(userVariable.getValue());
                                System.err.println("entering variable into commit '" + actCommit.getName()
                                        + "' (" + actVariable.getKey() + "=" + actVariable.getValue() + ")");
                                break;
                            }
                        }
                    }
                }
            } else {
                System.err.println("-commitvariable " + actOptionCommitvariable
                        + " does not match pattern \"NAME=VALUE\".");
                exiter();
            }

        }
    }

    if (commandline.hasOption("commitvariabledummy")) {
        // diese files werden nicht in bestehende commits der prozessdefinition eingetragen, sondern in ein spezielles commit
        Commit commitVariabledummy = new Commit();
        commitVariabledummy.setName("variableDummy");
        stepRoot.addCommit(commitVariabledummy);

        for (String actOptionCommitvariabledummy : commandline.getOptionValues("commitvariabledummy")) {
            String[] parts = actOptionCommitvariabledummy.split("=");
            Variable userVariable = new Variable();
            commitVariabledummy.addVariable(userVariable);

            if (parts.length == 1) {
                userVariable.setKey(parts[0]);
                userVariable.setValue(parts[0]);
            } else if (parts.length == 2) {
                userVariable.setKey(parts[0]);
                userVariable.setValue(parts[1]);
            } else {
                System.err.println("error in option -commitvariabledummy");
                exiter();
            }

            System.err.println("entering variable into commit '" + commitVariabledummy.getName() + "' ("
                    + userVariable.getKey() + "=" + userVariable.getValue() + ")");
        }
    }

    //      if (commandline.hasOption("basedir"))
    //      {
    //         p2.setBaseDir(commandline.getOptionValue("basedir"));
    //      }

    //         commit.doIt();
    stepRoot.commit();

    // root-verzeichnis erstellen
    p2.makeRootdir();

    // den pfad fuers binary setzen
    //      p2.setOutfilebinary(p2.getRootdir() + "/process.pmb");

    System.err.println("info: writing process instance " + p2.getOutfilebinary());

    // binary schreiben
    p2.writeBinary();

    try {
        Thread.sleep(1500, 0);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //         Runtime.getRuntime().exec("process-manager -help");

    // starten nur, falls es nicht abgewaehlt wurde
    if (!commandline.hasOption("nostart")) {
        System.err.println("info: starting processmanager for instance " + p2.getOutfilebinary());
        String aufrufString = ini.get("apps", "pkraft-manager") + " -instance " + p2.getOutfilebinary();
        System.err.println("calling: " + aufrufString);

        ArrayList<String> processSyscallWithArgs = new ArrayList<String>(
                Arrays.asList(aufrufString.split(" ")));

        ProcessBuilder pb = new ProcessBuilder(processSyscallWithArgs);

        //      ProcessBuilder pb = new ProcessBuilder("processmanager -instance "+p2.getOutfilebinary());
        //      Map<String,String> env = pb.environment();
        //      String path = env.get("PATH");
        //      System.out.println("PATH: "+path);
        //      
        java.lang.Process p = pb.start();
        System.err.println("pid: " + p.hashCode());
    } else {
        System.err.println("info: NOT starting processmanager for instance " + p2.getOutfilebinary());
    }

}