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 org.apache.commons.lang.StringUtils; 023 024/** 025 * @since 1.10 026 * @deprecated since 5.6 as {@link Resource} is deprecated 027 */ 028@Deprecated 029public final class ResourceUtils { 030 031 private ResourceUtils() { 032 } 033 034 /** 035 * @return whether the resource is a view 036 */ 037 public static boolean isView(Resource resource) { 038 return isSet(resource) && Qualifiers.VIEW.equals(resource.getQualifier()); 039 } 040 041 /** 042 * @return whether the resource is a subview (in the view tree) 043 */ 044 public static boolean isSubview(Resource resource) { 045 return isSet(resource) && Qualifiers.SUBVIEW.equals(resource.getQualifier()); 046 } 047 048 /** 049 * @return whether the resource is the root project 050 */ 051 public static boolean isRootProject(Resource resource) { 052 return Qualifiers.PROJECT.equals(resource.getQualifier()); 053 } 054 055 /** 056 * @return whether a resource is a maven module of project 057 */ 058 public static boolean isModuleProject(Resource resource) { 059 return Qualifiers.MODULE.equals(resource.getQualifier()); 060 } 061 062 /** 063 * @return whether a resource is a set 064 */ 065 public static boolean isSet(Resource resource) { 066 return resource != null && Scopes.PROJECT.equals(resource.getScope()); 067 } 068 069 /** 070 * @return whether a resource is a space 071 */ 072 public static boolean isSpace(Resource resource) { 073 return resource != null && Scopes.DIRECTORY.equals(resource.getScope()); 074 } 075 076 /** 077 * @return whether a resource is an entity. 078 */ 079 public static boolean isEntity(Resource resource) { 080 return resource != null && Scopes.FILE.equals(resource.getScope()); 081 } 082 083 /** 084 * This method equal isRootProject(resource) or isModuleProject(resource) or isView(resource) or isSubview(resource) 085 */ 086 public static boolean isProject(Resource resource) { 087 return isSet(resource); 088 } 089 090 /** 091 * Alias for {@link #isSpace(Resource)} 092 */ 093 public static boolean isDirectory(Resource resource) { 094 return isSpace(resource); 095 } 096 097 /** 098 * Alias for {@link #isEntity(Resource)} 099 */ 100 public static boolean isFile(Resource resource) { 101 return isEntity(resource); 102 } 103 104 /* QUALIFIERS */ 105 106 /** 107 * @return whether a resource is a unit test class 108 * @deprecated since 5.1 use {@link #isUnitTestFile(Resource)} 109 */ 110 @Deprecated 111 public static boolean isUnitTestClass(Resource resource) { 112 return isUnitTestFile(resource); 113 } 114 115 /** 116 * @return whether a resource is a unit test class 117 */ 118 public static boolean isUnitTestFile(Resource resource) { 119 return Qualifiers.UNIT_TEST_FILE.equals(resource.getQualifier()); 120 } 121 122 /** 123 * @deprecated since 5.2 No more design features 124 */ 125 @Deprecated 126 public static boolean isLibrary(Resource resource) { 127 return Qualifiers.LIBRARY.equals(resource.getQualifier()); 128 } 129 130 /** 131 * @param resource not nullable 132 * @return true if this type of resource is persisted in database 133 * @since 2.6 134 */ 135 public static boolean isPersistable(Resource resource) { 136 return StringUtils.equals(Scopes.PROJECT, resource.getScope()) || StringUtils.equals(Scopes.DIRECTORY, resource.getScope()) || 137 StringUtils.equals(Scopes.FILE, resource.getScope()); 138 } 139 140}