File: LcovMergerFlags.java

package info (click to toggle)
bazel-bootstrap 4.2.3%2Bds-11
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 85,704 kB
  • sloc: java: 721,717; sh: 55,859; cpp: 35,360; python: 12,139; xml: 295; objc: 269; makefile: 113; ansic: 106; ruby: 3
file content (116 lines) | stat: -rwxr-xr-x 3,660 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.coverageoutputgenerator;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.logging.Logger;
import javax.annotation.Nullable;

@Parameters(separators = "= ", optionPrefixes = "--")
class LcovMergerFlags {
  private static final Logger logger = Logger.getLogger(LcovMergerFlags.class.getName());
  private static final int DEFAULT_PARSE_FILE_PARALLELISM = 4;

  @Parameter(names = "--coverage_dir")
  private String coverageDir;

  @Nullable
  @Parameter(names = {"--reports_file", "--lcovfile_path"})
  private String reportsFile;

  @Parameter(names = "--output_file")
  private String outputFile;

  @Parameter(names = "--filter_sources")
  private List<String> filterSources;

  /**
   * The path to a source file manifest. This file contains multiple lines that represent file names
   * of the sources that the final coverage report must include. Additionally this file can also
   * contain coverage metadata files (e.g. gcno, .em), which can be ignored.
   *
   * @return
   */
  @Nullable
  @Parameter(names = "--source_file_manifest")
  private String sourceFileManifest;

  @Nullable
  @Parameter(names = "--sources_to_replace_file")
  private String sourcesToReplaceFile;

  @Parameter(names = "--parse_parallelism")
  private Integer parseParallelism;

  public String coverageDir() {
    return coverageDir;
  }

  public String outputFile() {
    return outputFile;
  }

  public List<String> filterSources() {
    return filterSources == null ? ImmutableList.of() : filterSources;
  }

  public String reportsFile() {
    return reportsFile;
  }

  public String sourceFileManifest() {
    return sourceFileManifest;
  }

  public String sourcesToReplaceFile() {
    return sourcesToReplaceFile;
  }

  boolean hasSourceFileManifest() {
    return sourceFileManifest != null;
  }

  int parseParallelism() {
    return parseParallelism == null ? DEFAULT_PARSE_FILE_PARALLELISM : parseParallelism;
  }

  static LcovMergerFlags parseFlags(String[] args) {
    LcovMergerFlags flags = new LcovMergerFlags();
    JCommander jCommander = new JCommander(flags);
    jCommander.setAllowParameterOverwriting(true);
    jCommander.setAcceptUnknownOptions(true);
    try {
      jCommander.parse(args);
    } catch (ParameterException e) {
      throw new IllegalArgumentException("Error parsing args", e);
    }
    if (flags.coverageDir == null && flags.reportsFile == null) {
      throw new IllegalArgumentException(
          "At least one of coverage_dir or reports_file should be specified.");
    }
    if (flags.coverageDir != null && flags.reportsFile != null) {
      logger.warning("Overriding --coverage_dir value in favor of --reports_file");
    }
    if (flags.outputFile == null) {
      throw new IllegalArgumentException("output_file was not specified.");
    }
    return flags;
  }
}