Skip to content

Instantly share code, notes, and snippets.

View sergiomichels's full-sized avatar

Sérgio Michels sergiomichels

View GitHub Profile
@sergiomichels
sergiomichels / ConstraintRegistrar.groovy
Created May 3, 2014 17:39
Utility to register new constraints
class ConstraintRegistrar {
static void registerConstraints() {
List<GrailsDomainClass> domainClasses = Holders.getGrailsApplication().getArtefacts("Domain")
domainClasses.each ConstraintRegistrar.&registerConstraints
}
static void registerConstraints(Class clazz) {
GrailsDomainClass domainClass = Holders.getGrailsApplication().getDomainClass(clazz.name)
registerConstraints(domainClass)
@sergiomichels
sergiomichels / gist:8418205
Created January 14, 2014 13:21
Dependency report - ClassNotFoundException: org.junit.internal.AssumptionViolatedException
|Loading Grails 2.3.4
|Configuring classpath
.
|Environment set to development
...
|Obtaining dependency data...
..
build - Dependencies for the build system only (total: 23)
+--- xalan:serializer:2.7.1
+--- org.grails:grails-bootstrap:2.3.4
@sergiomichels
sergiomichels / dependency-report
Created December 19, 2013 13:49
Dependency problem
cache: module revision found in cache: org.codehaus.griffon#swingxbuilder;0.3
found org.codehaus.griffon#swingxbuilder;0.3 in cache
== resolving dependencies org.codehaus.griffon.internal#cracha-inteligente;0.1->org.codehaus.griffon#swingxbuilder;0.3 [compile->runtime]
== resolving dependencies org.codehaus.griffon.internal#cracha-inteligente;0.1->org.codehaus.griffon#swingxbuilder;0.3 [compile->compile]
excluding dependency: org.codehaus.groovy#groovy-all;1.8.8 {compile=[compile(*), master(*)], runtime=[runtime(*)]} in compile
== resolving dependencies org.codehaus.griffon#swingxbuilder;0.3->org.swinglabs#swing-worker;1.1 [compile->master(*)]
excluding dependency: org.codehaus.groovy#groovy-all;1.8.8 {compile=[compile(*), master(*)], runtime=[runtime(*)]} in compile
cache: Checking cache for: dependency: org.swinglabs#swing-worker;1.1 {compile=[compile(*), master(*)], runtime=[runtime(*)]}
cache: module revision found in cache: org.swinglabs#swing-worker;1.1
found org.swinglabs#swing-worker;1
println grailsApplication.config.grails.databinding.useSpringBinder
Colaborador c = new Colaborador(nome: 'Sérgio Michels', dtAdmissao: '01/03/2007', dtNascimento: '11/10/1989', cpf: '020.234.920-92', matricula: 232040L)
c.validate()
println c.errors
Outputs:
true
@sergiomichels
sergiomichels / gist:7806009
Created December 5, 2013 14:33
Fatal error Griffon
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f1cf3693880, pid=4579, tid=139762827405056
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C 0x00007f1cf3693880
#
@sergiomichels
sergiomichels / Stacktrace.groovy
Created November 28, 2013 18:04
Some big stacktrace...
| Error Error executing script MavenInstall: null
java.lang.StackOverflowError
at java.util.regex.Pattern$CharProperty$1.isSatisfiedBy(Pattern.java:3337)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
@sergiomichels
sergiomichels / CheckDomainClass.groovy
Created November 28, 2013 16:43
Grails script that validates if the class name is a domain class
import grails.util.GrailsNameUtils
includeTargets << grailsScript("_GrailsBootstrap") //https://github.com/grails/grails-core/blob/master/scripts/_GrailsBootstrap.groovy
includeTargets << grailsScript("_GrailsCreateArtifacts") //https://github.com/grails/grails-core/blob/master/scripts/_GrailsCreateArtifacts.groovy
target ('default': 'Validates if the argument is a domain class') {
depends(loadApp)
promptForName(type: type)
@sergiomichels
sergiomichels / MyController.groovy
Created November 28, 2013 16:38
Get GrailsDomainClass in an controller
class MyController {
def grailsApplication
def index() {
def domainClass = grailsApplication.getDomainClass("package.DomainClassName")
}
}
import grails.plugin.jodatime.Html5DateTimeFormat
import org.grails.databinding.converters.ValueConverter
import org.joda.time.DateTime
import org.joda.time.Instant
import org.joda.time.LocalDate
import org.joda.time.LocalDateTime
import org.joda.time.LocalTime
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter
@sergiomichels
sergiomichels / MyTestSpec.groovy
Created October 25, 2013 19:37
Set the Locale of your integration test
import grails.plugin.spock.IntegrationSpec
import org.springframework.web.context.request.RequestContextHolder
class MyTestSpec extends IntegrationSpec {
/* Normally in your code you will use something like RequestContextUtils.getLocale(request) to get's the Locale to
* be used. Here we set the locale that will be returned by RCU to our tests.
*/
def setup() {