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