Skip to content

Commit

Permalink
Merge pull request #5 from jdaugherty/7.0.x
Browse files Browse the repository at this point in the history
7.0.x functioning
  • Loading branch information
codeconsole authored Oct 15, 2024
2 parents e7db473 + 5baa016 commit 1e27f5c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 91 deletions.
23 changes: 2 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,14 @@ Add a dependency in build.gradle

```groovy
repositories {
maven { url "https://jitpack.io" }
maven { url "https://repo.grails.org/grails/core/" }
}
dependencies {
compile 'com.github.gpc:grails-web-console:6.0-M2'
compile 'com.github.gpc:grails-web-console:7.0.0-SNAPSHOT'
}
```

In addition if you don't want to use jitpack.io then use following github package registry:

```groovy
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/gpc/grails-web-console")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
dependencies {
compile 'org.grails.plugins:grails-web-console:6.0-M2'
}
```

## Usage

Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ plugins {
group = "grails.app"

repositories {
mavenCentral()
maven { url "https://repo.grails.org/grails/core/" }
maven { url "https://repo.grails.org/grails/core" }
}

configurations {
Expand Down
2 changes: 0 additions & 2 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ plugins {
group "org.grails.plugins"

repositories {
mavenCentral()
maven { url "https://repo1.maven.org/maven2/" }
maven { url "https://repo.grails.org/grails/core" }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package org.grails.plugins.console
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ImportCustomizer
import grails.core.GrailsApplication
import org.grails.core.artefact.DomainClassArtefactHandler

import java.nio.charset.StandardCharsets

class ConsoleService {

Expand Down Expand Up @@ -37,7 +40,7 @@ class ConsoleService {
evaluation.totalTime = System.currentTimeMillis() - startTime

evaluation.console = console
evaluation.output = baos.toString('UTF8')
evaluation.output = baos.toString(StandardCharsets.UTF_8.name())
evaluation
}

Expand All @@ -57,7 +60,9 @@ class ConsoleService {
CompilerConfiguration configuration = new CompilerConfiguration()
if (autoImportDomains) {
ImportCustomizer importCustomizer = new ImportCustomizer()
importCustomizer.addImports(*grailsApplication.domainClasses*.fullName)
grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE).each { domainClass ->
importCustomizer.addImport(domainClass.clazz.simpleName, domainClass.clazz.name)
}
configuration.addCompilationCustomizers importCustomizer
}
configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,36 @@
package org.grails.plugins.console

import grails.config.Config
import grails.util.Environment

class ConsoleConfig {

boolean enabled
String newFileText = null
boolean indentWithTabs = false
int tabSize = 4
int indentUnit = 4
String remoteFileStoreDefaultPath = null
boolean remoteFileStoreEnabled = true
boolean csrfProtectionEnabled = true
String newFileText
boolean indentWithTabs
int tabSize
int indentUnit
String remoteFileStoreDefaultPath
boolean remoteFileStoreEnabled
boolean csrfProtectionEnabled
def baseUrl

ConsoleConfig(Map config) {

if (config.enabled instanceof Boolean) {
enabled = config.enabled
} else {
enabled = Environment.current == Environment.DEVELOPMENT
}

if (config.newFileText instanceof String) {
newFileText = config.newFileText
}

if (config.indentWithTabs instanceof Boolean) {
indentWithTabs = config.indentWithTabs
}

if (config.tabSize instanceof Integer) {
tabSize = config.tabSize as Integer
}

if (config.indentUnit instanceof Integer) {
indentUnit = config.indentUnit as Integer
}

if (config.fileStore && config.fileStore.remote && config.fileStore.remote.defaultPath instanceof String) {
remoteFileStoreDefaultPath = config.fileStore.remote.defaultPath
}

if (config.fileStore && config.fileStore.remote && config.fileStore.remote.enabled instanceof Boolean) {
remoteFileStoreEnabled = config.fileStore.remote.enabled
}

if (config.csrfProtection && config.csrfProtection.enabled instanceof Boolean) {
csrfProtectionEnabled = config.csrfProtection.enabled
}

if (config.baseUrl instanceof List || config.baseUrl instanceof String) {
baseUrl = config.baseUrl
ConsoleConfig(Config config, String basePath) {
enabled = config.getProperty("${basePath}${basePath ? '.' : ''}enabled", Boolean, Environment.current == Environment.DEVELOPMENT)
newFileText = config.getProperty("${basePath}${basePath ? '.' : ''}newFileText") as String
indentWithTabs = config.getProperty("${basePath}${basePath ? '.' : ''}indentWithTabs", Boolean, false)
tabSize = config.getProperty("${basePath}${basePath ? '.' : ''}tabSize", Integer, 4)
indentUnit = config.getProperty("${basePath}${basePath ? '.' : ''}indentUnit", Integer, 4)
remoteFileStoreDefaultPath = config.getProperty("${basePath}${basePath ? '.' : ''}fileStore.remote.defaultPath") as String
remoteFileStoreEnabled = config.getProperty("${basePath}${basePath ? '.' : ''}fileStore.remote.enabled", Boolean, true)
csrfProtectionEnabled = config.getProperty("${basePath}${basePath ? '.' : ''}csrfProtection.enabled", Boolean, true)

def configuredBaseUrl = config.getProperty("${basePath}${basePath ? '.' : ''}baseUrl")
if(configuredBaseUrl instanceof GString) {
configuredBaseUrl = configuredBaseUrl.toString()
}
if (configuredBaseUrl instanceof List || configuredBaseUrl instanceof String) {
baseUrl = configuredBaseUrl
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import grails.plugins.*
class WebConsoleGrailsPlugin extends Plugin {

// the version or versions of Grails the plugin is designed for
def grailsVersion = "6.2.0 > *"
def grailsVersion = "7.0.0 > *"

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


Closure doWithSpring() { {->
consoleConfig(ConsoleConfig, config.getProperty('grails.plugin.console', Map, [:]))
}
Closure doWithSpring() {
{->
consoleConfig(ConsoleConfig, config, 'grails.plugin.console')
}
}

void doWithDynamicMethods() {
// TODO Implement registering dynamic methods to classes (optional)
}

void doWithApplicationContext() {
// TODO set property
// config.grails.assets.plugin.'console'.excludes = ['**/*']
config.merge(['config.grails.assets.plugin.console.excludes': ['**/*']])

ConsoleUtil.initJsonConfig()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class ConsoleControllerSpec extends Specification implements ControllerUnitTest<

@Override
Closure doWithConfig() {{ config ->
// TODO: fix dot notation
// config.grails.plugin.console.fileStore.remote.enabled = true
// config.grails.plugin.console.csrfProtection.enabled = true
config.merge([
("config.grails.plugin.console.fileStore.remote.enabled"): true,
("config.grails.plugin.console.csrfProtection.enabled"): true
])
}}

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

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

controller.consoleConfig = new ConsoleConfig(config)
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")
}

void cleanup() {
FileUtils.deleteDirectory tempDir
config.clear()
config.merge([
("config.grails.plugin.console.fileStore.remote.enabled"): true,
("config.grails.plugin.console.csrfProtection.enabled"): true
])
}

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

// TODO: fix dot notation
void 'index - baseUrl with config'() {
when:
config['grails.plugin.console'] = [baseUrl:'http://localhost:5050/x/y/z/console']
controller.consoleConfig = new ConsoleConfig(config['grails.plugin.console'])
config.merge(["grails.plugin.console.baseUrl":'http://localhost:5050/x/y/z/console'])
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")
controller.index()

then:
Expand Down Expand Up @@ -149,12 +154,12 @@ class ConsoleControllerSpec extends Specification implements ControllerUnitTest<
response.json.error.contains 'Directory not found'
}

// TODO: fix dot notation
void 'listFiles - remote file store disabled'() {
given:
String path = tempDir.absolutePath
config['grails.plugin.console'] = [fileStore:[remote:[enabled: false]]]
controller.consoleConfig = new ConsoleConfig(config['grails.plugin.console'])

config.merge([("grails.plugin.console.fileStore.remote.enabled"):false])
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")

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

params.path = testFile1.absolutePath
config['grails.plugin.console'] = [fileStore:[remote:[enabled: false]]]
controller.consoleConfig = new ConsoleConfig(config['grails.plugin.console'])

config.merge([("grails.plugin.console.fileStore.remote.enabled"):false])
controller.consoleConfig = new ConsoleConfig(config, "grails.plugin.console")

when:
controller.file()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ConsoleServiceSpec extends Specification implements ServiceUnitTest<Consol
result.output.trim() == 'cba'
}

@Ignore
void 'eval with exception'() {
given:
String code = '''
Expand Down

0 comments on commit 1e27f5c

Please sign in to comment.