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