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