public static void main()

in mps-driver/src/main/java/org/jetbrains/mps/maven/driver/Driver.java [22:77]


    public static void main(String[] args) {
        if (args.length != 1) {
            System.err.println("Expected exactly one argument, got " + args.length);
            System.exit(1);
        }
        String inputFileName = args[0];

        GeneratorInput input;
        try (InputStream is = new FileInputStream(inputFileName);
             ObjectInputStream ois = new ObjectInputStream(is)) {
            input = (GeneratorInput) ois.readObject();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
            throw new AssertionError(e);
        }

        TemporarySolution solution = new TemporarySolution(input.moduleName, input.modelsDirectory, input.sourceRootDirectories, input.outputDirectory);
        Path solutionFile;
        try {
            solutionFile = Files.createTempFile("mpsmaven", ".msd");
            solutionFile.toFile().deleteOnExit();
            TemporarySolutionIO.writeToFile(solution, solutionFile);
        } catch (IOException | DescriptorIOException e) {
            System.err.println("Error creating temporary file");
            e.printStackTrace();
            System.exit(1);
            throw new AssertionError(e);
        }

        Script script = toScript(solutionFile, input);

        // TODO introduce proper support for mps core plugins
        GeneratorWorker worker = new GeneratorWorker(script) {
            @Override
            public void work() {

                try {
                    Class<?> modelRootFactoryClass = Class.forName("jetbrains.mps.java.core.sourceStubs.JavaSourceStubModelRootFactory");
                    PersistenceFacade.getInstance().setModelRootFactory(
                            TemporarySolutionIO.JAVA_SOURCE_STUBS_TYPE,
                            (ModelRootFactory) modelRootFactoryClass.newInstance()
                    );
                } catch (ClassNotFoundException e) {
                    System.out.println("Java source persistence class not found");
                } catch (InstantiationException | IllegalAccessException e) {
                    System.out.println("Could not instantiate java source stubs persistence support");
                }

                super.work();
            }
        };

        // workFromMain calls System.exit() with appropriate exit code.
        worker.workFromMain();
    }