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 import org.apache.commons.lang.StringUtils;
023 import org.apache.commons.lang.builder.ToStringBuilder;
024 import org.sonar.api.utils.WildcardPattern;
025
026 /**
027 * A class that represents a Java package in Sonar
028 *
029 * @since 1.10
030 */
031 public class JavaPackage extends Resource {
032
033 /**
034 * Default package name for classes without package definition
035 */
036 public static final String DEFAULT_PACKAGE_NAME = "[default]";
037
038 /**
039 * Defaul constructor
040 */
041 public JavaPackage() {
042 this(null);
043 }
044
045 /**
046 * Creates a JavaPackage from its key. Will use DEFAULT_PACKAGE_NAME if key is null
047 */
048 public JavaPackage(String key) {
049 setKey(StringUtils.defaultIfEmpty(StringUtils.trim(key), DEFAULT_PACKAGE_NAME));
050 }
051
052 /**
053 * @return whether the JavaPackage key is the defult key
054 */
055 public boolean isDefault() {
056 return StringUtils.equals(getKey(), DEFAULT_PACKAGE_NAME);
057 }
058
059 /**
060 * {@inheritDoc}
061 */
062 public boolean matchFilePattern(String antPattern) {
063 return false;
064 }
065
066 /**
067 * {@inheritDoc}
068 */
069 public String getDescription() {
070 return null;
071 }
072
073 /**
074 * @return SCOPE_SPACE
075 */
076 public String getScope() {
077 return Resource.SCOPE_SPACE;
078 }
079
080 /**
081 * @return QUALIFIER_PACKAGE
082 */
083 public String getQualifier() {
084 return Resource.QUALIFIER_PACKAGE;
085 }
086
087 /**
088 * {@inheritDoc}
089 */
090 public String getName() {
091 return getKey();
092 }
093
094 /**
095 * {@inheritDoc}
096 */
097 public Resource<?> getParent() {
098 return null;
099 }
100
101 /**
102 * {@inheritDoc}
103 */
104 public String getLongName() {
105 return null;
106 }
107
108 /**
109 * @return Java
110 */
111 public Language getLanguage() {
112 return Java.INSTANCE;
113 }
114
115 @Override
116 public String toString() {
117 return new ToStringBuilder(this)
118 .append("id", getId())
119 .append("key", getKey())
120 .toString();
121 }
122 }