org.jboss.maven.plugins.jdocbook.AbstractDocBookMojo Maven / Gradle / Ivy
/*
* Copyright © 2007 Red Hat Middleware, LLC. All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, v. 2.1. This program is distributed in the
* hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. You should have received a
* copy of the GNU Lesser General Public License, v.2.1 along with this
* distribution; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Red Hat Author(s): Steve Ebersole
*/
package org.jboss.maven.plugins.jdocbook;
import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.jboss.maven.plugins.jdocbook.gen.RenderingException;
import org.jboss.maven.plugins.jdocbook.gen.XSLTException;
import org.jboss.maven.plugins.jdocbook.gen.util.Formatting;
import org.jboss.maven.plugins.jdocbook.gen.util.StandardDocBookFormatSpecification;
/**
* Basic support for the various DocBook mojos in this packaging plugin.
* Mainly, we are defining common configuration attributes of the packaging.
*
* @author Steve Ebersole
*/
public abstract class AbstractDocBookMojo extends AbstractMojo {
public static final String PLUGIN_NAME = "jdocbook";
/**
* INTERNAL : The project being built
*
* @parameter expression="${project}"
* @required
* @readonly
*/
protected MavenProject project;
/**
* INTERNAL : The artifacts associated with the dependencies defined as part
* of the project to which we are being attached.
*
* @parameter expression="${project.artifacts}"
* @required
* @readonly
*/
protected Set projectArtifacts;
/**
* INTERNAL : The artifacts associated to the dependencies defined as part
* of our configuration within the project to which we are being attached.
*
* @parameter expression="${plugin.artifacts}"
* @required
* @readonly
*/
protected List pluginArtifacts;
/**
* INTERNAL : used to get reference to environemtn Archiver/UnArchiver.
*
* @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
* @required
* @readonly
*/
protected ArchiverManager archiverManager;
/**
* INTERNAL : used during packaging to attach produced artifacts
*
* @parameter expression="${component.org.apache.maven.project.MavenProjectHelper}"
* @required
* @readonly
*/
protected MavenProjectHelper projectHelper;
/**
* The name of the document (relative to sourceDirectory) which is the
* document to be rendered.
*
* @parameter
* @required
*/
protected String sourceDocumentName;
/**
* The directory where the sources are located.
*
* @parameter expression="${basedir}/src/main/docbook"
*/
protected File sourceDirectory;
/**
* A {@link Resource} describing project-local images.
*
* @parameter
*/
protected Resource imageResource;
/**
* A {@link Resource} describing project-local css.
*
* @parameter
*/
protected Resource cssResource;
// /**
// * The directory containing local fonts
// *
// * @parameter expression="${basedir}/src/main/fonts"
// */
// protected File fontsDirectory;
/**
* The directory where the output will be written.
*
* @parameter expression="${basedir}/target/docbook"
*/
protected File targetDirectory;
/**
* The directory where we can perform some staging staging occurs. Mainly
* this is used for (1) image/css staging; (2) font staging.
*
* @parameter expression="${basedir}/target/staging"
* @required
* @readonly
*/
protected File stagingDirectory;
/**
* The formats in which to perform rendering.
*
* @parameter
* @required
*/
protected Format[] formats;
/**
* The artifactId of the master translation (unless, of course, this is the
* master translation). It is assumed that the master translation:
* - is part of the same groupId
* - has its source defined as a dependency (classifier = source)
*
*
* @parameter
*/
protected String masterTranslationArtifactId;
/**
* Local path to the master translation to use for diff reporting.
*
* @parameter
*/
protected File masterTranslationFile;
/**
* The relative path font configuration to use.
*
* @parameter
*/
protected String fontConfig;
/**
* Whether or not to perform the attching of the format
* outputs as classified attachments.
*
* @parameter
*/
protected boolean attach = true;
/**
* Configurable options
*
* @parameter
*/
protected Options options;
/**
* The override method to perform the actual processing of the
* mojo.
*
* @param formattings The fomattings configured for render
* @throws RenderingException Indicates problem performing rendering
* @throws XSLTException Indicates problem building or executing XSLT transformer
*/
protected abstract void process(Formatting[] formattings) throws RenderingException, XSLTException;
public final void execute() throws MojoExecutionException, MojoFailureException {
try {
process( buildFormattings() );
}
catch ( XSLTException e ) {
throw new MojoExecutionException( "XSLT problem", e );
}
catch ( RenderingException e ) {
throw new MojoExecutionException( "Rendering problem", e );
}
}
private Formatting[] buildFormattings() {
Formatting[] formattings = new Formatting[ formats.length ];
for ( int i = 0; i < formats.length; i++ ) {
formattings[i] = new Formatting( StandardDocBookFormatSpecification.parse( formats[i].getFormatName() ), formats[i] );
}
return formattings;
}
protected static interface ArtifactProcessor {
public void process(org.apache.maven.artifact.Artifact artifact);
}
protected void processArtifacts(ArtifactProcessor processor) {
processProjectArtifacts( processor );
processPluginArtifacts( processor );
}
protected void processProjectArtifacts(ArtifactProcessor processor) {
processArtifacts( processor, projectArtifacts );
}
protected void processPluginArtifacts(ArtifactProcessor processor) {
processArtifacts( processor, pluginArtifacts );
}
private void processArtifacts(ArtifactProcessor processor, Collection artifacts) {
Iterator itr = artifacts.iterator();
while ( itr.hasNext() ) {
processor.process( ( org.apache.maven.artifact.Artifact ) itr.next() );
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy