aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java
blob: fb10916aeac0cf17d4d5e2db741ad0e33aad74ff (plain)
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
117
118
119
120
/*
 * SonarQube
 * Copyright (C) 2009-2025 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.scanner.protocol.output;

import java.io.File;
import javax.annotation.concurrent.Immutable;

/**
 * Structure of files in the zipped report
 */
@Immutable
public class FileStructure {

  public enum Domain {
    ISSUES("issues-", Domain.PB),
    EXTERNAL_ISSUES("external-issues-", Domain.PB),
    COMPONENT("component-", Domain.PB),
    MEASURES("measures-", Domain.PB),
    DUPLICATIONS("duplications-", Domain.PB),
    CPD_TEXT_BLOCKS("cpd-text-block-", Domain.PB),
    SYNTAX_HIGHLIGHTINGS("syntax-highlightings-", Domain.PB),
    CHANGESETS("changesets-", Domain.PB),
    SYMBOLS("symbols-", Domain.PB),
    COVERAGES("coverages-", Domain.PB),
    SOURCE("source-", ".txt"),
    SGNIFICANT_CODE("sgnificant-code-", Domain.PB),
    CHANGED_LINES("changed-lines-", Domain.PB);

    private static final String PB = ".pb";
    private final String filePrefix;
    private final String fileSuffix;

    Domain(String filePrefix, String fileSuffix) {
      this.filePrefix = filePrefix;
      this.fileSuffix = fileSuffix;
    }
  }

  private final File dir;

  public FileStructure(File dir) {
    if (!dir.exists() || !dir.isDirectory()) {
      throw new IllegalArgumentException("Directory of analysis report does not exist: " + dir);
    }
    this.dir = dir;
  }

  public File metadataFile() {
    return new File(dir, "metadata.pb");
  }

  public File analysisCache() {
    return new File(dir, "analysis-cache2.pb");
  }

  public File analysisLog() {
    return new File(dir, "analysis.log");
  }

  public File activeRules() {
    return new File(dir, "activerules.pb");
  }

  public File adHocRules() {
    return new File(dir, "adhocrules.pb");
  }

  public File fileFor(Domain domain, int componentRef) {
    return new File(dir, domain.filePrefix + componentRef + domain.fileSuffix);
  }

  public File contextProperties() {
    return new File(dir, "context-props.pb");
  }

  public File telemetryEntries() {
    return new File(dir, "telemetry-entries.pb");
  }

  public File analysisWarnings() {
    return new File(dir, "analysis-warnings.pb");
  }

  public File analysisData() {
    return new File(dir, "analysis-data.pb");
  }

  public File root() {
    return dir;
  }

  public File scaDir() {
    File sca = new File(dir, "sca");
    if (!sca.exists() && !sca.mkdirs()) {
      throw new IllegalStateException("Unable to create directory: " + sca);
    }
    return sca;
  }

  public File dependencyFilesZip() {
    return new File(scaDir(), "dependency-files.zip");
  }
}