Skip to content

Commit e8f94e1

Browse files
committed
Add Grails.org plugin portal updating support for Grails 3 plugins
1 parent 2ba2514 commit e8f94e1

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsCentralPublishGradlePlugin.groovy

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ The values can also be placed in PROJECT_HOME/gradle.properties or USER_HOME/gra
181181
}
182182
}
183183

184+
def grailsCentralUsername = System.getenv('GRAILS_CENTRAL_USERNAME') ?: project.hasProperty('grailsPluginsUsername') ? project.grailsPluginsUsername : ''
185+
def grailsCentralPassword = System.getenv("GRAILS_CENTRAL_PASSWORD") ?: project.hasProperty('grailsPluginsPassword') ? project.grailsPluginsPassword : ''
184186

185187
project.plugins.apply(BintrayPlugin)
186188

@@ -299,8 +301,6 @@ The values can also be placed in PROJECT_HOME/gradle.properties or USER_HOME/gra
299301
}
300302
}
301303

302-
def grailsCentralUsername = System.getenv('GRAILS_CENTRAL_USERNAME') ?: project.hasProperty('grailsPluginsUsername') ? project.grailsPluginsUsername : ''
303-
def grailsCentralPassword = System.getenv("GRAILS_CENTRAL_PASSWORD") ?: project.hasProperty('grailsPluginsPassword') ? project.grailsPluginsPassword : ''
304304

305305
if(grailsCentralUsername && grailsCentralPassword) {
306306

@@ -322,6 +322,70 @@ The values can also be placed in PROJECT_HOME/gradle.properties or USER_HOME/gra
322322
}
323323

324324
}
325+
326+
327+
// pluginInfo = [name:'..', group:'..', version:'..', isSnapshot: true/false, url: portalUrl]
328+
329+
330+
boolean isSnapshot = project.version.toString().endsWith('-SNAPSHOT')
331+
332+
333+
def portalNotify = project.tasks.create('notifyPluginPortal')
334+
portalNotify.dependsOn('generatePomFileForMavenPublication')
335+
portalNotify << {
336+
337+
GrailsPublishExtension extension = project.extensions.findByType(GrailsPublishExtension)
338+
if(extension?.portalUser && extension?.portalPassword) {
339+
def targetUrl = "${extension.portalUrl}/${project.name}"
340+
URL endpoint = new URL(targetUrl)
341+
HttpURLConnection conn = endpoint.openConnection()
342+
conn.doOutput = true
343+
conn.instanceFollowRedirects = false
344+
conn.useCaches = false
345+
conn.requestMethod = 'PUT'
346+
347+
String usernameAndPassword = "$extension.portalUser:$extension.portalPassword"
348+
349+
def sw = new StringWriter()
350+
usernameAndPassword.bytes.encodeBase64().writeTo(sw)
351+
conn.setRequestProperty "Authorization", "Basic ${sw.toString()}"
352+
conn.setRequestProperty "Content-type", "application/json"
353+
conn.setRequestProperty "Accept", "application/json"
354+
355+
String url = extension.centralRepoUrl
356+
OutputStream out
357+
358+
try {
359+
def data = """{"name":"${project.name}","group":"${project.group}","version":"${project.version}","isSnapshot":${isSnapshot},"url":"${url}"}""".toString()
360+
361+
conn.setRequestProperty( "Content-Length", Integer.toString( data.length() ));
362+
363+
out = conn.outputStream
364+
// write the data
365+
out << data
366+
out.flush()
367+
368+
def result = conn.responseCode
369+
if(result.toString().startsWith('2')) {
370+
println "Notification successful."
371+
}
372+
else {
373+
throw new RuntimeException( "(HTTP ${result}) An error occurred. " )
374+
}
375+
376+
} finally {
377+
try {
378+
out?.close()
379+
} catch (Throwable e) {
380+
// ignore
381+
}
382+
}
383+
}
384+
else {
385+
throw new RuntimeException("No Grails 'portalUser' and 'portalPassword' specified")
386+
}
387+
}
388+
325389
project.bintray {
326390
user = bintrayUser
327391
key = bintrayKey

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ class GrailsPublishExtension {
4545
* The password for the plugin portal
4646
*/
4747
String portalPassword
48+
49+
/**
50+
* The plugin endpoint for updating plugins
51+
*/
52+
String portalUrl = "https://grails.org/plugin"
53+
54+
/**
55+
* The location of the Grails central repository
56+
*/
57+
String centralRepoUrl = "http://repo.grails.org/grails/core"
4858
/**
4959
* The website URL of the plugin
5060
*/

0 commit comments

Comments
 (0)