Search in sources :

Example 16 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor in project maven-plugins by apache.

the class DescribeMojo method execute.

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    validateParameters();
    StringBuilder descriptionBuffer = new StringBuilder();
    boolean describePlugin = true;
    if (StringUtils.isNotEmpty(cmd)) {
        describePlugin = describeCommand(descriptionBuffer);
    }
    if (describePlugin) {
        PluginInfo pi = parsePluginLookupInfo();
        PluginDescriptor descriptor = lookupPluginDescriptor(pi);
        if (StringUtils.isNotEmpty(goal)) {
            MojoDescriptor mojo = descriptor.getMojo(goal);
            if (mojo == null) {
                throw new MojoFailureException("The mojo '" + goal + "' does not exist in the plugin '" + pi.getPrefix() + "'");
            }
            describeMojo(mojo, descriptionBuffer);
        } else {
            describePlugin(descriptor, descriptionBuffer);
        }
    }
    writeDescription(descriptionBuffer);
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 17 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor in project maven-plugins by apache.

the class CheckPluginDocumentationMojo method checkPackagingSpecificDocumentation.

protected void checkPackagingSpecificDocumentation(MavenProject project, DocumentationReporter reporter) {
    PluginDescriptor descriptor = new PluginDescriptor();
    try {
        mojoScanner.populatePluginDescriptor(project, descriptor);
    } catch (InvalidPluginDescriptorException e) {
        reporter.error("Failed to parse mojo descriptors.\nError: " + e.getMessage());
        descriptor = null;
    } catch (ExtractionException e) {
        reporter.error("Failed to parse mojo descriptors.\nError: " + e.getMessage());
        descriptor = null;
    }
    if (descriptor != null) {
        @SuppressWarnings("unchecked") List<MojoDescriptor> mojos = descriptor.getMojos();
        // ensure that all mojo classes are documented
        if (mojos != null && !mojos.isEmpty()) {
            for (MojoDescriptor mojo : mojos) {
                String mojoDescription = mojo.getDescription();
                if (mojoDescription == null || mojoDescription.trim().length() < MIN_DESCRIPTION_LENGTH) {
                    reporter.error("Mojo: \'" + mojo.getGoal() + "\' is missing a description.");
                }
                @SuppressWarnings("unchecked") List<Parameter> params = mojo.getParameters();
                // ensure that all parameters are documented
                if (params != null && !params.isEmpty()) {
                    for (Parameter param : params) {
                        if (param.getRequirement() == null && param.isEditable()) {
                            String paramDescription = param.getDescription();
                            if (paramDescription == null || paramDescription.trim().length() < MIN_DESCRIPTION_LENGTH) {
                                reporter.error("Parameter: \'" + param.getName() + "\' in mojo: \'" + mojo.getGoal() + "\' is missing a description.");
                            }
                        }
                    }
                }
            }
        }
    }
    checkConfiguredReportPlugins(project, reporter);
    checkProjectSite(project, reporter);
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ExtractionException(org.apache.maven.tools.plugin.extractor.ExtractionException) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) InvalidPluginDescriptorException(org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException) Parameter(org.apache.maven.plugin.descriptor.Parameter)

Example 18 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor in project liquibase by liquibase.

