1 package org.apache.maven.scm.provider.local.command.changelog;
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.ChangeFile;
23 import org.apache.maven.scm.ChangeSet;
24 import org.apache.maven.scm.ScmBranch;
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
28 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
29 import org.apache.maven.scm.command.changelog.ChangeLogSet;
30 import org.apache.maven.scm.provider.ScmProviderRepository;
31 import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
32 import org.codehaus.plexus.util.FileUtils;
33
34 import java.io.File;
35 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.Date;
39 import java.util.Iterator;
40 import java.util.List;
41
42
43
44
45
46 public class LocalChangeLogCommand
47 extends AbstractChangeLogCommand
48 {
49 protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
50 Date startDate, Date endDate, ScmBranch branch,
51 String datePattern )
52 throws ScmException
53 {
54 LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
55
56 if ( branch != null )
57 {
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 {
71 throw new ScmException(
72 "The working directory doesn't exist (" + baseDestination.getAbsolutePath() + ")." );
73 }
74
75 if ( !root.exists() )
76 {
77 throw new ScmException( "The base directory doesn't exist (" + root.getAbsolutePath() + ")." );
78 }
79
80 if ( !source.exists() )
81 {
82 throw new ScmException( "The module directory doesn't exist (" + source.getAbsolutePath() + ")." );
83 }
84
85 List changeLogList = new ArrayList();
86
87 try
88 {
89 File repoRoot = new File( repo.getRoot(), repo.getModule() );
90
91 List files = Arrays.asList( fileSet.getFiles() );
92
93 if ( files.isEmpty() )
94 {
95 files = FileUtils.getFiles( baseDestination, "**", null, false );
96 }
97
98 Iterator it = files.iterator();
99
100 while ( it.hasNext() )
101 {
102 File file = (File) it.next();
103
104 String path = file.getPath().replace( '\\', '/' );
105
106 File repoFile = new File( repoRoot, path );
107
108 file = new File( baseDestination, path );
109
110 ChangeSet changeSet = new ChangeSet();
111
112 int chop = repoRoot.getAbsolutePath().length();
113
114 String fileName = "/" + repoFile.getAbsolutePath().substring( chop + 1 );
115
116 changeSet.addFile( new ChangeFile( fileName, null ) );
117
118 if ( repoFile.exists() )
119 {
120 long lastModified = repoFile.lastModified();
121
122 Date modifiedDate = new Date( lastModified );
123
124 if ( startDate != null )
125 {
126 if ( startDate.before( modifiedDate ) || startDate.equals( modifiedDate ) )
127 {
128 if ( endDate != null )
129 {
130 if ( endDate.after( modifiedDate ) || endDate.equals( modifiedDate ) )
131 {
132 }
133 else
134 {
135 continue;
136 }
137 }
138 }
139 else
140 {
141 continue;
142 }
143 }
144
145 changeSet.setDate( modifiedDate );
146
147 changeLogList.add( changeSet );
148 }
149 else
150 {
151
152 changeLogList.add( changeSet );
153 }
154 }
155 }
156 catch ( IOException ex )
157 {
158 throw new ScmException( "Error while getting change logs.", ex );
159 }
160
161 return new ChangeLogScmResult( null, new ChangeLogSet( changeLogList, startDate, endDate ) );
162 }
163 }