001: package org.andromda.maven.plugin.site;
002:
003: import java.io.File;
004: import java.io.FileWriter;
005: import java.io.IOException;
006: import java.net.URL;
007:
008: import java.util.Iterator;
009: import java.util.List;
010:
011: import javax.xml.parsers.DocumentBuilder;
012: import javax.xml.parsers.DocumentBuilderFactory;
013:
014: import org.apache.commons.lang.StringUtils;
015: import org.apache.commons.lang.exception.ExceptionUtils;
016: import org.apache.maven.artifact.Artifact;
017: import org.apache.maven.plugin.AbstractMojo;
018: import org.apache.maven.plugin.MojoExecutionException;
019: import org.apache.maven.plugin.MojoFailureException;
020: import org.apache.maven.project.MavenProject;
021:
022: import org.andromda.core.common.ResourceUtils;
023: import org.dom4j.Document;
024: import org.dom4j.DocumentException;
025: import org.dom4j.DocumentHelper;
026: import org.dom4j.Element;
027: import org.dom4j.XPath;
028: import org.dom4j.io.SAXReader;
029: import org.dom4j.io.XMLWriter;
030: import org.xml.sax.InputSource;
031:
032: /**
033: * Used to perform the transformation of the profile XSL document to profile.xml xdoc format
034: * within the site plugin.
035: *
036: * @phase pre-site
037: * @goal profile-xsl
038: * @description runs AndroMDA site profile xsl transformation
039: * @author Vance Karimi
040: */
041: public class ProfileTransformerMojo extends AbstractMojo {
042: /**
043: * The name of the project injected from pom.xml
044: *
045: * @parameter default-value="${project.name}"
046: */
047: private String projectName;
048:
049: /**
050: * Path to the project profile.xml
051: *
052: * @parameter expression="${basedir}/src/main/resources/META-INF/andromda/profile.xml"
053: */
054: private String profileDocumentPath;
055:
056: /**
057: * Path to the project profile transformation XSL
058: */
059: private static final String PROFILE_TRANSFORMATION_URI = "META-INF/xsl/profile.xsl";
060:
061: /**
062: * @parameter expression="${basedir}/src/main/resources/META-INF/xsl/profile.xsl"
063: */
064: private String profileTransformationPath;
065:
066: /**
067: * Path to the project profile document output
068: *
069: * @parameter expression="${basedir}/src/site/axdoc/profile.xml"
070: */
071: private String profileOutputPath;
072:
073: /**
074: * @parameter expression="${project}"
075: * @required
076: * @readonly
077: */
078: protected MavenProject project;
079:
080: /**
081: * XSL Transformer
082: */
083: private XslTransformer xslTransformer;
084:
085: /**
086: * @see org.apache.maven.plugin.Mojo#execute()
087: */
088: public void execute() throws MojoExecutionException,
089: MojoFailureException {
090: this
091: .getLog()
092: .info(
093: "-----------------------------------------------------------------------------");
094: this
095: .getLog()
096: .info(
097: " A n d r o M D A S i t e P r o f i l e T r a n s f o r m a t i o n ");
098: this
099: .getLog()
100: .info(
101: "-----------------------------------------------------------------------------");
102:
103: if (xslTransformer == null) {
104: xslTransformer = new XslTransformer(projectName);
105: }
106:
107: this .getLog().info(
108: "Transforming profile " + this .profileDocumentPath);
109:
110: try {
111: final File profileDocumentFile = new File(
112: this .profileDocumentPath);
113: if (profileDocumentFile.exists()
114: && profileDocumentFile.isFile()) {
115: final URL profileTransformationUrl = ResourceUtils
116: .getResource(PROFILE_TRANSFORMATION_URI);
117: xslTransformer.transform(profileDocumentPath,
118: profileTransformationUrl, profileOutputPath);
119: }
120:
121: this .getLog().info(
122: "Transformation result " + this .profileOutputPath);
123: this .getLog().info("TRANSFORMING PROFILE SUCCESSFUL");
124: } catch (final Throwable throwable) {
125: if (throwable instanceof MojoExecutionException) {
126: throw (MojoExecutionException) throwable;
127: }
128: throw new MojoExecutionException(
129: "An error occured creating profile site document '"
130: + this .project.getArtifactId() + "'",
131: ExceptionUtils.getRootCause(throwable));
132: }
133: }
134: }
|