1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.plugin;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.Parameter;
27 import org.apache.maven.scm.ScmException;
28 import org.apache.maven.scm.command.diff.DiffScmResult;
29 import org.apache.maven.scm.repository.ScmRepository;
30 import org.codehaus.plexus.util.FileUtils;
31
32
33
34
35
36
37 @Mojo(name = "diff", aggregator = true)
38 public class DiffMojo extends AbstractScmMojo {
39
40
41
42 @Parameter(property = "startScmVersionType")
43 private String startScmVersionType;
44
45
46
47
48 @Parameter(property = "startScmVersion")
49 private String startScmVersion;
50
51
52
53
54 @Parameter(property = "endScmVersionType")
55 private String endScmVersionType;
56
57
58
59
60 @Parameter(property = "endScmVersion")
61 private String endScmVersion;
62
63
64
65
66 @Parameter(property = "outputFile", defaultValue = "${project.artifactId}.diff")
67 private File outputFile;
68
69
70 public void execute() throws MojoExecutionException {
71 super.execute();
72
73 try {
74 ScmRepository repository = getScmRepository();
75
76 DiffScmResult result = getScmManager()
77 .diff(
78 repository,
79 getFileSet(),
80 getScmVersion(startScmVersionType, startScmVersion),
81 getScmVersion(endScmVersionType, endScmVersion));
82
83 checkResult(result);
84
85 getLog().info(result.getPatch());
86
87 try {
88 if (outputFile != null) {
89 FileUtils.fileWrite(outputFile.getAbsolutePath(), result.getPatch());
90 }
91 } catch (IOException e) {
92 throw new MojoExecutionException("Can't write patch file.", e);
93 }
94 } catch (IOException | ScmException e) {
95 throw new MojoExecutionException("Cannot run diff command : ", e);
96 }
97 }
98 }