public void generate()

in maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java [297:399]


    public void generate() throws MojoExecutionException {
        if (!"maven-plugin".equalsIgnoreCase(project.getArtifactId())
                && project.getArtifactId().toLowerCase().startsWith("maven-")
                && project.getArtifactId().toLowerCase().endsWith("-plugin")
                && !"org.apache.maven.plugins".equals(project.getGroupId())) {
            getLog().warn(LS + LS + "Artifact Ids of the format maven-___-plugin are reserved for" + LS
                    + "plugins in the Group Id org.apache.maven.plugins" + LS
                    + "Please change your artifactId to the format ___-maven-plugin" + LS
                    + "In the future this error will break the build." + LS + LS);
        }

        if (skipDescriptor) {
            getLog().warn("Execution skipped");
            return;
        }

        if (checkExpectedProvidedScope) {
            Set<Artifact> wrongScopedArtifacts = dependenciesNotInProvidedScope();
            if (!wrongScopedArtifacts.isEmpty()) {
                StringBuilder message = new StringBuilder(
                        LS + LS + "Some dependencies of Maven Plugins are expected to be in provided scope." + LS
                                + "Please make sure that dependencies listed below declared in POM" + LS
                                + "have set '<scope>provided</scope>' as well." + LS + LS
                                + "The following dependencies are in wrong scope:" + LS);
                for (Artifact artifact : wrongScopedArtifacts) {
                    message.append(" * ").append(artifact).append(LS);
                }
                message.append(LS).append(LS);

                getLog().warn(message.toString());
            }
        }

        mojoScanner.setActiveExtractors(extractors);

        // TODO: could use this more, eg in the writing of the plugin descriptor!
        PluginDescriptor pluginDescriptor = new PluginDescriptor();

        pluginDescriptor.setGroupId(project.getGroupId());

        pluginDescriptor.setArtifactId(project.getArtifactId());

        pluginDescriptor.setVersion(project.getVersion());

        pluginDescriptor.setGoalPrefix(goalPrefix);

        pluginDescriptor.setName(project.getName());

        pluginDescriptor.setDescription(project.getDescription());

        if (encoding == null || encoding.length() < 1) {
            getLog().warn("Using platform encoding (" + ReaderFactory.FILE_ENCODING
                    + " actually) to read mojo source files, i.e. build is platform dependent!");
        } else {
            getLog().info("Using '" + encoding + "' encoding to read mojo source files.");
        }

        if (internalJavadocBaseUrl != null && !internalJavadocBaseUrl.getPath().endsWith("/")) {
            throw new MojoExecutionException("Given parameter 'internalJavadocBaseUrl' must end with a slash but is '"
                    + internalJavadocBaseUrl + "'");
        }
        try {
            List<ComponentDependency> deps = GeneratorUtils.toComponentDependencies(project.getArtifacts());
            pluginDescriptor.setDependencies(deps);

            PluginToolsRequest request = new DefaultPluginToolsRequest(project, pluginDescriptor);
            request.setEncoding(encoding);
            request.setSkipErrorNoDescriptorsFound(skipErrorNoDescriptorsFound);
            request.setDependencies(filterMojoDependencies());
            request.setRepoSession(mavenSession.getRepositorySession());
            request.setInternalJavadocBaseUrl(internalJavadocBaseUrl);
            request.setInternalJavadocVersion(internalJavadocVersion);
            request.setExternalJavadocBaseUrls(externalJavadocBaseUrls);
            request.setSettings(mavenSession.getSettings());

            mojoScanner.populatePluginDescriptor(request);
            request.setPluginDescriptor(extendPluginDescriptor(request));

            outputDirectory.mkdirs();

            PluginDescriptorFilesGenerator pluginDescriptorGenerator = new PluginDescriptorFilesGenerator();
            pluginDescriptorGenerator.execute(outputDirectory, request);

            // Generate the additional factories for v4 mojos
            generateFactories(request.getPluginDescriptor());

            // Generate index for v4 beans
            generateIndex();

            buildContext.refresh(outputDirectory);
        } catch (GeneratorException e) {
            throw new MojoExecutionException("Error writing plugin descriptor", e);
        } catch (InvalidPluginDescriptorException | ExtractionException e) {
            throw new MojoExecutionException(
                    "Error extracting plugin descriptor: '" + e.getLocalizedMessage() + "'", e);
        } catch (LinkageError e) {
            throw new MojoExecutionException(
                    "The API of the mojo scanner is not compatible with this plugin version."
                            + " Please check the plugin dependencies configured"
                            + " in the POM and ensure the versions match.",
                    e);
        }
    }