001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.report;
034:
035: import org.libresource.so6.core.command.Command;
036: import org.libresource.so6.core.command.Macro;
037: import org.libresource.so6.core.command.UpdateFile;
038: import org.libresource.so6.core.command.fs.AddDir;
039: import org.libresource.so6.core.command.fs.AddFile;
040: import org.libresource.so6.core.command.fs.Remove;
041: import org.libresource.so6.core.command.fs.Rename;
042: import org.libresource.so6.core.command.fs.UpdateBinaryFile;
043: import org.libresource.so6.core.engine.OpVectorFsImpl;
044:
045: import java.io.IOException;
046: import java.io.OutputStream;
047: import java.io.OutputStreamWriter;
048:
049: import java.util.ArrayList;
050: import java.util.Enumeration;
051: import java.util.Hashtable;
052: import java.util.ListIterator;
053:
054: /**
055: * @author smack
056: */
057: public class CVSReportMaker {
058: //
059: private OpVectorFsImpl opVector;
060: private Hashtable indexTable;
061: private long from;
062: private long to;
063:
064: public CVSReportMaker(String opVerctorFsImplBasePath) {
065: opVector = new OpVectorFsImpl(opVerctorFsImplBasePath);
066: opVector.load();
067: from = opVector.getFromTicket();
068: to = opVector.getToTicket();
069: indexTable = new Hashtable();
070: }
071:
072: public void buildIndexTable() throws Exception {
073: Command cmd = null;
074: ListIterator iterator = opVector.getCommands();
075:
076: while ((cmd = (Command) iterator.next()) != null) {
077: String path = cmd.getPath();
078: FileMetaData metaData = (FileMetaData) indexTable.get(path);
079:
080: if (metaData == null) {
081: metaData = new FileMetaData(path);
082: }
083:
084: metaData.applyCmd(cmd);
085: indexTable.put(path, metaData);
086: }
087: }
088:
089: public void writeReport(OutputStream out) throws IOException {
090: if (from == 0) {
091: return;
092: }
093:
094: OutputStreamWriter ostw = new OutputStreamWriter(out);
095: ostw.write("---\n");
096:
097: for (Enumeration e = indexTable.keys(); e.hasMoreElements();) {
098: String path = (String) e.nextElement();
099: FileMetaData data = (FileMetaData) indexTable.get(path);
100:
101: // print
102: ostw.write(data.toString() + "\n");
103: }
104:
105: ostw.write("---\n");
106: ostw.flush();
107: }
108:
109: public String getReport() throws IOException {
110: if (from == 0) {
111: return "";
112: }
113:
114: StringBuffer buffer = new StringBuffer();
115: buffer.append("---\n");
116:
117: for (Enumeration e = indexTable.keys(); e.hasMoreElements();) {
118: String path = (String) e.nextElement();
119: FileMetaData data = (FileMetaData) indexTable.get(path);
120:
121: // print
122: buffer.append(data.toString() + "\n");
123: }
124:
125: buffer.append("---\n");
126:
127: return buffer.toString();
128: }
129:
130: public long getFromTicket() {
131: return from;
132: }
133:
134: public long getToTicket() {
135: return to;
136: }
137:
138: public class FileMetaData {
139: private final static String CREATE = "A";
140: private final static String MOVE = "Moved";
141: private final static String DELETE = "R";
142: private final static String UPDATE = "U";
143: private final static String CONFLICT = "C";
144: private final static String CHANGE_TYPE = "Type changed";
145:
146: //
147: private boolean conflict = false;
148: private String path;
149: private ArrayList cmds;
150:
151: FileMetaData(String path) {
152: this .path = path;
153: cmds = new ArrayList();
154: }
155:
156: public void applyCmd(Command cmd) {
157: if (cmd instanceof Macro) {
158: this .applyCmd(((Macro) cmd).getCommand(1));
159: this .applyCmd(((Macro) cmd).getCommand(2));
160: } else {
161: if (cmd.isConflict()) {
162: conflict = true;
163: }
164:
165: if (cmd instanceof UpdateFile
166: || cmd instanceof UpdateBinaryFile) {
167: cmds.add(UPDATE);
168: }
169:
170: if (cmd instanceof Remove) {
171: cmds.add(DELETE);
172: }
173:
174: if (cmd instanceof AddFile) {
175: cmds.add(CREATE);
176: }
177:
178: if (cmd instanceof AddDir) {
179: cmds.add(CREATE);
180: }
181:
182: if (cmd instanceof Rename) {
183: cmds.add(MOVE);
184: }
185: }
186: }
187:
188: public ArrayList getCmdsList() {
189: return cmds;
190: }
191:
192: public String getType() {
193: if (cmds.contains(MOVE) && cmds.contains(CREATE)) {
194: return CREATE;
195: } else if (cmds.contains(DELETE) && cmds.contains(CREATE)) {
196: return CHANGE_TYPE;
197: } else if (cmds.contains(DELETE)) {
198: return DELETE;
199: } else if (cmds.contains(UPDATE)) {
200: return UPDATE;
201: } else if (cmds.contains(CREATE)) {
202: return CREATE;
203: } else if (cmds.contains(MOVE)) {
204: return MOVE;
205: }
206:
207: return "";
208: }
209:
210: public String toString() {
211: StringBuffer buffer = new StringBuffer();
212:
213: if (conflict) {
214: buffer.append(CONFLICT);
215: } else {
216: buffer.append(getType());
217: }
218:
219: buffer.append(" ");
220: buffer.append(path);
221:
222: return buffer.toString();
223: }
224: }
225: }
|