1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 22 */ 23 package org.opengrok.indexer.history; 24 25 import java.io.BufferedReader; 26 import java.io.IOException; 27 import java.io.InputStream; 28 import java.io.InputStreamReader; 29 import org.opengrok.indexer.util.Executor; 30 31 /** 32 * handles parsing the output of the {@code cleartool annotate} 33 * command into an annotation object. 34 */ 35 public class ClearCaseAnnotationParser implements Executor.StreamHandler { 36 37 /** 38 * Store annotation created by processStream. 39 */ 40 private final Annotation annotation; 41 42 /** 43 * @param fileName the name of the file being annotated 44 */ ClearCaseAnnotationParser(String fileName)45 public ClearCaseAnnotationParser(String fileName) { 46 annotation = new Annotation(fileName); 47 } 48 49 /** 50 * Returns the annotation that has been created. 51 * 52 * @return annotation an annotation object 53 */ getAnnotation()54 public Annotation getAnnotation() { 55 return annotation; 56 } 57 58 @Override processStream(InputStream input)59 public void processStream(InputStream input) throws IOException { 60 String line; 61 try (BufferedReader in = new BufferedReader( 62 new InputStreamReader(input))) { 63 while ((line = in.readLine()) != null) { 64 String[] parts = line.split("\\|"); 65 String aAuthor = parts[0]; 66 String aRevision = parts[1]; 67 aRevision = aRevision.replace('\\', '/'); 68 69 annotation.addLine(aRevision, aAuthor, true); 70 } 71 } 72 } 73 } 74