public void execute()

in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/CreateUpdateSiteMojo.java [155:298]


    public void execute() throws MojoExecutionException, MojoFailureException {
        Project antProject = registerNbmAntTasks();
        File nbmBuildDirFile = new File(outputDirectory, "netbeans_site");
        if (!nbmBuildDirFile.exists()) {
            nbmBuildDirFile.mkdirs();
        }

        boolean isRepository = false;
        if ("auto".equals(distBase)) {
            distBase = null;
        }
        ArtifactRepository distRepository = getDeploymentRepository(distBase, layouts);
        String oldDistBase = null;
        if (distRepository != null) {
            isRepository = true;
        } else {
            if (distBase != null && !distBase.contains("::")) {
                oldDistBase = distBase;
            }
        }

        if ("nbm-application".equals(project.getPackaging())) {
            @SuppressWarnings("unchecked")
            Set<Artifact> artifacts = project.getArtifacts();
            for (Artifact art : artifacts) {
                if (!matchesIncludes(art)) {
                    continue;
                }
                ArtifactResult res
                        = turnJarToNbmFile(art, artifactFactory, artifactResolver, project, session.getLocalRepository());
                if (res.hasConvertedArtifact()) {
                    art = res.getConvertedArtifact();
                }

                if (art.getType().equals("nbm-file")) {
                    Copy copyTask = (Copy) antProject.createTask("copy");
                    copyTask.setOverwrite(true);
                    copyTask.setFile(art.getFile());
                    if (!isRepository) {
                        copyTask.setFlatten(true);
                        copyTask.setTodir(nbmBuildDirFile);
                    } else {
                        String path = distRepository.pathOf(art);
                        File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar));
                        copyTask.setTofile(f);
                    }
                    try {
                        copyTask.execute();
                    } catch (BuildException ex) {
                        throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex);
                    }

                }
                if (res.isOSGiBundle()) {
                    // TODO check for bundles
                }
            }
            getLog().info("Created NetBeans module cluster(s) at " + nbmBuildDirFile.getAbsoluteFile());

        } else if (reactorProjects != null && reactorProjects.size() > 0) {

            Iterator it = reactorProjects.iterator();
            while (it.hasNext()) {
                MavenProject proj = (MavenProject) it.next();
                File projOutputDirectory = new File(proj.getBuild().getDirectory());
                if (projOutputDirectory != null && projOutputDirectory.exists()) {
                    Copy copyTask = (Copy) antProject.createTask("copy");
                    if (!isRepository) {
                        FileSet fs = new FileSet();
                        fs.setDir(projOutputDirectory);
                        fs.createInclude().setName("*.nbm");
                        copyTask.addFileset(fs);
                        copyTask.setOverwrite(true);
                        copyTask.setFlatten(true);
                        copyTask.setTodir(nbmBuildDirFile);
                    } else {
                        boolean has = false;
                        File[] fls = projOutputDirectory.listFiles();
                        if (fls != null) {
                            for (File fl : fls) {
                                if (fl.getName().endsWith(".nbm")) {
                                    copyTask.setFile(fl);
                                    has = true;
                                    break;
                                }
                            }
                        }
                        if (!has) {
                            continue;
                        }
                        Artifact art
                                = artifactFactory.createArtifact(proj.getGroupId(), proj.getArtifactId(), proj.
                                        getVersion(),
                                        null, "nbm-file");
                        String path = distRepository.pathOf(art);
                        File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar));
                        copyTask.setTofile(f);
                    }
                    try {
                        copyTask.execute();
                    } catch (BuildException ex) {
                        throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex);
                    }
                }
            }
        } else {
            throw new MojoExecutionException(
                    "This goal only makes sense on reactor projects or project with 'nbm-application' packaging.");

        }
        MakeUpdateDesc descTask = (MakeUpdateDesc) antProject.createTask("updatedist");
        File xmlFile = new File(nbmBuildDirFile, fileName);
        descTask.setDesc(xmlFile);
        if (oldDistBase != null) {
            descTask.setDistBase(oldDistBase);
        }
        if (distRepository != null) {
            descTask.setDistBase(distRepository.getUrl());
        }
        FileSet fs = new FileSet();
        fs.setDir(nbmBuildDirFile);
        fs.createInclude().setName("**/*.nbm");
        descTask.addFileset(fs);
        try {
            descTask.execute();
        } catch (BuildException ex) {
            throw new MojoExecutionException("Cannot create autoupdate site xml file", ex);
        }
        getLog().info("Generated autoupdate site content at " + nbmBuildDirFile.getAbsolutePath());

        try {
            GZipArchiver gz = new GZipArchiver();
            gz.addFile(xmlFile, fileName);
            File gzipped = new File(nbmBuildDirFile, fileName + ".gz");
            gz.setDestFile(gzipped);
            gz.createArchive();
            if ("nbm-application".equals(project.getPackaging())) {
                projectHelper.attachArtifact(project, "xml.gz", "updatesite", gzipped);
            }
        } catch (Exception ex) {
            throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex);
        }

    }