Skip to content

Commit 1e27f5c

Browse files
authored
Merge pull request #5 from jdaugherty/7.0.x
7.0.x functioning
2 parents e7db473 + 5baa016 commit 1e27f5c

File tree

8 files changed

+58
-91
lines changed

8 files changed

+58
-91
lines changed

README.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,14 @@ Add a dependency in build.gradle
1919

2020
```groovy
2121
repositories {
22-
maven { url "https://jitpack.io" }
22+
maven { url "https://repo.grails.org/grails/core/" }
2323
}
2424
2525
dependencies {
26-
compile 'com.github.gpc:grails-web-console:6.0-M2'
26+
compile 'com.github.gpc:grails-web-console:7.0.0-SNAPSHOT'
2727
}
2828
```
2929

30-
In addition if you don't want to use jitpack.io then use following github package registry:
31-
32-
```groovy
33-
repositories {
34-
maven {
35-
name = "GitHubPackages"
36-
url = uri("https://maven.pkg.github.com/gpc/grails-web-console")
37-
credentials {
38-
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
39-
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
40-
}
41-
}
42-
}
43-
44-
dependencies {
45-
compile 'org.grails.plugins:grails-web-console:6.0-M2'
46-
}
47-
48-
```
4930

5031
## Usage
5132

app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ plugins {
1313
group = "grails.app"
1414

1515
repositories {
16-
mavenCentral()
17-
maven { url "https://repo.grails.org/grails/core/" }
16+
maven { url "https://repo.grails.org/grails/core" }
1817
}
1918

2019
configurations {

plugin/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ plugins {
1313
group "org.grails.plugins"
1414

1515
repositories {
16-
mavenCentral()
17-
maven { url "https://repo1.maven.org/maven2/" }
1816
maven { url "https://repo.grails.org/grails/core" }
1917
}
2018

plugin/grails-app/services/org/grails/plugins/console/ConsoleService.groovy

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package org.grails.plugins.console
33
import org.codehaus.groovy.control.CompilerConfiguration
44
import org.codehaus.groovy.control.customizers.ImportCustomizer
55
import grails.core.GrailsApplication
6+
import org.grails.core.artefact.DomainClassArtefactHandler
7+
8+
import java.nio.charset.StandardCharsets
69

710
class ConsoleService {
811

@@ -37,7 +40,7 @@ class ConsoleService {
3740
evaluation.totalTime = System.currentTimeMillis() - startTime
3841

3942
evaluation.console = console
40-
evaluation.output = baos.toString('UTF8')
43+
evaluation.output = baos.toString(StandardCharsets.UTF_8.name())
4144
evaluation
4245
}
4346

@@ -57,7 +60,9 @@ class ConsoleService {
5760
CompilerConfiguration configuration = new CompilerConfiguration()
5861
if (autoImportDomains) {
5962
ImportCustomizer importCustomizer = new ImportCustomizer()
60-
importCustomizer.addImports(*grailsApplication.domainClasses*.fullName)
63+
grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE).each { domainClass ->
64+
importCustomizer.addImport(domainClass.clazz.simpleName, domainClass.clazz.name)
65+
}
6166
configuration.addCompilationCustomizers importCustomizer
6267
}
6368
configuration
Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,36 @@
11
package org.grails.plugins.console
22

3+
import grails.config.Config
34
import grails.util.Environment
45

56
class ConsoleConfig {
67

78
boolean enabled
8-
String newFileText = null
9-
boolean indentWithTabs = false
10-
int tabSize = 4
11-
int indentUnit = 4
12-
String remoteFileStoreDefaultPath = null
13-
boolean remoteFileStoreEnabled = true
14-
boolean csrfProtectionEnabled = true
9+
String newFileText
10+
boolean indentWithTabs
11+
int tabSize
12+
int indentUnit
13+
String remoteFileStoreDefaultPath
14+
boolean remoteFileStoreEnabled
15+
boolean csrfProtectionEnabled
1516
def baseUrl
1617

17-
ConsoleConfig(Map config) {
18-
19-
if (config.enabled instanceof Boolean) {
20-
enabled = config.enabled
21-
} else {
22-
enabled = Environment.current == Environment.DEVELOPMENT
23-
}
24-
25-
if (config.newFileText instanceof String) {
26-
newFileText = config.newFileText
27-
}
28-
29-
if (config.indentWithTabs instanceof Boolean) {
30-
indentWithTabs = config.indentWithTabs
31-
}
32-
33-
if (config.tabSize instanceof Integer) {
34-
tabSize = config.tabSize as Integer
35-
}
36-
37-
if (config.indentUnit instanceof Integer) {
38-
indentUnit = config.indentUnit as Integer
39-
}
40-
41-
if (config.fileStore && config.fileStore.remote && config.fileStore.remote.defaultPath instanceof String) {
42-
remoteFileStoreDefaultPath = config.fileStore.remote.defaultPath
43-
}
44-
45-
if (config.fileStore && config.fileStore.remote && config.fileStore.remote.enabled instanceof Boolean) {
46-
remoteFileStoreEnabled = config.fileStore.remote.enabled
47-
}
48-
49-
if (config.csrfProtection && config.csrfProtection.enabled instanceof Boolean) {
50-
csrfProtectionEnabled = config.csrfProtection.enabled
51-
}
52-
53-
if (config.baseUrl instanceof List || config.baseUrl instanceof String) {
54-
baseUrl = config.baseUrl
18+
ConsoleConfig(Config config, String basePath) {
19+
enabled = config.getProperty("${basePath}${basePath ? '.' : ''}enabled", Boolean, Environment.current == Environment.DEVELOPMENT)
20+
newFileText = config.getProperty("${basePath}${basePath ? '.' : ''}newFileText") as String
21+
indentWithTabs = config.getProperty("${basePath}${basePath ? '.' : ''}indentWithTabs", Boolean, false)
22+
tabSize = config.getProperty("${basePath}${basePath ? '.' : ''}tabSize", Integer, 4)
23+
indentUnit = config.getProperty("${basePath}${basePath ? '.' : ''}indentUnit", Integer, 4)
24+
remoteFileStoreDefaultPath = config.getProperty("${basePath}${basePath ? '.' : ''}fileStore.remote.defaultPath") as String
25+
remoteFileStoreEnabled = config.getProperty("${basePath}${basePath ? '.' : ''}fileStore.remote.enabled", Boolean, true)
26+
csrfProtectionEnabled = config.getProperty("${basePath}${basePath ? '.' : ''}csrfProtection.enabled", Boolean, true)
27+
28+
def configuredBaseUrl = config.getProperty("${basePath}${basePath ? '.' : ''}baseUrl")
29+
if(configuredBaseUrl instanceof GString) {
30+
configuredBaseUrl = configuredBaseUrl.toString()
31+
}
32+
if (configuredBaseUrl instanceof List || configuredBaseUrl instanceof String) {
33+
baseUrl = configuredBaseUrl
5534
}
5635
}
5736
}

plugin/src/main/groovy/org/grails/plugins/console/WebConsoleGrailsPlugin.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import grails.plugins.*
55
class WebConsoleGrailsPlugin extends Plugin {
66

77
// the version or versions of Grails the plugin is designed for
8-
def grailsVersion = "6.2.0 > *"
8+
def grailsVersion = "7.0.0 > *"
99

1010
// resources that are excluded from plugin packaging
1111
def pluginExcludes = [
@@ -34,18 +34,18 @@ class WebConsoleGrailsPlugin extends Plugin {
3434
def scm = [url: 'https://github.com/gpc/grails-web-console']
3535

3636

37-
Closure doWithSpring() { {->
38-
consoleConfig(ConsoleConfig, config.getProperty('grails.plugin.console', Map, [:]))
39-
}
37+
Closure doWithSpring() {
38+
{->
39+
consoleConfig(ConsoleConfig, config, 'grails.plugin.console')
40+
}
4041
}
4142

4243
void doWithDynamicMethods() {
4344
// TODO Implement registering dynamic methods to classes (optional)
4445
}
4546

4647
void doWithApplicationContext() {
47-
// TODO set property
48-
// config.grails.assets.plugin.'console'.excludes = ['**/*']
48+
config.merge(['config.grails.assets.plugin.console.excludes': ['**/*']])
4949

5050
ConsoleUtil.initJsonConfig()
5151
}

plugin/src/test/groovy/org/grails/plugins/console/ConsoleControllerSpec.groovy

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ class ConsoleControllerSpec extends Specification implements ControllerUnitTest<
1414

1515
@Override
1616
Closure doWithConfig() {{ config ->
17-
// TODO: fix dot notation
18-
// config.grails.plugin.console.fileStore.remote.enabled = true
19-
// config.grails.plugin.console.csrfProtection.enabled = true
17+
config.merge([
18+
("config.grails.plugin.console.fileStore.remote.enabled"): true,
19+
("config.grails.plugin.console.csrfProtection.enabled"): true
20+
])
2021
}}
2122

2223
void setup() {
@@ -27,11 +28,16 @@ class ConsoleControllerSpec extends Specification implements ControllerUnitTest<
2728

2829
tempDir = Files.createTempDirectory('console').toFile()
2930

30-
controller.consoleConfig = new ConsoleConfig(config)
31+
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")
3132
}
3233

3334
void cleanup() {
3435
FileUtils.deleteDirectory tempDir
36+
config.clear()
37+
config.merge([
38+
("config.grails.plugin.console.fileStore.remote.enabled"): true,
39+
("config.grails.plugin.console.csrfProtection.enabled"): true
40+
])
3541
}
3642

3743
void 'index'() {
@@ -51,11 +57,10 @@ class ConsoleControllerSpec extends Specification implements ControllerUnitTest<
5157
model.json.baseUrl == 'http://localhost:8080/console'
5258
}
5359

54-
// TODO: fix dot notation
5560
void 'index - baseUrl with config'() {
5661
when:
57-
config['grails.plugin.console'] = [baseUrl:'http://localhost:5050/x/y/z/console']
58-
controller.consoleConfig = new ConsoleConfig(config['grails.plugin.console'])
62+
config.merge(["grails.plugin.console.baseUrl":'http://localhost:5050/x/y/z/console'])
63+
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")
5964
controller.index()
6065

6166
then:
@@ -149,12 +154,12 @@ class ConsoleControllerSpec extends Specification implements ControllerUnitTest<
149154
response.json.error.contains 'Directory not found'
150155
}
151156

152-
// TODO: fix dot notation
153157
void 'listFiles - remote file store disabled'() {
154158
given:
155159
String path = tempDir.absolutePath
156-
config['grails.plugin.console'] = [fileStore:[remote:[enabled: false]]]
157-
controller.consoleConfig = new ConsoleConfig(config['grails.plugin.console'])
160+
161+
config.merge([("grails.plugin.console.fileStore.remote.enabled"):false])
162+
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")
158163

159164
when:
160165
controller.listFiles(path)
@@ -191,8 +196,9 @@ class ConsoleControllerSpec extends Specification implements ControllerUnitTest<
191196
request.method = 'GET'
192197

193198
params.path = testFile1.absolutePath
194-
config['grails.plugin.console'] = [fileStore:[remote:[enabled: false]]]
195-
controller.consoleConfig = new ConsoleConfig(config['grails.plugin.console'])
199+
200+
config.merge([("grails.plugin.console.fileStore.remote.enabled"):false])
201+
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")
196202

197203
when:
198204
controller.file()

plugin/src/test/groovy/org/grails/plugins/console/ConsoleServiceSpec.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ConsoleServiceSpec extends Specification implements ServiceUnitTest<Consol
2323
result.output.trim() == 'cba'
2424
}
2525

26-
@Ignore
2726
void 'eval with exception'() {
2827
given:
2928
String code = '''

0 commit comments

Comments
 (0)