Skip to content

Commit

Permalink
Merge branch '2.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed May 11, 2012
2 parents 20b2fae + d053932 commit 83db5d9
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 1 deletion.
@@ -0,0 +1,87 @@
/*
* Copyright 2012 SpringSource
*
* 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.
*/
package org.codehaus.groovy.grails.cli.maven

import org.codehaus.groovy.grails.cli.api.BaseSettingsApi
import grails.util.BuildSettings
import grails.util.Metadata
import org.codehaus.groovy.grails.resolve.EnhancedDefaultDependencyDescriptor
import org.apache.ivy.core.module.descriptor.DependencyDescriptor
import org.codehaus.groovy.grails.resolve.IvyDependencyManager

/**
* Generates a POM for a Grails application
*
* @author Graeme Rocher
* @since 2.1
*/
class MavenPomGenerator extends BaseSettingsApi{
MavenPomGenerator(BuildSettings buildSettings) {
super(buildSettings, false)
}

void generate(String group) {
def rootTemplate = grailsResource("src/grails/templates/maven/single.pom")

def baseDir = buildSettings.baseDir

final metadata = Metadata.getCurrent()
def name = metadata.getApplicationName()
def version = metadata.getApplicationVersion()

final pomFile = new File(baseDir, "pom.xml")
copyGrailsResource(pomFile,rootTemplate)

def dependencyManager = buildSettings.dependencyManager
List<String> dependencies = []
addDependenciesForScope(dependencyManager, "compile", dependencies)
addDependenciesForScope(dependencyManager, "runtime", dependencies)
addDependenciesForScope(dependencyManager, "test", dependencies)
addDependenciesForScope(dependencyManager, "provided", dependencies)
List<String> plugins = []
addDependenciesForScope(dependencyManager, "compile", plugins, "<type>zip</type>")
addDependenciesForScope(dependencyManager, "runtime", plugins, "<type>zip</type>")
addDependenciesForScope(dependencyManager, "test", plugins, "<type>zip</type>")
addDependenciesForScope(dependencyManager, "provided", plugins, "<type>zip</type>")


def ant = new AntBuilder()
ant.replace(file:pomFile) {
replacefilter token:"@grailsVersion@", value:buildSettings.grailsVersion
replacefilter token:"@group@", value:group
replacefilter token:"@name@", value:name
replacefilter token:"@version@", value:version
replacefilter token:"@dependencies@", value:dependencies.join(System.getProperty("line.separator"))
replacefilter token:"@plugins@", value:plugins.join(System.getProperty("line.separator"))

}
}

def addDependenciesForScope(IvyDependencyManager dependencyManager, String scope, ArrayList<String> dependencies, String type = "") {
final appDependencies = type ? dependencyManager.pluginDependencyDescriptors : dependencyManager.getApplicationDependencyDescriptors(scope)
dependencies.addAll(appDependencies.findAll { EnhancedDefaultDependencyDescriptor dd -> dd.scope == scope }.collect() { EnhancedDefaultDependencyDescriptor dd ->
"""
<dependency>
<groupId>$dd.dependencyId.organisation</groupId>
<artifactId>$dd.dependencyId.name</artifactId>
<version>$dd.dependencyRevisionId.revision</version>
<scope>runtime</scope>
$type
</dependency>
""".toString()
})
}
}
Expand Up @@ -283,7 +283,7 @@ public void setMetadataRegisteredPluginNames(Set<String> metadataRegisteredPlugi
/**
* Obtains a set of plugin dependency descriptors defined in the project
*/
Set<DependencyDescriptor> getPluginDependencyDescriptors() {
public Set<DependencyDescriptor> getPluginDependencyDescriptors() {
return pluginDependencyDescriptors;
}

Expand Down
127 changes: 127 additions & 0 deletions grails-resources/src/grails/templates/maven/single.pom
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>@group@</groupId>
<artifactId>@name@</artifactId>
<packaging>grails-app</packaging>
<version>@version@</version>
<name>@name@</name>
<description>@version@</description>

<properties>
<grails.version>@grailsVersion@</grails.version>
</properties>

<dependencies>

<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-dependencies</artifactId>
<version>${grails.version}</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-plugin-testing</artifactId>
<version>${grails.version}</version>
<scope>test</scope>
</dependency>

@dependencies@

@plugins@


</dependencies>

<build>
<pluginManagement />

<plugins>
<!-- Disables the Maven surefire plugin for Grails applications, as we have our own test runner -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>plugins</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>

<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<configuration>
<!-- Whether for Fork a JVM to run Grails commands -->
<fork>true</fork>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>grails</id>
<name>grails</name>
<url>http://repo.grails.org/grails/core</url>
</repository>
<repository>
<id>grails-plugins</id>
<name>grails-plugins</name>
<url>http://repo.grails.org/grails/plugins</url>
</repository>
</repositories>

<profiles>
<profile>
<id>tools</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
58 changes: 58 additions & 0 deletions scripts/CreatePom.groovy
@@ -0,0 +1,58 @@
/*
* Copyright 2004-2005 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.
*/

/**
* @author Graeme Rocher
* @since 2.1
*/

import org.codehaus.groovy.grails.cli.maven.MavenPomGenerator

includeTargets << grailsScript("_GrailsArgParsing")
target(default: "Creates a POM for a Grails project") {
depends(parseArguments)

if (!argsMap.params) {
println msg()
exit 1
}

def generator = new MavenPomGenerator(grailsSettings)
try {
def group = argsMap.params[0]?.trim()
if(group) {
generator.generate group
grailsConsole.addStatus "POM generated."
}
else {
println msg()
exit 1
}

}
catch(e) {
grailsConsole.error "Error occurred creating POM: ${e.message}", e
exit 1
}

}

String msg() {
return '''\
Usage: grails create-pom <group>
Example: grails create-pom com.mycompany
'''
}

0 comments on commit 83db5d9

Please sign in to comment.