001: package ru.emdev.EmForge.svn.web;
002:
003: import java.util.Collection;
004: import java.util.Date;
005: import java.util.HashMap;
006: import java.util.LinkedList;
007: import java.util.Map;
008:
009: import org.tmatesoft.svn.core.SVNException;
010: import org.tmatesoft.svn.core.SVNLogEntry;
011: import org.tmatesoft.svn.core.SVNLogEntryPath;
012: import org.tmatesoft.svn.core.SVNNodeKind;
013: import org.tmatesoft.svn.core.SVNProperty;
014:
015: import ru.emdev.EmForge.web.bean.MainMenuController.MainMenuItem;
016: import ru.emdev.EmForge.wiki.web.bean.Crumb;
017:
018: /**
019: * Change set backing bean
020: *
021: * @author Walter Mourao
022: *
023: */
024: public class SvnChangesetController extends SvnBaseController {
025:
026: public static final String PAGE_NAME = "svnchangeset.faces";
027: public static final String TITLE = "Files changes";
028:
029: @Override
030: public MainMenuItem getSelectionItemOnMainMenu() {
031: return MainMenuItem.SOURCES;
032: }
033:
034: @Override
035: public String getTitleImpl() {
036: return TITLE;
037: }
038:
039: @Override
040: public Crumb getTrailCrumbInfo() {
041: return null;
042: }
043:
044: @Override
045: protected void init() {
046: super .init();
047:
048: commitMessage = null;
049:
050: date = null;
051: age = null;
052: author = null;
053: changedFiles = null;
054: previousRevision = null;
055: nextRevision = null;
056: logEntries = null;
057:
058: loadChanges();
059: }
060:
061: //********* controller code ********//
062:
063: /**
064: * Fills the relevant properties
065: */
066: private void loadChanges() {
067:
068: final SVNLogEntry logEntry;
069:
070: if (logEntries == null) {
071: try {
072: logEntries = Helper.getLogEntries(getSvnRepository(),
073: getPath(), 0, -1, true).toArray(
074: new SVNLogEntry[0]);
075: } catch (SVNException e) {
076: this .addErrorMessage("Subversion error", e
077: .getLocalizedMessage());
078: logger.error(e.getLocalizedMessage());
079: changedFiles = new LinkedList<ChangedFile>();
080: return;
081: }
082: }
083:
084: final long baseRevision = Helper
085: .getCurrentRevision(getRevision());
086:
087: // It ia much more chanses - that we will look for latest revisions
088: // so, better to walk from the end
089: int entryIndex = logEntries.length - 1;
090: if (baseRevision > -1) {
091: for (int i = logEntries.length - 1; i >= 0; i--) {
092: if (logEntries[i].getRevision() == baseRevision) {
093: entryIndex = i;
094: break;
095: }
096: }
097: }
098:
099: if (entryIndex < logEntries.length - 1) {
100: nextRevision = logEntries[entryIndex + 1].getRevision();
101: }
102:
103: if (entryIndex > 0) {
104: previousRevision = logEntries[entryIndex - 1].getRevision();
105: }
106:
107: logEntry = logEntries[entryIndex];
108:
109: final Map<String, SVNLogEntryPath> changedPaths = logEntry
110: .getChangedPaths();
111:
112: changedFiles = new LinkedList<ChangedFile>();
113:
114: // iterate changed paths.
115: // if some path will be failed - just skip it
116: for (SVNLogEntryPath logPath : changedPaths.values()) {
117: final SVNNodeKind kind;
118: try {
119: kind = getSvnRepository().checkPath(logPath.getPath(),
120: logEntry.getRevision());
121: } catch (SVNException e) {
122: this .addErrorMessage("Subversion error", e
123: .getLocalizedMessage());
124: logger.error(e.getLocalizedMessage(), e);
125: continue;
126: }
127:
128: //avoid directory entries. is it needed ?
129: if (kind.equals(SVNNodeKind.FILE)) {
130: final Map fileProperties = new HashMap();
131: try {
132: getSvnRepository().getFile(logPath.getPath(),
133: logEntry.getRevision(), fileProperties,
134: null);
135:
136: String mimeType = (String) fileProperties
137: .get(SVNProperty.MIME_TYPE);
138:
139: /* I will skip it for now
140: final boolean fileTextType = SVNProperty.isTextMimeType( mimeType );
141:
142: final ByteArrayOutputStream baos = new ByteArrayOutputStream( );
143:
144: if (fileTextType) {
145: getSvnRepository().getFile( getPath() , logEntry.getRevision() , null , baos );
146: }
147: */
148:
149: changedFiles.add(new ChangedFile(logPath.getPath()
150: .substring(1), logPath.getType(), null,
151: false, mimeType));
152:
153: } catch (SVNException e) {
154: // [AKA] Whole log was full of the messages from here.
155: // So, I disabled messaging here
156: logger.error(e.getLocalizedMessage());
157: continue;
158: }
159: } else {
160: changedFiles.add(new ChangedFile(logPath.getPath()
161: .substring(1), logPath.getType(), null, false,
162: "directory"));
163: }
164: }
165:
166: age = Helper.formatAge(logEntry.getDate());
167: author = logEntry.getAuthor();
168: date = logEntry.getDate();
169: commitMessage = logEntry.getMessage();
170: setRevision(logEntry.getRevision());
171: }
172:
173: //********* attributes ***********//
174:
175: /**
176: * The subversion log entries
177: */
178: private SVNLogEntry[] logEntries;
179:
180: public SVNLogEntry[] getLogEntries() {
181: return logEntries;
182: }
183:
184: //the setter is needed only if using t:saveState
185: public void setLogEntries(SVNLogEntry[] logEntries) {
186: this .logEntries = logEntries;
187: }
188:
189: /**
190: * The log commit message
191: */
192: private String commitMessage;
193:
194: public String getCommitMessage() {
195: return commitMessage;
196: }
197:
198: /**
199: * The date of the change set
200: */
201: private Date date;
202:
203: public Date getDate() {
204: return date;
205: }
206:
207: /**
208: * The date of the change set in the form "xx months ago"
209: */
210: private String age;
211:
212: public String getAge() {
213: return age;
214: }
215:
216: /**
217: * The author of the revision
218: */
219: private String author;
220:
221: public String getAuthor() {
222: return author;
223: }
224:
225: /**
226: * The changed files information
227: */
228: private Collection<ChangedFile> changedFiles;
229:
230: public Collection<ChangedFile> getChangedFiles() {
231: return changedFiles;
232: }
233:
234: /**
235: * The next revision number, null if the current is the last.
236: */
237: private Long nextRevision;
238:
239: public Long getNextRevision() {
240: return nextRevision;
241: }
242:
243: /**
244: * The previous revision number, null if the current is the first.
245: */
246: private Long previousRevision;
247:
248: public Long getPreviousRevision() {
249: return previousRevision;
250: }
251:
252: /**
253: * The user properties of the current change set
254: */
255: private Collection<String[]> resourceProperties;
256:
257: public Collection<String[]> getResourceProperties() {
258: return resourceProperties;
259: }
260: }
|