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