3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.ce.task.projectanalysis.component;
22 import java.util.EnumSet;
23 import java.util.List;
25 import javax.annotation.CheckForNull;
27 public interface Component {
29 PROJECT(0), DIRECTORY(2), FILE(3), VIEW(0), SUBVIEW(1), PROJECT_VIEW(2);
31 private static final Set<Type> REPORT_TYPES = EnumSet.of(PROJECT, DIRECTORY, FILE);
32 private static final Set<Type> VIEWS_TYPES = EnumSet.of(VIEW, SUBVIEW, PROJECT_VIEW);
34 private final int depth;
40 public int getDepth() {
44 public boolean isDeeperThan(Type otherType) {
45 return this.getDepth() > otherType.getDepth();
48 public boolean isHigherThan(Type otherType) {
49 return this.getDepth() < otherType.getDepth();
52 public boolean isReportType() {
53 return REPORT_TYPES.contains(this);
56 public boolean isViewsType() {
57 return VIEWS_TYPES.contains(this);
62 * On a branch, CHANGED and ADDED are relative to the previous analysis.
63 * On a pull request, these are relative to the base branch.
66 UNAVAILABLE, SAME, CHANGED, ADDED
74 * Returns the component uuid
79 * Returns the key as it will be displayed in the ui.
80 * If legacy branch feature is used, the key will contain the branch name
81 * If new branch feature is used, the key will not contain the branch name
86 * The component long name. For files and directories this is the project relative path.
91 * Get component old relative path.
96 * The component short name. For files and directories this is the parent relative path (ie filename for files). For projects and view this is the same as {@link #getName()}
98 String getShortName();
101 * The optional description of the component.
104 String getDescription();
106 List<Component> getChildren();
109 * Returns the attributes specific to components of type {@link Type#PROJECT}.
111 * @throws IllegalStateException when the component's type is not {@link Type#PROJECT}.
113 ProjectAttributes getProjectAttributes();
116 * Returns the attributes specific to components of type {@link Type#PROJECT}, {@link Type#MODULE},
117 * {@link Type#DIRECTORY} or {@link Type#FILE}.
119 * @throws IllegalStateException when the component's type is neither {@link Type#PROJECT}, {@link Type#MODULE},
120 * {@link Type#DIRECTORY} nor {@link Type#FILE}.
122 ReportAttributes getReportAttributes();
125 * The attributes of the Component if it's type is File.
127 * @throws IllegalStateException if the Component's type is not {@link Type#FILE}
129 FileAttributes getFileAttributes();
132 * The attributes of the Component if it's type is {@link Type#PROJECT_VIEW}.
134 * @throws IllegalStateException if the Component's type is not {@link Type#PROJECT_VIEW}
136 ProjectViewAttributes getProjectViewAttributes();
139 * The attributes of the Component if it's type is {@link Type#SUBVIEW}.
141 * @throws IllegalStateException if the Component's type is not {@link Type#SUBVIEW}
143 SubViewAttributes getSubViewAttributes();
146 * The attributes of the Component if it's type is {@link Type#VIEW}.
148 * @throws IllegalStateException if the Component's type is not {@link Type#VIEW}
150 ViewAttributes getViewAttributes();