Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 378b02c9ee4e0f43febc216827d2280fb0b5fdf6 Craig Raw committed Jan 18, 2012
@@ -0,0 +1,14 @@
+<classpath>
+ <classpathentry kind="src" path="src/java"/>
+ <classpathentry kind="src" path="src/groovy"/>
+ <classpathentry kind="src" path="grails-app/conf"/>
+ <classpathentry kind="src" path="grails-app/controllers"/>
+ <classpathentry kind="src" path="grails-app/domain"/>
+ <classpathentry kind="src" path="grails-app/services"/>
+ <classpathentry kind="src" path="grails-app/taglib"/>
+ <classpathentry kind="src" path="test/integration"/>
+ <classpathentry kind="src" path="test/unit"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="com.springsource.sts.grails.core.CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="web-app/WEB-INF/classes"/>
+</classpath>
@@ -0,0 +1,7 @@
+.settings
+dependencies.groovy
+grails-errors*.zip*
+plugin.xml
+stacktrace.log
+target/
+web-app/
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>errors</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.springsource.sts.grails.core.nature</nature>
+ <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,32 @@
+class ErrorsGrailsPlugin {
+ // the plugin version
+ def version = "0.4"
+ // the version or versions of Grails the plugin is designed for
+ def grailsVersion = "2.0 > *"
+ // the other plugins this plugin depends on
+ def dependsOn = [:]
+ // resources that are excluded from plugin packaging
+ def pluginExcludes = [
+ "grails-app/views/error.gsp"
+ ]
+
+ // TODO Fill in these fields
+ def title = "Errors Plugin" // Headline display name of the plugin
+ def author = "Craig Raw"
+ def authorEmail = "craig@quirk.biz"
+ def description = '''\
+This plugin sets up some error handling for your application.
+It also looks for GSP pages matching the Grails convention of finding resources before rendering the 404 page, allowing pages to be added without further configuration.
@pledbrook

pledbrook May 30, 2012

This really needs to clarify that it installs an error controller that handles HTTP client and server error codes. I initially thought this plugin made debugging applications easier by making error reporting better :)

+'''
+
+ // URL to the plugin's documentation
+ def documentation = "http://grails.org/plugin/errors"
@pledbrook

pledbrook May 30, 2012

Are you planning to add documentation to the plugin portal page? If not, please update this to point to the GitHub README or some other documentation.

+
+ // Extra (optional) plugin metadata
+
+ // License: one of 'APACHE', 'GPL2', 'GPL3'
+ def license = "APACHE"
+
+ // Details of company behind the plugin (if there is one)
+ def organization = [ name: "Quirk Labs", url: "http://www.quirklabs.co.za" ]
+}
@@ -0,0 +1,8 @@
+Grails Errors Plugin
+====================
+
+This plugin sets up some basic error handling for your application, namely 403, 404 and 500 errors. Simply install, and it will prompt for a name for the controller to handle these errors.
+
+In addition, before rendering a 404, it will look for .gsp pages in the grails-app/view folder matching the Grails convention. This allows .gsp pages to be added without further configuration.
+
+For example, adding the file grails-app/view/company/aboutus.gsp will cause it be rendered for a request to /company/aboutus without further configuration.
@pledbrook

pledbrook May 30, 2012

I'm afraid I don't understand these last two paragraphs. What problem is this feature trying to solve? If the view exists, you wouldn't get a 404, surely? I'm confused, sorry.

@craigraw

craigraw May 30, 2012

Owner

Hopefully it's a little clearer now. My particular problem here was that I work in a agency environment where the team that works on the HTML is different from the team that writes the Groovy/Grails code. I want the HTML team to be able to add GSPs (plain HTML really) without bugging the engineering team for controller actions.

@pledbrook

pledbrook May 30, 2012

Yup, a light bulb went off in my head when I read the new version. Is it optional behaviour?

@craigraw

craigraw May 30, 2012

Owner

It's currently not configurable. Definitely not right for every project, but for simple websites it's, well, simple :)

