|
| 1 | +import grails.plugin.geb.GebGrailsPlugin |
| 2 | + |
| 3 | +namespace 'geb' |
| 4 | +description "Install Geb", "grace geb:install" |
| 5 | +visible false |
| 6 | + |
| 7 | +URL gebConfig = GebGrailsPlugin.getResource('/META-INF/templates/GebConfig.groovy') |
| 8 | +File projectDir = executionContext.baseDir |
| 9 | +File resourcesDir = new File(projectDir, 'src/integration-test/resources') |
| 10 | +File gebFile = new File(resourcesDir, 'GebConfig.groovy') |
| 11 | +File buildFile = new File(projectDir, 'build.gradle') |
| 12 | + |
| 13 | +if (!resourcesDir.exists()) { |
| 14 | + resourcesDir.mkdir() |
| 15 | +} |
| 16 | + |
| 17 | +use(FileCategory) { |
| 18 | + // Copy GebConfig.groovy to 'src/integration-test/resources' |
| 19 | + gebFile << gebConfig |
| 20 | + |
| 21 | + // Set system properties in the build.gradle |
| 22 | + buildFile.insertAfter 'useJUnitPlatform()', ''' |
| 23 | + systemProperty 'geb.env', System.getProperty('geb.env') |
| 24 | + systemProperty 'geb.build.reportsDir', reporting.file('geb/integrationTest')''' |
| 25 | +} |
| 26 | + |
| 27 | + |
| 28 | +class FileCategory { |
| 29 | + |
| 30 | + def static leftShift(File file, URL url) { |
| 31 | + url.withInputStream { is -> |
| 32 | + file.withOutputStream { os -> |
| 33 | + def bs = new BufferedOutputStream(os) |
| 34 | + bs << is |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + def static leftShift(File dest, File src) { |
| 40 | + src.withInputStream { is -> |
| 41 | + dest.withOutputStream { os -> |
| 42 | + def bs = new BufferedOutputStream(os) |
| 43 | + bs << is |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + def static insertAfter(File file, String searchString, String text) { |
| 49 | + if (!file?.exists()) return |
| 50 | + String content = file.text |
| 51 | + if (content?.indexOf(searchString) <= 0) return |
| 52 | + String before = content.takeBefore(searchString) |
| 53 | + String after = content.takeAfter(searchString) |
| 54 | + StringBuffer newContent = new StringBuffer() |
| 55 | + newContent << before << searchString << text << after |
| 56 | + file.text = newContent |
| 57 | + } |
| 58 | + |
| 59 | + def static insertBefore(File file, String searchString, String text) { |
| 60 | + if (!file?.exists()) return |
| 61 | + String content = file.text |
| 62 | + if (content?.indexOf(searchString) <= 0) return |
| 63 | + String before = content.takeBefore(searchString) |
| 64 | + String after = content.takeAfter(searchString) |
| 65 | + StringBuffer newContent = new StringBuffer() |
| 66 | + newContent << before << text << searchString << after |
| 67 | + file.text = newContent |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +consoleLogger.addStatus "Copying 'GebConfig.groovy' to 'src/integration-test/resources'" |
0 commit comments