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