Skip to content

Commit

Permalink
Use the Extensions component
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier committed Jan 7, 2019
1 parent 8cec8b5 commit a5eea94
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
23 changes: 20 additions & 3 deletions maven/src/main/java/org/jboss/shamrock/maven/AddExtensionMojo.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.jboss.shamrock.maven;

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.jboss.shamrock.maven.components.dependencies.Extensions;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import static org.jboss.shamrock.maven.components.dependencies.Extensions.addExtensions;

@Mojo(name = "add-extension", requiresProject = true)
public class AddExtensionMojo extends AbstractMojo {

Expand All @@ -27,11 +29,26 @@ public class AddExtensionMojo extends AbstractMojo {
@Parameter(property = "extensions")
private List<String> extensions;

/**
* Remote repositories used for the project.
*/
@Parameter(defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true)
private List<ArtifactRepository> repositories;

/**
* The current build session instance. This is used for
* plugin manager API calls.
*/
@Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;

@Component
private Extensions ext;

@Override
public void execute() throws MojoExecutionException {
Model model = project.getOriginalModel().clone();
if (addExtensions(model, extensions, getLog())) {
if (ext.addExtensions(model, extensions, session, repositories, getLog())) {
File pomFile = project.getFile();
save(pomFile, model);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.jboss.shamrock.maven;

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.*;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
Expand All @@ -29,6 +31,7 @@
import org.fusesource.jansi.Ansi;
import org.jboss.shamrock.maven.components.Prompter;
import org.jboss.shamrock.maven.components.SetupTemplates;
import org.jboss.shamrock.maven.components.dependencies.Extensions;
import org.jboss.shamrock.maven.utilities.MojoUtils;

import java.io.File;
Expand All @@ -38,7 +41,6 @@
import java.util.*;

import static org.fusesource.jansi.Ansi.ansi;
import static org.jboss.shamrock.maven.components.dependencies.Extensions.addExtensions;
import static org.jboss.shamrock.maven.utilities.MojoUtils.configuration;
import static org.jboss.shamrock.maven.utilities.MojoUtils.plugin;

Expand Down Expand Up @@ -92,6 +94,21 @@ public class CreateProjectMojo extends AbstractMojo {
@Component
private SetupTemplates templates;

@Component
private Extensions ext;

/**
* Remote repositories used for the project.
*/
@Parameter(defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true)
private List<ArtifactRepository> repositories;

/**
* The current build session instance. This is used for plugin manager API calls.
*/
@Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;

@Override
public void execute() throws MojoExecutionException {
File pomFile = project.getFile();
Expand All @@ -117,7 +134,7 @@ public void execute() throws MojoExecutionException {
addVersionProperty(model);
addBom(model);
addMainPluginConfig(model);
addExtensions(model, extensions, getLog());
ext.addExtensions(model, extensions, session, repositories, getLog());
addNativeProfile(model);
save(pomFile, model);
}
Expand Down Expand Up @@ -301,11 +318,12 @@ private File createPomFileFromUserInputs() throws MojoExecutionException {
project.setPomFile(pomFile);
project.setOriginalModel(model); // the current model is the original model as well

addExtensions(model, extensions, getLog());
ext.addExtensions(model, extensions, session, repositories, getLog());
save(pomFile, model);
return pomFile;
}


private void save(File pomFile, Model model) throws MojoExecutionException {
MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
try (FileWriter pomFileWriter = new FileWriter(pomFile)) {
Expand Down Expand Up @@ -341,4 +359,5 @@ private boolean isParentPom(Model model) {
return "pom".equals(model.getPackaging());
}


}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.jboss.shamrock.maven;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.jboss.shamrock.maven.components.dependencies.Extensions;

@Mojo(name = "list-extensions", requiresProject = false)
public class ListExtensionsMojo extends AbstractMojo {

@Component
Extensions extensions;

@Override
public void execute() {
getLog().info("Available extensions:");
Extensions.get().stream()
extensions.get().stream()
.sorted((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()))
.forEach(ext -> getLog().info("\t * " + ext.getName() + " (" + ext.getGroupId() + ":" + ext.getArtifactId() + ")"));

Expand Down

0 comments on commit a5eea94

Please sign in to comment.