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.platform; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.apache.commons.lang.builder.ToStringBuilder; 024 import org.sonar.api.database.BaseIdentifiable; 025 026 import java.util.Date; 027 import javax.persistence.*; 028 029 /** 030 * Locally installed extension. 031 * 032 * @since 2.2 033 */ 034 @Entity 035 @Table(name = "extensions") 036 public class LocalExtension extends BaseIdentifiable { 037 038 public static enum Type { 039 PLUGIN, PLUGIN_EXTENSION 040 } 041 042 @Column(name = "plugin_key", updatable = true, nullable = false, length = 100) 043 private String pluginKey; 044 045 @Column(name = "version", updatable = true, nullable = true, length = 100) 046 private String version; 047 048 @Enumerated(EnumType.STRING) 049 @Column(name = "extension_type", updatable = true, nullable = false) 050 private Type type = Type.PLUGIN; 051 052 @Column(name = "name", updatable = true, nullable = true, length = 100) 053 private String name; 054 055 @Column(name = "description", updatable = true, nullable = true, length = 3000) 056 private String description; 057 058 @Column(name = "organization", updatable = true, nullable = true, length = 100) 059 private String organization; 060 061 @Column(name = "organization_url", updatable = true, nullable = true, length = 500) 062 private String organizationUrl; 063 064 @Column(name = "license", updatable = true, nullable = true, length = 50) 065 private String license; 066 067 @Column(name = "checksum", updatable = true, nullable = true) 068 private long checksum; 069 070 @Column(name = "filename", updatable = true, nullable = false, length = 100) 071 private String filename; 072 073 @Column(name = "installation_date", updatable = true, nullable = true) 074 private Date installationDate; 075 076 @Column(name = "plugin_class", updatable = true, nullable = true, length = 100) 077 private String pluginClass; 078 079 @Column(name = "homepage", updatable = true, nullable = true, length = 500) 080 private String homepage; 081 082 @Column(name = "category", updatable = true, nullable = true, length = 100) 083 private String category; 084 085 public LocalExtension() { 086 } 087 088 public LocalExtension(Type type, String pluginKey) { 089 if (StringUtils.isBlank(pluginKey)) { 090 throw new IllegalArgumentException("LocalExtension.pluginKey can not be blank"); 091 } 092 if (type == null) { 093 throw new IllegalArgumentException("LocalExtension.type can not be null"); 094 } 095 this.pluginKey = pluginKey; 096 this.type = type; 097 } 098 099 public String getPluginKey() { 100 return pluginKey; 101 } 102 103 public LocalExtension setPluginKey(String s) { 104 this.pluginKey = s; 105 return this; 106 } 107 108 public Type getType() { 109 return type; 110 } 111 112 public LocalExtension setType(Type type) { 113 if (type == null) { 114 throw new IllegalArgumentException("LocalExtension.type can not be null"); 115 } 116 this.type = type; 117 return this; 118 } 119 120 public String getFilename() { 121 return filename; 122 } 123 124 public LocalExtension setFilename(String filename) { 125 this.filename = filename; 126 return this; 127 } 128 129 public String getName() { 130 return name; 131 } 132 133 public LocalExtension setName(String name) { 134 this.name = name; 135 return this; 136 } 137 138 public String getDescription() { 139 return description; 140 } 141 142 public LocalExtension setDescription(String description) { 143 this.description = description; 144 return this; 145 } 146 147 public String getOrganization() { 148 return organization; 149 } 150 151 public LocalExtension setOrganization(String organization) { 152 this.organization = organization; 153 return this; 154 } 155 156 public String getOrganizationUrl() { 157 return organizationUrl; 158 } 159 160 public LocalExtension setOrganizationUrl(String organizationUrl) { 161 this.organizationUrl = organizationUrl; 162 return this; 163 } 164 165 public String getLicense() { 166 return license; 167 } 168 169 public LocalExtension setLicense(String license) { 170 this.license = license; 171 return this; 172 } 173 174 public String getVersion() { 175 return version; 176 } 177 178 public LocalExtension setVersion(String s) { 179 this.version = s; 180 return this; 181 } 182 183 public long getChecksum() { 184 return checksum; 185 } 186 187 public LocalExtension setChecksum(long l) { 188 this.checksum = l; 189 return this; 190 } 191 192 public Date getInstallationDate() { 193 return installationDate; 194 } 195 196 public LocalExtension setInstallationDate(Date installationDate) { 197 this.installationDate = installationDate; 198 return this; 199 } 200 201 public String getPluginClass() { 202 return pluginClass; 203 } 204 205 public LocalExtension setPluginClass(String s) { 206 this.pluginClass = s; 207 return this; 208 } 209 210 public String getHomepage() { 211 return homepage; 212 } 213 214 public LocalExtension setHomepage(String homepage) { 215 this.homepage = homepage; 216 return this; 217 } 218 219 public String getCategory() { 220 return category; 221 } 222 223 public LocalExtension setCategory(String category) { 224 this.category = category; 225 return this; 226 } 227 228 @Override 229 public boolean equals(Object o) { 230 if (this == o) { 231 return true; 232 } 233 if (o == null || getClass() != o.getClass()) { 234 return false; 235 } 236 237 LocalExtension extension = (LocalExtension) o; 238 if (!pluginKey.equals(extension.pluginKey)) { 239 return false; 240 } 241 if (type != extension.type) { 242 return false; 243 } 244 if (type == LocalExtension.Type.PLUGIN_EXTENSION) { 245 return StringUtils.equals(name, extension.name); 246 } 247 return true; 248 } 249 250 @Override 251 public int hashCode() { 252 int result = pluginKey.hashCode(); 253 result = 31 * result + type.hashCode(); 254 if (type == LocalExtension.Type.PLUGIN_EXTENSION) { 255 result = 31 * result + (name != null ? name.hashCode() : 0); 256 } 257 return result; 258 } 259 260 @Override 261 public String toString() { 262 return new ToStringBuilder(this) 263 .append("id", getId()) 264 .append("type", type) 265 .append("pluginKey", pluginKey) 266 .append("version", version) 267 .append("checksum", checksum) 268 .append("homepage", homepage) 269 .append("category", category) 270 .append("installationDate", installationDate) 271 .toString(); 272 } 273 274 275 public static LocalExtension createPlugin(String pluginKey) { 276 return new LocalExtension(Type.PLUGIN, pluginKey); 277 } 278 279 public static LocalExtension createPluginExtension(String pluginKey, String extensionName) { 280 return new LocalExtension(Type.PLUGIN_EXTENSION, pluginKey).setName(extensionName).setFilename(extensionName); 281 } 282 }