Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial import of plugin source.

git-svn-id: https://svn.codehaus.org/grails/trunk@7522 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
  • Loading branch information...
commit 2308f54c1c5f3f8957151b4499751da2279653f0 0 parents
pledbrook authored
Showing with 5,134 additions and 0 deletions.
  1. +356 −0 pom.xml
  2. +335 −0 src/main/java/com/octo/mtg/plugin/AbstractGrailsMojo.java
  3. +107 −0 src/main/java/com/octo/mtg/plugin/CreatePomMojo.java
  4. +40 −0 src/main/java/com/octo/mtg/plugin/GrailsCleanMojo.java
  5. +46 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateAppMojo.java
  6. +48 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateControllerMojo.java
  7. +45 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateDomainClassMojo.java
  8. +48 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateIntegrationTestMojo.java
  9. +45 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateScriptMojo.java
  10. +45 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateServiceMojo.java
  11. +44 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateTaglibMojo.java
  12. +47 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateUnitTestMojo.java
  13. +45 −0 src/main/java/com/octo/mtg/plugin/GrailsCreateWebTestMojo.java
  14. +46 −0 src/main/java/com/octo/mtg/plugin/GrailsGenerateAllMojo.java
  15. +44 −0 src/main/java/com/octo/mtg/plugin/GrailsGenerateControllerMojo.java
  16. +45 −0 src/main/java/com/octo/mtg/plugin/GrailsGenerateViewsMojo.java
  17. +36 −0 src/main/java/com/octo/mtg/plugin/GrailsInstallTemplatesMojo.java
  18. +37 −0 src/main/java/com/octo/mtg/plugin/GrailsPackageMojo.java
  19. +67 −0 src/main/java/com/octo/mtg/plugin/GrailsPackagePluginMojo.java
  20. +36 −0 src/main/java/com/octo/mtg/plugin/GrailsRunAppHttpsMojo.java
  21. +36 −0 src/main/java/com/octo/mtg/plugin/GrailsRunAppMojo.java
  22. +36 −0 src/main/java/com/octo/mtg/plugin/GrailsRunWebTestMojo.java
  23. +36 −0 src/main/java/com/octo/mtg/plugin/GrailsTestAppMojo.java
  24. +36 −0 src/main/java/com/octo/mtg/plugin/GrailsWarMojo.java
  25. +43 −0 src/main/java/com/octo/mtg/plugin/MvnCleanMojo.java
  26. +43 −0 src/main/java/com/octo/mtg/plugin/MvnCompileMojo.java
  27. +74 −0 src/main/java/com/octo/mtg/plugin/MvnConfigDirectoriesMojo.java
  28. +109 −0 src/main/java/com/octo/mtg/plugin/MvnCopyDependenciesMojo.java
  29. +50 −0 src/main/java/com/octo/mtg/plugin/MvnRunWebTestMojo.java
  30. +78 −0 src/main/java/com/octo/mtg/plugin/MvnTestAppMojo.java
  31. +138 −0 src/main/java/com/octo/mtg/plugin/MvnValidateMojo.java
  32. +100 −0 src/main/java/com/octo/mtg/plugin/MvnWarMojo.java
  33. +49 −0 src/main/java/com/octo/mtg/plugin/package.html
  34. +362 −0 src/main/java/com/octo/mtg/plugin/tools/DefaultGrailsServices.java
  35. +69 −0 src/main/java/com/octo/mtg/plugin/tools/DefaultMojoServices.java
  36. +100 −0 src/main/java/com/octo/mtg/plugin/tools/DefaultPomServices.java
  37. +37 −0 src/main/java/com/octo/mtg/plugin/tools/GrailsPluginProject.java
  38. +56 −0 src/main/java/com/octo/mtg/plugin/tools/GrailsProject.java
  39. +128 −0 src/main/java/com/octo/mtg/plugin/tools/GrailsServices.java
  40. +36 −0 src/main/java/com/octo/mtg/plugin/tools/MojoServices.java
  41. +65 −0 src/main/java/com/octo/mtg/plugin/tools/PomServices.java
  42. +108 −0 src/main/java/com/octo/mtg/plugin/tools/RawStreamPumper.java
  43. +24 −0 src/main/java/com/octo/mtg/plugin/tools/package.html
  44. +36 −0 src/site/apt/examples/create-a-grails-app.apt
  45. +31 −0 src/site/apt/examples/mavenize-a-grails-app.apt
  46. +36 −0 src/site/apt/examples/setup-your-IDE.apt
  47. +114 −0 src/site/apt/index.apt
  48. +82 −0 src/site/apt/lifecycles.apt
  49. +115 −0 src/site/apt/usage.apt
  50. +54 −0 src/site/fml/faq.fml
  51. +37 −0 src/site/site.xml
  52. +144 −0 src/test/java/com/octo/mtg/plugin/LoadMojosTest.java
  53. +63 −0 src/test/java/com/octo/mtg/plugin/tools/GrailsServicesTest.java
  54. +89 −0 src/test/java/com/octo/mtg/plugin/tools/PomServicesTest.java
  55. +34 −0 src/test/resources/com/octo/mtg/plugin/create-pom/plugin-config.xml
  56. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-clean/plugin-config.xml
  57. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-app/plugin-config.xml
  58. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-controller/plugin-config.xml
  59. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-domain-class/plugin-config.xml
  60. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-integration-test/plugin-config.xml
  61. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-script/plugin-config.xml
  62. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-service/plugin-config.xml
  63. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-taglib/plugin-config.xml
  64. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-unit-test/plugin-config.xml
  65. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-create-web-test/plugin-config.xml
  66. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-generate-all/plugin-config.xml
  67. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-generate-controller/plugin-config.xml
  68. +35 −0 src/test/resources/com/octo/mtg/plugin/grails-generate-views/plugin-config.xml
  69. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-install-templates/plugin-config.xml
  70. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-package/plugin-config.xml
  71. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-run-app-https/plugin-config.xml
  72. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-run-app/plugin-config.xml
  73. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-run-webtest/plugin-config.xml
  74. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-test-app/plugin-config.xml
  75. +34 −0 src/test/resources/com/octo/mtg/plugin/grails-war/plugin-config.xml
  76. +34 −0 src/test/resources/com/octo/mtg/plugin/maven-clean/plugin-config.xml
  77. +34 −0 src/test/resources/com/octo/mtg/plugin/maven-copy-dependencies/plugin-config.xml
  78. +34 −0 src/test/resources/com/octo/mtg/plugin/maven-run-webtest/plugin-config.xml
  79. +34 −0 src/test/resources/com/octo/mtg/plugin/maven-test-app/plugin-config.xml
  80. +34 −0 src/test/resources/com/octo/mtg/plugin/maven-validate/plugin-config.xml
  81. +34 −0 src/test/resources/com/octo/mtg/plugin/maven-war/plugin-config.xml
  82. +28 −0 src/test/resources/com/octo/mtg/plugin/pom-services/pom.xml
