• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oracle / opengrok / #3691

09 Nov 2023 04:15PM UTC coverage: 74.721% (+8.6%) from 66.08%
#3691

push

web-flow
avoid annotations for binary files (#4476)

fixes #4473

6 of 13 new or added lines in 4 files covered. (46.15%)

258 existing lines in 28 files now uncovered.

43797 of 58614 relevant lines covered (74.72%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/opengrok-indexer/src/main/java/org/opengrok/indexer/history/MercurialAnnotationParser.java
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, 2023, 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.File;
27
import java.io.IOException;
28
import java.io.InputStream;
29
import java.io.InputStreamReader;
30
import java.util.HashMap;
31
import java.util.logging.Level;
32
import java.util.logging.Logger;
33
import java.util.regex.Matcher;
34
import java.util.regex.Pattern;
35
import org.opengrok.indexer.logger.LoggerFactory;
36
import org.opengrok.indexer.util.Executor;
37
import org.opengrok.indexer.web.Util;
38

39
/**
40
 * Handles parsing the output of the {@code hg annotate} command
41
 * into an {@link Annotation} object.
42
 */
43
class MercurialAnnotationParser implements Executor.StreamHandler {
UNCOV
44
    private static final Logger LOGGER = LoggerFactory.getLogger(MercurialAnnotationParser.class);
×
45

UNCOV
46
    private Annotation annotation = null;
×
47
    private final HashMap<String, HistoryEntry> revs;
48
    private final File file;
49

50
    /**
51
     * Pattern used to extract author/revision from the {@code hg annotate} command.
52
     */
UNCOV
53
    private static final Pattern ANNOTATION_PATTERN = Pattern.compile("^\\s*(\\d+):");
×
54

UNCOV
55
    MercurialAnnotationParser(File file, HashMap<String, HistoryEntry> revs) {
×
UNCOV
56
        this.file = file;
×
UNCOV
57
        this.revs = revs;
×
UNCOV
58
    }
×
59

60
    @Override
61
    public void processStream(InputStream input) throws IOException {
UNCOV
62
        annotation = new Annotation(file.getName());
×
63
        String line;
UNCOV
64
        int lineno = 0;
×
UNCOV
65
        Matcher matcher = ANNOTATION_PATTERN.matcher("");
×
66

UNCOV
67
        try (BufferedReader in = new BufferedReader(new InputStreamReader(input))) {
×
UNCOV
68
            while ((line = in.readLine()) != null) {
×
UNCOV
69
                ++lineno;
×
UNCOV
70
                matcher.reset(line);
×
UNCOV
71
                if (matcher.find()) {
×
UNCOV
72
                    String rev = matcher.group(1);
×
UNCOV
73
                    String author = "N/A";
×
74
                    // Use the history index hash map to get the author.
UNCOV
75
                    if (revs.get(rev) != null) {
×
UNCOV
76
                        author = revs.get(rev).getAuthor();
×
77
                    }
UNCOV
78
                    annotation.addLine(rev, Util.getEmail(author.trim()), true);
×
UNCOV
79
                } else {
×
80
                    LOGGER.log(Level.WARNING,
×
81
                            "Error: did not find annotation in line {0} for ''{1}'': [{2}]",
82
                            new Object[]{lineno, this.file, line});
×
83
                }
84
            }
85
        }
UNCOV
86
    }
×
87

88
    Annotation getAnnotation() {
UNCOV
89
        return this.annotation;
×
90
    }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc