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);
}
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);
}
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);
}
}
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);
}
}
}
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;
}
Aggregations