public void execute()

in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/CreateClusterMojo.java [78:173]


    public void execute() throws MojoExecutionException, MojoFailureException {
        Project antProject = registerNbmAntTasks();

        if (!clusterBuildDir.exists()) {
            clusterBuildDir.mkdirs();
        }

        List<MavenProject> reactorProjects = mavenSession.getProjects();
        if (reactorProjects != null && !reactorProjects.isEmpty()) {
            for (MavenProject proj : reactorProjects) {

                File nbmDir = new File(nbmBuildDir, "clusters");
                if (nbmDir.exists()) {
                    Copy copyTask = (Copy) antProject.createTask("copy");
                    copyTask.setTodir(clusterBuildDir);
                    copyTask.setOverwrite(true);
                    FileSet set = new FileSet();
                    set.setDir(nbmDir);
                    set.createInclude().setName("**");
                    copyTask.addFileset(set);

                    try {
                        copyTask.execute();
                    } catch (BuildException ex) {
                        getLog().error("Cannot merge modules into cluster");
                        throw new MojoExecutionException("Cannot merge modules into cluster", ex);
                    }
                } else {
                    if ("nbm".equals(proj.getPackaging())) {
                        String error
                                = "The NetBeans binary directory structure for "
                                + proj.getId()
                                + " is not created yet."
                                + "\n Please execute 'mvn install nbm:cluster' "
                                + "to build all relevant projects in the reactor.";
                        throw new MojoFailureException(error);
                    }
                    if ("bundle".equals(proj.getPackaging())) {
                        Artifact art = proj.getArtifact();
                        final ExamineManifest mnf = new ExamineManifest(getLog());

                        File jar = new File(proj.getBuild().getDirectory(), proj.getBuild().getFinalName() + ".jar");
                        if (!jar.exists()) {
                            getLog().error("Skipping " + proj.getId() + ". Cannot find the main artifact in output directory.");
                            continue;
                        }
                        mnf.setJarFile(jar);
                        mnf.checkFile();

                        File clusterDir = new File(clusterBuildDir, cluster);
                        getLog().debug("Copying " + art.getId() + " to cluster " + cluster);
                        File modules = new File(clusterDir, "modules");
                        modules.mkdirs();
                        File config = new File(clusterDir, "config");
                        File confModules = new File(config, "Modules");
                        confModules.mkdirs();
                        File updateTracting = new File(clusterDir, "update_tracking");
                        updateTracting.mkdirs();

                        final String cnb = mnf.getModule();
                        final String cnbDashed = cnb.replace(".", "-");
                        //do we need the file in some canotical name pattern for moduleArt?
                        final File moduleArt = new File(modules, cnbDashed + ".jar");
                        final String specVer = mnf.getSpecVersion();
                        try {
                            FileUtils.copyFile(jar, moduleArt);
                            final File moduleConf = new File(confModules, cnbDashed + ".xml");
                            FileUtils.copyStreamToFile(() -> new StringInputStream(CreateClusterAppMojo.createBundleConfigFile(cnb, mnf.isBundleAutoload()), "UTF-8"), moduleConf);
                            FileUtils.copyStreamToFile(() -> new StringInputStream(CreateClusterAppMojo.createBundleUpdateTracking(cnb, moduleArt, moduleConf, specVer), "UTF-8"), new File(updateTracting, cnbDashed + ".xml"));
                        } catch (IOException exc) {
                            getLog().error(exc);
                        }

                    }
                }
            }
            //in 6.1 the rebuilt modules will be cached if the timestamp is not touched.
            File[] files = clusterBuildDir.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    File stamp = new File(files[i], ".lastModified");
                    if (!stamp.exists()) {
                        try {
                            stamp.createNewFile();
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    }
                    stamp.setLastModified(getOutputTimestampOrNow(mavenSession.getCurrentProject()).getTime());
                }
            }
            getLog().info("Created NetBeans module cluster(s) at " + clusterBuildDir);
        } else {
            throw new MojoExecutionException("This goal only makes sense on reactor projects.");
        }
    }