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
44 public class LocalChangeLogCommand extends AbstractChangeLogCommand {
45
46 protected ChangeLogScmResult executeChangeLogCommand(
47 ScmProviderRepository repository,
48 ScmFileSet fileSet,
49 Date startDate,
50 Date endDate,
51 ScmBranch branch,
52 String datePattern)
53 throws ScmException {
54 LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
55
56 if (branch != null) {
57 throw new ScmException("The local scm doesn't support tags.");
58 }
59
60 File root = new File(repo.getRoot());
61
62 String module = repo.getModule();
63
64 File source = new File(root, module);
65
66 File baseDestination = fileSet.getBasedir();
67
68 if (!baseDestination.exists()) {
69 throw new ScmException("The working directory doesn't exist (" + baseDestination.getAbsolutePath() + ").");
70 }
71
72 if (!root.exists()) {
73 throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
74 }
75
76 if (!source.exists()) {
77 throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
78 }
79
80 List<ChangeSet> changeLogList = new ArrayList<>();
81
82 try {
83 File repoRoot = new File(repo.getRoot(), repo.getModule());
84
85 List<File> files = fileSet.getFileList();
86
87 if (files.isEmpty()) {
88 files = FileUtils.getFiles(baseDestination, "**", null, false);
89 }
90
91 for (File file : files) {
92
93 String path = file.getPath().replace('\\', '/');
94
95 File repoFile = new File(repoRoot, path);
96
97 file = new File(baseDestination, path);
98
99 ChangeSet changeSet = new ChangeSet();
100
101 int chop = repoRoot.getAbsolutePath().length();
102
103 String fileName = "/" + repoFile.getAbsolutePath().substring(chop + 1);
104
105 changeSet.addFile(new ChangeFile(fileName, null));
106
107 if (repoFile.exists()) {
108 long lastModified = repoFile.lastModified();
109
110 Date modifiedDate = new Date(lastModified);
111
112 if (startDate != null) {
113 if (startDate.before(modifiedDate) || startDate.equals(modifiedDate)) {
114 if (endDate != null) {
115 if (endDate.after(modifiedDate) || endDate.equals(modifiedDate)) {
116
117 } else {
118 continue;
119 }
120 }
121 } else {
122 continue;
123 }
124 }
125
126 changeSet.setDate(modifiedDate);
127
128 changeLogList.add(changeSet);
129 } else {
130
131 changeLogList.add(changeSet);
132 }
133 }
134 } catch (IOException ex) {
135 throw new ScmException("Error while getting change logs.", ex);
136 }
137
138 return new ChangeLogScmResult(null, new ChangeLogSet(changeLogList, startDate, endDate));
139 }
140 }