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      /**
031       * @return whether the resource is a view
032       */
033      public static boolean isView(Resource resource) {
034        return isSet(resource) && Resource.QUALIFIER_VIEW.equals(resource.getQualifier());
035      }
036    
037      /**
038       * @return whether the resource is a subview (in the view tree)
039       */
040      public static boolean isSubview(Resource resource) {
041        return isSet(resource) && Resource.QUALIFIER_SUBVIEW.equals(resource.getQualifier());
042      }
043    
044      /**
045       * @return whether the resource is the root project
046       */
047      public static boolean isRootProject(Resource resource) {
048        return Resource.QUALIFIER_PROJECT.equals(resource.getQualifier());
049      }
050    
051      /**
052       * @return whther a resource is a maven module of  project
053       */
054      public static boolean isModuleProject(Resource resource) {
055        return Resource.QUALIFIER_MODULE.equals(resource.getQualifier());
056      }
057    
058      /**
059       * @return whether a resource is a package
060       */
061      public static boolean isPackage(Resource resource) {
062        return resource != null && Resource.QUALIFIER_PACKAGE.equals(resource.getQualifier());
063      }
064    
065    
066      /**
067       * @return whether a resource is a set
068       */
069      public static boolean isSet(Resource resource) {
070        return resource != null && Resource.SCOPE_SET.equals(resource.getScope());
071      }
072    
073      /**
074       * @return whether a resource is a space
075       */
076      public static boolean isSpace(Resource resource) {
077        return resource != null && Resource.SCOPE_SPACE.equals(resource.getScope());
078      }
079    
080      /**
081       * @return whether a resource is an entity.
082       */
083      public static boolean isEntity(Resource resource) {
084        return resource != null && Resource.SCOPE_ENTITY.equals(resource.getScope());
085      }
086    
087      /**
088       * This method equal isRootProject(resource) or isModuleProject(resource)
089       */
090      public static boolean isProject(Resource resource) {
091        return isSet(resource);
092      }
093    
094      /**
095       * Alias for isDirectory(resource)
096       */
097      public static boolean isDirectory(Resource resource) {
098        return isSpace(resource);
099      }
100    
101      /**
102       * Alias for isEntity(resource)
103       */
104      public static boolean isFile(Resource resource) {
105        return isEntity(resource);
106      }
107    
108    
109      /* QUALIFIERS */
110    
111      /**
112       * @return whether a resource is a class
113       */
114      public static boolean isClass(Resource resource) {
115        return Resource.QUALIFIER_CLASS.equals(resource.getQualifier());
116      }
117    
118    
119      /**
120       * @return whether a resource is a unit test class
121       */
122      public static boolean isUnitTestClass(Resource resource) {
123        return Resource.QUALIFIER_UNIT_TEST_CLASS.equals(resource.getQualifier());
124      }
125    
126    
127      public static boolean isLibrary(Resource resource) {
128        return Resource.QUALIFIER_LIB.equals(resource.getQualifier());
129      }
130    }