Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. def player = new Player(name:"Bob")
  2. player.save()
  3.  
  4. java.lang.NoClassDefFoundError: gaming/Player
  5.  
  6. import gaming.Player
  7.  
  8. includeTargets << grailsScript("_GrailsBootstrap")
  9.  
  10. depends(configureProxy, packageApp, classpath, loadApp, configureApp, compile, bootstrap)
  11.  
  12. ApplicationHolder.application.getClassForName("gaming.Player")
  13.  
  14. import gaming.Player
  15.  
  16. import org.codehaus.groovy.grails.commons.ApplicationHolder
  17.  
  18. includeTargets << grailsScript("_GrailsInit")
  19. includeTargets << grailsScript("_GrailsBootstrap")
  20. includeTargets << grailsScript("_GrailsClasspath")
  21.  
  22. def handleHeaderLine(line) {
  23. def retval = []
  24. line.each {
  25. if(!it.equals("Game Name") && !it.equals("Total # of Copies")) {
  26. println("Creating Player: " + it)
  27. def player = new Player(name:it)
  28. player.save
  29. retval << it
  30. } else {
  31. retval << null
  32. }
  33. }
  34. return retval;
  35. }
  36.  
  37. def handleGameLine(header, line) {
  38. println("Creating Game: " + line[0])
  39. for(int i = 1; i < line.length - 1; i++) {
  40. if(!header[i].equals("Total # of Copies")) {
  41. def count = line[i] == "" ? 0 : Integer.parseInt(line[i]);
  42. for(int j = 0; j < count; j++) {
  43. println "Creating copy of " + line[0] + " owned by " + header[i]
  44. }
  45. }
  46. }
  47. }
  48.  
  49. target(loadAssets: "The description of the script goes here!") {
  50. depends(configureProxy, packageApp, classpath, loadApp, configureApp, compile, bootstrap)
  51.  
  52. ApplicationHolder.application.getClassForName("gaming.Player")
  53.  
  54. def tsv = new File("...")
  55.  
  56. def header = null;
  57. tsv.eachLine {
  58. def line = it.split("t")
  59. if(header == null) {
  60. header = handleHeaderLine(line)
  61. println header
  62. } else {
  63. handleGameLine(header, line)
  64. }
  65. }
  66. }
  67.  
  68. setDefaultTarget(loadAssets)
  69.  
  70. //scripts/player/PlayerScript.groovy
  71. def handleHeaderLine(line) {
  72. def retval = []
  73. line.each {
  74. if(!it.equals("Game Name") && !it.equals("Total # of Copies")) {
  75. println("Creating Player: " + it)
  76. def player = new Player(name: it)
  77. player.save(flush: true)
  78. retval << it
  79. } else {
  80. retval << null
  81. }
  82. }
  83. return retval
  84. }
  85.  
  86. def handleGameLine(header, line) {
  87. println("Creating Game: " + line[0])
  88. for(int i = 1; i < line.length - 1; i++) {
  89. if(!header[i].equals("Total # of Copies")) {
  90. def count = line[i] == "" ? 0 : Integer.parseInt(line[i]);
  91. for(int j = 0; j < count; j++) {
  92. println "Creating copy of " + line[0] + " owned by " + header[i]
  93. }
  94. }
  95. }
  96. }
  97.  
  98. def tsv = new File("...")
  99. def header = null
  100. tsv.eachLine {
  101. def line = it.split("t")
  102. if(header == null) {
  103. header = handleHeaderLine(line)
  104. println header
  105. } else {
  106. handleGameLine(header, line)
  107. }
  108. }
  109.  
  110. grails run-script scripts/player/PlayerScript.groovy
  111.  
  112. grails test run-script scripts/player/PlayerScript.groovy
  113.  
  114. plugins {
  115. if ( !System.getProperty("noTomcat") ) {
  116. build ":tomcat:7.0.52.1"
  117. }
  118. ....
  119. }
  120.  
  121. grails -DnoTomcat=true run-script scripts/player/PlayerScript.groovy
  122.  
  123. includeTargets << grailsScript("_GrailsInit")
  124. includeTargets << grailsScript("_GrailsBootstrap")
  125.  
  126. target(playerScript: "The description of the script goes here!") {
  127. depends configureProxy, packageApp, classpath, loadApp, configureApp
  128.  
  129. def playerClass = classLoader.loadClass("gaming.Player")
  130.  
  131. //Skeptical about how a domain class would behave
  132. //But a normal POGO should be good being used this way
  133. def player = playerClass.newInstance([[name: "Bob"]] as Object[])
  134. player.save(flush: true)
  135.  
  136. println player
  137. }
  138.  
  139. setDefaultTarget(playerScript)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement