001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2009 SonarSource SA
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     */
020    package org.sonar.api.resources;
021    
022    /**
023     * @since 1.10
024     */
025    public final class ResourceUtils {
026    
027      private ResourceUtils() {
028      }
029    
030      /* SCOPES */
031    
032      /**
033       * @return whether a resource is a set
034       */
035      public static boolean isSet(Resource resource) {
036        return Resource.SCOPE_SET.equals(resource.getScope());
037      }
038    
039      /**
040       * @return whether a resource is a space
041       */
042      public static boolean isSpace(Resource resource) {
043        return Resource.SCOPE_SPACE.equals(resource.getScope());
044      }
045    
046      /**
047       * @return whether a resource is an entity
048       */
049      public static boolean isEntity(Resource resource) {
050        return Resource.SCOPE_ENTITY.equals(resource.getScope());
051      }
052    
053      /**
054       * Use isSet() instead
055       */
056      @Deprecated
057      public static boolean isProject(Resource resource) {
058        return isSet(resource);
059      }
060    
061      /**
062       * Use isSpace() instead
063       */
064      @Deprecated
065      public static boolean isDirectory(Resource resource) {
066        return isSpace(resource);
067      }
068    
069      /**
070       * Use isEntity() instead
071       */
072      @Deprecated
073      public static boolean isFile(Resource resource) {
074        return isEntity(resource);
075      }
076    
077    
078      /* QUALIFIERS */
079    
080      /**
081       * @return whether a resource is a class
082       */
083      public static boolean isClass(Resource resource) {
084        return Resource.QUALIFIER_CLASS.equals(resource.getQualifier());
085      }
086    
087      /**
088       * @return whether a resource is a package
089       */
090      public static boolean isPackage(Resource resource) {
091        return Resource.QUALIFIER_PACKAGE.equals(resource.getQualifier());
092      }
093    
094      /**
095       * @return whether a resource is a unit test class
096       */
097      public static boolean isUnitTestClass(Resource resource) {
098        return Resource.QUALIFIER_UNIT_TEST_CLASS.equals(resource.getQualifier());
099      }
100    
101      /**
102       * @return whether the resource is the root project
103       */
104      public static boolean isRootProject(Resource resource) {
105        return Resource.QUALIFIER_PROJECT.equals(resource.getQualifier());
106      }
107    
108      /**
109       * @return whther a resource is a maven module of  project
110       */
111      public static boolean isModuleProject(Resource resource) {
112        return Resource.QUALIFIER_MODULE.equals(resource.getQualifier());
113      }
114    }