forked from grails/grails-core
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...s-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/maven/MavenPomGenerator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
''' | ||
} |