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