001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.batch.protocol.output; 021 022import java.io.File; 023 024/** 025 * Structure of files in the zipped report 026 */ 027public class FileStructure { 028 029 public enum Domain { 030 ISSUES("issues-", Domain.PB), 031 COMPONENT("component-", Domain.PB), 032 MEASURES("measures-", Domain.PB), 033 DUPLICATIONS("duplications-", Domain.PB), 034 CPD_TEXT_BLOCKS("cpd-text-block-", Domain.PB), 035 SYNTAX_HIGHLIGHTINGS("syntax-highlightings-", Domain.PB), 036 CHANGESETS("changesets-", Domain.PB), 037 SYMBOLS("symbols-", Domain.PB), 038 COVERAGES("coverages-", Domain.PB), 039 TESTS("tests-", Domain.PB), 040 COVERAGE_DETAILS("coverage-details-", Domain.PB), 041 SOURCE("source-", ".txt"); 042 043 private static final String PB = ".pb"; 044 private final String filePrefix; 045 private final String fileSuffix; 046 047 Domain(String filePrefix, String fileSuffix) { 048 this.filePrefix = filePrefix; 049 this.fileSuffix = fileSuffix; 050 } 051 } 052 053 private final File dir; 054 055 public FileStructure(File dir) { 056 if (!dir.exists() || !dir.isDirectory()) { 057 throw new IllegalArgumentException("Directory of analysis report does not exist: " + dir); 058 } 059 this.dir = dir; 060 } 061 062 public File metadataFile() { 063 return new File(dir, "metadata.pb"); 064 } 065 066 public File analysisLog() { 067 return new File(dir, "analysis.log"); 068 } 069 070 public File activeRules() { 071 return new File(dir, "activerules.pb"); 072 } 073 074 public File fileFor(Domain domain, int componentRef) { 075 return new File(dir, domain.filePrefix + componentRef + domain.fileSuffix); 076 } 077 078}