1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.local.command.changelog;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.List;
26
27 import org.apache.maven.scm.ChangeFile;
28 import org.apache.maven.scm.ChangeSet;
29 import org.apache.maven.scm.ScmBranch;
30 import org.apache.maven.scm.ScmException;
31 import org.apache.maven.scm.ScmFileSet;
32 import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
33 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
34 import org.apache.maven.scm.command.changelog.ChangeLogSet;
35 import org.apache.maven.scm.provider.ScmProviderRepository;
36 import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
37 import org.codehaus.plexus.util.FileUtils;
38
39
40
41
42
43 public class LocalChangeLogCommand extends AbstractChangeLogCommand {
44
45
46
47 protected ChangeLogScmResult executeChangeLogCommand(
48 ScmProviderRepository repository,
49 ScmFileSet fileSet,
50 Date startDate,
51 Date endDate,
52 ScmBranch branch,
53 String datePattern)
54 throws ScmException {
55 LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
56
57 if (branch != null) {
58 throw new ScmException("The local scm doesn't support tags.");
59 }
60
61 File root = new File(repo.getRoot());
62
63 String module = repo.getModule();
64
65 File source = new File(root, module);
66
67 File baseDestination = fileSet.getBasedir();
68
69 if (!baseDestination.exists()) {
70 throw new ScmException("The working directory doesn't exist (" + baseDestination.getAbsolutePath() + ").");
71 }
72
73 if (!root.exists()) {
74 throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
75 }
76
77 if (!source.exists()) {
78 throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
79 }
80
81 List<ChangeSet> changeLogList = new ArrayList<>();
82
83 try {
84 File repoRoot = new File(repo.getRoot(), repo.getModule());
85
86 List<File> files = fileSet.getFileList();
87
88 if (files.isEmpty()) {
89 files = FileUtils.getFiles(baseDestination, "**", null, false);
90 }
91
92 for (File file : files) {
93
94 String path = file.getPath().replace('\\', '/');
95
96 File repoFile = new File(repoRoot, path);
97
98 file = new File(baseDestination, path);
99
100 ChangeSet changeSet = new ChangeSet();
101
102 int chop = repoRoot.getAbsolutePath().length();
103
104 String fileName = "/" + repoFile.getAbsolutePath().substring(chop + 1);
105
106 changeSet.addFile(new ChangeFile(fileName, null));
107
108 if (repoFile.exists()) {
109 long lastModified = repoFile.lastModified();
110
111 Date modifiedDate = new Date(lastModified);
112
113 if (startDate != null) {
114 if (startDate.before(modifiedDate) || startDate.equals(modifiedDate)) {
115 if (endDate != null) {
116 if (endDate.after(modifiedDate) || endDate.equals(modifiedDate)) {
117
118 } else {
119 continue;
120 }
121 }
122 } else {
123 continue;
124 }
125 }
126
127 changeSet.setDate(modifiedDate);
128
129 changeLogList.add(changeSet);
130 } else {
131
132 changeLogList.add(changeSet);
133 }
134 }
135 } catch (IOException ex) {
136 throw new ScmException("Error while getting change logs.", ex);
137 }
138
139 return new ChangeLogScmResult(null, new ChangeLogSet(changeLogList, startDate, endDate));
140 }
141 }