1 package org.apache.maven.scm.command.update;
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.scm.ChangeSet;
23 import org.apache.maven.scm.CommandParameter;
24 import org.apache.maven.scm.CommandParameters;
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFile;
27 import org.apache.maven.scm.ScmFileSet;
28 import org.apache.maven.scm.ScmResult;
29 import org.apache.maven.scm.ScmVersion;
30 import org.apache.maven.scm.command.AbstractCommand;
31 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
32 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
33 import org.apache.maven.scm.command.changelog.ChangeLogSet;
34 import org.apache.maven.scm.provider.ScmProviderRepository;
35
36 import java.util.ArrayList;
37 import java.util.Date;
38 import java.util.List;
39
40
41
42
43
44
45 public abstract class AbstractUpdateCommand
46 extends AbstractCommand
47 {
48 protected abstract UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet fileSet,
49 ScmVersion scmVersion )
50 throws ScmException;
51
52
53 public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
54 CommandParameters parameters )
55 throws ScmException
56 {
57 ScmVersion scmVersion = parameters.getScmVersion( CommandParameter.SCM_VERSION, null );
58
59 boolean runChangelog = Boolean.valueOf(
60 parameters.getString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, "true" ) ).booleanValue();
61
62 UpdateScmResult updateScmResult = executeUpdateCommand( repository, fileSet, scmVersion );
63
64 List<ScmFile> filesList = updateScmResult.getUpdatedFiles();
65
66 if ( !runChangelog )
67 {
68 return updateScmResult;
69 }
70
71 ChangeLogCommand changeLogCmd = getChangeLogCommand();
72
73 if ( filesList != null && filesList.size() > 0 && changeLogCmd != null )
74 {
75 ChangeLogScmResult changeLogScmResult =
76 (ChangeLogScmResult) changeLogCmd.executeCommand( repository, fileSet, parameters );
77
78 List<ChangeSet> changes = new ArrayList<ChangeSet>();
79
80 ChangeLogSet changeLogSet = changeLogScmResult.getChangeLog();
81
82 if ( changeLogSet != null )
83 {
84 Date startDate = null;
85
86 try
87 {
88 startDate = parameters.getDate( CommandParameter.START_DATE );
89 }
90 catch ( ScmException e )
91 {
92
93 }
94
95 for ( ChangeSet change : changeLogSet.getChangeSets() )
96 {
97 if ( startDate != null && change.getDate() != null )
98 {
99 if ( startDate.after( change.getDate() ) )
100 {
101 continue;
102 }
103 }
104
105 for ( ScmFile currentFile : filesList )
106 {
107 if ( change.containsFilename( currentFile.getPath() ) )
108 {
109 changes.add( change );
110
111 break;
112 }
113 }
114 }
115 }
116
117 updateScmResult.setChanges( changes );
118 }
119
120 return updateScmResult;
121 }
122
123 protected abstract ChangeLogCommand getChangeLogCommand();
124 }