1 package org.andromda.maven.plugin.modelarchiver;
2
3 import java.io.File;
4 import org.apache.commons.io.FileUtils;
5 import org.apache.maven.plugin.MojoExecutionException;
6
7
8
9
10
11
12
13
14
15
16 public class UmlArchiverMojo
17 extends BaseArchiveMojo
18 {
19 private static final String ARTIFACT_TYPE = "uml";
20
21
22
23
24
25
26
27 protected String replacementExtensions;
28
29
30
31
32
33
34
35
36 private String modelFilePattern;
37
38
39
40
41
42
43
44
45 public void execute()
46 throws MojoExecutionException
47 {
48 if (getLog().isDebugEnabled())
49 {
50 getLog().debug(" ======= UmlArchiverMojo settings =======");
51 getLog().debug("modelSourceDirectory[" + modelSourceDirectory + ']');
52 getLog().debug("workDirectory[" + workDirectory + ']');
53 getLog().debug("outputDirectory[" + outputDirectory + ']');
54 getLog().debug("finalName[" + finalName + ']');
55 getLog().debug("replaceExtensions[" + replaceExtensions + ']');
56 }
57
58 try
59 {
60 final File buildDirectory = this.workDirectory;
61 if (buildDirectory.exists())
62 {
63 deleteFiles(buildDirectory.getAbsolutePath(), ARTIFACT_TYPE);
64 }
65 else
66 {
67 buildDirectory.mkdirs();
68 }
69
70 if (modelSourceDirectory.exists())
71 {
72 getLog().info("Copy " + ARTIFACT_TYPE + " resources to " + buildDirectory.getAbsolutePath());
73 final File[] modelFiles = modelSourceDirectory.listFiles();
74 for (final File file : modelFiles)
75 {
76 if (file.isFile() && file.toString().matches(this.modelFilePattern))
77 {
78 final File newFile =
79 new File(buildDirectory,
80 this.finalName + '.' + ARTIFACT_TYPE);
81 FileUtils.copyFile(file, newFile);
82
83 if (replaceExtensions)
84 {
85 getLog().info("Replace extensions in " + newFile);
86 replaceExtensions(this.replacementExtensions, newFile);
87 }
88
89 setArtifactFile(newFile);
90 }
91 }
92 }
93 }
94 catch (final Throwable throwable)
95 {
96 throw new MojoExecutionException("Error assembling model", throwable);
97 }
98 }
99 }