001/* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar 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 * Sonar 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 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020package org.sonar.api.resources; 021 022import org.apache.commons.lang.StringUtils; 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 private Qualifiers() { 033 // only static methods 034 } 035 036 /** 037 * Root views. Scope of views is Scopes.PROJECT 038 */ 039 public static final String VIEW = "VW"; 040 041 /** 042 * Sub-views, defined in root views. Scope of sub-views is Scopes.PROJECT 043 */ 044 public static final String SUBVIEW = "SVW"; 045 046 /** 047 * Library, for example a JAR dependency of Java projects. 048 * Scope of libraries is Scopes.PROJECT 049 */ 050 public static final String LIBRARY = "LIB"; 051 052 /** 053 * Single project or root of multi-modules projects 054 * Scope is Scopes.PROJECT 055 */ 056 public static final String PROJECT = "TRK"; 057 058 /** 059 * Module of a multi-modules project. It's sometimes called "sub-project". 060 * Scope of modules is Scopes.PROJECT 061 */ 062 public static final String MODULE = "BRC"; 063 064 public static final String PACKAGE = "PAC"; 065 public static final String DIRECTORY = "DIR"; 066 public static final String FILE = "FIL"; 067 public static final String CLASS = "CLA"; 068 public static final String PARAGRAPH = "PAR"; 069 public static final String METHOD = "MET"; 070 public static final String FIELD = "FLD"; 071 072 // ugly, should be replaced by "natures" 073 public static final String UNIT_TEST_FILE = "UTS"; 074 075 /** 076 * @param resource not nullable 077 */ 078 public static boolean isView(final Resource resource, final boolean acceptSubViews) { 079 boolean isView = StringUtils.equals(VIEW, resource.getQualifier()); 080 if (!isView && acceptSubViews) { 081 isView = StringUtils.equals(SUBVIEW, resource.getQualifier()); 082 } 083 084 return isView; 085 } 086 087 /** 088 * @param resource not nullable 089 */ 090 public static boolean isSubview(final Resource resource) { 091 return StringUtils.equals(SUBVIEW, resource.getScope()); 092 } 093 094 /** 095 * @param resource not nullable 096 */ 097 public static boolean isProject(final Resource resource, final boolean acceptModules) { 098 boolean isProject = StringUtils.equals(PROJECT, resource.getQualifier()); 099 if (!isProject && acceptModules) { 100 isProject = StringUtils.equals(MODULE, resource.getQualifier()); 101 } 102 return isProject; 103 } 104 105 /** 106 * @param resource not nullable 107 */ 108 public static boolean isModule(final Resource resource) { 109 return StringUtils.equals(MODULE, resource.getQualifier()); 110 } 111 112 /** 113 * @param resource not nullable 114 */ 115 public static boolean isDirectory(final Resource resource) { 116 return StringUtils.equals(DIRECTORY, resource.getQualifier()); 117 } 118 119 /** 120 * @param resource not nullable 121 */ 122 public static boolean isPackage(final Resource resource) { 123 return StringUtils.equals(PACKAGE, resource.getQualifier()); 124 } 125 126 /** 127 * @param resource not nullable 128 */ 129 public static boolean isFile(final Resource resource) { 130 return StringUtils.equals(FILE, resource.getQualifier()); 131 } 132 133 /** 134 * @param resource not nullable 135 */ 136 public static boolean isClass(final Resource resource) { 137 return StringUtils.equals(CLASS, resource.getQualifier()); 138 } 139 140 /** 141 * @param resource not nullable 142 */ 143 public static boolean isMethod(final Resource resource) { 144 return StringUtils.equals(METHOD, resource.getQualifier()); 145 } 146 147 /** 148 * @param resource not nullable 149 */ 150 public static boolean isParagraph(final Resource resource) { 151 return StringUtils.equals(PARAGRAPH, resource.getQualifier()); 152 } 153}