Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def player = new Player(name:"Bob")
- player.save()
- java.lang.NoClassDefFoundError: gaming/Player
- import gaming.Player
- includeTargets << grailsScript("_GrailsBootstrap")
- depends(configureProxy, packageApp, classpath, loadApp, configureApp, compile, bootstrap)
- ApplicationHolder.application.getClassForName("gaming.Player")
- import gaming.Player
- import org.codehaus.groovy.grails.commons.ApplicationHolder
- includeTargets << grailsScript("_GrailsInit")
- includeTargets << grailsScript("_GrailsBootstrap")
- includeTargets << grailsScript("_GrailsClasspath")
- def handleHeaderLine(line) {
- def retval = []
- line.each {
- if(!it.equals("Game Name") && !it.equals("Total # of Copies")) {
- println("Creating Player: " + it)
- def player = new Player(name:it)
- player.save
- retval << it
- } else {
- retval << null
- }
- }
- return retval;
- }
- def handleGameLine(header, line) {
- println("Creating Game: " + line[0])
- for(int i = 1; i < line.length - 1; i++) {
- if(!header[i].equals("Total # of Copies")) {
- def count = line[i] == "" ? 0 : Integer.parseInt(line[i]);
- for(int j = 0; j < count; j++) {
- println "Creating copy of " + line[0] + " owned by " + header[i]
- }
- }
- }
- }
- target(loadAssets: "The description of the script goes here!") {
- depends(configureProxy, packageApp, classpath, loadApp, configureApp, compile, bootstrap)
- ApplicationHolder.application.getClassForName("gaming.Player")
- def tsv = new File("...")
- def header = null;
- tsv.eachLine {
- def line = it.split("t")
- if(header == null) {
- header = handleHeaderLine(line)
- println header
- } else {
- handleGameLine(header, line)
- }
- }
- }
- setDefaultTarget(loadAssets)
- //scripts/player/PlayerScript.groovy
- def handleHeaderLine(line) {
- def retval = []
- line.each {
- if(!it.equals("Game Name") && !it.equals("Total # of Copies")) {
- println("Creating Player: " + it)
- def player = new Player(name: it)
- player.save(flush: true)
- retval << it
- } else {
- retval << null
- }
- }
- return retval
- }
- def handleGameLine(header, line) {
- println("Creating Game: " + line[0])
- for(int i = 1; i < line.length - 1; i++) {
- if(!header[i].equals("Total # of Copies")) {
- def count = line[i] == "" ? 0 : Integer.parseInt(line[i]);
- for(int j = 0; j < count; j++) {
- println "Creating copy of " + line[0] + " owned by " + header[i]
- }
- }
- }
- }
- def tsv = new File("...")
- def header = null
- tsv.eachLine {
- def line = it.split("t")
- if(header == null) {
- header = handleHeaderLine(line)
- println header
- } else {
- handleGameLine(header, line)
- }
- }
- grails run-script scripts/player/PlayerScript.groovy
- grails test run-script scripts/player/PlayerScript.groovy
- plugins {
- if ( !System.getProperty("noTomcat") ) {
- build ":tomcat:7.0.52.1"
- }
- ....
- }
- grails -DnoTomcat=true run-script scripts/player/PlayerScript.groovy
- includeTargets << grailsScript("_GrailsInit")
- includeTargets << grailsScript("_GrailsBootstrap")
- target(playerScript: "The description of the script goes here!") {
- depends configureProxy, packageApp, classpath, loadApp, configureApp
- def playerClass = classLoader.loadClass("gaming.Player")
- //Skeptical about how a domain class would behave
- //But a normal POGO should be good being used this way
- def player = playerClass.newInstance([[name: "Bob"]] as Object[])
- player.save(flush: true)
- println player
- }
- setDefaultTarget(playerScript)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement