private static CommandLine getCommandLine()

in mps-maven-plugin/src/main/java/org/jetbrains/mps/mavenplugin/Mps.java [45:84]


    private static CommandLine getCommandLine(GeneratorStartupInfo generatorStartupInfo, GeneratorInput input) throws MojoExecutionException, MojoFailureException {
        Collection<File> classPaths = new ArrayList<>();
        classPaths.add(getToolsJar());
        classPaths.addAll(calculateMpsClassPath(generatorStartupInfo.mpsHome));
        classPaths.addAll(generatorStartupInfo.driverClassPath);

        CommandLine commandLine = new CommandLine(System.getProperty("java.home") + "/bin/java");
        commandLine.addArguments(DEFAULT_JVM_ARGS);
        // TODO allow overriding JVM args

        StringBuilder sb = new StringBuilder();
        Set<String> entries = new HashSet<>();

        for (File cp : classPaths) {
            String entry = cp.getAbsolutePath();
            if (!(entries.contains(entry))) {
                entries.add(entry);
                sb.append(File.pathSeparator);
                sb.append(entry);
            }
        }
        commandLine.addArgument("-classpath");
        commandLine.addArgument(sb.toString());
        commandLine.addArgument(generatorStartupInfo.driverClassName);

        Path inputFile;
        try {
            inputFile = Files.createTempFile("mpsinput", ".bin");
            inputFile.toFile().deleteOnExit();
            try (OutputStream stream = Files.newOutputStream(inputFile);
                 ObjectOutputStream oos = new ObjectOutputStream(stream)) {
                oos.writeObject(input);
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Error writing generation script to file", e);
        }

        commandLine.addArgument(inputFile.toAbsolutePath().toString());
        return commandLine;
    }