From 2308f54c1c5f3f8957151b4499751da2279653f0 Mon Sep 17 00:00:00 2001 From: pledbrook Date: Thu, 6 Nov 2008 15:32:40 +0000 Subject: [PATCH] Initial import of plugin source. git-svn-id: https://svn.codehaus.org/grails/trunk@7522 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d --- pom.xml | 356 +++++++++++++++++ .../octo/mtg/plugin/AbstractGrailsMojo.java | 335 ++++++++++++++++ .../com/octo/mtg/plugin/CreatePomMojo.java | 107 ++++++ .../com/octo/mtg/plugin/GrailsCleanMojo.java | 40 ++ .../octo/mtg/plugin/GrailsCreateAppMojo.java | 46 +++ .../plugin/GrailsCreateControllerMojo.java | 48 +++ .../plugin/GrailsCreateDomainClassMojo.java | 45 +++ .../GrailsCreateIntegrationTestMojo.java | 48 +++ .../mtg/plugin/GrailsCreateScriptMojo.java | 45 +++ .../mtg/plugin/GrailsCreateServiceMojo.java | 45 +++ .../mtg/plugin/GrailsCreateTaglibMojo.java | 44 +++ .../mtg/plugin/GrailsCreateUnitTestMojo.java | 47 +++ .../mtg/plugin/GrailsCreateWebTestMojo.java | 45 +++ .../mtg/plugin/GrailsGenerateAllMojo.java | 46 +++ .../plugin/GrailsGenerateControllerMojo.java | 44 +++ .../mtg/plugin/GrailsGenerateViewsMojo.java | 45 +++ .../plugin/GrailsInstallTemplatesMojo.java | 36 ++ .../octo/mtg/plugin/GrailsPackageMojo.java | 37 ++ .../mtg/plugin/GrailsPackagePluginMojo.java | 67 ++++ .../mtg/plugin/GrailsRunAppHttpsMojo.java | 36 ++ .../com/octo/mtg/plugin/GrailsRunAppMojo.java | 36 ++ .../octo/mtg/plugin/GrailsRunWebTestMojo.java | 36 ++ .../octo/mtg/plugin/GrailsTestAppMojo.java | 36 ++ .../com/octo/mtg/plugin/GrailsWarMojo.java | 36 ++ .../com/octo/mtg/plugin/MvnCleanMojo.java | 43 +++ .../com/octo/mtg/plugin/MvnCompileMojo.java | 43 +++ .../mtg/plugin/MvnConfigDirectoriesMojo.java | 74 ++++ .../mtg/plugin/MvnCopyDependenciesMojo.java | 109 ++++++ .../octo/mtg/plugin/MvnRunWebTestMojo.java | 50 +++ .../com/octo/mtg/plugin/MvnTestAppMojo.java | 78 ++++ .../com/octo/mtg/plugin/MvnValidateMojo.java | 138 +++++++ .../java/com/octo/mtg/plugin/MvnWarMojo.java | 100 +++++ .../java/com/octo/mtg/plugin/package.html | 49 +++ .../plugin/tools/DefaultGrailsServices.java | 362 ++++++++++++++++++ .../mtg/plugin/tools/DefaultMojoServices.java | 69 ++++ .../mtg/plugin/tools/DefaultPomServices.java | 100 +++++ .../mtg/plugin/tools/GrailsPluginProject.java | 37 ++ .../octo/mtg/plugin/tools/GrailsProject.java | 56 +++ .../octo/mtg/plugin/tools/GrailsServices.java | 128 +++++++ .../octo/mtg/plugin/tools/MojoServices.java | 36 ++ .../octo/mtg/plugin/tools/PomServices.java | 65 ++++ .../mtg/plugin/tools/RawStreamPumper.java | 108 ++++++ .../com/octo/mtg/plugin/tools/package.html | 24 ++ src/site/apt/examples/create-a-grails-app.apt | 36 ++ .../apt/examples/mavenize-a-grails-app.apt | 31 ++ src/site/apt/examples/setup-your-IDE.apt | 36 ++ src/site/apt/index.apt | 114 ++++++ src/site/apt/lifecycles.apt | 82 ++++ src/site/apt/usage.apt | 115 ++++++ src/site/fml/faq.fml | 54 +++ src/site/site.xml | 37 ++ .../com/octo/mtg/plugin/LoadMojosTest.java | 144 +++++++ .../mtg/plugin/tools/GrailsServicesTest.java | 63 +++ .../mtg/plugin/tools/PomServicesTest.java | 89 +++++ .../mtg/plugin/create-pom/plugin-config.xml | 34 ++ .../mtg/plugin/grails-clean/plugin-config.xml | 34 ++ .../grails-create-app/plugin-config.xml | 35 ++ .../plugin-config.xml | 35 ++ .../plugin-config.xml | 35 ++ .../plugin-config.xml | 35 ++ .../grails-create-script/plugin-config.xml | 35 ++ .../grails-create-service/plugin-config.xml | 35 ++ .../grails-create-taglib/plugin-config.xml | 35 ++ .../grails-create-unit-test/plugin-config.xml | 35 ++ .../grails-create-web-test/plugin-config.xml | 35 ++ .../grails-generate-all/plugin-config.xml | 35 ++ .../plugin-config.xml | 35 ++ .../grails-generate-views/plugin-config.xml | 35 ++ .../plugin-config.xml | 34 ++ .../plugin/grails-package/plugin-config.xml | 34 ++ .../grails-run-app-https/plugin-config.xml | 34 ++ .../plugin/grails-run-app/plugin-config.xml | 34 ++ .../grails-run-webtest/plugin-config.xml | 34 ++ .../plugin/grails-test-app/plugin-config.xml | 34 ++ .../mtg/plugin/grails-war/plugin-config.xml | 34 ++ .../mtg/plugin/maven-clean/plugin-config.xml | 34 ++ .../maven-copy-dependencies/plugin-config.xml | 34 ++ .../maven-run-webtest/plugin-config.xml | 34 ++ .../plugin/maven-test-app/plugin-config.xml | 34 ++ .../plugin/maven-validate/plugin-config.xml | 34 ++ .../mtg/plugin/maven-war/plugin-config.xml | 34 ++ .../com/octo/mtg/plugin/pom-services/pom.xml | 28 ++ 82 files changed, 5134 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/octo/mtg/plugin/AbstractGrailsMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/CreatePomMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCleanMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateAppMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateControllerMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateDomainClassMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateIntegrationTestMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateScriptMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateServiceMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateTaglibMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateUnitTestMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsCreateWebTestMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsGenerateAllMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsGenerateControllerMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsGenerateViewsMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsInstallTemplatesMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsPackageMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsPackagePluginMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsRunAppHttpsMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsRunAppMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsRunWebTestMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsTestAppMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/GrailsWarMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnCleanMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnCompileMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnConfigDirectoriesMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnCopyDependenciesMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnRunWebTestMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnTestAppMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnValidateMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/MvnWarMojo.java create mode 100644 src/main/java/com/octo/mtg/plugin/package.html create mode 100644 src/main/java/com/octo/mtg/plugin/tools/DefaultGrailsServices.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/DefaultMojoServices.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/DefaultPomServices.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/GrailsPluginProject.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/GrailsProject.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/GrailsServices.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/MojoServices.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/PomServices.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/RawStreamPumper.java create mode 100644 src/main/java/com/octo/mtg/plugin/tools/package.html create mode 100644 src/site/apt/examples/create-a-grails-app.apt create mode 100644 src/site/apt/examples/mavenize-a-grails-app.apt create mode 100644 src/site/apt/examples/setup-your-IDE.apt create mode 100644 src/site/apt/index.apt create mode 100644 src/site/apt/lifecycles.apt create mode 100644 src/site/apt/usage.apt create mode 100644 src/site/fml/faq.fml create mode 100644 src/site/site.xml create mode 100644 src/test/java/com/octo/mtg/plugin/LoadMojosTest.java create mode 100644 src/test/java/com/octo/mtg/plugin/tools/GrailsServicesTest.java create mode 100644 src/test/java/com/octo/mtg/plugin/tools/PomServicesTest.java create mode 100644 src/test/resources/com/octo/mtg/plugin/create-pom/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-clean/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-app/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-controller/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-domain-class/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-integration-test/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-script/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-service/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-taglib/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-unit-test/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-create-web-test/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-generate-all/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-generate-controller/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-generate-views/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-install-templates/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-package/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-run-app-https/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-run-app/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-run-webtest/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-test-app/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/grails-war/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/maven-clean/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/maven-copy-dependencies/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/maven-run-webtest/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/maven-test-app/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/maven-validate/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/maven-war/plugin-config.xml create mode 100644 src/test/resources/com/octo/mtg/plugin/pom-services/pom.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..dea941a --- /dev/null +++ b/pom.xml @@ -0,0 +1,356 @@ + + + + 4.0.0 + org.grails + grails-maven-plugin + 0.4-SNAPSHOT + maven-plugin + Maven plugin for GRAILS applications + This plugin allows you to integrate GRAILS applications into maven 2 builds. + http://forge.octo.com/maven/sites/mtg/grails-maven-plugin + + + codehaus.org + Grails Main Repository + dav:https://dav.codehaus.org/repository/grails + + + codehaus.org + Grails Snapshots Repository + dav:https://dav.codehaus.org/snapshots.repository/grails + + + + 2.0.5 + + + + org.apache.maven + maven-model + 2.0.7 + + + org.apache.maven + maven-project + 2.0.7 + + + org.apache.maven + maven-plugin-api + 2.0.7 + + + org.apache.maven + maven-archiver + 2.2 + + + org.codehaus.plexus + plexus-utils + 1.4.5 + + + org.codehaus.groovy + groovy + 1.5.7 + + + junit + junit + 3.8.2 + test + + + org.apache.maven.shared + maven-plugin-testing-harness + 1.1 + test + + + xmlunit + xmlunit + 1.0 + test + + + org.grails + grails-bootstrap + 1.1-SNAPSHOT + runtime + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + + generated-helpmojo + + helpmojo + + + + + + org.codehaus.plexus + plexus-maven-plugin + + + generate + + descriptor + + process-sources + + ${project.build.directory}/generated-resources/plexus + + + + merge + + merge-descriptors + + + + ${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml + + + + + + + org.apache.maven.plugins + maven-docck-plugin + + + pre-site + + check + + + + + + + + + + maven-project-info-reports-plugin + 2.0.1 + + + maven-plugin-plugin + 2.4.1 + + + org.codehaus.plexus + plexus-maven-plugin + 1.3.5 + + + maven-javadoc-plugin + 2.4 + + + + plexus.component + a + This class is a plexus component + + + component + a + This property is a component injected by plexus. + + + readonly + a + The user cannot override this property from the command line. + + + description + a + Description : + + + requiresProject + a + This Mojo needs to be launched in a maven 2 project + + + goal + a + The goal name for the Mojo : + + + + + + maven-jxr-plugin + 2.1 + + + maven-changelog-plugin + 2.1 + + + maven-surefire-report-plugin + 2.4.3 + + + maven-checkstyle-plugin + 2.1 + + + maven-pmd-plugin + 2.2 + + true + 20 + 1.4 + + + + org.codehaus.mojo + findbugs-maven-plugin + 1.1.1 + + + org.codehaus.mojo + rat-maven-plugin + 1.0-alpha-3 + + + **/it/** + + + + + + + + integration-tests + + + integration-tests + true + + + + + + org.codehaus.mojo + shitty-maven-plugin + + + + clean + install + test + + + + + src/it + + ${includeITs} + + + ${excludeITs} + + + + true + 2 + -DgrailsHome-0.5.6=${grailsHome-0.5.6} -DgrailsHome-0.6=${grailsHome-0.6} + + + + + + + + + + false + + codehaus.snapshots + http://snapshots.repository.codehaus.org/ + + + + + + false + + codehaus.snapshots + http://snapshots.repository.codehaus.org/ + + + + **/pom4test.xml + **/run-webtest/pom4test.xml + + + + release + + + + org.codehaus.mojo + rat-maven-plugin + + + verify + + check + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + + + + diff --git a/src/main/java/com/octo/mtg/plugin/AbstractGrailsMojo.java b/src/main/java/com/octo/mtg/plugin/AbstractGrailsMojo.java new file mode 100644 index 0000000..58bc135 --- /dev/null +++ b/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 Arnaud HERITIER + * @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(); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/CreatePomMojo.java b/src/main/java/com/octo/mtg/plugin/CreatePomMojo.java new file mode 100644 index 0000000..a82065d --- /dev/null +++ b/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 Arnaud HERITIER + * @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)); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCleanMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCleanMojo.java new file mode 100644 index 0000000..13aa36a --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateAppMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateAppMojo.java new file mode 100644 index 0000000..cdb36d6 --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateControllerMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateControllerMojo.java new file mode 100644 index 0000000..5b26fe9 --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateDomainClassMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateDomainClassMojo.java new file mode 100644 index 0000000..91992ba --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateIntegrationTestMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateIntegrationTestMojo.java new file mode 100644 index 0000000..c5f12c1 --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateScriptMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateScriptMojo.java new file mode 100644 index 0000000..2533be8 --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateServiceMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateServiceMojo.java new file mode 100644 index 0000000..4506085 --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateTaglibMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateTaglibMojo.java new file mode 100644 index 0000000..28ccee1 --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateUnitTestMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateUnitTestMojo.java new file mode 100644 index 0000000..5c2bc42 --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsCreateWebTestMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsCreateWebTestMojo.java new file mode 100644 index 0000000..1ef8e8f --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsGenerateAllMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsGenerateAllMojo.java new file mode 100644 index 0000000..d86416b --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsGenerateControllerMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsGenerateControllerMojo.java new file mode 100644 index 0000000..9cfaa21 --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsGenerateViewsMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsGenerateViewsMojo.java new file mode 100644 index 0000000..240808a --- /dev/null +++ b/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 Arnaud HERITIER + * @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}); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsInstallTemplatesMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsInstallTemplatesMojo.java new file mode 100644 index 0000000..9ca4c8c --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsPackageMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsPackageMojo.java new file mode 100644 index 0000000..d14170b --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsPackagePluginMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsPackagePluginMojo.java new file mode 100644 index 0000000..4415021 --- /dev/null +++ b/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 Arnaud HERITIER + * @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); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsRunAppHttpsMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsRunAppHttpsMojo.java new file mode 100644 index 0000000..aca842c --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsRunAppMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsRunAppMojo.java new file mode 100644 index 0000000..666db44 --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsRunWebTestMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsRunWebTestMojo.java new file mode 100644 index 0000000..a4c4b1f --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsTestAppMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsTestAppMojo.java new file mode 100644 index 0000000..65d9b78 --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/GrailsWarMojo.java b/src/main/java/com/octo/mtg/plugin/GrailsWarMojo.java new file mode 100644 index 0000000..5e378cf --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnCleanMojo.java b/src/main/java/com/octo/mtg/plugin/MvnCleanMojo.java new file mode 100644 index 0000000..0f13cd9 --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnCompileMojo.java b/src/main/java/com/octo/mtg/plugin/MvnCompileMojo.java new file mode 100644 index 0000000..0df82c8 --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnConfigDirectoriesMojo.java b/src/main/java/com/octo/mtg/plugin/MvnConfigDirectoriesMojo.java new file mode 100644 index 0000000..0f726fe --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnCopyDependenciesMojo.java b/src/main/java/com/octo/mtg/plugin/MvnCopyDependenciesMojo.java new file mode 100644 index 0000000..037b16a --- /dev/null +++ b/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 Arnaud HERITIER + * @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); + } + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnRunWebTestMojo.java b/src/main/java/com/octo/mtg/plugin/MvnRunWebTestMojo.java new file mode 100644 index 0000000..c34c532 --- /dev/null +++ b/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. By default, this + * mojo used in the grails-app lifecycle is deactivated. + * + * @author Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnTestAppMojo.java b/src/main/java/com/octo/mtg/plugin/MvnTestAppMojo.java new file mode 100644 index 0000000..f996111 --- /dev/null +++ b/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 Arnaud HERITIER + * @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"); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnValidateMojo.java b/src/main/java/com/octo/mtg/plugin/MvnValidateMojo.java new file mode 100644 index 0000000..ad1e57b --- /dev/null +++ b/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 Arnaud HERITIER + * @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 [" + pomVersion + "] in the pom.xml"); + } + } +} diff --git a/src/main/java/com/octo/mtg/plugin/MvnWarMojo.java b/src/main/java/com/octo/mtg/plugin/MvnWarMojo.java new file mode 100644 index 0000000..b61f0d9 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/MvnWarMojo.java @@ -0,0 +1,100 @@ +/* + * 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 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; + +/** + * Creates a WAR archive and register it in maven. + * + * @author Arnaud HERITIER + * @version $Id$ + * @description Creates a WAR archive and register it in maven. + * @goal maven-war + * @phase package + * @requiresDependencyResolution + * @since 0.1 + */ +public class MvnWarMojo extends AbstractGrailsMojo { + + /** + * The maven artifact. + * + * @parameter expression="${project.artifact}" + * @required + * @readonly + */ + private Artifact artifact; + + /** + * The build directory. The WAR file will end up here. + * + * @parameter expression="${project.build.directory}" + * @required + * @readonly + */ + private File buildDirectory; + + /** + * The final name of the artifact without the extension. + * + * @parameter expression="${project.build.finalName}" + * @required + * @readonly + */ + private String finalName; + + /** + * The artifact handler. + * + * @parameter expression="${component.org.apache.maven.artifact.handler.ArtifactHandler#grails-app}" + * @required + * @readonly + */ + protected ArtifactHandler artifactHandler; + + /** + * Executes the MvnWarMojo on the current project. + * + * @throws MojoExecutionException if an error occured while building the webapp + */ + public void execute() throws MojoExecutionException, MojoFailureException { + runGrails("War"); +// GrailsProject grailsProject = getGrailsServices().readProjectDescriptor(); +// +// getGrailsServices().launchGrails(grailsHome, env, "war"); +// String warFileName = grailsProject.getAppName() + "-" + grailsProject.getAppVersion() + ".war"; +// File warGeneratedByGrails = new File(getBasedir(), warFileName); +// +// if (!buildDirectory.isDirectory() && !buildDirectory.mkdirs()) { +// throw new MojoExecutionException("Unable to create directory: " + buildDirectory.getAbsolutePath()); +// } +// +// File mavenWarFile = new File(buildDirectory, finalName + ".war"); +// mavenWarFile.delete(); +// if (!warGeneratedByGrails.renameTo(mavenWarFile)) { +// throw new MojoExecutionException("Unable to copy the war in the target directory"); +// } +// artifact.setFile(mavenWarFile); +// artifact.setArtifactHandler(artifactHandler); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/package.html b/src/main/java/com/octo/mtg/plugin/package.html new file mode 100644 index 0000000..4e6ab98 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/package.html @@ -0,0 +1,49 @@ + + + + + + +Provides MOJOs used in grails-maven-plugin. + +

