From d943effdec5d3b220c04da064eac8006263f07e7 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Sat, 16 Mar 2013 16:17:40 -1000 Subject: [PATCH] #135: grails tests passing again --- .../application.properties | 5 - .../build.gradle | 19 +--- .../grails-app/conf/BootStrap.groovy | 6 +- .../grails-app/conf/BuildConfig.groovy | 105 ++++++++++-------- .../console/controllers/UserController.groovy | 6 +- .../linkedin/glu/console/domain/User.groovy | 3 +- .../glu/console/realms/ShiroLdapRealm.groovy | 3 +- .../domain/UserIntegrationTests.groovy | 5 +- docs/manual/build.gradle | 4 +- .../grails-external-domain-classes-1.0.0.zip | Bin .../CustomDeltaDefinitionStorageImpl.groovy | 34 +++++- project-spec.groovy | 15 +-- settings.gradle | 10 +- 13 files changed, 116 insertions(+), 99 deletions(-) rename local-maven-repo/{com/pongasoft/grails-external-domain-classes => org/grails/plugins/external-domain-classes}/1.0.0/grails-external-domain-classes-1.0.0.zip (100%) diff --git a/console/org.linkedin.glu.console-webapp/application.properties b/console/org.linkedin.glu.console-webapp/application.properties index 3051697a..a776c416 100644 --- a/console/org.linkedin.glu.console-webapp/application.properties +++ b/console/org.linkedin.glu.console-webapp/application.properties @@ -4,8 +4,3 @@ app.grails.version=2.2.1 app.name=console app.servlet.version=2.5 app.version=dev -plugins.external-domain-classes=1.0.0 -plugins.hibernate=2.2.1 -plugins.jquery=1.6.1.1 -plugins.shiro=1.1-SNAPSHOT -plugins.tomcat=2.2.1 diff --git a/console/org.linkedin.glu.console-webapp/build.gradle b/console/org.linkedin.glu.console-webapp/build.gradle index aada36fb..b5897699 100644 --- a/console/org.linkedin.glu.console-webapp/build.gradle +++ b/console/org.linkedin.glu.console-webapp/build.gradle @@ -31,6 +31,7 @@ dependencies { compile spec.external.groovy + runtime spec.external.hsqldb runtime spec.external.slf4jLog4j runtime spec.external.log4j } @@ -55,13 +56,13 @@ def facets = """ """ -ideaModule { - whenConfigured { module -> +idea.module.iml { + whenMerged { module -> ['grails-app/utils', 'grails-app/controllers', 'grails-app/domain', 'grails-app/services', 'grails-app/realms', 'grails-app/taglib', 'grails-app/conf'].each { - module.sourceFolders << new org.gradle.plugins.idea.model.Path("file://\$MODULE_DIR\$/${it}") + module.sourceFolders << new org.gradle.plugins.ide.idea.model.Path("file://\$MODULE_DIR\$/${it}") } ['test/unit', 'test/integration'].each { - module.testSourceFolders << new org.gradle.plugins.idea.model.Path("file://\$MODULE_DIR\$/${it}") + module.testSourceFolders << new org.gradle.plugins.ide.idea.model.Path("file://\$MODULE_DIR\$/${it}") } } @@ -78,18 +79,12 @@ project.clean << { fileTree(dir: 'lib').each { it.delete() } } -workaroundDir = new File(buildDir, "distributions/lib") - task lib(dependsOn: jar) << { fileTree(dir: 'lib').each { it.delete() } copy { from configurations.runtime into 'lib' } - // workaround against /org/apache/tools/ant/antlib.xml:37: Problem: failed to create - // task or type componentdef - ant.move(file: file('lib/ant-1.8.1.jar'), todir: workaroundDir) - ant.move(file: file('lib/ant-launcher-1.8.1.jar'), todir: workaroundDir) // issue is that we end up with duplicate files (with slightly different names!) because grails // add them! @@ -136,10 +131,6 @@ task war(dependsOn: lib) << { ant.exec(dir: '.', executable: "grails") { arg(line: "-Dgrails.project.war.file=${warFile} -Dbuild.version=${project.version} war") } - - ant.war(destfile: warFile, update: true) { - lib(dir: workaroundDir, includes: '*.jar') - } } task([type: SingleArtifactTask, dependsOn: 'war'], 'package-war') { diff --git a/console/org.linkedin.glu.console-webapp/grails-app/conf/BootStrap.groovy b/console/org.linkedin.glu.console-webapp/grails-app/conf/BootStrap.groovy index b37befa3..c943ae95 100644 --- a/console/org.linkedin.glu.console-webapp/grails-app/conf/BootStrap.groovy +++ b/console/org.linkedin.glu.console-webapp/grails-app/conf/BootStrap.groovy @@ -1,6 +1,6 @@ /* * Copyright (c) 2010-2010 LinkedIn, Inc - * Portions Copyright (c) 2011 Yan Pujante + * Portions Copyright (c) 2011-2013 Yan Pujante * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -99,7 +99,7 @@ class BootStrap { ].each { username, roles -> User.withTransaction { status -> User user = new User(username: username) - user.setRoles(roles) + user.updateRoles(roles) if(!user.save()) throw new RuntimeException("could not create ${username} user") @@ -121,7 +121,7 @@ class BootStrap { User.withTransaction { status -> def userInstance = new User(username: "admin") - userInstance.setRoles([RoleName.USER, RoleName.RELEASE, RoleName.ADMIN]) + userInstance.updateRoles([RoleName.USER, RoleName.RELEASE, RoleName.ADMIN]) if(!userInstance.save()) throw new RuntimeException("could not create admin user") diff --git a/console/org.linkedin.glu.console-webapp/grails-app/conf/BuildConfig.groovy b/console/org.linkedin.glu.console-webapp/grails-app/conf/BuildConfig.groovy index 0d7b64ab..e76ac542 100644 --- a/console/org.linkedin.glu.console-webapp/grails-app/conf/BuildConfig.groovy +++ b/console/org.linkedin.glu.console-webapp/grails-app/conf/BuildConfig.groovy @@ -27,53 +27,62 @@ grails.project.source.level = 1.6 // run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256] //] +//def externalDomainClassesInPlacePluginPath = new File("../external-domain-classes") +//grails.plugin.location.'external-domain-classes' = +// externalDomainClassesInPlacePluginPath.canonicalPath + grails.project.dependency.resolution = { - // inherit Grails' default dependencies - inherits("global") { - // specify dependency exclusions here; for example, uncomment this to disable ehcache: - // excludes 'ehcache' - } - log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose' - checksums true // Whether to verify checksums on resolve - legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility - - repositories { - inherits true // Whether to inherit repository definitions from plugins - - grailsPlugins() - grailsHome() - grailsCentral() - - mavenLocal() - mavenCentral() - - // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories - //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 e.g. - - // runtime 'mysql:mysql-connector-java:5.1.22' - } - - plugins { - runtime ":hibernate:$grailsVersion" - runtime ":jquery:1.8.3" - runtime ":resources:1.1.6" - - // Uncomment these (or add new ones) to enable additional resources capabilities - //runtime ":zipped-resources:1.0" - //runtime ":cached-resources:1.0" - //runtime ":yui-minify-resources:0.1.5" - - build ":tomcat:$grailsVersion" - - runtime ":database-migration:1.3.2" - - compile ':cache:1.0.1' - } + // inherit Grails' default dependencies + inherits("global") { + // specify dependency exclusions here; for example, uncomment this to disable ehcache: + // excludes 'ehcache' + } + log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose' + checksums true // Whether to verify checksums on resolve + legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility + + repositories { + inherits true // Whether to inherit repository definitions from plugins + + grailsPlugins() + grailsHome() + grailsCentral() + + mavenLocal() + mavenCentral() + + mavenRepo new File("../../local-maven-repo").canonicalFile.toURI().toString() + + // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories + //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 e.g. + + // runtime 'mysql:mysql-connector-java:5.1.22' + } + + plugins { + + runtime ":hibernate:$grailsVersion" + runtime ":jquery:1.8.3" + runtime ":resources:1.1.6" + runtime ":external-domain-classes:1.0.0" + + // Uncomment these (or add new ones) to enable additional resources capabilities + //runtime ":zipped-resources:1.0" + //runtime ":cached-resources:1.0" + //runtime ":yui-minify-resources:0.1.5" + + build ":tomcat:$grailsVersion" + + runtime ":database-migration:1.3.2" + + compile ':cache:1.0.1' + compile ":shiro:1.1.4" + } } diff --git a/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/UserController.groovy b/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/UserController.groovy index 43b3aa98..63074946 100644 --- a/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/UserController.groovy +++ b/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/UserController.groovy @@ -1,6 +1,6 @@ /* * Copyright (c) 2010-2010 LinkedIn, Inc - * Portions Copyright (c) 2011 Yan Pujante + * Portions Copyright (c) 2011-2013 Yan Pujante * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -112,7 +112,7 @@ class UserController extends ControllerBase return } } - userInstance.setRoles(role) + userInstance.updateRoles(role) if(!userInstance.hasErrors() && userInstance.save([flush: true])) { flash.success = "User ${userInstance.username} updated" @@ -156,7 +156,7 @@ class UserController extends ControllerBase return } - userInstance.setRoles(RoleName.USER) + userInstance.updateRoles(RoleName.USER) DbUserCredentials ucr = new DbUserCredentials(username: params.username, password: params.password) diff --git a/console/org.linkedin.glu.console-webapp/grails-app/domain/org/linkedin/glu/console/domain/User.groovy b/console/org.linkedin.glu.console-webapp/grails-app/domain/org/linkedin/glu/console/domain/User.groovy index 38138a77..33e0d6be 100644 --- a/console/org.linkedin.glu.console-webapp/grails-app/domain/org/linkedin/glu/console/domain/User.groovy +++ b/console/org.linkedin.glu.console-webapp/grails-app/domain/org/linkedin/glu/console/domain/User.groovy @@ -1,5 +1,6 @@ /* * Copyright (c) 2010-2010 LinkedIn, Inc + * Portions Copyright (c) 2013 Yan Pujante * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -94,7 +95,7 @@ class User * Set the roles to be exactly what is provided: conceptually remove all the roles and add only * the new ones. */ - def setRoles(newRoles) + def updateRoles(newRoles) { newRoles = newRoles?.collect { RoleName.valueOf(it.toString()) } ?: [] diff --git a/console/org.linkedin.glu.console-webapp/grails-app/realms/org/linkedin/glu/console/realms/ShiroLdapRealm.groovy b/console/org.linkedin.glu.console-webapp/grails-app/realms/org/linkedin/glu/console/realms/ShiroLdapRealm.groovy index 243db1e1..e2a68911 100644 --- a/console/org.linkedin.glu.console-webapp/grails-app/realms/org/linkedin/glu/console/realms/ShiroLdapRealm.groovy +++ b/console/org.linkedin.glu.console-webapp/grails-app/realms/org/linkedin/glu/console/realms/ShiroLdapRealm.groovy @@ -1,5 +1,6 @@ /* * Copyright (c) 2010-2010 LinkedIn, Inc + * Portions Copyright (c) 2013 Yan Pujante * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -182,7 +183,7 @@ class ShiroLdapRealm if(!User.findByUsername(username)) { User user = new User(username: username) - user.setRoles([RoleName.USER]) + user.updateRoles([RoleName.USER]) if(!user.save()) { def msg = "Could not create user ${username} => ${user.errors.toString()}".toString() diff --git a/console/org.linkedin.glu.console-webapp/test/integration/org/linkedin/glu/console/domain/UserIntegrationTests.groovy b/console/org.linkedin.glu.console-webapp/test/integration/org/linkedin/glu/console/domain/UserIntegrationTests.groovy index 1523d670..af539c89 100644 --- a/console/org.linkedin.glu.console-webapp/test/integration/org/linkedin/glu/console/domain/UserIntegrationTests.groovy +++ b/console/org.linkedin.glu.console-webapp/test/integration/org/linkedin/glu/console/domain/UserIntegrationTests.groovy @@ -1,5 +1,6 @@ /* * Copyright (c) 2010-2010 LinkedIn, Inc + * Portions Copyright (c) 2013 Yan Pujante * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -75,7 +76,7 @@ class UserIntegrationTests extends GroovyTestCase assertFalseUsingGroovyTruth(user.impliesRole(RoleName.RESTRICTED)) // we test the setRoles method - user.setRoles([RoleName.USER, RoleName.ADMIN, RoleName.RELEASE]) + user.updateRoles([RoleName.USER, RoleName.ADMIN, RoleName.RELEASE]) assertNotNull(user.save()) assertEquals('user1', user.username) @@ -88,7 +89,7 @@ class UserIntegrationTests extends GroovyTestCase assertFalseUsingGroovyTruth(user.impliesRole(RoleName.RESTRICTED)) // we test the setRoles method - user.setRoles([RoleName.USER, RoleName.RESTRICTED]) + user.updateRoles([RoleName.USER, RoleName.RESTRICTED]) assertNotNull(user.save()) assertEquals('user1', user.username) diff --git a/docs/manual/build.gradle b/docs/manual/build.gradle index 65aeb2cb..57907a93 100644 --- a/docs/manual/build.gradle +++ b/docs/manual/build.gradle @@ -20,7 +20,9 @@ import org.apache.tools.ant.filters.ReplaceTokens def sphinxDir = new File(buildDir, "sphinx") -def htmlDocDir = new File(sphinxDir, "build/html") +ext { + htmlDocDir = new File(sphinxDir, "build/html") +} def syncDir = new File(userConfig.doc.sync.dir ?: "${rootDir}/../linkedin.github.com/glu/docs/latest/html").canonicalFile diff --git a/local-maven-repo/com/pongasoft/grails-external-domain-classes/1.0.0/grails-external-domain-classes-1.0.0.zip b/local-maven-repo/org/grails/plugins/external-domain-classes/1.0.0/grails-external-domain-classes-1.0.0.zip similarity index 100% rename from local-maven-repo/com/pongasoft/grails-external-domain-classes/1.0.0/grails-external-domain-classes-1.0.0.zip rename to local-maven-repo/org/grails/plugins/external-domain-classes/1.0.0/grails-external-domain-classes-1.0.0.zip diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/groovy/org/linkedin/glu/orchestration/engine/delta/CustomDeltaDefinitionStorageImpl.groovy b/orchestration/org.linkedin.glu.orchestration-engine/src/main/groovy/org/linkedin/glu/orchestration/engine/delta/CustomDeltaDefinitionStorageImpl.groovy index d512690c..1df0a503 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/groovy/org/linkedin/glu/orchestration/engine/delta/CustomDeltaDefinitionStorageImpl.groovy +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/groovy/org/linkedin/glu/orchestration/engine/delta/CustomDeltaDefinitionStorageImpl.groovy @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Yan Pujante + * Copyright (c) 2011-2013 Yan Pujante * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -17,23 +17,31 @@ package org.linkedin.glu.orchestration.engine.delta import org.linkedin.util.annotations.Initializable +import org.slf4j.Logger +import org.slf4j.LoggerFactory /** * @author yan@pongasoft.com */ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionStorage { + public static final String MODULE = CustomDeltaDefinitionStorageImpl.class.getName(); + public static final Logger log = LoggerFactory.getLogger(MODULE); + @Initializable(required = true) CustomDeltaDefinitionSerializer customDeltaDefinitionSerializer @Override boolean save(UserCustomDeltaDefinition definition) { + definition = autoWire(definition) definition.save([flush: true]) } @Override boolean delete(UserCustomDeltaDefinition definition) { + definition = autoWire(definition) + // TODO MED YP: somehow definition.delete([flush: true]) is not working and giving the following // messsage: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are // not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into @@ -46,7 +54,7 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt @Override UserCustomDeltaDefinition findByUsernameAndName(String username, String name) { - UserCustomDeltaDefinition.findByUsernameAndName(username, name) + autoWire(UserCustomDeltaDefinition.findByUsernameAndName(username, name)) } @Override @@ -60,7 +68,7 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt if(includeDetails) { - list = UserCustomDeltaDefinition.findAllByUsername(username, params) + list = autoWire(UserCustomDeltaDefinition.findAllByUsername(username, params)) } else { @@ -84,7 +92,7 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt if(includeDetails) { - list = UserCustomDeltaDefinition.findAllByShareable(true, params) + list = autoWire(UserCustomDeltaDefinition.findAllByShareable(true, params)) } else { @@ -97,6 +105,24 @@ public class CustomDeltaDefinitionStorageImpl implements CustomDeltaDefinitionSt ] } + /** + * This method is a workaround for 2.x which breaks auto-wiring + */ + protected UserCustomDeltaDefinition autoWire(UserCustomDeltaDefinition ucdd) + { + ucdd.customDeltaDefinitionSerializer = customDeltaDefinitionSerializer + return ucdd + } + + /** + * This method is a workaround for 2.x which breaks auto-wiring + */ + protected Collection autoWire(Collection list) + { + list.each { autoWire(it) } + return list + } + protected def processParams(params) { if(params.offset == null) diff --git a/project-spec.groovy b/project-spec.groovy index 5206c74d..94d8987b 100644 --- a/project-spec.groovy +++ b/project-spec.groovy @@ -55,6 +55,7 @@ spec.external = [ grailsCore: "org.grails:grails-core:${spec.versions.grails}", groovy: "org.codehaus.groovy:groovy:${spec.versions.groovy}", groovyTest: "org.codehaus.groovy:groovy-test:${spec.versions.groovy}", + hsqldb: "hsqldb:hsqldb:1.8.0.10", httpClient: "org.apache.httpcomponents:httpclient:4.2.3", ivy: 'org.apache.ivy:ivy:2.2.0', jettyPackage: [ @@ -67,19 +68,9 @@ spec.external = [ linkedinUtilsCore: "org.linkedin:org.linkedin.util-core:${spec.versions.linkedinUtils}", linkedinUtilsGroovy: "org.linkedin:org.linkedin.util-groovy:${spec.versions.linkedinUtils}", linkedinZookeeperCliImpl: "org.linkedin:org.linkedin.zookeeper-cli-impl:${spec.versions.linkedinZookeeper}", - linkedinZookeeperCliPackage: [ - group: "org.linkedin", - name: "org.linkedin.zookeeper-cli", - version: spec.versions.linkedinZookeeper, - packaging: "tgz" - ], + linkedinZookeeperCliPackage: "org.linkedin:org.linkedin.zookeeper-cli:${spec.versions.linkedinZookeeper}@tgz", linkedinZookeeperImpl: "org.linkedin:org.linkedin.zookeeper-impl:${spec.versions.linkedinZookeeper}", - linkedinZookeeperServerPackage: [ - group: "org.linkedin", - name: "org.linkedin.zookeeper-server", - version: spec.versions.linkedinZookeeper, - packaging: "tgz" - ], + linkedinZookeeperServerPackage: "org.linkedin:org.linkedin.zookeeper-server:${spec.versions.linkedinZookeeper}@tgz", log4j: 'log4j:log4j:1.2.16', mimeUtil: 'eu.medsea.mimeutil:mime-util:2.1.3', restlet: "org.restlet.jse:org.restlet:${spec.versions.restlet}", diff --git a/settings.gradle b/settings.gradle index 13c11173..87e96e0c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,14 +27,14 @@ include ':agent:org.linkedin.glu.agent-api', ':agent:org.linkedin.glu.agent-server', ':agent:org.linkedin.glu.agent-tracker', ':commands:org.linkedin.glu.commands-impl', -// ':console:org.linkedin.glu.console-webapp', -// ':console:org.linkedin.glu.console-server', -// ':console:org.linkedin.glu.console-cli', + ':console:org.linkedin.glu.console-webapp', + ':console:org.linkedin.glu.console-server', + ':console:org.linkedin.glu.console-cli', ':docs:manual', ':orchestration:org.linkedin.glu.orchestration-engine', ':provisioner:org.linkedin.glu.provisioner-core', -// ':packaging:org.linkedin.glu.packaging-setup', -// ':packaging:org.linkedin.glu.packaging-all', + ':packaging:org.linkedin.glu.packaging-setup', + ':packaging:org.linkedin.glu.packaging-all', ':scripts:org.linkedin.glu.script-jetty', ':scripts:org.linkedin.glu.script-noop', ':scripts:org.linkedin.glu.script-hello-world',