Permalink
Browse files

maven publisher plugin for Grails that allows deploying Grails war fi…

…les and Grails plugins into a Maven repository
  • Loading branch information...
graemerocher committed Feb 4, 2010
1 parent 8d1a604 commit 8bcc61807f6753ffb63e6bcca05db4cfc3cc0c6b
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2004-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
@@ -0,0 +1,18 @@
+class MavenPublisherGrailsPlugin {
+ def version = "0.1"
+ // the version or versions of Grails the plugin is designed for
+ def grailsVersion = "1.2 > *"
+ // resources that are excluded from plugin packaging
+ def pluginExcludes = [
+ "grails-app/views/error.gsp"
+ ]
+
+ def author = "Graeme Rocher"
+ def authorEmail = "grocher@vmware.com"
+ def title = "A plugin that allows you to publish and/or resolve Grails application and plugins to Maven repositories without needing to use Maven directly"
+ def description = '''\\
+Brief description of the plugin.
+'''
+
+ def documentation = "http://grails.org/plugin/maven-publisher"
+}
@@ -0,0 +1,6 @@
+#Grails Metadata file
+#Thu Feb 04 12:34:47 CET 2010
+app.grails.version=1.2.1
+app.name=maven-publisher
+plugins.hibernate=1.2.1
+plugins.tomcat=1.2.1
@@ -0,0 +1,30 @@
+grails.project.class.dir = "target/classes"
+grails.project.test.class.dir = "target/test-classes"
+grails.project.test.reports.dir = "target/test-reports"
+grails.project.dependency.resolution = {
+ // inherit Grails' default dependencies
+ inherits( "global" ) {
+ // uncomment to disable ehcache
+ // excludes 'ehcache'
+ }
+ log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
+ repositories {
+ grailsPlugins()
+ grailsHome()
+
+ // uncomment the below to enable remote dependency resolution
+ // from public Maven repositories
+ mavenLocal()
+ mavenCentral()
+ //mavenRepo "http://snapshots.repository.codehaus.org"
+ //mavenRepo "http://repository.codehaus.org"
+ //mavenRepo "http://download.java.net/maven/2/"
+ //mavenRepo "http://repository.jboss.com/maven2/"
+ }
+ dependencies {
+ // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
+
+ build 'org.apache.maven:maven-ant-tasks:2.1.0'
+ }
+
+}
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2004-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+includeTargets << new File("${mavenPublisherPluginDir}/scripts/_GrailsMaven.groovy")
+
+target(main:"Installs a Grails plugin as a Maven artefact") {
+ depends(parseArguments)
+ mavenDeploy()
+ println "Maven deploy complete."
+}
+setDefaultTarget(main)
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2004-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+includeTargets << new File("${mavenPublisherPluginDir}/scripts/_GrailsMaven.groovy")
+
+target(main:"Installs a Grails plugin as a Maven artefact") {
+
+ mavenInstall()
+ println "Maven install complete."
+}
+setDefaultTarget(main)
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2004-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import grails.util.*
+import org.codehaus.groovy.grails.plugins.*
+
+
+includeTargets << grailsScript("_GrailsPackage")
+
+artifact = groovy.xml.NamespaceBuilder.newInstance(ant, 'antlib:org.apache.maven.artifact.ant')
+
+packageApp()
+
+plugin = pluginManager?.allPlugins?.find { it.basePlugin }
+pom = "${grailsSettings.projectTargetDir}/pom.xml"
+basePom = new File( "${basedir}/pom.xml" )
+if(basePom.exists())
+ pom = basePom.absolutePath
+
+
+
+if(!plugin) {
+ includeTargets << grailsScript("_GrailsWar")
+ war()
+}
+else {
+ includeTargets << grailsScript("_GrailsPluginDev")
+ packagePlugin()
+ plugin = pluginManager?.allPlugins?.find { it.basePlugin }
+ pluginInstance = plugin.pluginClass.newInstance()
+}
+
+if(!basePom.exists()) {
+ new File(pom).withWriter { w ->
+ xml = new groovy.xml.MarkupBuilder(w)
+
+ xml.project {
+ modelVersion "4.0.0"
+ if(plugin) {
+ if(pluginInstance.hasProperty('group'))
+ groupId pluginInstance.group ?: "org.grails.plugins"
+ else
+ groupId "org.grails.plugins"
+
+ artifactId plugin.fileSystemShortName
+ packaging "zip"
+ version plugin.version
+ name plugin.fileSystemShortName
+ }
+ else {
+ groupId config?.grails?.project?.groupId ?: grailsAppName
+ artifactId GrailsNameUtils.getScriptName(grailsAppName)
+ packaging "war"
+ version grailsAppVersion
+ name grailsAppName
+ }
+
+
+ if(plugin && plugin.dependencyNames) {
+ dependencies {
+ corePlugins = pluginManager.allPlugins.findAll { it.pluginClass.name.startsWith("org.codehaus.groovy.grails.plugins") }*.name
+
+ for(dep in pluginInstance.dependsOn) {
+ String depName = dep.key
+ if(!corePlugins.contains(dep.key)) {
+ // Note: specifying group in dependsOn is a Grails 1.3 feature
+ // 1.2 users don't have this capability
+ def depGroup = "org.grails.plugins"
+ if(depName.contains(":")) {
+ def i = depName.split(":")
+ depGroup = i[0]
+ depName = i[1]
+ }
+ String depVersion = dep.value
+ def upper = GrailsPluginUtils.getUpperVersion(depVersion)
+ def lower = GrailsPluginUtils.getLowerVersion(depVersion)
+ if(upper == lower) depVersion = upper
+ else {
+ upper = upper == '*' ? '' : upper
+ lower = lower == '*' ? '' : lower
+
+ depVersion = "[$upper,$lower]"
+ }
+
+ dependency {
+ groupId depGroup
+ artifactId depName
+ version depVersion
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
+
+
+target(mavenInstall:"Installs a plugin or application into your local Maven cache") {
+ def deployFile = plugin ? new File(pluginZip) : grailsSettings.projectWarFile
+ def ext = plugin ? "zip" : "war"
+ ant.checksum file:pom, algorithm:"sha1", todir:projectTargetDir
+ ant.checksum file:deployFile, algorithm:"sha1", todir:projectTargetDir
+ artifact.install(file: deployFile) {
+ attach file:"${projectTargetDir}/pom.xml.sha1",type:"pom.sha1"
+ attach file:"${projectTargetDir}/${deployFile.name}.sha1",type:"${ext}.sha1"
+ pom(file: pom)
+ }
+}
+
+target(mavenDeploy:"Deploys the plugin to a Maven repository") {
+ depends(parseArguments)
+
+ def protocols = [ http: "wagon-http",
+ scp: "wagon-ssh",
+ scpexe: "wagon-ssh-external",
+ ftp: "wagon-ftp",
+ webdav: "wagon-webdav" ]
+
+ def distInfo = new DistributionManagementInfo()
+ if(grailsSettings.config.grails.project.dependency.distribution instanceof Closure) {
+ def callable = grailsSettings.config.grails.project.dependency.distribution
+ callable.delegate = distInfo
+ callable.resolveStrategy = Closure.DELEGATE_FIRST
+ try {
+ callable.call()
+ }
+ catch(e) {
+ println "Error reading dependency distribution settings: ${e.message}"
+ exit 1
+ }
+
+ }
+ def protocol = protocols.http
+ def repo = argsMap.repository ? distInfo.remoteRepos[argsMap.repository] : null
+ if(argsMap.protocol) {
+ protocol = argsMap.protocols[argsMap.protocol]
+ }
+ else if(repo) {
+ def url = repo?.args?.url
+ if(url) {
+ def i = url.indexOf('://')
+ def urlProt = url[0..i-1]
+ protocol = protocols[urlProt] ?: protocol
+ }
+ }
+
+ artifact.'install-provider'(artifactId:protocol, version:"1.0-beta-2")
+ ant.checksum file:pom, algorithm:"sha1", todir:projectTargetDir
+
+ def deployFile = plugin ? new File(pluginZip) : grailsSettings.projectWarFile
+ def ext = plugin ? "zip" : "war"
+ ant.checksum file:deployFile, algorithm:"sha1", todir:projectTargetDir
+ try {
+ artifact.deploy(file: deployFile) {
+ attach file:"${projectTargetDir}/pom.xml.sha1",type:"pom.sha1"
+ attach file:"${projectTargetDir}/${deployFile.name}.sha1",type:"${ext}.sha1"
+ pom(file: pom)
+ if(repo) {
+ if(repo.configurer) {
+ remoteRepository(repo.args, repo.configurer)
+ }
+ else {
+ remoteRepository(repo.args)
+ }
+ }
+ if(distInfo.local) {
+ localRepository(path:distInfo.local)
+ }
+ }
+ }
+ catch(e) {
+ println "Error deploying artifact: ${e.message}"
+ println "Have you specified a configured repository to deploy to (--repository argument) or specified distributionManagement in your POM?"
+ }
+}
+
+
+
+class DistributionManagementInfo {
+ Map remoteRepos = [:]
+ String local
+ void localRepository(String s) { local = s }
+ void remoteRepository(Map args, Closure c = null) {
+ if(!args?.id) throw new Exception("Remote repository misconfigured: Please specify a repository 'id'. Eg. remoteRepository(id:'myRepo')")
+ if(!args?.url) throw new Exception("Remote repository misconfigured: Please specify a repository 'url'. Eg. remoteRepository(url:'http://..')")
+ def e = new Expando()
+ e.args = args
+ e.configurer = c
+ remoteRepos[args.id] = e
+ }
+}
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
+ <description>Grails application factory bean</description>
+ <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
+ <property name="grailsResourceLoader" ref="grailsResourceLoader" />
+ </bean>
+
+ <bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
+ <description>A bean that manages Grails plugins</description>
+ <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
+ <property name="application" ref="grailsApplication" />
+ </bean>
+
+ <bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
+ <constructor-arg>
+ <ref bean="grailsApplication" />
+ </constructor-arg>
+ <property name="pluginManager" ref="pluginManager" />
+ </bean>
+
+ <bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean">
+ <property name="grailsResourceHolder" ref="grailsResourceHolder" />
+ </bean>
+
+ <bean id="grailsResourceHolder" scope="prototype" class="org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder">
+ <property name="resources">
+ <value>classpath*:**/grails-app/**/*.groovy</value>
+ </property>
+ </bean>
+
+ <bean id="characterEncodingFilter"
+ class="org.springframework.web.filter.CharacterEncodingFilter">
+ <property name="encoding">
+ <value>utf-8</value>
+ </property>
+ </bean>
+</beans>
@@ -0,0 +1,14 @@
+<sitemesh>
+ <page-parsers>
+ <parser content-type="text/html"
+ class="org.codehaus.groovy.grails.web.sitemesh.GrailsHTMLPageParser" />
+ <parser content-type="text/html;charset=ISO-8859-1"
+ class="org.codehaus.groovy.grails.web.sitemesh.GrailsHTMLPageParser" />
+ <parser content-type="text/html;charset=UTF-8"
+ class="org.codehaus.groovy.grails.web.sitemesh.GrailsHTMLPageParser" />
+ </page-parsers>
+
+ <decorator-mappers>
+ <mapper class="org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutDecoratorMapper" />
+ </decorator-mappers>
+</sitemesh>
Oops, something went wrong.

0 comments on commit 8bcc618

Please sign in to comment.