001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2013 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube 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 * SonarQube 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 License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.resources; 021 022import org.apache.commons.lang.StringUtils; 023import org.apache.commons.lang.builder.ToStringBuilder; 024 025/** 026 * A class that represents a Java package in Sonar 027 * 028 * @since 1.10 029 * @deprecated since 4.2 use {@link Directory} instead 030 */ 031@Deprecated 032public class JavaPackage extends Resource { 033 034 /** 035 * Default package name for classes without package definition 036 */ 037 public static final String DEFAULT_PACKAGE_NAME = "[default]"; 038 039 /** 040 * Default constructor 041 * @deprecated since 4.2 use {@link #create(String, String)} 042 */ 043 @Deprecated 044 public JavaPackage() { 045 this(null); 046 } 047 048 /** 049 * Creates a JavaPackage from its key. 050 * @deprecated since 4.2 use {@link #create(String, String)} 051 */ 052 @Deprecated 053 public JavaPackage(String deprecatedKey) { 054 if (DEFAULT_PACKAGE_NAME.equals(deprecatedKey)) { 055 deprecatedKey = Directory.ROOT; 056 } 057 String deprecatedDirectoryKey = StringUtils.trimToEmpty(deprecatedKey); 058 deprecatedDirectoryKey = deprecatedDirectoryKey.replaceAll("\\.", Directory.SEPARATOR); 059 setDeprecatedKey(StringUtils.defaultIfEmpty(deprecatedDirectoryKey, Directory.ROOT)); 060 } 061 062 /** 063 * @return whether the JavaPackage key is the default key 064 */ 065 public boolean isDefault() { 066 return StringUtils.equals(getDeprecatedKey(), Directory.ROOT); 067 } 068 069 /** 070 * {@inheritDoc} 071 */ 072 @Override 073 public boolean matchFilePattern(String antPattern) { 074 return false; 075 } 076 077 /** 078 * {@inheritDoc} 079 */ 080 @Override 081 public String getDescription() { 082 return null; 083 } 084 085 /** 086 * @return SCOPE_SPACE 087 */ 088 @Override 089 public String getScope() { 090 return Scopes.DIRECTORY; 091 } 092 093 /** 094 * @return QUALIFIER_PACKAGE 095 */ 096 @Override 097 public String getQualifier() { 098 return Qualifiers.DIRECTORY; 099 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 @Override 105 public String getName() { 106 return getKey(); 107 } 108 109 /** 110 * {@inheritDoc} 111 */ 112 @Override 113 public Resource getParent() { 114 return null; 115 } 116 117 /** 118 * {@inheritDoc} 119 */ 120 @Override 121 public String getLongName() { 122 return null; 123 } 124 125 /** 126 * @return null 127 */ 128 @Override 129 public Language getLanguage() { 130 return null; 131 } 132 133 @Override 134 public String toString() { 135 return new ToStringBuilder(this) 136 .append("id", getId()) 137 .append("key", getKey()) 138 .append("deprecatedKey", getDeprecatedKey()) 139 .toString(); 140 } 141}