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