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 | 0 | 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 | 0 | ScmVersion scmVersion = parameters.getScmVersion( CommandParameter.SCM_VERSION, null ); |
58 | |
|
59 | 0 | boolean runChangelog = Boolean.valueOf( |
60 | |
parameters.getString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, "true" ) ).booleanValue(); |
61 | |
|
62 | 0 | UpdateScmResult updateScmResult = executeUpdateCommand( repository, fileSet, scmVersion ); |
63 | |
|
64 | 0 | List<ScmFile> filesList = updateScmResult.getUpdatedFiles(); |
65 | |
|
66 | 0 | if ( !runChangelog ) |
67 | |
{ |
68 | 0 | return updateScmResult; |
69 | |
} |
70 | |
|
71 | 0 | ChangeLogCommand changeLogCmd = getChangeLogCommand(); |
72 | |
|
73 | 0 | if ( filesList != null && filesList.size() > 0 && changeLogCmd != null ) |
74 | |
{ |
75 | 0 | ChangeLogScmResult changeLogScmResult = |
76 | |
(ChangeLogScmResult) changeLogCmd.executeCommand( repository, fileSet, parameters ); |
77 | |
|
78 | 0 | List<ChangeSet> changes = new ArrayList<ChangeSet>(); |
79 | |
|
80 | 0 | ChangeLogSet changeLogSet = changeLogScmResult.getChangeLog(); |
81 | |
|
82 | 0 | if ( changeLogSet != null ) |
83 | |
{ |
84 | 0 | Date startDate = null; |
85 | |
|
86 | |
try |
87 | |
{ |
88 | 0 | startDate = parameters.getDate( CommandParameter.START_DATE ); |
89 | |
} |
90 | 0 | catch ( ScmException e ) |
91 | |
{ |
92 | |
|
93 | 0 | } |
94 | |
|
95 | 0 | for ( ChangeSet change : changeLogSet.getChangeSets() ) |
96 | |
{ |
97 | 0 | if ( startDate != null && change.getDate() != null ) |
98 | |
{ |
99 | 0 | if ( startDate.after( change.getDate() ) ) |
100 | |
{ |
101 | 0 | continue; |
102 | |
} |
103 | |
} |
104 | |
|
105 | 0 | for ( ScmFile currentFile : filesList ) |
106 | |
{ |
107 | 0 | if ( change.containsFilename( currentFile.getPath() ) ) |
108 | |
{ |
109 | 0 | changes.add( change ); |
110 | |
|
111 | 0 | break; |
112 | |
} |
113 | |
} |
114 | |
} |
115 | |
} |
116 | |
|
117 | 0 | updateScmResult.setChanges( changes ); |
118 | |
} |
119 | |
|
120 | 0 | return updateScmResult; |
121 | |
} |
122 | |
|
123 | |
protected abstract ChangeLogCommand getChangeLogCommand(); |
124 | |
} |