public void execute()

in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/CreateNetBeansFileStructure.java [240:434]


    public void execute() throws MojoExecutionException, MojoFailureException {
        antProject = registerNbmAntTasks();
        if (descriptor != null && descriptor.exists()) {
            module = readModuleDescriptor(descriptor);
        } else {
            module = createDefaultDescriptor(project, false);
        }
        //same moduleType related code in NetBeansManifestUpdateMojo.java
        String type = moduleType;
        if ("normal".equals(type) && module.getModuleType() != null) {
            type = module.getModuleType();
            getLog().warn("moduleType in module descriptor is deprecated, use the plugin's parameter moduleType");
        }
        if (!"normal".equals(type) && !"autoload".equals(type) && !"eager".equals(type) && !"disabled".equals(
                type)) {
            getLog().error("Only 'normal,autoload,eager,disabled' are allowed values in the moduleType parameter");
        }
        boolean autoload = "autoload".equals(type);
        boolean eager = "eager".equals(type);
        boolean disabled = "disabled".equals(type);
        // 1. initialization
        String moduleName = codeNameBase;
        if (module.getCodeNameBase() != null) {
            moduleName = module.getCodeNameBase();
            getLog().warn("codeNameBase in module descriptor is deprecated, use the plugin's parameter codeNameBase");
        }
        moduleName = NetBeansManifestUpdateMojo.stripVersionFromCodebaseName(moduleName.replaceAll("-", "."));
        moduleJarName = moduleName.replace('.', '-');
        if ("extra".equals(cluster) && module.getCluster() != null) {
            getLog().warn("Parameter cluster in module descriptor is deprecated, use the plugin configuration element.");
            cluster = module.getCluster();
        }
        File jarFile = new File(buildDir, finalName + ".jar");
        clusterDir = new File(nbmBuildDir, "clusters" + File.separator + cluster);
        File moduleJarLocation = new File(clusterDir, "modules");
        moduleJarLocation.mkdirs();

        //2. create nbm resources
        File moduleFile = new File(moduleJarLocation, moduleJarName + ".jar");

        try {
            getLog().info("Copying module JAR to " + moduleJarLocation);
            FileUtils.getFileUtils().copyFile(jarFile, moduleFile, null, true, false);
        } catch (IOException x) {
            throw new MojoExecutionException("Cannot copy module JAR", x);
        }

        try (JarInputStream jis = new JarInputStream(Files.newInputStream(jarFile.toPath()))) {
            Manifest m = jis.getManifest();
            Attributes a = m.getMainAttributes();
            String classPath = (String) a.remove(new Attributes.Name("X-Class-Path"));

            if (classPath != null) {
                // update the manifest
                getLog().info("Updating manifest of copied module JAR");
                a.putValue("Class-Path", classPath);
                a.remove(new Attributes.Name("Maven-Class-Path"));

                try (FileSystem fs = FileSystems.newFileSystem(moduleFile.toPath(), (ClassLoader) null)) {
                    try (BufferedOutputStream mfWriter
                            = new BufferedOutputStream(Files.newOutputStream(fs.getPath(JarFile.MANIFEST_NAME)))) {
                        m.write(mfWriter);
                    } catch (IOException ioex) {
                        throw new MojoExecutionException("Could not overwrite manifest entry", ioex);
                    }
                } catch (IOException ex) {
                    throw new MojoExecutionException("Unable to create zip filesystem", ex);
                }
            }
        } catch (IOException x) {
            throw new MojoExecutionException("Could not read manifest of module JAR", x);
        }

        ExamineManifest modExaminator = new ExamineManifest(getLog());
        modExaminator.setJarFile(moduleFile);
        modExaminator.checkFile();
        String classpathValue = modExaminator.getClasspath();

        if (module != null) {
            // copy libraries to the designated place..
            @SuppressWarnings("unchecked")
            List<Artifact> artifacts = project.getRuntimeArtifacts();
            for (Artifact artifact : artifacts) {
                File source = artifact.getFile();

                String path = NetBeansManifestUpdateMojo.artifactToClassPathEntry(artifact, codeNameBase);

                if (classpathValue.contains(path)) {
                    File target = new File(moduleJarLocation, path);

                    File targetDir = target.getParentFile();
                    targetDir.mkdirs();

                    try {
                        FileUtils.getFileUtils().copyFile(source, target, null, true, false);
                        if (externals != null && externals.contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) {// MNBMODULE-138

                            String name = target.getName();
                            getLog().info("Using *.external replacement for " + name);
                            try (PrintWriter external = new PrintWriter(new File(targetDir, name + ".external"), "UTF-8")) {
                                writeExternal(external, artifact);
                            }
                        }
                    } catch (IOException ex) {
                        getLog().error("Cannot copy library jar");
                        throw new MojoExecutionException("Cannot copy library jar", ex);
                    }
                }
            }
            if (nbmResources != null) {
                copyNbmResources();
            }
            copyDeprecatedNbmResources();
        }

        //javahelp stuff.
        if (nbmJavahelpSource.exists()) {
            getLog().warn("src/main/javahelp/ deprecated; use @HelpSetRegistration instead");
            File javahelpTarget = new File(buildDir, "javahelp");
            String javahelpbase = moduleJarName.replace('-', File.separatorChar) + File.separator + "docs";
            String javahelpSearch = "JavaHelpSearch";
            File b = new File(javahelpTarget, javahelpbase);
            File p = new File(b, javahelpSearch);
            p.mkdirs();
            Copy cp = (Copy) antProject.createTask("copy");
            cp.setTodir(javahelpTarget);
            FileSet set = new FileSet();
            set.setDir(nbmJavahelpSource);
            cp.addFileset(set);
            cp.execute();
            getLog().info("Generating JavaHelp Index...");

            JHIndexer jhTask = (JHIndexer) antProject.createTask("jhindexer");
            jhTask.setBasedir(b);
            jhTask.setDb(p);
            jhTask.setIncludes("**/*.html");
            jhTask.setExcludes(javahelpSearch);
            Path path = new Path(antProject);
            jhTask.setClassPath(path);
            clearStaticFieldsInJavaHelpIndexer();
            try {
                jhTask.execute();
            } catch (BuildException e) {
                getLog().error("Cannot generate JavaHelp index.");
                throw new MojoExecutionException(e.getMessage(), e);
            }
            File helpJarLocation = new File(clusterDir, "modules/docs");
            helpJarLocation.mkdirs();
            Jar jar = (Jar) antProject.createTask("jar");
            jar.setDestFile(new File(helpJarLocation, moduleJarName + ".jar"));
            set = new FileSet();
            set.setDir(javahelpTarget);
            jar.addFileset(set);
            jar.execute();
        }

        File configDir = new File(clusterDir, "config" + File.separator + "Modules");
        configDir.mkdirs();
        CreateModuleXML moduleXmlTask = (CreateModuleXML) antProject.createTask("createmodulexml");
        moduleXmlTask.setXmldir(configDir);
        FileSet fs = new FileSet();
        fs.setDir(clusterDir);
        fs.setIncludes("modules" + File.separator + moduleJarName + ".jar");
        if (autoload) {
            moduleXmlTask.addAutoload(fs);
        } else if (eager) {
            moduleXmlTask.addEager(fs);
        } else if (disabled) {
            moduleXmlTask.addDisabled(fs);
        } else {
            moduleXmlTask.addEnabled(fs);
        }
        try {
            moduleXmlTask.execute();
        } catch (BuildException e) {
            getLog().error("Cannot generate config file.");
            throw new MojoExecutionException(e.getMessage(), e);
        }
        MakeListOfNBM makeTask = (MakeListOfNBM) antProject.createTask("genlist");
        antProject.setNewProperty("module.name", finalName);
        antProject.setProperty("cluster.dir", cluster);
        FileSet set = makeTask.createFileSet();
        set.setDir(clusterDir);
        PatternSet pattern = set.createPatternSet();
        pattern.setIncludes("**");
        makeTask.setModule("modules" + File.separator + moduleJarName + ".jar");
        makeTask.setOutputfiledir(clusterDir);
        try {
            makeTask.execute();
        } catch (BuildException e) {
            getLog().error("Cannot Generate nbm list");
            throw new MojoExecutionException(e.getMessage(), e);
        }

    }