001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2011 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.core.plugin;
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.hibernate.annotations.Cascade;
026 import org.sonar.api.database.BaseIdentifiable;
027
028 import java.net.URI;
029 import java.util.ArrayList;
030 import java.util.Date;
031 import java.util.List;
032
033 import javax.persistence.CascadeType;
034 import javax.persistence.Column;
035 import javax.persistence.Entity;
036 import javax.persistence.FetchType;
037 import javax.persistence.OneToMany;
038 import javax.persistence.Table;
039
040 /**
041 * Installed plugins
042 *
043 * @since 2.2
044 */
045 @Entity
046 @Table(name = "plugins")
047 public class JpaPlugin extends BaseIdentifiable {
048
049 @Column(name = "plugin_key", updatable = true, nullable = false, length = 100)
050 private String key;
051
052 @Column(name = "version", updatable = true, nullable = true, length = 100)
053 private String version;
054
055 @Column(name = "name", updatable = true, nullable = true, length = 100)
056 private String name;
057
058 @Column(name = "description", updatable = true, nullable = true, length = 3000)
059 private String description;
060
061 @Column(name = "organization", updatable = true, nullable = true, length = 100)
062 private String organization;
063
064 @Column(name = "organization_url", updatable = true, nullable = true, length = 500)
065 private String organizationUrl;
066
067 @Column(name = "license", updatable = true, nullable = true, length = 50)
068 private String license;
069
070 @Column(name = "installation_date", updatable = true, nullable = true)
071 private Date installationDate;
072
073 @Column(name = "plugin_class", updatable = true, nullable = true, length = 100)
074 private String pluginClass;
075
076 @Column(name = "homepage", updatable = true, nullable = true, length = 500)
077 private String homepage;
078
079 @Column(name = "core", updatable = true, nullable = true)
080 private Boolean core;
081
082 @Column(name = "child_first_classloader", updatable = true, nullable = true)
083 private Boolean childFirstClassLoader = Boolean.FALSE;
084
085 @Column(name = "base_plugin", updatable = true, nullable = true)
086 private String basePlugin;
087
088 @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE,
089 org.hibernate.annotations.CascadeType.DELETE,
090 org.hibernate.annotations.CascadeType.MERGE,
091 org.hibernate.annotations.CascadeType.PERSIST,
092 org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
093 @OneToMany(mappedBy = "plugin", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
094 private List<JpaPluginFile> files = new ArrayList<JpaPluginFile>();
095
096 public JpaPlugin() {
097 }
098
099 public JpaPlugin(String pluginKey) {
100 if (StringUtils.isBlank(pluginKey)) {
101 throw new IllegalArgumentException("LocalExtension.pluginKey can not be blank");
102 }
103 this.key = pluginKey;
104 }
105
106 public String getKey() {
107 return key;
108 }
109
110 public JpaPlugin setKey(String s) {
111 this.key = s;
112 return this;
113 }
114
115 public String getName() {
116 return name;
117 }
118
119 public JpaPlugin setName(String name) {
120 this.name = name;
121 return this;
122 }
123
124 public String getDescription() {
125 return description;
126 }
127
128 public JpaPlugin setDescription(String description) {
129 this.description = description;
130 return this;
131 }
132
133 public String getOrganization() {
134 return organization;
135 }
136
137 public JpaPlugin setOrganization(String organization) {
138 this.organization = organization;
139 return this;
140 }
141
142 public String getOrganizationUrl() {
143 return organizationUrl;
144 }
145
146 public JpaPlugin setOrganizationUrl(URI uri) {
147 this.organizationUrl = (uri != null ? uri.toString() : null);
148 return this;
149 }
150
151 public JpaPlugin setOrganizationUrl(String s) {
152 this.organizationUrl = s;
153 return this;
154 }
155
156 public String getLicense() {
157 return license;
158 }
159
160 public JpaPlugin setLicense(String license) {
161 this.license = license;
162 return this;
163 }
164
165 public String getVersion() {
166 return version;
167 }
168
169 public JpaPlugin setVersion(String s) {
170 this.version = s;
171 return this;
172 }
173
174 public Date getInstallationDate() {
175 return installationDate;
176 }
177
178 public JpaPlugin setInstallationDate(Date installationDate) {
179 this.installationDate = installationDate;
180 return this;
181 }
182
183 public String getPluginClass() {
184 return pluginClass;
185 }
186
187 public JpaPlugin setPluginClass(String s) {
188 this.pluginClass = s;
189 return this;
190 }
191
192 public String getHomepage() {
193 return homepage;
194 }
195
196 public JpaPlugin setHomepage(URI uri) {
197 this.homepage = (uri != null ? uri.toString() : null);
198 return this;
199 }
200
201 public JpaPlugin setHomepage(String s) {
202 this.homepage = s;
203 return this;
204 }
205
206 public Boolean isCore() {
207 return core;
208 }
209
210 public JpaPlugin setCore(Boolean b) {
211 this.core = b;
212 return this;
213 }
214
215 public Boolean isUseChildFirstClassLoader() {
216 return childFirstClassLoader;
217 }
218
219 public JpaPlugin setUseChildFirstClassLoader(boolean use) {
220 this.childFirstClassLoader = use;
221 return this;
222 }
223
224 public String getBasePlugin() {
225 return basePlugin;
226 }
227
228 public void setBasePlugin(String basePlugin) {
229 this.basePlugin = basePlugin;
230 }
231
232 public void createFile(String filename) {
233 JpaPluginFile file = new JpaPluginFile(this, filename);
234 this.files.add(file);
235 }
236
237 public List<JpaPluginFile> getFiles() {
238 return files;
239 }
240
241 public void removeFiles() {
242 files.clear();
243 }
244
245 @Override
246 public boolean equals(Object o) {
247 if (this == o) {
248 return true;
249 }
250 if (o == null || getClass() != o.getClass()) {
251 return false;
252 }
253 JpaPlugin other = (JpaPlugin) o;
254 return key.equals(other.key);
255 }
256
257 @Override
258 public int hashCode() {
259 return key.hashCode();
260 }
261
262 @Override
263 public String toString() {
264 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
265 .append("id", getId())
266 .append("key", key)
267 .append("version", version)
268 .append("homepage", homepage)
269 .append("installationDate", installationDate)
270 .toString();
271 }
272
273 public static JpaPlugin create(String pluginKey) {
274 return new JpaPlugin(pluginKey);
275 }
276
277 }