001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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    SYNTAX_HIGHLIGHTINGS("syntax-highlightings-", Domain.PB),
035    CHANGESETS("changesets-", Domain.PB),
036    SYMBOLS("symbols-", Domain.PB),
037    COVERAGES("coverages-", Domain.PB),
038    TESTS("tests-", Domain.PB),
039    COVERAGE_DETAILS("coverage-details-", Domain.PB),
040    SOURCE("source-", ".txt");
041
042    private static final String PB = ".pb";
043    private final String filePrefix;
044    private final String fileSuffix;
045
046    Domain(String filePrefix, String fileSuffix) {
047      this.filePrefix = filePrefix;
048      this.fileSuffix = fileSuffix;
049    }
050  }
051
052  private final File dir;
053
054  public FileStructure(File dir) {
055    if (!dir.exists() || !dir.isDirectory()) {
056      throw new IllegalArgumentException("Directory of analysis report does not exist: " + dir);
057    }
058    this.dir = dir;
059  }
060
061  public File metadataFile() {
062    return new File(dir, "metadata.pb");
063  }
064
065  public File analysisLog() {
066    return new File(dir, "analysis.log");
067  }
068
069  public File activeRules() {
070    return new File(dir, "activerules.pb");
071  }
072
073  public File fileFor(Domain domain, int componentRef) {
074    return new File(dir, domain.filePrefix + componentRef + domain.fileSuffix);
075  }
076
077}