protected final void doRun()

in cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java [42:114]


    protected final void doRun(MavenProject project, boolean apply) throws MojoExecutionException, MojoFailureException {
        try {
            String sourceLevel = "1.5";
            Xpp3Dom sourceLevelConfiguration = Utils.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin");

            if (sourceLevelConfiguration != null) {
                Xpp3Dom source = sourceLevelConfiguration.getChild("source");

                if (source != null) {
                    sourceLevel = source.getValue();
                }
            }

            String configurationFile = Utils.getJackpotConfigurationFile(project);
            boolean failOnWarnings = Utils.getJackpotFailOnWarnings(project);

            List<String> cmdLine = new ArrayList<String>();

            if (apply)
                cmdLine.add("--apply");
            else
                cmdLine.add("--no-apply");

            cmdLine.addAll(sourceAndCompileClassPaths(Collections.singletonList(project)));
            cmdLine.add("--source");
            cmdLine.add(sourceLevel);

            if (configurationFile != null) {
                cmdLine.add("--config-file");
                cmdLine.add(configurationFile);
            }

            if (failOnWarnings) {
                cmdLine.add("--fail-on-warnings");
            }

            boolean hasSourceRoots = false;

            for (String sr : (List<String>) project.getCompileSourceRoots()) {
                if (!hasSourceRoots && new File(sr).isDirectory()) {
                    hasSourceRoots = true;
                }
                cmdLine.add(sr);
            }

            if (!hasSourceRoots) {
                getLog().debug("jackpot30 analyze: Not source roots to operate on");
                return ;
            }

            Path bin = Paths.get(System.getProperty("java.home"))
                            .resolve("bin");
            Path launcher = bin.resolve("java");
            if (!Files.exists(launcher)) {
                launcher = bin.resolve("java.exe");
            }
            cmdLine.addAll(0, Arrays.asList(launcher.toAbsolutePath().toString(),
                                            "-classpath", Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(),
                                            "-XX:+IgnoreUnrecognizedVMOptions",
                                            "--add-opens=java.base/java.net=ALL-UNNAMED",
                                            "--add-opens=java.desktop/sun.awt=ALL-UNNAMED",
                                            Main.class.getCanonicalName()));
            if (new ProcessBuilder(cmdLine).inheritIO().start().waitFor() != 0) {
                throw new MojoExecutionException("jackpo30 failed.");
            }
        } catch (IOException ex) {
            throw new MojoExecutionException(ex.getMessage(), ex);
        } catch (InterruptedException ex) {
            throw new MojoExecutionException(ex.getMessage(), ex);
        } catch (DependencyResolutionRequiredException ex) {
            throw new MojoExecutionException(ex.getMessage(), ex);
        }
    }