1 package org.andromda.maven.plugin.site;
2
3 import java.io.File;
4 import java.net.URL;
5 import org.andromda.core.common.ResourceUtils;
6 import org.apache.commons.lang.exception.ExceptionUtils;
7 import org.apache.maven.plugin.AbstractMojo;
8 import org.apache.maven.plugin.MojoExecutionException;
9 import org.apache.maven.plugin.MojoFailureException;
10 import org.apache.maven.project.MavenProject;
11
12
13
14
15
16
17
18
19
20
21 public class ProfileTransformerMojo
22 extends AbstractMojo
23 {
24
25
26
27
28
29 private String projectName;
30
31
32
33
34
35
36 private File profileDocumentPath;
37
38
39
40
41 private static final String PROFILE_TRANSFORMATION_URI = "META-INF/xsl/profile.xsl";
42
43
44
45
46 @SuppressWarnings("unused")
47 private File profileTransformationPath;
48
49
50
51
52
53
54 private File profileOutputPath;
55
56
57
58
59
60
61 protected MavenProject project;
62
63
64
65
66 private XslTransformer xslTransformer;
67
68
69
70
71
72 public void execute()
73 throws MojoExecutionException, MojoFailureException
74 {
75 this.getLog().info("-----------------------------------------------------------------------------");
76 this.getLog().info(" 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 ");
77 this.getLog().info("-----------------------------------------------------------------------------");
78
79 if (xslTransformer == null)
80 {
81 xslTransformer = new XslTransformer(projectName);
82 }
83
84 this.getLog().info("Transforming profile " + this.profileDocumentPath);
85
86 try
87 {
88 if (this.profileDocumentPath.exists() && this.profileDocumentPath.isFile())
89 {
90 final URL profileTransformationUrl = ResourceUtils.getResource(PROFILE_TRANSFORMATION_URI);
91 xslTransformer.transform(profileDocumentPath.getAbsolutePath(), profileTransformationUrl, profileOutputPath.getAbsolutePath());
92 }
93
94 this.getLog().info("Transformation result " + this.profileOutputPath);
95 this.getLog().info("TRANSFORMING PROFILE SUCCESSFUL");
96 }
97 catch (final Throwable throwable)
98 {
99 if (throwable instanceof MojoExecutionException)
100 {
101 throw (MojoExecutionException)throwable;
102 }
103 throw new MojoExecutionException("An error occurred creating profile site document '" +
104 this.project.getArtifactId() + '\'',
105 ExceptionUtils.getRootCause(throwable));
106 }
107 }
108 }