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.scm.ScmException;
24 import org.apache.maven.scm.command.diff.DiffScmResult;
25 import org.apache.maven.scm.repository.ScmRepository;
26 import org.codehaus.plexus.util.FileUtils;
27
28 import java.io.File;
29 import java.io.IOException;
30
31
32
33
34
35
36
37
38
39
40 public class DiffMojo
41 extends AbstractScmMojo
42 {
43
44
45
46
47
48 private String startScmVersionType;
49
50
51
52
53
54
55 private String startScmVersion;
56
57
58
59
60
61
62 private String endScmVersionType;
63
64
65
66
67
68
69 private String endScmVersion;
70
71
72
73
74
75
76
77 private File outputFile;
78
79 public void execute()
80 throws MojoExecutionException
81 {
82 super.execute();
83
84 try
85 {
86 ScmRepository repository = getScmRepository();
87
88 DiffScmResult result = getScmManager().diff( repository, getFileSet(),
89 getScmVersion( startScmVersionType, startScmVersion ),
90 getScmVersion( endScmVersionType, endScmVersion ) );
91
92 checkResult( result );
93
94 getLog().info( result.getPatch() );
95
96 try
97 {
98 if ( outputFile != null )
99 {
100 FileUtils.fileWrite( outputFile.getAbsolutePath(), result.getPatch() );
101 }
102 }
103 catch ( IOException e )
104 {
105 throw new MojoExecutionException( "Can't write patch file.", e );
106 }
107 }
108 catch ( IOException e )
109 {
110 throw new MojoExecutionException( "Cannot run diff command : ", e );
111 }
112 catch ( ScmException e )
113 {
114 throw new MojoExecutionException( "Cannot run diff command : ", e );
115 }
116 }
117 }