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

oracle / opengrok / #3690

09 Nov 2023 04:15PM UTC coverage: 75.439% (+9.4%) from 66.08%
#3690

push

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

fixes #4473

8 of 13 new or added lines in 4 files covered. (61.54%)

250 existing lines in 27 files now uncovered.

44218 of 58614 relevant lines covered (75.44%)

0.75 hits per line

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

87.5
/opengrok-indexer/src/main/java/org/opengrok/indexer/history/SCCSRepositoryAnnotationParser.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.Map;
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

38
/**
39
 * handles parsing into Annotation object.
40
 */
41
public class SCCSRepositoryAnnotationParser implements Executor.StreamHandler {
42
    private static final Logger LOGGER = LoggerFactory.getLogger(SCCSRepositoryAnnotationParser.class);
1✔
43

44
    /**
45
     * Store annotation created by {@link #processStream(InputStream)}.
46
     */
47
    private final Annotation annotation;
48

49
    private final Map<String, String> authors;
50

51
    private final File file;
52

53
    /**
54
     * Pattern used to extract revision from the {@code sccs get} command.
55
     */
56
    private static final Pattern ANNOTATION_PATTERN = Pattern.compile("^([\\d.]+)\\s+");
1✔
57

58
    SCCSRepositoryAnnotationParser(File file, Map<String, String> authors) {
1✔
59
        this.file = file;
1✔
60
        this.annotation = new Annotation(file.getName());
1✔
61
        this.authors = authors;
1✔
62
    }
1✔
63

64
    /**
65
     * Returns the annotation that has been created.
66
     *
67
     * @return annotation an annotation object
68
     */
69
    public Annotation getAnnotation() {
70
        return annotation;
1✔
71
    }
72

73
    @Override
74
    public void processStream(InputStream input) throws IOException {
75
        try (BufferedReader in = new BufferedReader(new InputStreamReader(input))) {
1✔
76
            String line;
77
            int lineno = 0;
1✔
78
            while ((line = in.readLine()) != null) {
1✔
79
                ++lineno;
1✔
80
                Matcher matcher = ANNOTATION_PATTERN.matcher(line);
1✔
81
                if (matcher.find()) {
1✔
82
                    String rev = matcher.group(1);
1✔
83
                    String author = authors.get(rev);
1✔
84
                    if (author == null) {
1✔
85
                        author = "unknown";
×
86
                    }
87

88
                    annotation.addLine(rev, author, true);
1✔
89
                } else {
1✔
90
                    LOGGER.log(Level.SEVERE,
×
91
                            "Error: did not find annotations in line {0} for ''{2}'': [{1}]",
NEW
92
                            new Object[]{lineno, line, file});
×
93
                }
94
            }
1✔
95
        }
96
    }
1✔
97
}
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

© 2026 Coveralls, Inc