the class AbstractLiquibaseMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (StringUtil.trimToNull(logging) != null) {
        getLog().error("The liquibase-maven-plugin now manages logging via the standard maven logging config, not the 'logging' configuration. Use the -e, -X or -q flags or see https://maven.apache.org/maven-logging.html");
    }
    try {
        Scope.child(Scope.Attr.logService, new MavenLogService(getLog()), () -> {
            getLog().info(MavenUtils.LOG_SEPARATOR);
            if (server != null) {
                AuthenticationInfo info = wagonManager.getAuthenticationInfo(server);
                if (info != null) {
                    username = info.getUserName();
                    password = info.getPassword();
                }
            }
            processSystemProperties();
            if (!LiquibaseCommandLineConfiguration.SHOULD_RUN.getCurrentValue()) {
                getLog().info("Liquibase did not run because " + LiquibaseCommandLineConfiguration.SHOULD_RUN.getKey() + " was set to false");
                return;
            }
            if (skip) {
                getLog().warn("Liquibase skipped due to Maven configuration");
                return;
            }
            ClassLoader mavenClassLoader = getClassLoaderIncludingProjectClasspath();
            Map<String, Object> scopeValues = new HashMap<>();
            scopeValues.put(Scope.Attr.resourceAccessor.name(), getResourceAccessor(mavenClassLoader));
            scopeValues.put(Scope.Attr.classLoader.name(), getClassLoaderIncludingProjectClasspath());
            IntegrationDetails integrationDetails = new IntegrationDetails();
            integrationDetails.setName("maven");
            final PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
            for (MojoDescriptor descriptor : pluginDescriptor.getMojos()) {
                if (!descriptor.getImplementationClass().equals(this.getClass())) {
                    continue;
                }
                for (Parameter param : descriptor.getParameters()) {
                    final String name = param.getName();
                    if (name.equalsIgnoreCase("project") || name.equalsIgnoreCase("systemProperties")) {
                        continue;
                    }
                    final Field field = getField(this.getClass(), name);
                    if (field == null) {
                        getLog().debug("Cannot read current maven value for. Will not send the value to hub " + name);
                    } else {
                        field.setAccessible(true);
                        final Object value = field.get(this);
                        if (value != null) {
                            try {
                                integrationDetails.setParameter("maven__" + param.getName().replaceAll("[${}]", ""), String.valueOf(value));
                            } catch (Throwable e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
            scopeValues.put("integrationDetails", integrationDetails);
            final Map pluginContext = this.getPluginContext();
            System.out.println(pluginContext.keySet());
            Scope.child(scopeValues, () -> {
                configureFieldsAndValues();
                // 
                // Check for a LiquibasePro license
                // 
                hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
                getLog().info(CommandLineUtils.getBanner());
                // Displays the settings for the Mojo depending of verbosity mode.
                displayMojoSettings();
                // Check that all the parameters that must be specified have been by the user.
                checkRequiredParametersAreSpecified();
                Database database = null;
                try {
                    String dbPassword = (emptyPassword || (password == null)) ? "" : password;
                    String driverPropsFile = (driverPropertiesFile == null) ? null : driverPropertiesFile.getAbsolutePath();
                    database = CommandLineUtils.createDatabaseObject(mavenClassLoader, url, username, dbPassword, driver, defaultCatalogName, defaultSchemaName, outputDefaultCatalog, outputDefaultSchema, databaseClass, driverPropsFile, propertyProviderClass, changelogCatalogName, changelogSchemaName, databaseChangeLogTableName, databaseChangeLogLockTableName);
                    liquibase = createLiquibase(database);
                    configureChangeLogProperties();
                    getLog().debug("expressionVars = " + String.valueOf(expressionVars));
                    if (expressionVars != null) {
                        for (Map.Entry<Object, Object> var : expressionVars.entrySet()) {
                            this.liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());
                        }
                    }
                    getLog().debug("expressionVariables = " + String.valueOf(expressionVariables));
                    if (expressionVariables != null) {
                        for (Map.Entry var : (Set<Map.Entry>) expressionVariables.entrySet()) {
                            if (var.getValue() != null) {
                                this.liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());
                            }
                        }
                    }
                    if (clearCheckSums) {
                        getLog().info("Clearing the Liquibase checksums on the database");
                        liquibase.clearCheckSums();
                    }
                    getLog().info("Executing on Database: " + url);
                    if (isPromptOnNonLocalDatabase()) {
                        getLog().info("NOTE: The promptOnLocalDatabase functionality has been removed");
                    }
                    setupBindInfoPackage();
                    performLiquibaseTask(liquibase);
                } catch (LiquibaseException e) {
                    cleanup(database);
                    throw new MojoExecutionException("\nError setting up or running Liquibase:\n" + e.getMessage(), e);
                }
                cleanup(database);
                getLog().info(MavenUtils.LOG_SEPARATOR);
                getLog().info("");
            });
        });
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IntegrationDetails(liquibase.integration.IntegrationDetails) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) MalformedURLException(java.net.MalformedURLException) DatabaseException(liquibase.exception.DatabaseException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LiquibaseException(liquibase.exception.LiquibaseException) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) Field(java.lang.reflect.Field) Database(liquibase.database.Database) URLClassLoader(java.net.URLClassLoader) Parameter(org.apache.maven.plugin.descriptor.Parameter) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 19 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor in project intellij-plugins by JetBrains.

the class RepositoryReplicatorMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final String localRepositoryBasedir = session.getLocalRepository().getBasedir();
    File localRepositoryFile = new File(localRepositoryBasedir);
    localRepositoryBasedirLength = localRepositoryBasedir.length();
    try {
        final PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(session.getTopLevelProject().getPlugin("org.sonatype.flexmojos:flexmojos-maven-plugin"), session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession());
        final File compilerLibsDirectory = new File(outputDirectory, "../build-gant/compiler-libs");
        //noinspection ResultOfMethodCallIgnored
        compilerLibsDirectory.mkdirs();
        for (ComponentDependency dependency : pluginDescriptor.getDependencies()) {
            if (dependency.getGroupId().equals("com.adobe.flex.compiler") && dependency.getType().equals("jar")) {
                final String artifactId = dependency.getArtifactId();
                if (artifactId.equals("adt") || artifactId.equals("asdoc") || artifactId.equals("digest") || artifactId.equals("fcsh") || artifactId.equals("fdb") || artifactId.equals("optimizer") || artifactId.equals("swcdepends")) {
                    continue;
                }
                copyIfLastModifiedNotEquals(new File(localRepositoryFile, "com/adobe/flex/compiler/" + artifactId + "/" + dependency.getVersion() + "/" + artifactId + "-" + dependency.getVersion() + ".jar"), new File(compilerLibsDirectory, artifactId + ".jar"));
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Cannot find flemxojos maven plugin", e);
    }
    if (outputDirectory.exists()) {
        try {
            FileUtils.deleteDirectory(outputDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException("", e);
        }
    }
    //noinspection ResultOfMethodCallIgnored
    outputDirectory.mkdirs();
    for (MavenProject project : session.getProjects()) {
        // skip projects artifacts
        copiedArtifacts.add(project.getArtifact());
        try {
            copyProjectArtifacts(localRepositoryFile, project);
        } catch (IOException e) {
            throw new MojoExecutionException("", e);
        }
        for (Plugin plugin : project.getBuildPlugins()) {
            if (plugin.getGroupId().startsWith("org.apache.maven")) {
                continue;
            }
            try {
                resolveAndCopyArtifact(repositorySystem.createPluginArtifact(plugin));
            } catch (IOException e) {
                throw new MojoExecutionException("", e);
            }
        }
    }
    for (MavenProject project : session.getProjects()) {
        try {
            copyParentPom(project.getParent());
        } catch (IOException e) {
            throw new MojoExecutionException("", e);
        }
    }
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProject(org.apache.maven.project.MavenProject) IOException(java.io.IOException) File(java.io.File) ComponentDependency(org.codehaus.plexus.component.repository.ComponentDependency) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Plugin(org.apache.maven.model.Plugin)

Example 20 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor in project maven-plugins by apache.

the class JavadocReportTest method lookupMojo.

private JavadocReport lookupMojo(File testPom) throws Exception {
    JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom);
    PluginDescriptor pluginDescriptor = new PluginDescriptor();
    pluginDescriptor.setPlugin(new Plugin());
    setVariableValueToObject(mojo, "plugin", pluginDescriptor);
    return mojo;
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) Plugin(org.apache.maven.model.Plugin)

Aggregations

PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)25 Plugin (org.apache.maven.model.Plugin)12 File (java.io.File)7 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 MavenProject (org.apache.maven.project.MavenProject)5 IOException (java.io.IOException)3 URLClassLoader (java.net.URLClassLoader)3 Artifact (org.apache.maven.artifact.Artifact)3 MavenSession (org.apache.maven.execution.MavenSession)3 MojoDescriptorCreator (org.apache.maven.lifecycle.internal.MojoDescriptorCreator)3 PluginVersionRequest (org.apache.maven.plugin.version.PluginVersionRequest)3 PluginVersionResolver (org.apache.maven.plugin.version.PluginVersionResolver)3 PluginInfo (org.apache.maven.plugins.help.DescribeMojo.PluginInfo)3 MavenPluginManagerHelper (org.apache.maven.reporting.exec.MavenPluginManagerHelper)3 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2