/
Plugin.groovy
193 lines (167 loc) · 5.36 KB
/
Plugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package org.grails.plugin
import org.grails.meta.UserInfo
import org.grails.taggable.Tag
import org.grails.taggable.Taggable
import org.grails.taggable.TagLink
import org.grails.rateable.Rateable
import org.joda.time.DateTime
/*
* author: Matthew Taylor
*/
class Plugin implements Taggable, Rateable {
static final WHITE_LIST = [
"title",
"groupId",
"summary",
"defaultDependencyScope",
"currentRelease",
"organization",
"organizationUrl",
"documentationUrl",
"downloadUrl",
"scmUrl",
"issuesUrl",
"grailsVersion" ]
static final DEFAULT_GROUP = "org.grails.plugins"
static final DEFAULT_SCOPE = "compile"
static final WIKIS = ['installation','description','faq','screenshots']
static final VERSION_PATTERN = /^(\d+(?:\.\d+)*)([\.\-\w]*)?$/
transient cacheService
transient grailsApplication
transient pluginService
transient taggableService
String name
String title
String groupId = DEFAULT_GROUP
String summary
String defaultDependencyScope = DEFAULT_SCOPE
PluginTab description
PluginTab installation
PluginTab faq
PluginTab screenshots
String author
String authorEmail
String currentRelease
String organization
String organizationUrl
String documentationUrl
String downloadUrl
String scmUrl
String issuesUrl
String grailsVersion // version it was developed against
Boolean official = false // specifies SpringSource support
Boolean featured = false
boolean zombie = false
BigDecimal usage
DateTime dateCreated
DateTime lastUpdated
DateTime lastReleased = new DateTime()
List authors
List mavenRepositories
static hasMany = [licenses: License, mavenRepositories: String, authors: UserInfo, releases: PluginRelease]
static searchable = {
only = [
'name', 'title', 'summary', 'author', 'authorEmail',
'installation','description','faq','screenshots', 'tags',
'featured', 'official', 'organization'
]
title boost: 5.0
description component: true
installation component: true
faq component: true
screenshots component: true
currentRelease index: "no", store: "yes"
grailsVersion index: "no", store: "yes"
organizationUrl index: "no", store: "yes"
documentationUrl index: "no", store: "yes"
downloadUrl index: "no", store: "yes"
scmUrl index: "no", store: "yes"
issuesUrl index: "no", store: "yes"
avgRating index: "not_analyzed", store: "yes"
ratingCount index: "not_analyzed", store: "yes"
lastReleased index: "no", store: "yes"
tags component: true
}
static transients = [
'avgRating',
'ratingCount',
'fisheye',
'tags',
'dependencyDeclation',
'customRepositoriesDeclaration',
'inDefaultGroup' ]
static constraints = {
name unique: true, matches: /[\w-]+/
title blank: false
groupId nullable: false, blank: false
summary nullable: true
description nullable: true
installation nullable: true
faq nullable: true
screenshots nullable: true
author nullable: true
authorEmail nullable: true
organization nullable: true
organizationUrl nullable: true
scmUrl nullable: true, blank: true
issuesUrl nullable: true, blank: true
grailsVersion nullable:true, blank:true, maxLength:16
lastReleased nullable:true
currentRelease blank: false, matches: VERSION_PATTERN
usage nullable: true
}
static mapping = {
cache 'nonstrict-read-write'
summary type: 'text'
usage column: '`usage`'
}
String getFisheye() {
downloadUrl ? "${grailsApplication.config.plugins.fisheye}/grails-${name}" : ''
}
String getDependencyDeclaration() {
return "${inDefaultGroup ? '' : groupId}:${name}:${currentRelease}"
}
String getCustomRepositoriesDeclaration() {
if (!mavenRepositories.size()) return null
return mavenRepositories.collect { url -> "mavenRepo \"${url}\"" }.join('\n')
}
boolean isInDefaultGroup() {
return groupId == DEFAULT_GROUP
}
Collection<Tag> getTags() {
if (!id) {
return []
}
else {
return TagLink.findAllByTagRefAndTypeInList(
id,
taggableService.domainClassFamilies[this.class.name],
[cache:true]).tag
}
}
Double getAvgRating() {
// Dynamic call to method added by Rateable plugin.
return averageRating
}
Integer getRatingCount() {
return totalRatings
}
def onAddComment = { comment ->
cacheService.flushWikiCache()
}
def isNewerThan(version) {
pluginService.compareVersions(currentRelease, version) > 0
}
def isScmGitHub() {
if (!scmUrl) return false
def pattern = ~/.*github.*/
def matches = pattern.matcher(scmUrl).matches()
return matches
}
String toString() {
"$name : $title"
}
static Collection<Tag> getAllTags() {
TagLink.findAllByType('Plugin')
}
}