@@ -0,0 +1,5 @@
+#Grails Metadata file
+#Tue Jan 17 15:35:31 SAST 2012
+app.grails.version=2.0.0
+app.name=errors
+plugins.svn=1.0.1
Binary file not shown.
@@ -0,0 +1,37 @@
+grails.project.class.dir = "target/classes"
+grails.project.test.class.dir = "target/test-classes"
+grails.project.test.reports.dir = "target/test-reports"
+grails.project.target.level = 1.6
+//grails.project.war.file = "target/${appName}-${appVersion}.war"
+
+grails.project.dependency.resolution = {
+ // inherit Grails' default dependencies
+ inherits("global") {
+ // uncomment to disable ehcache
+ // excludes 'ehcache'
+ }
+ log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
+ repositories {
+ grailsCentral()
+ // uncomment the below to enable remote dependency resolution
+ // from public Maven repositories
+ //mavenCentral()
+ //mavenLocal()
+ //mavenRepo "http://snapshots.repository.codehaus.org"
+ //mavenRepo "http://repository.codehaus.org"
+ //mavenRepo "http://download.java.net/maven/2/"
+ //mavenRepo "http://repository.jboss.com/maven2/"
+ }
+ dependencies {
+ // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
+
+ // runtime 'mysql:mysql-connector-java:5.1.5'
+ }
+
+ plugins {
+ build(":tomcat:$grailsVersion",
+ ":release:1.0.0") {
@pledbrook

pledbrook May 30, 2012

This will need to be updated to Release 2.0.x before publishing to the Grails central repository.

+ export = false
+ }
+ }
+}
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Grails Runtime Exception</title>
+ <meta name="layout" content="main">
+ <link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css">
+ </head>
+ <body>
+ <g:renderException exception="${exception}" />
+ </body>
+</html>
@@ -0,0 +1,6 @@
+includeTargets << new File("$errorsPluginDir/scripts/_GenerateErrorsArtifacts.groovy")
+
+target ('default': "Creates the errors controller with associated GSPs and configures it to handle errors") {
+ depends(checkVersion, parseArguments)
+ generateErrorsArtifacts(argsMap)
+}
@@ -0,0 +1,52 @@
+includeTargets << grailsScript("_GrailsInit")
+includeTargets << grailsScript("_GrailsCreateArtifacts")
+
+generateErrorsArtifacts = { Map argsMap = [:] ->
+ ant.mkdir(dir:"${basedir}/grails-app/controllers")
+
+ def type = "Controller"
+ if (!argsMap["params"]) {
+ argsMap["params"] = []
+ argsMap["params"] << grailsConsole.userInput("Specify a fully qualified class name for your errors Controller (e.g. com.xyz.ErrorsController):")
+ }
+
+ for (name in argsMap["params"]) {
+ name = purgeRedundantArtifactSuffix(name, type)
+ createArtifact(name: name, suffix: type, type: "ErrorsController", path: "grails-app/controllers")
+ createUnitTest(name: name, suffix: type)
+ }
+
+ ant.mkdir(dir:"${basedir}/grails-app/views/errors")
+
+ def errorTypes = ["403","404","500"]
+ for (error in errorTypes) {
+ def artifactFile = "${basedir}/grails-app/views/errors/error${error}.gsp"
+ def templateFile = resolveResources("file:${pluginsHome}/*/src/templates/errors/error${error}.gsp")[0]
+ copyGrailsResource(artifactFile, templateFile)
+ }
+
+ // Very hacky way of doing this, only really works on a new project. Needs improvement
+ def mappingsFile = new File("${basedir}/grails-app/conf/UrlMappings.groovy")
+ def mappings = '''\n\t\t// Added by Errors plugin\n\t\t"403"(controller: "errors", action: "error403")\n\t\t"404"(controller: "errors", action: "error404")\n\t\t"500"(controller: "errors", action: "error500")\n'''
+ def writer = new StringWriter()
+ boolean added = false
+ if (mappingsFile.exists()) {
+ mappingsFile.eachLine { line ->
+ if( line.contains('''"500"(view:'/error')''') ) {
+ writer.append(mappings)
+ added = true
+ }
+ else {
+ writer.append("${line}\n")
+ }
+ }
+ }
+
+ if (added) {
+ mappingsFile.text = writer.toString()
+ grailsConsole.addStatus "Modified grails-app/conf/UrlMappings.groovy, please check mappings"
+ }
+ else {
+ grailsConsole.warn "UrlMappings.groovy not modified, please add the following to it: ${mappings}"
+ }
+}
@@ -0,0 +1,2 @@
+includeTargets << new File("$errorsPluginDir/scripts/_GenerateErrorsArtifacts.groovy")
+generateErrorsArtifacts << [:]
@@ -0,0 +1,20 @@
+@artifact.package@class @artifact.name@ {
+
+ def groovyPagesTemplateEngine
+
+ def error403 = {}
+
+ def error404 = {
+ def contextPath = request.contextPath
+ def path = request.forwardURI.replaceFirst("^$contextPath", "")
+ def engine = groovyPagesTemplateEngine
+
+ if (engine.getResourceForUri("${path}.gsp").exists() || engine.getResourceForUri("/grails-app/views/${path}.gsp").exists()) {
+ render(view: path, model: [])
+ }
+
+ []
+ }
+
+ def error500 = {}
+}
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Access denied!</title>
+<meta name='layout' content='main' />
+</head>
+<body>
+<h1>Access Denied</h1>
+<p>We're sorry, but you are not authorized to perform the requested operation.</p>
+</body>
+</html>
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Not Found</title>
+<meta name='layout' content='main' />
+</head>
+<body>
+<h1>Not Found</h1>
+<p>We're sorry, but that page doesn't exist.</p>
+</body>
+</html>
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Error</title>
+<meta name='layout' content='main' />
+</head>
+<body>
+<h1>Error</h1>
+<p>Sorry, there was an error. Please try again later.</p>
+</body>
+</html>

0 comments on commit 378b02c

Please sign in to comment.