356 pom.xml
@@ -0,0 +1,356 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Copyright 2007 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.
+-->
+<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>org.grails</groupId>
+ <artifactId>grails-maven-plugin</artifactId>
+ <version>0.4-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+ <name>Maven plugin for GRAILS applications</name>
+ <description>This plugin allows you to integrate GRAILS applications into maven 2 builds.</description>
+ <url>http://forge.octo.com/maven/sites/mtg/grails-maven-plugin</url>
+ <distributionManagement>
+ <repository>
+ <id>codehaus.org</id>
+ <name>Grails Main Repository</name>
+ <url>dav:https://dav.codehaus.org/repository/grails</url>
+ </repository>
+ <snapshotRepository>
+ <id>codehaus.org</id>
+ <name>Grails Snapshots Repository</name>
+ <url>dav:https://dav.codehaus.org/snapshots.repository/grails</url>
+ </snapshotRepository>
+ </distributionManagement>
+ <prerequisites>
+ <maven>2.0.5</maven>
+ </prerequisites>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-archiver</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.4.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>1.5.7</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.grails</groupId>
+ <artifactId>grails-bootstrap</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generated-helpmojo</id>
+ <goals>
+ <goal>helpmojo</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate</id>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ <phase>process-sources</phase>
+ <configuration>
+ <outputDirectory>${project.build.directory}/generated-resources/plexus</outputDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>merge</id>
+ <goals>
+ <goal>merge-descriptors</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-docck-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>pre-site</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.0.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.4.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <version>1.3.5</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <tags>
+ <tag>
+ <name>plexus.component</name>
+ <placement>a</placement>
+ <head>This class is a plexus component</head>
+ </tag>
+ <tag>
+ <name>component</name>
+ <placement>a</placement>
+ <head>This property is a component injected by plexus.</head>
+ </tag>
+ <tag>
+ <name>readonly</name>
+ <placement>a</placement>
+ <head>The user cannot override this property from the command line.</head>
+ </tag>
+ <tag>
+ <name>description</name>
+ <placement>a</placement>
+ <head>Description :</head>
+ </tag>
+ <tag>
+ <name>requiresProject</name>
+ <placement>a</placement>
+ <head>This Mojo needs to be launched in a maven 2 project</head>
+ </tag>
+ <tag>
+ <name>goal</name>
+ <placement>a</placement>
+ <head>The goal name for the Mojo :</head>
+ </tag>
+ </tags>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>2.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-changelog-plugin</artifactId>
+ <version>2.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <version>2.4.3</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>2.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <linkXref>true</linkXref>
+ <minimumTokens>20</minimumTokens>
+ <targetJdk>1.4</targetJdk>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>1.1.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <version>1.0-alpha-3</version>
+ <configuration>
+ <excludes>
+ <exclude>**/it/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+ <profiles>
+ <profile>
+ <id>integration-tests</id>
+ <activation>
+ <property>
+ <name>integration-tests</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>shitty-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>clean</goal>
+ <goal>install</goal>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <projects>
+ <fileset>
+ <directory>src/it</directory>
+ <includes>
+ <include>${includeITs}</include>
+ </includes>
+ <excludes>
+ <exclude>${excludeITs}</exclude>
+ </excludes>
+ </fileset>
+ </projects>
+ <parallel>true</parallel>
+ <threadCount>2</threadCount>
+ <flags>-DgrailsHome-0.5.6=${grailsHome-0.5.6} -DgrailsHome-0.6=${grailsHome-0.6}</flags>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <id>codehaus.snapshots</id>
+ <url>http://snapshots.repository.codehaus.org/</url>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <id>codehaus.snapshots</id>
+ <url>http://snapshots.repository.codehaus.org/</url>
+ </pluginRepository>
+ </pluginRepositories>
+ <properties>
+ <includeITs>**/pom4test.xml</includeITs>
+ <excludeITs>**/run-webtest/pom4test.xml</excludeITs>
+ </properties>
+ </profile>
+ <profile>
+ <id>release</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
335 src/main/java/com/octo/mtg/plugin/AbstractGrailsMojo.java
@@ -0,0 +1,335 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import com.octo.mtg.plugin.tools.GrailsServices;
+import com.octo.mtg.plugin.tools.MojoServices;
+import com.octo.mtg.plugin.tools.PomServices;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.artifact.MavenMetadataSource;
+import org.codehaus.groovy.tools.RootLoader;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.*;
+
+/**
+ * Common services for all Mojos using Grails
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ */
+public abstract class AbstractGrailsMojo extends AbstractMojo {
+ /**
+ * The directory where is launched the mvn command.
+ *
+ * @parameter default-value="${basedir}"
+ * @required
+ */
+ protected File basedir;
+
+ /**
+ * The Grails environment to use.
+ *
+ * @parameter expression="${grails.env}"
+ */
+ protected String env;
+
+ /**
+ * The path to GRAILS' HOME.
+ *
+ * @parameter expression="${grailsHome}"
+// * @required
+ */
+ protected String grailsHome;
+
+ /**
+ * POM
+ *
+ * @parameter expression="${project}"
+ * @readonly
+ * @required
+ */
+ protected MavenProject project;
+
+ /**
+ * @component
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
+ * @component
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @required
+ * @readonly
+ */
+ private List remoteRepositories;
+
+ /**
+ * @component
+ */
+ private MavenProjectBuilder projectBuilder;
+
+ /**
+ * @component
+ * @readonly
+ */
+ private GrailsServices grailsServices;
+
+ /**
+ * @component
+ * @readonly
+ */
+ private MojoServices mojoServices;
+
+ /**
+ * @component
+ * @readonly
+ */
+ private PomServices pomServices;
+
+ protected File getBasedir() {
+ if(basedir == null) {
+ throw new RuntimeException("Your subclass have a field called 'basedir'. Remove it and use getBasedir() " +
+ "instead.");
+ }
+
+ return this.basedir;
+ }
+
+ /**
+ * OutputStream to write the content of stdout.
+ */
+ private OutputStream infoOutputStream = new OutputStream() {
+ StringBuffer buffer = new StringBuffer();
+
+ public void write(int b) throws IOException {
+ if (b == '\n') {
+ getLog().info(buffer.toString());
+ buffer.setLength(0);
+ } else {
+ buffer.append((char) b);
+ }
+ }
+ };
+
+ /**
+ * OutputStream to write the content of stderr.
+ */
+ private OutputStream warnOutputStream = new OutputStream() {
+ StringBuffer buffer = new StringBuffer();
+
+ public void write(int b) throws IOException {
+ if (b == '\n') {
+ getLog().warn(buffer.toString());
+ buffer.setLength(0);
+ } else {
+ buffer.append((char) b);
+ }
+ }
+ };
+
+ protected GrailsServices getGrailsServices() throws MojoExecutionException {
+ grailsServices.setBasedir(basedir);
+ grailsServices.setDependencies(getPluginDependencies(getBootStrapPOM()));
+
+ return grailsServices;
+ }
+
+ protected PomServices getPomServices() {
+ pomServices.setBasedir(basedir);
+
+ return pomServices;
+ }
+
+ protected Artifact getBootStrapPOM() {
+ return this.artifactFactory.createBuildArtifact("org.grails", "grails-bootstrap", "1.1-SNAPSHOT", "pom");
+ }
+
+ protected List getPluginDependencies(Artifact pom) throws MojoExecutionException {
+ try {
+ MavenProject project = this.projectBuilder.buildFromRepository(pom,
+ this.remoteRepositories,
+ this.localRepository);
+
+ //get all of the dependencies for the executable project
+ List dependencies = project.getDependencies();
+
+ //make Artifacts of all the dependencies
+ Set dependencyArtifacts =
+ MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, null, null, null);
+
+ //not forgetting the Artifact of the project itself
+ dependencyArtifacts.add(project.getArtifact());
+
+ //resolve all dependencies transitively to obtain a comprehensive list of assemblies
+ List artifacts = new ArrayList(dependencyArtifacts.size());
+ for (Iterator iter = dependencyArtifacts.iterator(); iter.hasNext();) {
+ Artifact artifact = (Artifact) iter.next();
+ this.artifactResolver.resolve(artifact, this.remoteRepositories, this.localRepository);
+ artifacts.add(artifact);
+ }
+
+ return artifacts;
+ } catch ( Exception ex ) {
+ throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " +
+ "in preparation for its execution.", ex);
+ }
+ }
+
+ protected void runGrails(String targetName) throws MojoExecutionException {
+ runGrails(targetName, null, "runtime");
+ }
+
+ protected void runGrails(String targetName, String args, String scope) throws MojoExecutionException {
+// List pluginDependencies = getPluginDependencies(getBootStrapPOM());
+// List runtimeDependencies = this.project.getRuntimeArtifacts();
+// List systemDependencies = this.project.getSystemArtifacts();
+ Set allArtifacts = new HashSet(getPluginDependencies(getBootStrapPOM()));
+ allArtifacts.addAll(this.project.getDependencyArtifacts());
+
+ if (scope.equals("compile")) {
+ allArtifacts.addAll(this.project.getCompileArtifacts());
+ } else if (scope.equals("runtime")) {
+ allArtifacts.addAll(this.project.getRuntimeArtifacts());
+ } else if (scope.equals("test")) {
+ allArtifacts.addAll(this.project.getTestArtifacts());
+ } else if (scope.equals("system")) {
+ allArtifacts.addAll(this.project.getSystemArtifacts());
+ }
+
+ URL[] classpath;
+ try {
+ classpath = new URL[allArtifacts.size()];
+ int index = 0;
+ for (Iterator iter = allArtifacts.iterator(); iter.hasNext();) {
+ classpath[index++] = ((Artifact) iter.next()).getFile().toURI().toURL();
+ }
+
+// for (Iterator iter = runtimeDependencies.iterator(); iter.hasNext();) {
+// classpath[index++] = ((Artifact) iter.next()).getFile().toURI().toURL();
+// }
+//
+// for (Iterator iter = systemDependencies.iterator(); iter.hasNext();) {
+// classpath[index++] = ((Artifact) iter.next()).getFile().toURI().toURL();
+// }
+
+// Commandline cmd = new Commandline();
+// cmd.setWorkingDirectory(getBasedir());
+// cmd.setExecutable("java");
+// cmd.createArg().setValue("-cp");
+// cmd.createArg().setValue(toClasspath(classpath));
+// cmd.createArg().setValue("org.codehaus.groovy.grails.cli.GrailsScriptRunner");
+// cmd.createArg().setValue(targetName);
+//
+// int returnCode = mojoServices.executeCommandLine(cmd, System.in, infoOutputStream, warnOutputStream);
+// getLog().debug("Grails ended with the return code: " + returnCode);
+// if (returnCode != 0) {
+// throw new MojoExecutionException("Grails ended with a non null return code: " + returnCode);
+// }
+
+ // Setup grails env
+// if (env != null) {
+// // For default environments, we use the command line arg
+// // as a workaround for [GRAILS-1658]
+// if ("dev".equals(env)) {
+// cmd.createArg().setValue("dev");
+// } else if ("prod".equals(env)) {
+// cmd.createArg().setValue("prod");
+// } else if ("test".equals(env)) {
+// cmd.createArg().setValue("test");
+// } else {
+// cmd.createArg().setValue("-Dgrails.env=" + env);
+// }
+// }
+ List mainArgs = new ArrayList();
+ mainArgs.add(targetName);
+
+// if (env != null) {
+// mainArgs.add(env);
+// }
+
+// if (args != null && args.length > 0) {
+// mainArgs.addAll(Arrays.asList(args));
+// }
+
+ System.setProperty("grails.project.work.dir", this.project.getBuild().getDirectory());
+
+ RootLoader rootLoader = new RootLoader(classpath, getClass().getClassLoader());
+ Class mainClass = rootLoader.loadClass("org.codehaus.groovy.grails.cli.GrailsScriptRunner");
+ Object scriptRunner = mainClass.newInstance();
+
+ mainClass.getDeclaredMethod("setOut", new Class[]{ PrintStream.class }).invoke(
+ scriptRunner,
+ new Object[] { new PrintStream(infoOutputStream) });
+
+ Method mainMethod = mainClass.getDeclaredMethod(
+ "executeCommand",
+ new Class[]{ String.class, String.class, String.class });
+ Object retval = mainMethod.invoke(
+ scriptRunner,
+ new Object[] { targetName, args, env });
+ if (((Integer) retval).intValue() != 0) {
+ throw new MojoExecutionException("Grails returned non-zero value.");
+ }
+// } catch (MalformedURLException ex) {
+// throw new MojoExecutionException("Something went wrong", ex);
+// } catch (CommandLineException ex) {
+// throw new MojoExecutionException("Something went wrong", ex);
+ } catch (MojoExecutionException ex) {
+ // Simply rethrow it.
+ throw ex;
+ } catch (Exception ex) {
+ throw new MojoExecutionException("Unable to start Grails", ex);
+ }
+ }
+
+ private String toClasspath(URL[] urls) {
+ if (urls.length == 0) return "";
+
+ String pathSeparator = System.getProperty("path.separator");
+ StringBuffer buf = new StringBuffer(urls[0].getPath());
+ for (int i = 1; i < urls.length; i++) {
+ buf.append(pathSeparator);
+ buf.append(urls[i].getPath());
+ }
+
+ return buf.toString();
+ }
+}
107 src/main/java/com/octo/mtg/plugin/CreatePomMojo.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import com.octo.mtg.plugin.tools.GrailsProject;
+import com.octo.mtg.plugin.tools.GrailsServices;
+import com.octo.mtg.plugin.tools.PomServices;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+
+/**
+ * Creates a creates a maven 2 POM for on an existing Grails project.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a creates a maven 2 POM for on an existing Grails
+ * project.
+ * @goal create-pom
+ * @requiresProject false
+ * @since 0.1
+ */
+public class CreatePomMojo extends AbstractMojo {
+
+ /**
+ * The Group Id of the project to be build.
+ *
+ * @parameter expression="${groupId}"
+ * @required
+ */
+ private String groupId;
+
+ /**
+ * Does the plugin generate maven-eclipse-plugin settings in your pom ?
+ *
+ * @parameter expression="${addEclipseSettings}"
+ */
+ private boolean addEclipseSettings;
+
+ /**
+ * @parameter expression="${plugin.artifactId}"
+ * @required
+ * @readonly
+ */
+ private String pluginArtifactId;
+
+ /**
+ * @parameter expression="${plugin.groupId}"
+ * @required
+ * @readonly
+ */
+ private String pluginGroupId;
+
+ /**
+ * @parameter expression="${plugin.version}"
+ * @required
+ * @readonly
+ */
+ private String pluginVersion;
+
+ /**
+ * @parameter expression="${basedir}"
+ * @required
+ * @readonly
+ */
+ private File basedir;
+
+ /**
+ * @component
+ * @readonly
+ */
+ protected PomServices pomServices;
+
+ /**
+ * @component
+ * @readonly
+ */
+ protected GrailsServices grailsServices;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ grailsServices.setBasedir(basedir);
+ pomServices.setBasedir(basedir);
+
+ GrailsProject grailsDescr;
+
+ grailsDescr = grailsServices.readProjectDescriptor();
+
+ pomServices.write(grailsServices.createPOM(groupId, grailsDescr, pluginGroupId, pluginArtifactId,
+ pluginVersion, addEclipseSettings));
+ }
+}
40 src/main/java/com/octo/mtg/plugin/GrailsCleanMojo.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Cleans a Grails project.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Cleans a Grails project.
+ * @goal clean
+ * @requiresProject true
+ * @requiresDependencyResolution runtime
+ * @since 0.1
+ */
+public class GrailsCleanMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ runGrails("clean");
+ }
+}
46 src/main/java/com/octo/mtg/plugin/GrailsCreateAppMojo.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a Grails project, including the necessary directory structure, and
+ * commons files.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a Grails project, including the necessary directory
+ * structure, and commons files.
+ * @goal create-app
+ * @requiresDependencyResolution runtime
+ * @since 0.1
+ */
+public class GrailsCreateAppMojo extends AbstractGrailsMojo {
+
+ /**
+ * The application name.
+ *
+ * @parameter expression="${appName}"
+ */
+ private String appName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ runGrails("create-app", new String[]{appName}, "runtime");
+ }
+}
48 src/main/java/com/octo/mtg/plugin/GrailsCreateControllerMojo.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2007 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.
+ */
+
+/**
+ *
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a new controller.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a new controller.
+ * @goal create-controller
+ * @requiresDependencyResolution runtime
+ * @since 0.1
+ */
+public class GrailsCreateControllerMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the controller to create.
+ *
+ * @parameter expression="${controllerName}"
+ */
+ private String controllerName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ runGrails("create-controller", new String[]{this.controllerName}, "runtime");
+ }
+}
45 src/main/java/com/octo/mtg/plugin/GrailsCreateDomainClassMojo.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a new domain class.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a new domain class.
+ * @goal create-domain-class
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsCreateDomainClassMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the domain class to create.
+ *
+ * @parameter expression="${domainClassName}"
+ */
+ private String domainClassName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "create-domain-class",
+ new String[]{this.domainClassName});
+ }
+}
48 src/main/java/com/octo/mtg/plugin/GrailsCreateIntegrationTestMojo.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a new Grails integration test which loads the whole Grails
+ * environment when run.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id: GrailsCreateIntegrationTestMojo.java 422 2007-10-11 22:13:54Z
+ * ahe $
+ * @description Creates a new Grails integration test which loads the whole
+ * Grails environment when run.
+ * @goal create-integration-test
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsCreateIntegrationTestMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the unit test to create.
+ *
+ * @parameter expression="${integrationTestName}"
+ */
+ private String integrationTestName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "create-integration-test",
+ new String[]{this.integrationTestName});
+ }
+}
45 src/main/java/com/octo/mtg/plugin/GrailsCreateScriptMojo.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a Grails Gant Script.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a Grails Gant Script.
+ * @goal create-script
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsCreateScriptMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the script to create.
+ *
+ * @parameter expression="${scriptName}"
+ */
+ private String scriptName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "create-script",
+ new String[]{this.scriptName});
+ }
+}
45 src/main/java/com/octo/mtg/plugin/GrailsCreateServiceMojo.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a new service class.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a new service class.
+ * @goal create-service
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsCreateServiceMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the service to create.
+ *
+ * @parameter expression="${serviceName}"
+ */
+ private String serviceName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "create-service",
+ new String[]{this.serviceName});
+ }
+}
44 src/main/java/com/octo/mtg/plugin/GrailsCreateTaglibMojo.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a new taglib.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a new taglib.
+ * @goal create-taglib
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsCreateTaglibMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the taglib to create.
+ *
+ * @parameter expression="${taglibName}"
+ */
+ private String taglibName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "create-taglib",
+ new String[]{this.taglibName});
+ }
+}
47 src/main/java/com/octo/mtg/plugin/GrailsCreateUnitTestMojo.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a new Grails unit test. A unit test requires that you mock out access
+ * to dynamic methods, but executes a lot quicker.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a new Grails unit test. A unit test requires that you
+ * mock out access to dynamic methods, but executes a lot quicker.
+ * @goal create-unit-test
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsCreateUnitTestMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the unit test to create.
+ *
+ * @parameter expression="${unitTestName}"
+ */
+ private String unitTestName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "create-unit-test",
+ new String[]{this.unitTestName});
+ }
+}
45 src/main/java/com/octo/mtg/plugin/GrailsCreateWebTestMojo.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a skeleton of a Canoo WebTest (functional test) for a given name.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a skeleton of a Canoo WebTest (functional test) for a
+ * given name.
+ * @goal create-web-test
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsCreateWebTestMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name for the web test to create.
+ *
+ * @parameter expression="${webTestName}"
+ */
+ private String webTestName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "create-webtest",
+ new String[]{this.webTestName});
+ }
+}
46 src/main/java/com/octo/mtg/plugin/GrailsGenerateAllMojo.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Generates a CRUD interface (controller + views) for a domain class.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Generates a CRUD interface (controller + views) for a domain
+ * class.
+ * @goal generate-all
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsGenerateAllMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name of the domain class to generate the CRUD interface.
+ *
+ * @parameter expression="${domainClass}"
+ */
+ private String domainClassName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "generate-all",
+ new String[]{this.domainClassName});
+ }
+}
44 src/main/java/com/octo/mtg/plugin/GrailsGenerateControllerMojo.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Generates a CRUD controller for a specified domain class.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Generates a CRUD controller for a specified domain class.
+ * @goal generate-controller
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsGenerateControllerMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name of the domain class to generate the CRUD controller.
+ *
+ * @parameter expression="${domainClassName}"
+ */
+ private String domainClassName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "generate-controller",
+ new String[]{this.domainClassName});
+ }
+}
45 src/main/java/com/octo/mtg/plugin/GrailsGenerateViewsMojo.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Generates the CRUD views for a specified domain class.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Generates the CRUD views for a specified domain class.
+ * @goal generate-views
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsGenerateViewsMojo extends AbstractGrailsMojo {
+
+ /**
+ * The name of the domain class to generate the CRUD views.
+ *
+ * @parameter expression="${domainClass}"
+ */
+ private String domainClassName;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "generate-views",
+ new String[]{this.domainClassName});
+ }
+}
36 src/main/java/com/octo/mtg/plugin/GrailsInstallTemplatesMojo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Installs the artifact and scaffolding templates.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Installs the artifact and scaffolding templates.
+ * @goal install-templates
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsInstallTemplatesMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "install-templates");
+ }
+}
37 src/main/java/com/octo/mtg/plugin/GrailsPackageMojo.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Packages the Grails application into the web-app folder for running.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Packages the Grails application into the web-app folder for
+ * running.
+ * @goal package
+ * @requiresProject false
+ * @since 0.2
+ */
+public class GrailsPackageMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "package");
+ }
+}
67 src/main/java/com/octo/mtg/plugin/GrailsPackagePluginMojo.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import com.octo.mtg.plugin.tools.GrailsPluginProject;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+
+/**
+ * Packages the Grails plugin.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Packages the Grails plugin.
+ * @goal package-plugin
+ * @requiresProject true
+ * @since 0.4
+ */
+public class GrailsPackagePluginMojo extends AbstractGrailsMojo {
+
+ /**
+ * The artifact that this project procuces.
+ *
+ * @parameter expression="${project.artifact}"
+ * @required
+ * @readonly
+ */
+ private Artifact artifact;
+
+ /**
+ * The artifact handler.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.handler.ArtifactHandler#grails-plugin}"
+ * @required
+ * @readonly
+ */
+ protected ArtifactHandler artifactHandler;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ GrailsPluginProject pluginProject = getGrailsServices().readGrailsPluginProject();
+
+ getGrailsServices().launchGrails(grailsHome, env, "package-plugin");
+
+ String zipFileName = "grails-" + pluginProject.getPluginName() + "-" + pluginProject.getVersion() + ".zip";
+
+ File pluginFile = new File(basedir, zipFileName);
+ artifact.setFile(pluginFile);
+ artifact.setArtifactHandler(artifactHandler);
+ }
+}
36 src/main/java/com/octo/mtg/plugin/GrailsRunAppHttpsMojo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Runs a Grails application in Jetty with HTTPS listener.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Runs a Grails application in Jetty with HTTPS listener.
+ * @goal run-app-https
+ * @requiresProject false
+ * @since 0.3
+ */
+public class GrailsRunAppHttpsMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "run-app-https");
+ }
+}
36 src/main/java/com/octo/mtg/plugin/GrailsRunAppMojo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Runs a Grails application in Jetty.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Runs a Grails application in Jetty.
+ * @goal run-app
+ * @requiresProject false
+ * @since 0.3
+ */
+public class GrailsRunAppMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "run-app");
+ }
+}
36 src/main/java/com/octo/mtg/plugin/GrailsRunWebTestMojo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Runs all of the Web tests against a Grails application.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Runs all of the Web tests against a Grails application.
+ * @goal run-webtest
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsRunWebTestMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "run-webtest");
+ }
+}
36 src/main/java/com/octo/mtg/plugin/GrailsTestAppMojo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Runs a Grails applications unit tests and integration tests.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Runs a Grails applications unit tests and integration tests.
+ * @goal test-app
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsTestAppMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getGrailsServices().launchGrails(grailsHome, env, "test-app");
+ }
+}
36 src/main/java/com/octo/mtg/plugin/GrailsWarMojo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Creates a WAR archive.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Creates a WAR archive.
+ * @goal war
+ * @requiresProject false
+ * @since 0.1
+ */
+public class GrailsWarMojo extends AbstractGrailsMojo {
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ runGrails("war");
+ }
+}
43 src/main/java/com/octo/mtg/plugin/MvnCleanMojo.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Cleans a Grails project and jars in lib directory.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Cleans a Grails project and jars in lib directory.
+ * @goal maven-clean
+ * @phase clean
+ * @requiresProject true
+ * @requiresDependencyResolution
+ * @since 0.1
+ */
+public class MvnCleanMojo extends AbstractGrailsMojo {
+
+ /**
+ * Executes the MvnWarMojo on the current project.
+ *
+ * @throws MojoExecutionException if an error occured while building the webapp
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ runGrails("Clean");
+ }
+}
43 src/main/java/com/octo/mtg/plugin/MvnCompileMojo.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Compiles a Grails project.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Compiles a Grails project.
+ * @goal maven-compile
+ * @phase compile
+ * @requiresProject true
+ * @requiresDependencyResolution
+ * @since 0.1
+ */
+public class MvnCompileMojo extends AbstractGrailsMojo {
+
+ /**
+ * Executes the MvnWarMojo on the current project.
+ *
+ * @throws org.apache.maven.plugin.MojoExecutionException if an error occured while building the webapp
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ runGrails("Compile");
+ }
+}
74 src/main/java/com/octo/mtg/plugin/MvnConfigDirectoriesMojo.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.io.FileFilter;
+
+/**
+ * Set sources/tests directories to be compatible with the directories layout used by grails.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Set sources/tests directories to be compatible with the directories layout used by grails.
+ * @goal config-directories
+ * @phase generate-sources
+ * @since 0.3
+ */
+public class MvnConfigDirectoriesMojo extends AbstractGrailsMojo {
+
+ /*
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+// private MavenProject project;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ File projectDir = this.project.getBasedir();
+
+ // Get all the sub-directories of the "plugins" dir.
+ File pluginsDir = new File(projectDir, "plugins");
+// File[] dirs = pluginsDir.listFiles(new FileFilter() {
+// public boolean accept(File file) {
+// return file.isDirectory();
+// }
+// });
+
+ // Add the "src/java" directory in each plugin to the compiler's
+ // source.
+// for (int i = 0; i < dirs.length; i++) {
+// this.project.addCompileSourceRoot(new File(dirs[i], "src/java").getAbsolutePath());
+// }
+
+ // Add sources directories
+ this.project.addCompileSourceRoot((new File(projectDir, "src/java")).getAbsolutePath());
+ // Add tests directories
+// this.project.addTestCompileSourceRoot((new File(projectDir, "test/unit")).getAbsolutePath());
+// this.project.addTestCompileSourceRoot((new File(projectDir, "test/integration")).getAbsolutePath());
+ // Change output dir
+// this.project.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes");
+ }
+}
109 src/main/java/com/octo/mtg/plugin/MvnCopyDependenciesMojo.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Copy the POM dependencies in the lib directory of the grails project.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Copy the POM dependencies in the lib directory of the grails project.
+ * @goal copy-dependencies
+ * @phase process-resources
+ * @requiresDependencyResolution runtime
+ * @since 0.3
+ */
+public class MvnCopyDependenciesMojo extends AbstractGrailsMojo {
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getLog().info("Executing copy dependencies...");
+ File outputDir = new File(project.getBuild().getDirectory(), "grails-lib");
+
+// if (!outputDir.exists()) {
+// getLog().info("Creating '" + outputDir + "' directory for Grails JARs");
+// outputDir.mkdir();
+// }
+
+ for (Iterator it = this.project.getRuntimeArtifacts().iterator(); it.hasNext();) {
+ Artifact artifact = (Artifact) it.next();
+
+ if ("grails-plugin".equals(artifact.getType())) {
+ installGrailsPlugin(artifact);
+ } else {
+ installJarArtifact(artifact, outputDir);
+ }
+ }
+ }
+
+ private void installGrailsPlugin(Artifact artifact) throws MojoExecutionException {
+ File source = artifact.getFile();
+
+ File target = new File(new File(getBasedir(), "plugins"), source.getName());
+
+ if (target.exists() && target.lastModified() > source.lastModified()) {
+ getLog().debug("Target is newer than source, skipping " + artifact.getId() + ".");
+
+ return;
+ }
+
+ // This is a workaround the grails binary that doesn't parse command line arguments with spaces.
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+ File tmp = new File(tmpDir, source.getName());
+
+ getLog().debug("Copying the .zip file to a temporary file: '" + tmp.getAbsolutePath() + "'.");
+
+ try {
+ FileUtils.copyFileToDirectory(source, tmpDir);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to copy file from '" + source.getAbsolutePath() + "' to " +
+ "directory '" + tmpDir.getAbsolutePath() + "'.", e);
+ }
+
+ getLog().debug("Installing plugin: '" + source.getAbsolutePath() + "'.");
+
+ getGrailsServices().launchGrails(grailsHome, env, "install-plugin", new String[]{tmp.getAbsolutePath()});
+ }
+
+ private void installJarArtifact(Artifact artifact, File outputDir) throws MojoExecutionException {
+ File source = artifact.getFile();
+
+ File target = new File(outputDir, source.getName());
+
+ if (target.exists() && target.lastModified() > source.lastModified()) {
+ getLog().debug("Target is newer than source, skipping " + artifact.getId() + ".");
+
+ return;
+ }
+
+ try {
+ getLog().debug("Copying file from '" + source.getAbsolutePath() + "' to '" +
+ target.getAbsolutePath() + "'.");
+ FileUtils.copyFile(source, target);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not copy file from '" + source.getAbsolutePath() + "' to '" +
+ target.getAbsolutePath() + "'.", e);
+ }
+ }
+}
50 src/main/java/com/octo/mtg/plugin/MvnRunWebTestMojo.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2007 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.
+ */
+
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Runs all of the Web tests against a Grails application. <b> By default, this
+ * mojo used in the grails-app lifecycle is deactivated. </b>
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Runs all of the Web tests against a Grails application. By
+ * default, this mojo used in the grails-app lifecycle is
+ * deactivated.
+ * @goal maven-run-webtest
+ * @requiresProject true
+ * @since 0.3
+ */
+public class MvnRunWebTestMojo extends AbstractGrailsMojo {
+
+ /**
+ * Set this to 'true' to enable web tests. Used to enable them in an
+ * integration profile for example.
+ *
+ * @parameter expression="${grails.webtest.enable}"
+ * @since 0.3
+ */
+ private boolean enable;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (enable)
+ getGrailsServices().launchGrails(grailsHome, env, "run-webtest");
+ }
+}
78 src/main/java/com/octo/mtg/plugin/MvnTestAppMojo.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Runs a Grails applications unit tests and integration tests.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Runs a Grails applications unit tests and integration tests.
+ * @goal maven-test
+ * @phase test
+ * @requiresProject true
+ * @since 0.3
+ */
+public class MvnTestAppMojo extends AbstractGrailsMojo {
+
+ /**
+ * Set this to 'true' to bypass unit/integration tests entirely. Its use is
+ * NOT RECOMMENDED, but quite convenient on occasion.
+ *
+ * @parameter expression="${grails.test.skip}"
+ * @since 0.3
+ */
+ private boolean skip;
+
+ /**
+ * Set this to 'true' to bypass unit/integration tests entirely. Its use is
+ * NOT RECOMMENDED, but quite convenient on occasion.
+ *
+ * @parameter expression="${maven.test.skip}"
+ * @since 0.3
+ */
+ private Boolean mavenSkip;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (skip) {
+ return;
+ }
+
+ if (mavenSkip != null && mavenSkip.booleanValue()) {
+ return;
+ }
+
+ // -----------------------------------------------------------------------
+ // If the current environment is test or production, default to not run
+ // the tests
+ // -----------------------------------------------------------------------
+
+ if (mavenSkip == null && env != null) {
+ if (env.equals("test") || env.startsWith("prod")) {
+ getLog().info("Skipping tests as the current environment is set to test or production.");
+ getLog().info("Set maven.test.skip to false to prevent this behaviour");
+
+ return;
+ }
+ }
+
+// getGrailsServices().launchGrails(grailsHome, env, "test-app");
+ runGrails("TestApp", null, "test");
+ }
+}
138 src/main/java/com/octo/mtg/plugin/MvnValidateMojo.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2007 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.
+ */
+package com.octo.mtg.plugin;
+
+import com.octo.mtg.plugin.tools.GrailsPluginProject;
+import com.octo.mtg.plugin.tools.GrailsProject;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+
+/**
+ * Validate consistency between Grails and Maven settings.
+ *
+ * @author <a href="mailto:aheritier@gmail.com">Arnaud HERITIER</a>
+ * @version $Id$
+ * @description Validate consistency between Grails (application.properties) and Maven (pom.xml) settings.
+ * @goal validate
+ * @phase validate
+ * @requiresDependencyResolution runtime
+ * @since 0.1
+ */
+public class MvnValidateMojo extends AbstractGrailsMojo {
+
+ /**
+ * The artifact id of the project.
+ *
+ * @parameter expression="${project.artifactId}"
+ * @required
+ * @readonly
+ */
+ private String artifactId;
+
+ /**
+ * The packaging of the project.
+ *
+ * @parameter expression="${project.packaging}"
+ * @required
+ * @readonly
+ */
+ private String packaging;
+
+ /**
+ * The version id of the project.
+ *
+ * @parameter expression="${project.version}"
+ * @required
+ * @readonly
+ */
+ private String version;
+
+ private static final String PLUGIN_PREFIX = "grails-";
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if ("grails-plugin".equals(packaging)) {
+ validateGrailsPlugin();
+ } else {
+ validateGrailsApp();
+ }
+ }
+
+ private void validateGrailsApp() throws MojoExecutionException, MojoFailureException {
+ GrailsProject grailsProject;
+ try {
+ grailsProject = getGrailsServices().readProjectDescriptor();
+ } catch (MojoExecutionException ex) {
+ // Initialise the app.
+ getLog().info("Cannot read application info, so initialising new application.");
+ File outputDir = new File(project.getBuild().getDirectory(), "grails-lib");
+ getLog().info("Creating '" + outputDir + "' directory for Grails JARs");
+ outputDir.mkdirs();
+ runGrails("CreateApp", "--inplace --appVersion=" + version + " " + artifactId, "runtime");
+ grailsProject = getGrailsServices().readProjectDescriptor();
+ }
+
+ if (!artifactId.equals(grailsProject.getAppName())) {
+ throw new MojoFailureException("app.name [" + grailsProject.getAppName() + "] in " +
+ "application.properties is different of the artifactId [" + artifactId + "] in the pom.xml");
+ }
+
+ String pomVersion = version.trim();
+ String grailsVersion = grailsProject.getAppVersion().trim();
+
+ if (!grailsVersion.equals(pomVersion)) {
+ throw new MojoFailureException("app.version [" + grailsVersion + "] in " +
+ "application.properties is different of the version [" + pomVersion + "] in the pom.xml");
+ }
+
+ // We have to set the application version in grails settings for old versions
+ if (grailsProject.getAppVersion() == null) {
+ grailsProject.setAppVersion(GrailsProject.DEFAULT_APP_VERSION);
+ getLog().warn("application.properties didn't contain an app.version property");
+ getLog().warn("Setting to default value '" + grailsProject.getAppVersion() + "'.");
+
+ getGrailsServices().writeProjectDescriptor(getBasedir(), grailsProject);
+ }
+ }
+
+ private void validateGrailsPlugin() throws MojoExecutionException, MojoFailureException {
+
+ GrailsPluginProject project = getGrailsServices().readGrailsPluginProject();
+
+ String pluginName = project.getPluginName();
+
+ if (artifactId.equals(pluginName)) {
+ throw new MojoFailureException("The artifact id in pom.xml has to be the same as in " +
+ project.getFileName() + " prefixed with '" + PLUGIN_PREFIX + "'. This is to avoid confustion when " +
+ "the artifact is installed in the Maven repository.");
+ }
+
+ if (!artifactId.equals(PLUGIN_PREFIX + pluginName)) {
+ throw new MojoFailureException("The plugin name in [" + pluginName + "] in " + project.getFileName() +
+ " is not the expected " + PLUGIN_PREFIX + pluginName + ". Please correct the pom or the plugin " +
+ "descriptor.");
+ }
+
+ String pomVersion = version.trim();
+ String grailsVersion = project.getVersion();
+
+ if (!grailsVersion.equals(pomVersion)) {
+ throw new MojoFailureException("The version specified in the plugin configuration " +
+ "[" + grailsVersion + "] in is different of the version [