1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.torque.mojo;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.apache.torque.mojo.morph.FileMorphRequest;
23 import org.apache.torque.mojo.morph.MorphRequest;
24 import org.apache.torque.mojo.morph.Morpher;
25 import org.apache.torque.mojo.morph.VersionTableMorpher;
26 import org.codehaus.plexus.util.FileUtils;
27
28
29
30
31
32
33
34
35 public class MorphVersionTableMojo extends AbstractMorphSingleMojo {
36
37
38
39
40
41
42
43
44 private File newVersionXMLFile;
45
46
47
48
49
50
51
52
53 private File oldVersionXMLFile;
54
55 protected void beforeExecution() {
56 setNewFile(newVersionXMLFile);
57 setOldFile(oldVersionXMLFile);
58 }
59
60 @Override
61 protected boolean isMorphNeeded() {
62
63 if (!getOldFile().exists()) {
64 getLog().debug("file:" + getOldFile().getAbsolutePath() + " does not exist");
65 return false;
66 } else {
67 return true;
68 }
69 }
70
71 @Override
72 protected void executeMojo() throws MojoExecutionException {
73 getLog().info("------------------------------------------------------------------------");
74 getLog().info("Converting version table XML file");
75 getLog().info("------------------------------------------------------------------------");
76 try {
77 FileUtils.forceMkdir(new File(FileUtils.getPath(getNewFile().getAbsolutePath())));
78 MorphRequest request = new FileMorphRequest(getOldFile(), getNewFile());
79 request.setName(getOldFile().getName());
80 request.setEncoding(getEncoding());
81 Morpher morpher = getMorpher(request, getProject().getArtifactId());
82 morpher.executeMorph();
83 } catch (IOException e) {
84 throw new MojoExecutionException("Unexpected error while attempting to morph " + getOldFile().getAbsolutePath(), e);
85 }
86 }
87
88 protected Morpher getMorpher(MorphRequest request, String artifactId) {
89 VersionTableMorpher morpher = new VersionTableMorpher(request, artifactId);
90 morpher.setProjectVersion(getProject().getVersion());
91 return morpher;
92 }
93
94
95
96
97 public File getNewVersionXMLFile() {
98 return newVersionXMLFile;
99 }
100
101
102
103
104
105 public void setNewVersionXMLFile(final File newVersionXMLFile) {
106 this.newVersionXMLFile = newVersionXMLFile;
107 }
108
109
110
111
112 public File getOldVersionXMLFile() {
113 return oldVersionXMLFile;
114 }
115
116
117
118
119
120 public void setOldVersionXMLFile(final File oldVersionXMLFile) {
121 this.oldVersionXMLFile = oldVersionXMLFile;
122 }
123 }