@@ -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
0 commit comments