Burt Beckwith avatar Burt Beckwith committed 9a89a59

cleanup

Comments (0)

Files changed (8)

 stacktrace.log
 target
 /plugins
-/web-app/plugins
-/web-app/WEB-INF/classes
-web-app/WEB-INF/tld/c.tld
-web-app/WEB-INF/tld/fmt.tld
+/web-app
+plugin.xml
+*.zip

JSONExclusionMarshallerGrailsPlugin.groovy

+import grails.converters.JSON
+import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
+
 class JSONExclusionMarshallerGrailsPlugin {
-    // the plugin version
     def version = "0.2"
-    // the version or versions of Grails the plugin is designed for
     def grailsVersion = "2.0 > *"
-    // resources that are excluded from plugin packaging
     def pluginExcludes = [
-        "grails-app/views/error.gsp"
+        "grails-app/domain/**"
     ]
 
-    // TODO Fill in these fields
-    def title = "JSON Exclusion Marshaller Plugin" // Headline display name of the plugin
+    def title = "JSON Exclusion Marshaller Plugin"
     def author = "Jason Stonebraker"
     def authorEmail = "jasonstonebraker@gmail.com"
-    def description = '''\
-A Grails plugin that adds a convenience method to the Grails JSON converter for excluding properties from JSON output. Example use: excludeForPublicAPI(MyDomainClass, ['id', 'class']).
-'''
+    def description = '''Adds a convenience method to the Grails JSON converter for excluding properties from JSON output. Example use: excludeForPublicAPI(MyDomainClass, ['id', 'class']).'''
 
-    // URL to the plugin's documentation
     def documentation = "http://grails.org/plugin/json-exclusion-marshaller"
 
-    // Extra (optional) plugin metadata
-
-    // License: one of 'APACHE', 'GPL2', 'GPL3'
-//    def license = "APACHE"
-
-    // Details of company behind the plugin (if there is one)
-//    def organization = [ name: "My Company", url: "http://www.my-company.com/" ]
-
-    // Any additional developers beyond the author specified above.
-//    def developers = [ [ name: "Joe Bloggs", email: "joe@bloggs.net" ]]
-
-    // Location of the plugin's issue tracker.
-   def issueManagement = [ system: "Bitbucket", url: "https://bitbucket.org/stonebraker/jsonexclusionmarshaller/issues" ]
-
-    // Online location of the plugin's browseable source code.
-   def scm = [ url: "https://bitbucket.org/stonebraker/jsonexclusionmarshaller/src" ]
-
-    def doWithWebDescriptor = { xml ->
-        // TODO Implement additions to web.xml (optional), this event occurs before
-    }
-
-    def doWithSpring = {
-        // TODO Implement runtime spring config (optional)
-    }
+    def license = "APACHE"
+    def issueManagement = [ system: "Bitbucket", url: "https://bitbucket.org/stonebraker/jsonexclusionmarshaller/issues" ]
+    def scm = [ url: "https://bitbucket.org/stonebraker/jsonexclusionmarshaller/src" ]
 
     def doWithDynamicMethods = { ctx ->
         // TODO Implement registering dynamic methods to classes (optional)
         // println "Do with dynamic methods called..."
 
-        grails.converters.JSON.metaClass.'static'.methodMissing = { String name, args ->
+        JSON.metaClass.static.methodMissing = { String name, args ->
             def jsonConverter = delegate
-            def isAnExclusionaryMethod = name.startsWith('excludeFor')
-
-            if (isAnExclusionaryMethod) {
-                def impl = { Object[] vargs ->
-                    def configName = name // The name of the missing method called
-                    def type = vargs[0]
-                    def propertiesToExclude = vargs[1]
+            boolean isAnExclusionaryMethod = name.startsWith('excludeFor')
 
-                    jsonConverter.createNamedConfig(configName) {
-                        it.registerObjectMarshaller(type) {
-                            def obj = it, // Object being marshalled
-                                gdc = new org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass(type),
-                                map = [:]
+            if (!isAnExclusionaryMethod) {
+                throw new MissingMethodException(name, JSON, args)
+            }
 
-                            map["${gdc.identifier.name}"] = obj."${gdc.identifier.name}"
-                            map['class'] = obj.getClass().name
+            def impl = { Object[] vargs ->
+                String configName = name // The name of the missing method called
+                def type = vargs[0]
+                def propertiesToExclude = vargs[1]
 
-                            gdc.persistentProperties.each { property ->
-                                map["${property.name}"] = obj."${property.name}"
-                            }
+                jsonConverter.createNamedConfig(configName) {
+                    it.registerObjectMarshaller(type) {
+                        def obj = it // Object being marshalled
+                        def gdc = new DefaultGrailsDomainClass(type)
+                        def map = [:]
 
-                            propertiesToExclude.each { property -> map.remove(property) }
+                        map["${gdc.identifier.name}"] = obj."${gdc.identifier.name}"
+                        map['class'] = obj.getClass().name
 
-                            return map
+                        gdc.persistentProperties.each { property ->
+                            map["${property.name}"] = obj."${property.name}"
                         }
+
+                        propertiesToExclude.each { property -> map.remove(property) }
+
+                        return map
                     }
                 }
 
-                grails.converters.JSON.metaClass."$name" = impl //future calls will use this
+                JSON.metaClass."$name" = impl //future calls will use this
 
                 return impl(args)
-            } else {
-                throw new MissingMethodException(name, grails.converters.JSON.class, args)
             }
         }
-
-    }
-
-    def doWithApplicationContext = { applicationContext ->
-        // TODO Implement post initialization spring config (optional)
-    }
-
-    def onChange = { event ->
-        // TODO Implement code that is executed when any artefact that this plugin is
-        // watching is modified and reloaded. The event contains: event.source,
-        // event.application, event.manager, event.ctx, and event.plugin.
-    }
-
-    def onConfigChange = { event ->
-        // TODO Implement code that is executed when the project configuration changes.
-        // The event is the same as for 'onChange'.
-    }
-
-    def onShutdown = { event ->
-        // TODO Implement code that is executed when the application shuts down (optional)
     }
 }

application.properties

-#Grails Metadata file
-#Fri Jun 28 17:59:51 EDT 2013
 app.grails.version=2.2.2
-app.name=JSONExclusionMarshaller

grails-app/conf/BuildConfig.groovy

-grails.project.class.dir = "target/classes"
-grails.project.test.class.dir = "target/test-classes"
-grails.project.test.reports.dir = "target/test-reports"
+grails.project.work.dir = 'target'
 
 grails.project.dependency.resolution = {
-    // inherit Grails' default dependencies
-    inherits("global") {
-        // uncomment to disable ehcache
-        // excludes 'ehcache'
-    }
-    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
-    legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
-    repositories {
-        grailsCentral()
-        mavenCentral()
-        // uncomment the below to enable remote dependency resolution
-        // from public Maven repositories
-        //mavenLocal()
-        //mavenRepo "http://snapshots.repository.codehaus.org"
-        //mavenRepo "http://repository.codehaus.org"
-        //mavenRepo "http://download.java.net/maven/2/"
-        //mavenRepo "http://repository.jboss.com/maven2/"
-    }
-    dependencies {
-        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
 
-        // runtime 'mysql:mysql-connector-java:5.1.21'
-    }
+	inherits 'global'
+	log 'warn'
 
-    plugins {
-        build(":tomcat:$grailsVersion",
-              ":release:2.2.1",
-              ":rest-client-builder:1.0.3") {
-            export = false
-        }
-    }
+	repositories {
+		grailsCentral()
+	}
+
+	plugins {
+		build ':release:2.2.1', ':rest-client-builder:1.0.3', {
+			export = false
+		}
+	}
 }

grails-app/conf/Config.groovy

-// configuration for plugin testing - will not be included in the plugin zip
-
 log4j = {
-    // Example of changing the log pattern for the default console
-    // appender:
-    //
-    //appenders {
-    //    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
-    //}
-
-    error  'org.codehaus.groovy.grails.web.servlet',  //  controllers
-           'org.codehaus.groovy.grails.web.pages', //  GSP
-           'org.codehaus.groovy.grails.web.sitemesh', //  layouts
-           'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
-           'org.codehaus.groovy.grails.web.mapping', // URL mapping
-           'org.codehaus.groovy.grails.commons', // core / classloading
-           'org.codehaus.groovy.grails.plugins', // plugins
-           'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
-           'org.springframework',
-           'org.hibernate',
-           'net.sf.ehcache.hibernate'
-
-    warn   'org.mortbay.log'
+	error 'org.codehaus.groovy.grails',
+	      'org.springframework',
+	      'org.hibernate',
+	      'net.sf.ehcache.hibernate'
 }

grails-app/conf/DataSource.groovy

 dataSource {
-    pooled = true
-    driverClassName = "org.h2.Driver"
-    username = "sa"
-    password = ""
+	pooled = true
+	driverClassName = 'org.h2.Driver'
+	username = 'sa'
+	password = ''
+	dbCreate = 'update'
+	url = 'jdbc:h2:mem:testDb'
 }
+
 hibernate {
-    cache.use_second_level_cache = true
-    cache.use_query_cache = false
-    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
-}
-// environment specific settings
-environments {
-    development {
-        dataSource {
-            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
-            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
-        }
-    }
-    test {
-        dataSource {
-            dbCreate = "update"
-            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
-        }
-    }
-    production {
-        dataSource {
-            dbCreate = "update"
-            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
-            pooled = true
-            properties {
-               maxActive = -1
-               minEvictableIdleTimeMillis=1800000
-               timeBetweenEvictionRunsMillis=1800000
-               numTestsPerEvictionRun=3
-               testOnBorrow=true
-               testWhileIdle=true
-               testOnReturn=true
-               validationQuery="SELECT 1"
-            }
-        }
-    }
+	cache.use_second_level_cache = false
+	cache.use_query_cache = false
+	cache.provider_class = 'org.hibernate.cache.EhCacheProvider'
 }

grails-app/domain/stonebraker/jxm/TestStudent.groovy

 	Number gradePointAverage
 	String studentID
 	String socialSecurityNumber
-
-    static constraints = {
-    }
 }

test/integration/stonebraker/jxm/TestStudentTests.groovy

 class TestStudentTests {
     // Logger log = LoggerFactory.getLogger(TestStudentTests)
 
-    @Before
-    void setUp() {
-        // Setup logic here
-    }
-
-    @After
-    void tearDown() {
-        // Tear down logic here
-    }
-
     @Test
     void testCanPrintATestStudentAsJSON() {
         // Given
         // it may warrant some explanation. Though hopefully not a lot.
 
         // In order to exclude class properties from JSON output, we create 'excluders.' Don't go looking for
-        // an 'Excluder' class, you won't find it. That's just what I call ObjectMarshallers that exclude 
+        // an 'Excluder' class, you won't find it. That's just what I call ObjectMarshallers that exclude
         // properties from rendering.
 
         // Excluders are created using: excludeFor*(Class class, List<String> propertiesToExclude)
         // Each excluder needs an excluder name, the target class name, and a list of properties to exclude from that class.
 
         // We'll look at the 'excludeForTeachers' excluder.
-        // Name: "excludeForTeachers" <--- You can use anything you want after "excludeFor", in this case I 
-        //       chose "Teachers" since in my domain, teachers aren't allowed to see a student's social 
+        // Name: "excludeForTeachers" <--- You can use anything you want after "excludeFor", in this case I
+        //       chose "Teachers" since in my domain, teachers aren't allowed to see a student's social
         //       security number. In this way, I'm able to use domain specific language in code.
         // Class: TestStudent <--- The domain class being marshalled
         // List<String>: ['socialSecurityNumber', 'id', 'class'] <--- The properties that will be excluded
         // Usage: Once you've created an excluder, you simply call JSON.use('excludeForWhatever') { ... }
         // ... and of course do stuff within the closure per the example below.
         // As seen here, we can create multiple excluders and use them as needed.
-        
+
         JSON.excludeForTeachers(TestStudent, ['socialSecurityNumber', 'id', 'class'])
         JSON.excludeForOtherStudents(TestStudent, ['gradePointAverage', 'studentID', 'socialSecurityNumber', 'id', 'class'])
         JSON.excludeForTestAdministrators(TestStudent, ['gradePointAverage', 'socialSecurityNumber', 'id', 'class'])
 
 /*
 
-What's actually happening? Basically the excludeFor*() method creates a Named Configuration with a name of 
+What's actually happening? Basically the excludeFor*() method creates a Named Configuration with a name of
 'excludeForWhateverYouDecideToNameIt'. The Named Configuration then registers a custom ObjectMarshaller for the
 TestStudent domain class. The custom object marshaller is built into the excludesFor* sythesized method. It
 removes the properties we provided to it in the list. The JSON converter then outputs the desired JSON formatted string.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.