001/* 002 * SonarQube 003 * Copyright (C) 2009-2017 SonarSource SA 004 * mailto:info 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.api.resources; 021 022import java.util.Objects; 023 024/** 025 * The qualifier determines the exact type of a resource. 026 * Plugins can define their own qualifiers. 027 * 028 * @since 2.6 029 */ 030public final class Qualifiers { 031 032 /** 033 * Root portfolios. Scope of portfolios is Scopes.PROJECT 034 */ 035 public static final String VIEW = "VW"; 036 037 /** 038 * Sub-portfolios, defined in root portfolios. Scope of sub-portfolios is Scopes.PROJECT 039 */ 040 public static final String SUBVIEW = "SVW"; 041 042 /** 043 * Application portfolios. Scope of application is Scopes.PROJECT 044 */ 045 public static final String APP = "APP"; 046 047 /** 048 * Library, for example a JAR dependency of Java projects. 049 * Scope of libraries is Scopes.PROJECT 050 * @deprecated since 5.2 No more design features 051 */ 052 @Deprecated 053 public static final String LIBRARY = "LIB"; 054 055 /** 056 * Single project or root of multi-modules projects 057 * Scope is Scopes.PROJECT 058 */ 059 public static final String PROJECT = "TRK"; 060 061 /** 062 * Module of a multi-modules project. It's sometimes called "sub-project". 063 * Scope of modules is Scopes.PROJECT 064 */ 065 public static final String MODULE = "BRC"; 066 067 public static final String DIRECTORY = "DIR"; 068 public static final String FILE = "FIL"; 069 070 // ugly, should be replaced by "natures" 071 public static final String UNIT_TEST_FILE = "UTS"; 072 073 private Qualifiers() { 074 // only static methods 075 } 076 077 /** 078 * @param resource not nullable 079 */ 080 public static boolean isView(final Resource resource, final boolean acceptSubViews) { 081 boolean isView = Objects.equals(VIEW, resource.getQualifier()); 082 if (!isView && acceptSubViews) { 083 isView = Objects.equals(SUBVIEW, resource.getQualifier()); 084 } 085 086 return isView; 087 } 088 089 /** 090 * @param resource not nullable 091 */ 092 public static boolean isSubview(final Resource resource) { 093 return Objects.equals(SUBVIEW, resource.getScope()); 094 } 095 096 /** 097 * @param resource not nullable 098 */ 099 public static boolean isProject(final Resource resource, final boolean acceptModules) { 100 boolean isProject = Objects.equals(PROJECT, resource.getQualifier()); 101 if (!isProject && acceptModules) { 102 isProject = Objects.equals(MODULE, resource.getQualifier()); 103 } 104 return isProject; 105 } 106 107 /** 108 * @param resource not nullable 109 */ 110 public static boolean isModule(final Resource resource) { 111 return Objects.equals(MODULE, resource.getQualifier()); 112 } 113 114 /** 115 * @param resource not nullable 116 */ 117 public static boolean isDirectory(final Resource resource) { 118 return Objects.equals(DIRECTORY, resource.getQualifier()); 119 } 120 121 /** 122 * @param resource not nullable 123 */ 124 public static boolean isFile(final Resource resource) { 125 return Objects.equals(FILE, resource.getQualifier()); 126 } 127}