Related Documentation

+ +For overviews, tutorials, examples, guides, and tool documentation, +please see: + + +

Technical Notes

+ +

Grails*Mojo are calling grails and don't require a POM to work.

+

Mvn*Mojo require a POM.

+ + +@since 0.1 + + diff --git a/src/main/java/com/octo/mtg/plugin/tools/DefaultGrailsServices.java b/src/main/java/com/octo/mtg/plugin/tools/DefaultGrailsServices.java new file mode 100644 index 0000000..2e3ade8 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/DefaultGrailsServices.java @@ -0,0 +1,362 @@ +/* + * 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.tools; + +import groovy.lang.GroovyClassLoader; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.cli.CommandLineException; +import org.codehaus.plexus.util.cli.Commandline; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.groovy.tools.RootLoader; + +import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; +import java.net.URL; + +/** + * @author Arnaud HERITIER + * @version $Id$ + * @plexus.component role="com.octo.mtg.plugin.tools.GrailsServices" + * @since 0.1 + */ +public class DefaultGrailsServices extends AbstractLogEnabled implements GrailsServices { + + private static final String FILE_SUFFIX = "GrailsPlugin.groovy"; + + /** + * @plexus.requirement + */ + private PomServices pomServices; + + /** + * @plexus.requirement + */ + private MojoServices mojoServices; + + private File _basedir; + private List _dependencyPaths; + + /** + * 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') { + getLogger().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') { + getLogger().warn(buffer.toString()); + buffer.setLength(0); + } else { + buffer.append((char) b); + } + } + }; + + private File getBasedir() { + if (_basedir != null) { + return _basedir; + } + + throw new RuntimeException("The basedir has to be set before any of the service methods are invoked."); + } + + // ----------------------------------------------------------------------- + // GrailsServices Implementation + // ----------------------------------------------------------------------- + + public void setBasedir(File basedir) { + this._basedir = basedir; + } + + public void setDependencies(List deps) { + this._dependencyPaths = deps; + } + + public MavenProject createPOM(String groupId, GrailsProject grailsProjectDescriptor, String mtgGroupId, + String grailsPluginArtifactId, String mtgVersion) { + return createPOM(groupId, grailsProjectDescriptor, mtgGroupId, grailsPluginArtifactId, mtgVersion, false); + } + + public MavenProject createPOM(String groupId, GrailsProject grailsProjectDescriptor, String mtgGroupId, + String grailsPluginArtifactId, String mtgVersion, boolean addEclipseSettings) { + MavenProject pom = new MavenProject(); + if (pom.getBuild().getPluginManagement() == null) { + pom.getBuild().setPluginManagement(new PluginManagement()); + } + PluginManagement pluginMgt = pom.getPluginManagement(); + + // Those four properties are needed. + pom.setModelVersion("4.0.0"); + pom.setPackaging("grails-app"); + // Specific for GRAILS + pom.getModel().getProperties().setProperty("grailsHome", "${env.GRAILS_HOME}"); + pom.getModel().getProperties().setProperty("grailsVersion", grailsProjectDescriptor.getAppGrailsVersion()); + // Add our own plugin + Plugin grailsPlugin = new Plugin(); + grailsPlugin.setGroupId(mtgGroupId); + grailsPlugin.setArtifactId(grailsPluginArtifactId); + grailsPlugin.setVersion(mtgVersion); + grailsPlugin.setExtensions(true); + pom.addPlugin(grailsPlugin); + // Add compiler plugin settings + Plugin compilerPlugin = new Plugin(); + compilerPlugin.setGroupId("org.apache.maven.plugins"); + compilerPlugin.setArtifactId("maven-compiler-plugin"); + Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); + Xpp3Dom source = new Xpp3Dom("source"); + source.setValue("1.5"); + compilerConfig.addChild(source); + Xpp3Dom target = new Xpp3Dom("target"); + target.setValue("1.5"); + compilerConfig.addChild(target); + compilerPlugin.setConfiguration(compilerConfig); + pom.addPlugin(compilerPlugin); + // Add eclipse plugin settings + if (addEclipseSettings) { + Plugin warPlugin = new Plugin(); + warPlugin.setGroupId("org.apache.maven.plugins"); + warPlugin.setArtifactId("maven-war-plugin"); + Xpp3Dom warConfig = new Xpp3Dom("configuration"); + Xpp3Dom warSourceDirectory = new Xpp3Dom("warSourceDirectory"); + warSourceDirectory.setValue("web-app"); + warConfig.addChild(warSourceDirectory); + warPlugin.setConfiguration(warConfig); + pluginMgt.addPlugin(warPlugin); + + Plugin eclipsePlugin = new Plugin(); + eclipsePlugin.setGroupId("org.apache.maven.plugins"); + eclipsePlugin.setArtifactId("maven-eclipse-plugin"); + Xpp3Dom configuration = new Xpp3Dom("configuration"); + Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); + Xpp3Dom projectnature = new Xpp3Dom("projectnature"); + projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); + projectnatures.addChild(projectnature); + configuration.addChild(projectnatures); + Xpp3Dom additionalBuildcommands = new Xpp3Dom( + "additionalBuildcommands"); + Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); + buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); + additionalBuildcommands.addChild(buildcommand); + configuration.addChild(additionalBuildcommands); + // Xpp3Dom additionalProjectFacets = new Xpp3Dom( + // "additionalProjectFacets"); + // Xpp3Dom jstWeb = new Xpp3Dom("jst.web"); + // jstWeb.setValue("2.5"); + // additionalProjectFacets.addChild(jstWeb); + // configuration.addChild(additionalProjectFacets); + Xpp3Dom packaging = new Xpp3Dom("packaging"); + packaging.setValue("war"); + configuration.addChild(packaging); + + eclipsePlugin.setConfiguration(configuration); + pluginMgt.addPlugin(eclipsePlugin); + } + // Change the default output directory to generate classes + pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); + + pom.setArtifactId(grailsProjectDescriptor.getAppName()); + pom.setName(grailsProjectDescriptor.getAppName()); + pom.setGroupId(groupId); + pom.setVersion(grailsProjectDescriptor.getAppVersion()); + if (!grailsProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { + getLogger().warn("====================================================================="); + getLogger().warn("If your project is currently in development, in accordance with maven "); + getLogger().warn("standards, its version must be " + grailsProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + grailsProjectDescriptor.getAppVersion() + "."); + getLogger().warn("Please, change your version in the application.properties descriptor"); + getLogger().warn("and regenerate your pom."); + getLogger().warn("====================================================================="); + } + return pom; + } + + public GrailsProject readProjectDescriptor() throws MojoExecutionException { + // Load existing Grails properties + FileInputStream fis = null; + try { + Properties properties = new Properties(); + fis = new FileInputStream(new File(getBasedir(), "application.properties")); + properties.load(fis); + + GrailsProject grailsProject = new GrailsProject(); + grailsProject.setAppGrailsVersion(properties.getProperty("app.grails.version")); + grailsProject.setAppName(properties.getProperty("app.name")); + grailsProject.setAppVersion(properties.getProperty("app.version")); + + return grailsProject; + } catch (IOException e) { + throw new MojoExecutionException("Unable to read grails project descriptor.", e); + } finally { + IOUtil.close(fis); + } + } + + public void writeProjectDescriptor(File projectDir, GrailsProject grailsProjectDescriptor) throws MojoExecutionException { + String description = "Grails Descriptor updated by grails-maven-plugin on " + new Date(); + + FileOutputStream fos = null; + try { + fos = new FileOutputStream(new File(projectDir, "application.properties")); + Properties properties = new Properties(); + properties.setProperty("app.grails.version", grailsProjectDescriptor.getAppGrailsVersion()); + properties.setProperty("app.name", grailsProjectDescriptor.getAppName()); + properties.setProperty("app.version", grailsProjectDescriptor.getAppVersion()); + properties.store(fos, description); + } catch (IOException e) { + throw new MojoExecutionException("Unable to write grails project descriptor.", e); + } finally { + IOUtil.close(fos); + } + } + + public GrailsPluginProject readGrailsPluginProject() throws MojoExecutionException { + GrailsPluginProject pluginProject = new GrailsPluginProject(); + + File[] files = getBasedir().listFiles(new FilenameFilter() { + public boolean accept(File file, String s) { + return s.endsWith(FILE_SUFFIX) && s.length() > FILE_SUFFIX.length(); + } + }); + + if(files == null || files.length != 1) { + throw new MojoExecutionException("Could not find a plugin descriptor. Expected to find exactly one file " + + "called FooGrailsPlugin.groovy in '" + getBasedir().getAbsolutePath() + "'."); + } + + File descriptor = files[0]; + + String pluginName = descriptor.getName().substring(0, descriptor.getName().length() - FILE_SUFFIX.length()); + pluginName = pluginName.substring(0, 1).toLowerCase() + pluginName.substring(1); + + pluginProject.setPluginName(pluginName); + + try { + GroovyClassLoader classLoader = new GroovyClassLoader(); + Class clazz = classLoader.parseClass(descriptor); + Object instance = clazz.newInstance(); + + Object o = clazz.getMethod("getVersion", new Class[]{}).invoke(instance, new Object[]{}); + + if (o == null) { + throw new MojoExecutionException("getVersion() returned null!"); + } + + pluginProject.setVersion(o.toString()); + } catch (IOException e) { + throw new MojoExecutionException("Error reading groovy file.", e); + } catch (InstantiationException e) { + throw new MojoExecutionException("Unable to create a new instance of the plugin configuration.", e); + } catch (NoSuchMethodException e) { + throw new MojoExecutionException("Unable to call getVersion() on the plugin configuration.", e); + } catch (InvocationTargetException e) { + throw new MojoExecutionException("Unable to call getVersion() on the plugin configuration.", e); + } catch (IllegalAccessException e) { + throw new MojoExecutionException("Unable to call getVersion() on the plugin configuration.", e); + } + return pluginProject; + } + + /** + * Launch a GRAILS commandLine with a target and no parameter. + * + * @param targetName the grails target to call + * @throws CommandLineException If a problem occurs to call Grails. + */ + public void launchGrails(String grailsHome, String env, String targetName) throws MojoExecutionException { + launchGrails(grailsHome, env, targetName, null); + } + + /** + * Launch a GRAILS commandLine with a target and its parameters. + * + * @param targetName the grails target to call + * @param targetParams the target parameters + * @throws CommandLineException If a problem occurs to call Grails. + */ + public void launchGrails(String grailsHome, String env, String targetName, String[] targetParams) + throws MojoExecutionException { + Commandline cmd = new Commandline(); + try { + cmd.addSystemEnvironment(); + } catch (Exception e1) { + getLogger().warn("Unable to use system environment variables to launch Grails", e1); + } + + getLogger().debug("Setting environment variable GRAILS_HOME to '" + grailsHome + "'."); +// cmd.addEnvironment("GRAILS_HOME", grailsHome); + + getLogger().debug("Working directory " + getBasedir() + "'."); + cmd.setWorkingDirectory(getBasedir()); + + cmd.setExecutable("java"); + + // 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); + } + } + + cmd.createArg().setValue(targetName); + if (targetParams != null) { + for (int i = 0; i < targetParams.length; i++) { + if (targetParams[i] != null) + cmd.createArg().setValue(targetParams[i]); + } + } + + try { + getLogger().debug("Command line: " + cmd.toString()); + int returnCode = mojoServices.executeCommandLine(cmd, System.in, infoOutputStream, warnOutputStream); + getLogger().debug("Grails ended with the return code: " + returnCode); + if (returnCode != 0) { + throw new MojoExecutionException("Grails ended with a non null return code: " + returnCode); + } + } catch (CommandLineException e) { + throw new MojoExecutionException("Unable to execute grails", e); + } + } +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/DefaultMojoServices.java b/src/main/java/com/octo/mtg/plugin/tools/DefaultMojoServices.java new file mode 100644 index 0000000..311a10a --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/DefaultMojoServices.java @@ -0,0 +1,69 @@ +/* + * 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.tools; + +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.cli.CommandLineException; +import org.codehaus.plexus.util.cli.Commandline; + +import java.io.InputStream; +import java.io.OutputStream; + +/** + * @author Arnaud HERITIER + * @version $Id$ + * @plexus.component role="com.octo.mtg.plugin.tools.MojoServices" + */ +public class DefaultMojoServices extends AbstractLogEnabled implements MojoServices { + + public int executeCommandLine(Commandline cl, InputStream systemIn, OutputStream systemOut, OutputStream systemErr) + throws CommandLineException { + if (cl == null) { + throw new IllegalArgumentException("cl cannot be null."); + } + + Process p = cl.execute(); + RawStreamPumper inputFeeder = null; + if (systemIn != null) { + inputFeeder = new RawStreamPumper(systemIn, p.getOutputStream()); + } + RawStreamPumper outputPumper = new RawStreamPumper(p.getInputStream(), systemOut); + RawStreamPumper errorPumper = new RawStreamPumper(p.getErrorStream(), systemErr); + if (inputFeeder != null) { + inputFeeder.start(); + } + outputPumper.start(); + errorPumper.start(); + try { + int returnValue = p.waitFor(); + if (inputFeeder != null) { + inputFeeder.setDone(); + } + outputPumper.setDone(); + errorPumper.setDone(); + + return returnValue; + } catch (InterruptedException ex) { + throw new CommandLineException("Error while executing external command, process killed.", ex); + } finally { + errorPumper.closeInput(); + outputPumper.closeInput(); + if (inputFeeder != null) { + inputFeeder.closeOutput(); + } + } + } +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/DefaultPomServices.java b/src/main/java/com/octo/mtg/plugin/tools/DefaultPomServices.java new file mode 100644 index 0000000..d685623 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/DefaultPomServices.java @@ -0,0 +1,100 @@ +/* + * 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.tools; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.WriterFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +/** + * POMs utilities. + * + * @author Arnaud HERITIER + * @version $Id$ + * @plexus.component role="com.octo.mtg.plugin.tools.PomServices" + */ +public class DefaultPomServices extends AbstractLogEnabled implements PomServices { + + private File b; + + public void setBasedir(File basedir) { + this.b = basedir; + } + + public Dependency createDependency(String groupId, String artifactId, String version, String type, String scope) { + Dependency dep = new Dependency(); + dep.setGroupId(groupId); + dep.setArtifactId(artifactId); + dep.setVersion(version); + dep.setType(type); + dep.setScope(scope); + + return dep; + } + + public MavenProject read(File projectDirectory) throws XmlPullParserException, IOException { + MavenXpp3Reader reader = new MavenXpp3Reader(); + + return new MavenProject(reader.read(new FileReader(new File(projectDirectory, "pom.xml")))); + } + + public void write(MavenProject project) throws MojoExecutionException { + // MavenXpp3Writer pomWriter = new MavenXpp3Writer(); + Writer writer = null; + Writer tempOutput = null; + try { + // temporary hack to add namespace declaration, not + // supported by modello/MavenXpp3Writer + // MavenXpp3Writer doesn't support writing the xsd + // declaration, do it manually + tempOutput = new StringWriter(); + project.writeModel(tempOutput); + // pomWriter.write(tempOutput, pom); + String pomString = tempOutput.toString(); + pomString = StringUtils.replaceOnce(pomString, "", + ""); + writer = WriterFactory.newXmlWriter(new File(getBasedir(), "pom.xml")); + writer.write(pomString); + } catch (IOException e) { + throw new MojoExecutionException("Unable to create the pom : " + e.getMessage(), e); + } finally { + IOUtil.close(tempOutput); + IOUtil.close(writer); + } + } + + private File getBasedir() { + if (b != null) { + return b; + } + + throw new RuntimeException("The basedir has to be set before any of the service methods are invoked."); + } +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/GrailsPluginProject.java b/src/main/java/com/octo/mtg/plugin/tools/GrailsPluginProject.java new file mode 100644 index 0000000..92f925a --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/GrailsPluginProject.java @@ -0,0 +1,37 @@ +package com.octo.mtg.plugin.tools; + +import java.io.File; + +/** + * @author Trygve Laugstøl + * @version $Id$ + */ +public class GrailsPluginProject { + private String pluginName; + private File fileName; + private String version; + + public String getPluginName() { + return pluginName; + } + + public void setPluginName(String pluginName) { + this.pluginName = pluginName; + } + + public File getFileName() { + return fileName; + } + + public void setFileName(File fileName) { + this.fileName = fileName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/GrailsProject.java b/src/main/java/com/octo/mtg/plugin/tools/GrailsProject.java new file mode 100644 index 0000000..206fd15 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/GrailsProject.java @@ -0,0 +1,56 @@ +/* + * 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.tools; + +/** + * @author Arnaud HERITIER + * @version $Id$ + */ +public class GrailsProject { + + private String appGrailsVersion; + private String appName; + private String appVersion; + + /** + * The default value for app.version when it's not defined in older grails versions. + */ + public static final String DEFAULT_APP_VERSION = "1.0-SNAPSHOT"; + + public String getAppGrailsVersion() { + return appGrailsVersion; + } + + public void setAppGrailsVersion(String appGrailsVersion) { + this.appGrailsVersion = appGrailsVersion; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getAppVersion() { + return appVersion; + } + + public void setAppVersion(String appVersion) { + this.appVersion = appVersion; + } +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/GrailsServices.java b/src/main/java/com/octo/mtg/plugin/tools/GrailsServices.java new file mode 100644 index 0000000..c708818 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/GrailsServices.java @@ -0,0 +1,128 @@ +/* + * 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.tools; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.cli.CommandLineException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +public interface GrailsServices { + + /** + * Sets the basedir that all commands are executed from + * + * @since 0.3 + */ + void setBasedir(File basedir); + + void setDependencies(List deps); + + /** + * Create a pom from a grails project. + * + * @param newProjectGroupId + * The groupId to identify the project + * @param grailsProjectDescriptor + * The Grails project descriptor + * @param mtgGroupId + * The groupId of the plugin + * @param mtgArtifactId + * The artifactId of the plugin + * @param grailsVersion + * The grails version used by the application + * @return a maven's POM + * @since 0.1 + */ + MavenProject createPOM(String newProjectGroupId, GrailsProject grailsProjectDescriptor, + String mtgGroupId, String mtgArtifactId, String grailsVersion); + + /** + * Create a pom from a grails project. + * + * @param newProjectGroupId + * The groupId to identify the project + * @param grailsProjectDescriptor + * The Grails project descriptor + * @param mtgGroupId + * The groupId of the plugin + * @param mtgArtifactId + * The artifactId of the plugin + * @param grailsVersion + * The grails version used by the application + * @param addEclipseSettings + * Activate or not the generation of the entry to configure + * the eclipse plugin + * @return a maven's POM + * @since 0.3 + */ + MavenProject createPOM(String newProjectGroupId, GrailsProject grailsProjectDescriptor, String mtgGroupId, + String mtgArtifactId, String grailsVersion, boolean addEclipseSettings); + + /** + * Read a grails project descriptor (application.properties) from a file. + * + * @return A Grails Project Descriptor + * @throws Exception + * if a problem occurs + */ + GrailsProject readProjectDescriptor() throws MojoExecutionException; + + /** + * Write a grails project descriptor (application.properties) in a file. + * + * @param projectDir + * The Grails project directory. + * @param grailsProjectDescriptor + * The descriptor to write. + * @throws FileNotFoundException + * If the project directory isn't found. + * @throws IOException + * If a problem occurs during the write. + */ + void writeProjectDescriptor(File projectDir, GrailsProject grailsProjectDescriptor) + throws MojoExecutionException; + + GrailsPluginProject readGrailsPluginProject() throws MojoExecutionException; + + /** + * Launch a GRAILS commandLine with a target and no parameter. + * + * @param targetName + * the grails target to call + * @throws CommandLineException + * If a problem occurs to call Grails. + */ + void launchGrails(String grailsHome, String env, String targetName) + throws MojoExecutionException; + + /** + * Launch a GRAILS commandLine with a target and its parameters. + * + * @param targetName + * the grails target to call + * @param targetParams + * the target parameters + * @throws CommandLineException + * If a problem occurs to call Grails. + */ + void launchGrails(String grailsHome, String env, String targetName, String[] targetParams) + throws MojoExecutionException; +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/MojoServices.java b/src/main/java/com/octo/mtg/plugin/tools/MojoServices.java new file mode 100644 index 0000000..30f040d --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/MojoServices.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.tools; + +import org.codehaus.plexus.util.cli.CommandLineException; +import org.codehaus.plexus.util.cli.Commandline; + +import java.io.InputStream; +import java.io.OutputStream; + +public interface MojoServices { + + /** + * @param cl + * @param systemIn + * @param systemOut + * @param systemErr + * @return + * @throws CommandLineException + */ + public int executeCommandLine(Commandline cl, InputStream systemIn, OutputStream systemOut, OutputStream systemErr) + throws CommandLineException; +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/PomServices.java b/src/main/java/com/octo/mtg/plugin/tools/PomServices.java new file mode 100644 index 0000000..3134ac9 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/PomServices.java @@ -0,0 +1,65 @@ +/* + * 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.tools; + +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; + +public interface PomServices { + + /** + * Sets the basedir that all commands are executed from + * + * @since 0.3 + */ + void setBasedir(File basedir); + + /** + * @param groupId + * @param artifactId + * @param version + * @param type + * @param scope + * @return + */ + public Dependency createDependency(String groupId, String artifactId, String version, String type, String scope); + + /** + * Read a maven pom from a file. + * + * @param projectDirectory + * The parent directory where the pom must be write + * @return A POM for maven + * @throws Exception + * if a problem occurs + */ + public MavenProject read(File projectDirectory) throws XmlPullParserException, IOException; + + /** + * Write a maven POM in a file. + * + * @param project + * The pom to write + * @throws Exception + * If a problem occurs + */ + public void write(MavenProject project) throws MojoExecutionException; +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/RawStreamPumper.java b/src/main/java/com/octo/mtg/plugin/tools/RawStreamPumper.java new file mode 100644 index 0000000..7f4bb42 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/RawStreamPumper.java @@ -0,0 +1,108 @@ +package com.octo.mtg.plugin.tools; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.codehaus.plexus.util.IOUtil; + +import java.io.InputStream; +import java.io.OutputStream; + +public class RawStreamPumper extends Thread { + byte buffer[] = new byte[256]; + + boolean done; + + private InputStream in; + + private OutputStream out; + + boolean poll; + + public RawStreamPumper(InputStream in, OutputStream out) { + + this.in = in; + this.out = out; + this.poll = false; + + } + + public RawStreamPumper(InputStream in, OutputStream out, boolean poll) { + + this.in = in; + this.out = out; + this.poll = poll; + + } + + public void closeInput() { + + IOUtil.close(in); + + } + + public void closeOutput() { + + IOUtil.close(out); + + } + + public void run() { + + try { + if (poll) { + while (!done) { + if (in.available() > 0) { + int i = in.read(buffer); + if (i != -1) { + out.write(buffer, 0, i); + out.flush(); + } else { + done = true; + } + } else { + Thread.sleep(1); + } + } + } else { + int i = in.read(buffer); + while (i != -1 && !done) { + if (i != -1) { + out.write(buffer, 0, i); + out.flush(); + } else { + done = true; + } + i = in.read(buffer); + } + } + } catch (Throwable e) { + // Catched everything + } finally { + done = true; + } + + } + + public void setDone() { + + done = true; + + } +} diff --git a/src/main/java/com/octo/mtg/plugin/tools/package.html b/src/main/java/com/octo/mtg/plugin/tools/package.html new file mode 100644 index 0000000..b7eebf5 --- /dev/null +++ b/src/main/java/com/octo/mtg/plugin/tools/package.html @@ -0,0 +1,24 @@ + + + + + + +Provides services reused in MOJOs. +@since 0.3 + + diff --git a/src/site/apt/examples/create-a-grails-app.apt b/src/site/apt/examples/create-a-grails-app.apt new file mode 100644 index 0000000..aedb975 --- /dev/null +++ b/src/site/apt/examples/create-a-grails-app.apt @@ -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. +~~ + + ------ + Create a GRAILS Project + ------ + Arnaud HERITIER + ------ + July 23, 2007 + +How can I create a grails application from Maven ? + + Just by launching : + ++------+ + mvn grails:create-app ++------+ + + <> + +Why didn't you deliver an archetype for Grails applications ? + + Because Grails evolves really quickly and it could be a big consumption of time to maintain this artifact for each new release of Grails. \ No newline at end of file diff --git a/src/site/apt/examples/mavenize-a-grails-app.apt b/src/site/apt/examples/mavenize-a-grails-app.apt new file mode 100644 index 0000000..df51ec9 --- /dev/null +++ b/src/site/apt/examples/mavenize-a-grails-app.apt @@ -0,0 +1,31 @@ +~~ +~~ 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. +~~ + + ------ + Create a GRAILS Project + ------ + Arnaud HERITIER + ------ + August 19, 2007 + +How can I <"mavenize"> a newly created project or an existing one ? + + To <"mavenize"> a Grails project you have to create in its root directory a POM. + To ease this step we created a goal to create it for you. You just have to define a groupId for your project. + ++-------------------------------------------------------------------+ +mvn grails:create-pom -DgroupId=com.mycompany ++-------------------------------------------------------------------+ \ No newline at end of file diff --git a/src/site/apt/examples/setup-your-IDE.apt b/src/site/apt/examples/setup-your-IDE.apt new file mode 100644 index 0000000..5f66f79 --- /dev/null +++ b/src/site/apt/examples/setup-your-IDE.apt @@ -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. +~~ + + ------ + Setup the project in the IDE + ------ + Arnaud HERITIER + ------ + October 15, 2007 + +Setting up your grails project in your IDE + + The plugin ease the integration of your project in your IDE using maven dedicated plugins. + + * Eclipse + + The grails:create-app mojo can generate the necessary configuration for eclipse. + Using a recent SNAPSHOT of the version 2.5 of the maven-eclipse-plugin, you'll be able to setup WTP. + The deployment of the webapp using WTP isn't yet supported. + + * IDEA + + Not yet tested ... diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt new file mode 100644 index 0000000..0926461 --- /dev/null +++ b/src/site/apt/index.apt @@ -0,0 +1,114 @@ +~~ +~~ 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. +~~ + + ------ + Introduction + ------ + Arnaud HERITIER + ------ + July 12, 2007 + +What is the Grails plugin for Maven ? + + The Grails plugin for maven is a set of goals to easily develop a Grails application using maven 2. + +* Goals Overview + +** Enhanced Grails services for maven 2 + + * <<{{{./create-pom-mojo.html}grails:create-pom}}>> to create a maven2 pom for an existing Grails project. + + * A <> packaging defining + + * a customized <> with the following services : + + * runs grails unit-tests and integration-tests in <> + + * runs (if grails.webtest.enable = true) grails web-tests in <> + + * copies projects dependencies of type jar which have not a provided or system scope in the lib directory. + + * creates a WAR archive using grails which can be installed and deployed by maven. + + * a customized <> which call the clean target of grails and delete the libraries found + in the lib directory (populated in the package phase of the default lifecycle) + +** Standard Grails services + + Those goals don't require a POM to be executed. They are just wrappers around Grails commands. + + * <<{{{./create-app-mojo.html}grails:create-app}}>> to create a Grails project, including the necessary + directory structure, and commons files. + + * <<{{{./create-domain-class-mojo.html}grails:create-domain-class}}>> to create a new domain class. + + * <<{{{./create-controller-mojo.html}grails:create-controller}}>> to create a new controller. + + * <<{{{./create-service-mojo.html}grails:create-service}}>> to create a new service class. + + * <<{{{./create-taglib-mojo.html}grails:create-taglib}}>> to create a new taglib. + + * <<{{{./create-script-mojo.html}grails:create-script}}>> to creates a Grails Gant Script. + + * <<{{{./create-unit-test-mojo.html}grails:create-unit-test}}>> to create a new Grails unit test. + + * <<{{{./create-integration-test-mojo.html}grails:create-integration-test}}>> to create a new Grails + integration test which loads the whole Grails environment when run. + + * <<{{{./create-web-test-mojo.html}grails:create-web-test}}>> to create a skeleton of a Canoo + WebTest (functional test). + + * <<{{{./generate-all-mojo.html}grails:generate-all}}>> to generate a CRUD interface + (controller + views) for a domain class. + + * <<{{{./generate-controller-mojo.html}grails:generate-controller}}>> to generate a + CRUD controller for a specified domain class. + + * <<{{{./generate-views-mojo.html}grails:generate-views}}>> to generate the CRUD + views for a specified domain class. + + * <<{{{./install-templates-mojo.html}grails:install-templates}}>> to install + the artifact and scaffolding templates. + + * <<{{{./clean-mojo.html}grails:clean}}>> to clean a Grails project. + + * <<{{{./test-app-mojo.html}grails:test-app}}>> to run unit tests and integration tests.. + + * <<{{{./run-webtests-mojo.html}grails:run-webtests}}>> to run all of the Web + tests against a Grails application.. + + * <<{{{./package-mojo.html}grails:package}}>> to package the Grails application into the web-app folder for running. + + * <<{{{./war-mojo.html}grails:war}}>> to create a WAR archive. + + * <<{{{./run-app-mojo.html}grails:run-app}}>> to run the Grails application in Jetty. + + * <<{{{./run-app-mojo.html}grails:run-app-https}}>> to run the Grails application in Jetty with HTTPS listener. + +* Usage + + Instructions on how to use the Grails plugin can be found {{{./usage.html}here}}. + +* Examples + + To provide you with better understanding of some usages of the Grails plugin, + you can take a look into the following examples: + + * {{{./examples/create-a-grails-app.html}How to start a grails project.}} + + * {{{./examples/mavenize-a-grails-app.html}How to mavenize an existing grails project.}} + + * {{{./examples/setup-your-IDE.html}How to setup your IDE.}} \ No newline at end of file diff --git a/src/site/apt/lifecycles.apt b/src/site/apt/lifecycles.apt new file mode 100644 index 0000000..c0f471a --- /dev/null +++ b/src/site/apt/lifecycles.apt @@ -0,0 +1,82 @@ +~~ +~~ 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. +~~ + + ------ + Maven Lifecycles for a Grails application + ------ + Arnaud HERITIER + ------ + August 19, 2007 + + +Lifecycles + + The grails plugin redefine the default and the clean lifecycles. + Those lifecycles are activated in the pom with the usage of the plugin with its extensions + ++-------+ + + + + com.octo.mtg + grails-maven-plugin + true + + + ++-------+ + + and a packaging set to "grails-app" + ++-------+ + grails-app ++-------+ + +* Default Lifecycle + +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + <> | <> | <> +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + validate | {{{./validate-mojo.html}com.octo.mtg:grails-maven-plugin:validate}} | Check that the Grails application.properties and the pom.xml in maven use the same application name and version +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + generate-sources | {{{./config-directories-mojo.html}com.octo.mtg:grails-maven-plugin:config-directories}} | Set sources/tests directories to be compatible with the directories layout used by grails +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + process-resources * | {{{./copy-dependencies-mojo.html}com.octo.mtg:grails-maven-plugin:copy-dependencies}} | Copy the POM dependencies in the lib directory of the grails project +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + test | {{{./test-app-mojo.html}com.octo.mtg:grails-maven-plugin:maven-test-app}} | Call the grails:test-app command to run unit and integration tests +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + package | {{{./maven-war-mojo.html}com.octo.mtg:grails-maven-plugin:maven-war}} | Call the grails:war command and put the result in the standard location for maven +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + integration-test | {{{./run-webtest-mojo.html}com.octo.mtg:grails-maven-plugin:maven-run-webtest}} | Call the grails:run-webtest command to run Cannoo web tests (if grails.webtest.enable = true). +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + install | org.apache.maven.plugins:maven-install-plugin:install | Install the WAR in the local repository +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ + deploy | org.apache.maven.plugins:maven-deploy-plugin:deploy | Deploy the WAR in the remote repository +*--------------------+------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+ +Default Lifecycle phases + + ( * ) The validate phase requires to call the process-resources phase of a forked lifecycle called grailsCopyDependencies. In this phase the copy-dependencies mojo of the plugin org.apache.maven.plugins:maven-dependency-plugin is called to copy in the lib directory all projects dependencies of type jar which have not a provided scope or system. + +* Clean Lifecycle + +*--------+---------------------------------------------------------------------+-------------------------------+ +<>| <> | <> +*--------+---------------------------------------------------------------------+-------------------------------+ + clean * | {{{./clean-mojo.html}com.octo.mtg:grails-maven-plugin:maven-clean}} | Call the grails clean command and the default clean command of maven +*--------+---------------------------------------------------------------------+-------------------------------+ +Clean Lifecycle phases + + ( * ) The clean phase requires to call the clean phase of a forked lifecycle called grailsClean. In this phase the clean mojo of the plugin org.apache.maven.plugins:maven-clean-plugin is called to remove jars from the lib directory. \ No newline at end of file diff --git a/src/site/apt/usage.apt b/src/site/apt/usage.apt new file mode 100644 index 0000000..52f0412 --- /dev/null +++ b/src/site/apt/usage.apt @@ -0,0 +1,115 @@ +~~ +~~ 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. +~~ + + ------ + Usage + ------ + Arnaud HERITIER + ------ + July 23, 2007 + +How should I setup my environment to use the grails plugin ? + + <> : + + * GRAILS must be installed locally and the environment variable GRAILS_HOME set. + + * This plugin is compatible with maven 2.0.5+. + + * This plugin is compatible with grails 0.5.6+. + +* Setup to use a released version + + Because our groupId isn't referenced by maven to be a plugin groupId (by default maven knows only + org.apache.maven.plugins and org.codehaus.mojo) you have to add it in your user's settings + (~/.m2/settings.xml) : + ++-------+ + + ... + + com.octo.mtg + + ... + ++-------+ + + To use the plugin you just have to launch : + ++-------+ + mvn grails: ++-------+ + +* Setup to use a snapshot version + + To use a snapshot version of the plugin, in addition of the settings explained on top you also have to had in your settings + a profile with our repositories to download the plugin and its dependencies. + ++-------+ + + ... + + + mtg + + + mtg.snapshots + Forge Snapshot Repository + http://forge.octo.com/archiva/repository/mtg-snapshots + + false + + + + + + mtg.snapshots + Forge Snapshot Repository + http://forge.octo.com/archiva/repository/mtg-snapshots + + false + + + + + + ... + ++-------+ + + You can activate this profile permanently in your settings + ++-------+ + + ... + + mtg + + ... + ++-------+ + + Or just when necessary with the command line parameter + ++-------+ + mvn -Pmtg ++-------+ + + To use the snapshot version of the plugin you can declare it in your project POM or you can use the long syntax to call the plugin : + ++-------+ + mvn com.octo.mtg:grails-maven-plugin:-SNAPSHOT: ++-------+ diff --git a/src/site/fml/faq.fml b/src/site/fml/faq.fml new file mode 100644 index 0000000..19c2659 --- /dev/null +++ b/src/site/fml/faq.fml @@ -0,0 +1,54 @@ + + + + + + + "The plugin 'org.apache.maven.plugins:maven-grails-plugin' does not exist or no valid version could be found." + + +

Behind this error there are several possible causes :

+
    +
  1. You haven't defined in your settings our groupId as a pluginGroup or you didn't defined the grails-maven-plugin in your POM.
  2. +
+

+ All these settings are documented in the + usage + page. +

+ + + + Why the build freeze when executing web tests on a continuous integration server on windows ? + +

+ If grails is launched in a continuous integration server, which is launched itself as a windows service, the build freezes just after the webtest, because grails tries to open the web page containing the result of the test but the process can't interact with the desktop to open a browser. This issue was reported to the grails team under the number + GRAILS-1546. +

+

A workaround is to edit the file WebTest.groovy that you'll find in the dist/grails-web-X.X.X.jar. At the end of the file, you have to comment these lines

+
+// on windows, start the standard browser on the report file
+if(! props.'os.name'?.contains('Windows')) return
+def reportHtml = "$props.webtest_resultpath/$props.webtest_resultfile" - '.xml' + '.html'
+def filename = new File(reportHtml).canonicalPath
+println "opening: $filename"
+"cmd /c $filename".execute()
+        
+
+
+ + \ No newline at end of file diff --git a/src/site/site.xml b/src/site/site.xml new file mode 100644 index 0000000..b45cf46 --- /dev/null +++ b/src/site/site.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/com/octo/mtg/plugin/LoadMojosTest.java b/src/test/java/com/octo/mtg/plugin/LoadMojosTest.java new file mode 100644 index 0000000..6c6e695 --- /dev/null +++ b/src/test/java/com/octo/mtg/plugin/LoadMojosTest.java @@ -0,0 +1,144 @@ +/* + * 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.testing.AbstractMojoTestCase; + +import java.io.File; + +/** + * @author Arnaud HERITIER + * @version $Id$ + */ +public class LoadMojosTest extends AbstractMojoTestCase { + + private void mojoTest(String pluginConfig, String mojoName, Class mojoClass) throws Exception { + File testPom = getTestFile("src/test/resources/com/octo/mtg/plugin/" + pluginConfig); + Object mojo = lookupMojo(mojoName, testPom); + assertNotNull(mojo); + assertEquals(mojo.getClass(), mojoClass); + release(mojo); + } + + public void testLoadCreatePomMojoLookup() throws Exception { + mojoTest("create-pom/plugin-config.xml", "create-pom", CreatePomMojo.class); + } + + public void testLoadGrailsCleanMojoLookup() throws Exception { + mojoTest("grails-clean/plugin-config.xml", "clean", GrailsCleanMojo.class); + } + + public void testLoadGrailsCreateAppMojoLookup() throws Exception { + mojoTest("grails-create-app/plugin-config.xml", "create-app", GrailsCreateAppMojo.class); + } + + public void testLoadGrailsCreateControllerMojoLookup() throws Exception { + mojoTest("grails-create-controller/plugin-config.xml", "create-controller", GrailsCreateControllerMojo.class); + } + + public void testLoadGrailsCreateDomainClassMojoLookup() throws Exception { + mojoTest("grails-create-domain-class/plugin-config.xml", "create-domain-class", GrailsCreateDomainClassMojo.class); + } + + public void testLoadGrailsCreateIntegrationTestMojoLookup() throws Exception { + mojoTest("grails-create-integration-test/plugin-config.xml", "create-integration-test", GrailsCreateIntegrationTestMojo.class); + } + + public void testLoadGrailsCreateScriptMojoLookup() throws Exception { + mojoTest("grails-create-script/plugin-config.xml", "create-script", GrailsCreateScriptMojo.class); + } + + public void testLoadGrailsCreateServiceMojoLookup() throws Exception { + mojoTest("grails-create-service/plugin-config.xml", "create-service", GrailsCreateServiceMojo.class); + } + + public void testLoadGrailsCreateTaglibMojoLookup() throws Exception { + mojoTest("grails-create-taglib/plugin-config.xml", "create-taglib", GrailsCreateTaglibMojo.class); + } + + public void testLoadGrailsCreateUnitTestMojoLookup() throws Exception { + mojoTest("grails-create-unit-test/plugin-config.xml", "create-unit-test", GrailsCreateUnitTestMojo.class); + } + + public void testLoadGrailsCreateWebTestMojoLookup() throws Exception { + mojoTest("grails-create-web-test/plugin-config.xml", "create-web-test", GrailsCreateWebTestMojo.class); + } + + public void testLoadGrailsGenerateAllMojoLookup() throws Exception { + mojoTest("grails-generate-all/plugin-config.xml", "generate-all", GrailsGenerateAllMojo.class); + } + + public void testLoadGrailsGenerateControllerMojoLookup() throws Exception { + mojoTest("grails-generate-controller/plugin-config.xml", "generate-controller", GrailsGenerateControllerMojo.class); + } + + public void testLoadGrailsGenerateViewsMojoLookup() throws Exception { + mojoTest("grails-generate-views/plugin-config.xml", "generate-views", GrailsGenerateViewsMojo.class); + } + + public void testLoadGrailsInstallTemplatesMojoLookup() throws Exception { + mojoTest("grails-install-templates/plugin-config.xml", "install-templates", GrailsInstallTemplatesMojo.class); + } + + public void testLoadGrailsPackageMojoLookup() throws Exception { + mojoTest("grails-package/plugin-config.xml", "package", GrailsPackageMojo.class); + } + + public void testLoadGrailsRunAppMojoLookup() throws Exception { + mojoTest("grails-run-app/plugin-config.xml", "run-app", GrailsRunAppMojo.class); + } + + public void testLoadGrailsRunAppHttpsMojoLookup() throws Exception { + mojoTest("grails-run-app-https/plugin-config.xml", "run-app-https", GrailsRunAppHttpsMojo.class); + } + + public void testLoadGrailsRunWebTestMojoLookup() throws Exception { + mojoTest("grails-run-webtest/plugin-config.xml", "run-webtest", GrailsRunWebTestMojo.class); + } + + public void testLoadGrailsTestAppMojoLookup() throws Exception { + mojoTest("grails-test-app/plugin-config.xml", "test-app", GrailsTestAppMojo.class); + } + + public void testLoadGrailsWarMojoLookup() throws Exception { + mojoTest("grails-war/plugin-config.xml", "war", GrailsWarMojo.class); + } + + public void testLoadMavenCleanMojoLookup() throws Exception { + mojoTest("maven-clean/plugin-config.xml", "maven-clean", MvnCleanMojo.class); + } + + public void testLoadMavenCopyDependenciesMojoLookup() throws Exception { + mojoTest("maven-copy-dependencies/plugin-config.xml", "copy-dependencies", MvnCopyDependenciesMojo.class); + } + + public void testLoadMavenRunWebTestMojoLookup() throws Exception { + mojoTest("maven-run-webtest/plugin-config.xml", "maven-run-webtest", MvnRunWebTestMojo.class); + } + + public void testLoadMavenTestAppMojoLookup() throws Exception { + mojoTest("maven-test-app/plugin-config.xml", "maven-test-app", MvnTestAppMojo.class); + } + + public void testLoadMavenValidateMojoLookup() throws Exception { + mojoTest("maven-validate/plugin-config.xml", "validate", MvnValidateMojo.class); + } + + public void testLoadMavenWarMojoLookup() throws Exception { + mojoTest("maven-war/plugin-config.xml", "maven-war", MvnWarMojo.class); + } +} diff --git a/src/test/java/com/octo/mtg/plugin/tools/GrailsServicesTest.java b/src/test/java/com/octo/mtg/plugin/tools/GrailsServicesTest.java new file mode 100644 index 0000000..ebbe8d4 --- /dev/null +++ b/src/test/java/com/octo/mtg/plugin/tools/GrailsServicesTest.java @@ -0,0 +1,63 @@ +/* + * 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.tools; + +import org.apache.maven.project.validation.ModelValidator; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusTestCase; + +/** + * Tests GrailsServices component. + * + * @author Arnaud HERITIER + * @version $Id$ + */ +public class GrailsServicesTest extends PlexusTestCase { + + /** + * A minimal grails descriptor to test + */ + private GrailsProject grailsDescriptorTest = new GrailsProject(); + + /** + * Sets up a Plexus container instance for running test. + */ + protected void setUp() throws Exception { + + // call this to enable super class to setup a Plexus container test + // instance and enable component lookup. + super.setUp(); + grailsDescriptorTest.setAppGrailsVersion("0.5.6"); + grailsDescriptorTest.setAppName("a-grails-app"); + grailsDescriptorTest.setAppVersion("1.0-SNAPSHOT"); + + } + + public void testPomIsValid() throws Exception { + ModelValidator modelValidator = (ModelValidator) lookup(ModelValidator.class.getName()); + GrailsServices grailsServices = (GrailsServices) lookup(GrailsServices.class.getName()); + + grailsServices.setBasedir(getTestFile("")); + + MavenProject pom = grailsServices.createPOM("a.group", grailsDescriptorTest, "com.octo.mtg", + "grails-maven-plugin", "1.0"); + + assertEquals(0, modelValidator.validate(pom.getModel()).getMessageCount()); + release(modelValidator); + release(grailsServices); + } +} diff --git a/src/test/java/com/octo/mtg/plugin/tools/PomServicesTest.java b/src/test/java/com/octo/mtg/plugin/tools/PomServicesTest.java new file mode 100644 index 0000000..f2e32e7 --- /dev/null +++ b/src/test/java/com/octo/mtg/plugin/tools/PomServicesTest.java @@ -0,0 +1,89 @@ +/* + * 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.tools; + +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.custommonkey.xmlunit.XMLAssert; + +import java.io.File; +import java.io.FileReader; + +/** + * Tests DefaultPomServices component. + * + * @author Arnaud HERITIER + * @version $Id$ + */ +public class PomServicesTest extends PlexusTestCase { + + /** + * A minimal pom to test + */ + private MavenProject projectTest = new MavenProject(); + + /** + * Sets up a Plexus container instance for running test. + */ + protected void setUp() throws Exception { + // call this to enable super class to setup a Plexus container test + // instance and enable component lookup. + super.setUp(); + projectTest.setModelVersion("4.0.0"); + projectTest.setGroupId("com.octo.maven.plugins"); + projectTest.setArtifactId("grails-maven-plugin-test"); + projectTest.setVersion("0.1-SNAPSHOT"); + projectTest.setPackaging("maven-plugin"); + + } + + /** + * Check that we correctly read the pom from a file. + * + * @throws Exception + */ + public void testReadPom() throws Exception { + PomServices pomServices = (PomServices) lookup(PomServices.class.getName()); + pomServices.setBasedir(getTestFile("")); + MavenProject project = pomServices.read(getTestFile("src/test/resources/com/octo/mtg/plugin/pom-services/")); + assertEquals(projectTest, project); + release(pomServices); + } + + /** + * Check that we correctly write the project into a file. + * + * @throws Exception + */ + public void testWriteproject() throws Exception { + + PomServices pomServices = (PomServices) lookup(PomServices.class.getName()); + File projectDir = getTestFile("target/write-project-test"); + FileUtils.deleteDirectory(projectDir); + assertTrue(projectDir.mkdirs()); + pomServices.setBasedir(projectDir); + pomServices.write(projectTest); + + File pomFile = new File(projectDir, "pom.xml"); + XMLAssert.assertXMLEqual( + new FileReader(getTestFile("src/test/resources/com/octo/mtg/plugin/pom-services/pom.xml")), + new FileReader(pomFile)); + pomFile.delete(); + release(pomServices); + } +} diff --git a/src/test/resources/com/octo/mtg/plugin/create-pom/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/create-pom/plugin-config.xml new file mode 100644 index 0000000..0af9b93 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/create-pom/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + my-group + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-clean/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-clean/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-clean/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-app/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-app/plugin-config.xml new file mode 100644 index 0000000..024a264 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-app/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + my-grails-app + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-controller/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-controller/plugin-config.xml new file mode 100644 index 0000000..dac892c --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-controller/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyController + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-domain-class/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-domain-class/plugin-config.xml new file mode 100644 index 0000000..12a397c --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-domain-class/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyObject + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-integration-test/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-integration-test/plugin-config.xml new file mode 100644 index 0000000..bbecf10 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-integration-test/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyIntegrationTest + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-script/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-script/plugin-config.xml new file mode 100644 index 0000000..7612888 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-script/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyScript + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-service/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-service/plugin-config.xml new file mode 100644 index 0000000..d4747fe --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-service/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyService + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-taglib/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-taglib/plugin-config.xml new file mode 100644 index 0000000..0369b1b --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-taglib/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyController + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-unit-test/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-unit-test/plugin-config.xml new file mode 100644 index 0000000..9befe9d --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-unit-test/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyUnitTest + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-create-web-test/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-create-web-test/plugin-config.xml new file mode 100644 index 0000000..3c9cf83 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-create-web-test/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyWebTest + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-generate-all/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-generate-all/plugin-config.xml new file mode 100644 index 0000000..12a397c --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-generate-all/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyObject + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-generate-controller/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-generate-controller/plugin-config.xml new file mode 100644 index 0000000..12a397c --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-generate-controller/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyObject + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-generate-views/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-generate-views/plugin-config.xml new file mode 100644 index 0000000..12a397c --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-generate-views/plugin-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + MyObject + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-install-templates/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-install-templates/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-install-templates/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-package/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-package/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-package/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-run-app-https/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-run-app-https/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-run-app-https/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-run-app/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-run-app/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-run-app/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-run-webtest/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-run-webtest/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-run-webtest/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-test-app/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-test-app/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-test-app/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/grails-war/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/grails-war/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/grails-war/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/maven-clean/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/maven-clean/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/maven-clean/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/maven-copy-dependencies/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/maven-copy-dependencies/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/maven-copy-dependencies/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/maven-run-webtest/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/maven-run-webtest/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/maven-run-webtest/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/maven-test-app/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/maven-test-app/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/maven-test-app/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/maven-validate/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/maven-validate/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/maven-validate/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/maven-war/plugin-config.xml b/src/test/resources/com/octo/mtg/plugin/maven-war/plugin-config.xml new file mode 100644 index 0000000..c7da255 --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/maven-war/plugin-config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + com.octo.maven.plugins + grails-maven-plugin + true + + ${env.GRAILS_HOME} + + + + + \ No newline at end of file diff --git a/src/test/resources/com/octo/mtg/plugin/pom-services/pom.xml b/src/test/resources/com/octo/mtg/plugin/pom-services/pom.xml new file mode 100644 index 0000000..77b504a --- /dev/null +++ b/src/test/resources/com/octo/mtg/plugin/pom-services/pom.xml @@ -0,0 +1,28 @@ + + + + + + + 4.0.0 + com.octo.maven.plugins + grails-maven-plugin-test + 0.1-SNAPSHOT + maven-plugin + \ No newline at end of file