Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grails2 format-only column #18

Open
wants to merge 2 commits into
base: grails2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Eclipse
.classpath
.project
.gradle
.slcache
build/
.settings/
target-eclipse/

# Intellij
.idea/
*.iml
*.iws

*.log
test/reports
target
/docs
.DS_Store
plugin.xml
*.zip
*.zip.sha1
web-app
*~
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class AbstractExporter implements Exporter {
}

protected Object getValue(Object domain, String field){
return formatValue(domain, ExporterUtil.getNestedValue(domain, field), field)
return formatValue(domain, ExporterUtil.getNestedValue(domain, field, formatters?.containsKey(field)), field)
}

protected Writer getOutputStreamWriter(OutputStream outputStream) {
Expand Down
11 changes: 8 additions & 3 deletions src/groovy/de/andreasschmitt/export/exporter/ExporterUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ExporterUtil {
throw new AssertionError()
}

public static Object getNestedValue(Object domain, String field){
public static Object getNestedValue(Object domain, String field, boolean hasFormatter){
try {
// Doesn't work for dynamic properties such as tags used in taggable
return PropertyUtils.getProperty(domain, field)
Expand All @@ -35,25 +35,30 @@ class ExporterUtil {

int i = 0
def lastProp
def lastE
for(prop in subProps){
if(i == 0){
try {
lastProp = domain?."$prop"
}
catch(Exception e){
log.info("Couldn't retrieve property ${prop}", e)
lastE = e
}
}
else {
try {
lastProp = lastProp?."$prop"
}
catch(Exception e){
log.info("Couldn't retrieve property ${prop}", e)
lastE = e
}
}
i += 1
}

if (lastE && !hasFormatter) {
log.info("Couldn't retrieve property ${field}", lastE)
}

return lastProp
}
Expand Down