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.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 * @deprecated since 4.2 Package are now directory. Use {@link #isDirectory(Resource)} 064 */ 065 @Deprecated 066 public static boolean isPackage(Resource resource) { 067 return resource != null && Qualifiers.PACKAGE.equals(resource.getQualifier()); 068 } 069 070 /** 071 * @return whether a resource is a set 072 */ 073 public static boolean isSet(Resource resource) { 074 return resource != null && Scopes.PROJECT.equals(resource.getScope()); 075 } 076 077 /** 078 * @return whether a resource is a space 079 */ 080 public static boolean isSpace(Resource resource) { 081 return resource != null && Scopes.DIRECTORY.equals(resource.getScope()); 082 } 083 084 /** 085 * @return whether a resource is an entity. 086 */ 087 public static boolean isEntity(Resource resource) { 088 return resource != null && Scopes.FILE.equals(resource.getScope()); 089 } 090 091 /** 092 * This method equal isRootProject(resource) or isModuleProject(resource) or isView(resource) or isSubview(resource) 093 */ 094 public static boolean isProject(Resource resource) { 095 return isSet(resource); 096 } 097 098 /** 099 * Alias for {@link #isSpace(Resource)} 100 */ 101 public static boolean isDirectory(Resource resource) { 102 return isSpace(resource); 103 } 104 105 /** 106 * Alias for {@link #isEntity(Resource)} 107 */ 108 public static boolean isFile(Resource resource) { 109 return isEntity(resource); 110 } 111 112 /* QUALIFIERS */ 113 114 /** 115 * @return whether a resource is a class 116 * @deprecated since 4.2 CLA qualifier is deprecated 117 */ 118 @Deprecated 119 public static boolean isClass(Resource resource) { 120 return Qualifiers.CLASS.equals(resource.getQualifier()); 121 } 122 123 /** 124 * @return whether a resource is a unit test class 125 * @deprecated since 5.1 use {@link #isUnitTestFile(Resource)} 126 */ 127 @Deprecated 128 public static boolean isUnitTestClass(Resource resource) { 129 return isUnitTestFile(resource); 130 } 131 132 /** 133 * @return whether a resource is a unit test class 134 */ 135 public static boolean isUnitTestFile(Resource resource) { 136 return Qualifiers.UNIT_TEST_FILE.equals(resource.getQualifier()); 137 } 138 139 /** 140 * @deprecated since 5.2 No more design features 141 */ 142 @Deprecated 143 public static boolean isLibrary(Resource resource) { 144 return Qualifiers.LIBRARY.equals(resource.getQualifier()); 145 } 146 147 /** 148 * @param resource not nullable 149 * @return true if this type of resource is persisted in database 150 * @since 2.6 151 */ 152 public static boolean isPersistable(Resource resource) { 153 return StringUtils.equals(Scopes.PROJECT, resource.getScope()) || StringUtils.equals(Scopes.DIRECTORY, resource.getScope()) || 154 StringUtils.equals(Scopes.FILE, resource.getScope()); 155 } 156 157}