com.github.praxissoftware.maven.plugins.GenerateFeaturesMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of features-maven-plugin Show documentation
Show all versions of features-maven-plugin Show documentation
This mojo allows for manipulation of OSGi features.xml files.
package com.github.praxissoftware.maven.plugins;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.common.io.CharStreams;
import com.google.common.io.Closeables;
import com.google.common.io.InputSupplier;
import com.sampullara.mustache.Mustache;
import com.sampullara.mustache.MustacheBuilder;
/**
* Generates a single feature with all relevant dependencies inside of it.
* @goal generate-features-xml
*/
public class GenerateFeaturesMojo extends AbstractMojo {
/**
* The Maven project to analyze.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* The file to output the features.xml to.
*
* @parameter expression="${project.build.outputDirectory}/feature.xml"
*/
private File outputFile;
@SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException {
Writer out = null;
try {
// Get the template text from the jar's resources.
final InputSupplier supplier = CharStreams.newReaderSupplier(new InputSupplier() {
@Override
public InputStream getInput() throws IOException {
return getClass().getClassLoader().getResourceAsStream("features.mustache.xml");
}
}, Charsets.UTF_8);
final String template = CharStreams.toString(supplier);
// Create the mustache factory from the loaded template.
final Mustache mustache = new MustacheBuilder().parse(template, "features.mustache.xml");
// Establish output stream.
final File featureFile = setUpFile(outputFile);
out = new FileWriter(featureFile);
// Build context.
final Map context = convert(project.getArtifact());
final List