1 11 package org.eclipse.team.internal.ccvs.core.client.listeners; 12 13 import java.io.*; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; 21 22 public class AnnotateListener extends CommandOutputListener { 23 24 27 ByteArrayOutputStream aStream = new ByteArrayOutputStream(); 28 List blocks = new ArrayList (); 29 int lineNumber; 30 31 public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { 32 String error = null; 33 CVSAnnotateBlock aBlock = new CVSAnnotateBlock(line, lineNumber++); 34 if (!aBlock.isValid()) { 35 error = line; 36 } 37 38 41 try { 42 aStream.write(line.substring(aBlock.getSourceOffset()).getBytes()); 43 if (!(line.endsWith("\r") || line.endsWith("\r\n"))) { aStream.write(System.getProperty("line.separator").getBytes()); } 46 } catch (IOException e) { 47 } 48 add(aBlock); 49 if (error != null) 50 return new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE_PARSE_FAILURE, error, commandRoot); 51 return OK; 52 } 53 54 public InputStream getContents() { 55 return new ByteArrayInputStream(aStream.toByteArray()); 56 } 57 58 public List getCvsAnnotateBlocks() { 59 return blocks; 60 } 61 66 private void add(CVSAnnotateBlock aBlock) { 67 68 int size = blocks.size(); 69 if (size == 0) { 70 blocks.add(aBlock); 71 } else { 72 CVSAnnotateBlock lastBlock = (CVSAnnotateBlock) blocks.get(size - 1); 73 if (lastBlock.getRevision().equals(aBlock.getRevision())) { 74 lastBlock.setEndLine(aBlock.getStartLine()); 75 } else { 76 blocks.add(aBlock); 77 } 78 } 79 } 80 81 84 public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { 85 if(line.startsWith(CVSMessages.AnnotateListener_3)) { 86 String error = CVSMessages.AnnotateListener_4; 87 return new CVSStatus(IStatus.ERROR, CVSStatus.SERVER_ERROR, error, commandRoot); 88 } 89 return super.errorLine(line, location, commandRoot, monitor); 90 } 91 92 98 public void setContents(InputStream remoteContents) { 99 try { 100 ByteArrayOutputStream stream = new ByteArrayOutputStream(); 101 byte[] buffer = new byte[1024]; 102 int n = remoteContents.read(buffer); 103 while (n != -1) { 104 stream.write(buffer, 0, n); 105 n = remoteContents.read(buffer); 106 } 107 aStream = stream; 108 } catch (IOException e) { 109 CVSProviderPlugin.log(CVSException.wrapException(e)); 111 } 112 } 113 } 114 | Popular Tags |