View Javadoc

1   package org.apache.maven.plugins.scm;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.io.File;
22  
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.command.diff.DiffScmResult;
25  import org.apache.maven.scm.manager.ScmManager;
26  import org.apache.maven.scm.repository.ScmRepository;
27  import org.codehaus.plexus.util.FileUtils;
28  
29  /**
30   * A bean for using the Maven SCM API because wrangling objects in Jelly is no fun.
31   *
32   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
33   */
34  public class ScmDiffBean
35      extends ScmPatternBean
36  {
37      private String patchFile;
38  
39      private String startRevision;
40  
41      private String endRevision;
42  
43      public void diff()
44          throws Exception
45      {
46          ScmManager scmManager = lookupScmManager();
47  
48          ScmRepository repository = getScmRepository( scmManager );
49  
50          ScmFileSet fileSet = new ScmFileSet( new File( getWorkingDirectory() ), getIncludes(), getExcludes() );
51          DiffScmResult result = scmManager.getProviderByRepository( repository ).diff( repository, fileSet,
52                                                                                        startRevision, endRevision );
53          checkResult( result );
54  
55          FileUtils.fileWrite( patchFile, result.getPatch() );
56      }
57  
58      public void setPatchFile( String patchFile )
59      {
60          this.patchFile = patchFile;
61      }
62  
63      public String getPatchFile()
64      {
65          return patchFile;
66      }
67  
68      public String getStartRevision()
69      {
70          return startRevision;
71      }
72  
73      public void setStartRevision( String startRevision )
74      {
75          this.startRevision = startRevision;
76      }
77  
78      public String getEndRevision()
79      {
80          return endRevision;
81      }
82  
83      public void setEndRevision( String endRevision )
84      {
85          this.endRevision = endRevision;
86      }
87  }