Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DiffMojo |
|
| 8.0;8 |
1 | package org.apache.maven.scm.plugin; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
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 | * Display the difference of the working copy with the latest copy in the configured scm url. | |
33 | * | |
34 | * @author <a href="evenisse@apache.org">Emmanuel Venisse</a> | |
35 | * @version $Id: DiffMojo.java 685670 2008-08-13 20:25:56Z vsiveton $ | |
36 | * @goal diff | |
37 | * @aggregator | |
38 | */ | |
39 | 0 | public class DiffMojo |
40 | extends AbstractScmMojo | |
41 | { | |
42 | /** | |
43 | * The version type (branch/tag/revision) of scmVersion. | |
44 | * | |
45 | * @parameter expression="${startScmVersionType}" | |
46 | */ | |
47 | private String startScmVersionType; | |
48 | ||
49 | /** | |
50 | * The version (revision number/branch name/tag name). | |
51 | * | |
52 | * @parameter expression="${startScmVersion}" | |
53 | */ | |
54 | private String startScmVersion; | |
55 | ||
56 | /** | |
57 | * The version type (branch/tag/revision) of scmVersion. | |
58 | * | |
59 | * @parameter expression="${endScmVersionType}" | |
60 | */ | |
61 | private String endScmVersionType; | |
62 | ||
63 | /** | |
64 | * The version (revision number/branch name/tag name). | |
65 | * | |
66 | * @parameter expression="${startScmVersion}" | |
67 | */ | |
68 | private String endScmVersion; | |
69 | ||
70 | /** | |
71 | * Output file name. | |
72 | * | |
73 | * @parameter expression="${outputFile}" | |
74 | * default-value="${project.artifactId}.diff" | |
75 | */ | |
76 | private File outputFile; | |
77 | ||
78 | /** {@inheritDoc} */ | |
79 | public void execute() | |
80 | throws MojoExecutionException | |
81 | { | |
82 | 0 | super.execute(); |
83 | ||
84 | try | |
85 | { | |
86 | 0 | ScmRepository repository = getScmRepository(); |
87 | ||
88 | 0 | DiffScmResult result = getScmManager().diff( repository, getFileSet(), |
89 | getScmVersion( startScmVersionType, startScmVersion ), | |
90 | getScmVersion( endScmVersionType, endScmVersion ) ); | |
91 | ||
92 | 0 | checkResult( result ); |
93 | ||
94 | 0 | getLog().info( result.getPatch() ); |
95 | ||
96 | try | |
97 | { | |
98 | 0 | if ( outputFile != null ) |
99 | { | |
100 | 0 | FileUtils.fileWrite( outputFile.getAbsolutePath(), result.getPatch() ); |
101 | } | |
102 | } | |
103 | 0 | catch ( IOException e ) |
104 | { | |
105 | 0 | throw new MojoExecutionException( "Can't write patch file.", e ); |
106 | 0 | } |
107 | } | |
108 | 0 | catch ( IOException e ) |
109 | { | |
110 | 0 | throw new MojoExecutionException( "Cannot run diff command : ", e ); |
111 | } | |
112 | 0 | catch ( ScmException e ) |
113 | { | |
114 | 0 | throw new MojoExecutionException( "Cannot run diff command : ", e ); |
115 | 0 | } |
116 | 0 | } |
117 | } |