Skip to content

Commit

Permalink
upgraded codenarc and fixed violations
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Jan 31, 2022
1 parent 2b52c9b commit 896fb86
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ subprojects { Project subproject ->
}

codenarc {
toolVersion = '1.2.1'
toolVersion = '2.1.0'
}

config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.micronaut.core.annotation.Introspected
'GrailsDomainHasEquals',
'GrailsDomainHasToString',
'FieldTypeRequired',
'NoDef',
])
class Manager {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {

testCompile project(':micronaut-grails-jpa-generator')

testCompile 'com.agorapulse.testing:fixt:0.2.1.1'
testCompile 'com.agorapulse.testing:fixt:0.2.3'

testCompile 'io.micronaut:micronaut-inject-groovy'
testCompile 'org.mariadb.jdbc:mariadb-java-client:2.7.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.agorapulse.micronaut.grails.domain
// tag::body[]
import com.agorapulse.micronaut.grails.jpa.generator.MicronautJpaGenerator
import com.agorapulse.testing.fixt.Fixt
import groovy.transform.CompileDynamic
import io.micronaut.context.ApplicationContext
import org.grails.datastore.gorm.validation.constraints.eval.DefaultConstraintEvaluator
import org.grails.orm.hibernate.HibernateDatastore
Expand All @@ -29,6 +30,7 @@ import spock.lang.Specification
/**
* Example specification generating JPA entities from GORM entities.
*/
@CompileDynamic
class MicronautGeneratorSpec extends Specification {

Fixt fixt = Fixt.create(MicronautGeneratorSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dependencies {
testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:3.14.0"
testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:3.14.0"

testCompile 'com.agorapulse.testing:fixt:0.2.1.1'
testCompile 'com.agorapulse.testing:fixt:0.2.3'
}

bootRun {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dockerApiVersion = 3.2.12
groovyClosureSupportVersion = 0.6.3
kordampVersion=0.46.0
nexusPluginVersion=1.0.0
grailsTestingSupportVersion=2.1.2

# this should be aligned to Micronaut version
# required for AWS CBOR marshalling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ config {

dependencies {
api project(':micronaut-grails')
api 'org.grails:grails-testing-support:2.1.2'
api "org.grails:grails-testing-support:$grailsTestingSupportVersion"
implementation 'org.opentest4j:opentest4j:1.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class MicronautGrailsIntegrationTestMixinTransformation implements ASTTransforma

if (servletApi != null) {

if( GrailsASTUtils.findAnnotation(classNode, SpringBootTest) == null) {
if (GrailsASTUtils.findAnnotation(classNode, SpringBootTest) == null) {
AnnotationNode webIntegrationTestAnnotation = GrailsASTUtils.addAnnotationOrGetExisting(classNode, SpringBootTest)
webIntegrationTestAnnotation.addMember("webEnvironment", propX(classX(SpringBootTest.WebEnvironment), "RANDOM_PORT"))
if(classNode.getProperty("serverPort") == null) {
Expand All @@ -198,7 +198,7 @@ class MicronautGrailsIntegrationTestMixinTransformation implements ASTTransforma
valueAnnotation.setMember("value", new ConstantExpression('${local.server.port}'))
serverPortField.addAnnotation(valueAnnotation)

classNode.addProperty(new PropertyNode(serverPortField, Modifier.PUBLIC, null, null ))
classNode.addProperty(new PropertyNode(serverPortField, Modifier.PUBLIC, null, null))
}
}
} else {
Expand Down Expand Up @@ -256,4 +256,5 @@ class MicronautGrailsIntegrationTestMixinTransformation implements ASTTransforma
classNode.addMethod(method)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ class MicronautJdbcGenerator extends MicronautDataGenerator {
}
""".stripIndent().trim()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ class MicronautJpaGenerator extends MicronautDataGenerator {
}
""".stripIndent().trim()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ class BootInitializerClassInjector extends GlobalClassInjectorAdapter {
@Override
void performInjectionInternal(SourceUnit source, ClassNode classNode) {
// if this is a plugin source, then exit
if( classNode.getAnnotations(PLUGIN_SOURCE_ANNOTATION) ) {
if (classNode.getAnnotations(PLUGIN_SOURCE_ANNOTATION)) {
return
}
// don't generate for plugins
if( classNode.getNodeMetaData('isPlugin') ) return
if (classNode.getNodeMetaData('isPlugin')) return


if(GrailsASTUtils.isAssignableFrom(GRAILS_CONFIGURATION_CLASS_NODE, classNode) && !GrailsASTUtils.isSubclassOfOrImplementsInterface(classNode, GrailsPluginApplication.name)) {
Expand All @@ -100,7 +100,7 @@ class BootInitializerClassInjector extends GlobalClassInjectorAdapter {
def mainMethodBody = mn.code
if(mainMethodBody instanceof BlockStatement) {
BlockStatement bs = (BlockStatement)mainMethodBody
if( !bs.statements.isEmpty() ) {
if (!bs.statements.isEmpty()) {

def methodCallExpression = new MethodCallExpression(
new ClassExpression(ClassHelper.make(System)),
Expand All @@ -124,8 +124,8 @@ class BootInitializerClassInjector extends GlobalClassInjectorAdapter {
def parameter = new Parameter(springApplicationBuilder, "application")
def methodBody = new BlockStatement()

methodBody.addStatement( new ExpressionStatement( new MethodCallExpression( new VariableExpression(parameter), "sources", new ClassExpression(classNode))))
loaderClassNode.addMethod( new MethodNode("configure", Modifier.PROTECTED, springApplicationBuilder, [parameter] as Parameter[], [] as ClassNode[], methodBody))
methodBody.addStatement(new ExpressionStatement(new MethodCallExpression(new VariableExpression(parameter), 'sources', new ClassExpression(classNode))))
loaderClassNode.addMethod(new MethodNode("configure", Modifier.PROTECTED, springApplicationBuilder, [parameter] as Parameter[], [] as ClassNode[], methodBody))
source.getAST().addClass(
loaderClassNode
)
Expand All @@ -135,4 +135,5 @@ class BootInitializerClassInjector extends GlobalClassInjectorAdapter {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.agorapulse.micronaut.grails

import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import io.micronaut.context.annotation.Factory
import io.micronaut.context.annotation.Primary
Expand All @@ -43,6 +44,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME
/**
* Tests for micronaut Spring bean processor.
*/
@CompileDynamic
@ContextConfiguration(classes = [GrailsConfig, MicronautGrailsConfiguration])
@TestPropertySource('classpath:com/agorapulse/micronaut/grails/GrailsMicronautBeanProcessorSpec.properties')
class GrailsMicronautBeanProcessorSpec extends Specification {
Expand Down Expand Up @@ -98,6 +100,7 @@ class GrailsMicronautBeanProcessorSpec extends Specification {
!translatingEnvironment.containsProperty('redis.host')
!translatingEnvironment.getProperty('redis.host', String).present
}

}

// tag::configuration[]
Expand All @@ -107,7 +110,7 @@ class GrailsConfig {

@Bean
MicronautBeanImporter myImporter() { // <2>
MicronautBeanImporter.create()
return MicronautBeanImporter.create()
.addByType(Widget) // <3>
.addByType('someInterface', SomeInterface) // <4>
.addByStereotype('custom', SomeCustomScope) // <5>
Expand All @@ -124,20 +127,30 @@ class GrailsConfig {
}
// end::configuration[]

interface SomeInterface { }
@CompileStatic
interface SomeInterface {

}

@Singleton
class SomeImplementation implements SomeInterface { }
@CompileStatic
class SomeImplementation implements SomeInterface {

}

@CompileStatic
class SomeNamed {

final String name

SomeNamed(String name) {
this.name = name
}

}

@Factory
@CompileStatic
class SomeNamedFactory {

@io.micronaut.context.annotation.Bean
Expand All @@ -158,20 +171,32 @@ class SomeNamedFactory {

@Primary
@Singleton
class Widget { }
@CompileStatic
class Widget {

}

@Singleton
@CompileStatic
@Requires(notEnv = 'test')
class TestWidget extends Widget { }
class TestWidget extends Widget {

}

interface Minion { }
interface Minion {

}

@Documented
@Retention(RUNTIME)
@Scope
@CompileStatic
@io.micronaut.context.annotation.Bean
@interface SomeCustomScope { }
@interface SomeCustomScope {

}

@CompileStatic
@SomeCustomScope
class CustomBean {

Expand All @@ -188,15 +213,25 @@ class CustomBean {
this.redisPort = redisPort
this.redisTimeout = redisTimeout
}

}

@Singleton
@CompileStatic
@Named('gadget')
class SomeGadget { }
class SomeGadget {

}

@Singleton
@CompileStatic
@Named('other')
class OtherMinion implements Minion { }
class OtherMinion implements Minion {

}

@Singleton
class NormalMinion implements Minion { }
@CompileStatic
class NormalMinion implements Minion {

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.agorapulse.micronaut.grails

import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import io.micronaut.inject.qualifiers.Qualifiers
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -31,6 +32,7 @@ import spock.lang.Specification
/**
* Tests for micronaut Spring bean processor.
*/
@CompileDynamic
@ContextConfiguration(classes = [GrailsLegacyConfig])
@TestPropertySource('classpath:com/agorapulse/micronaut/grails/GrailsMicronautBeanProcessorSpec.properties')
class LegacyGrailsMicronautBeanProcessorSpec extends Specification {
Expand Down Expand Up @@ -67,6 +69,7 @@ class LegacyGrailsMicronautBeanProcessorSpec extends Specification {
prototypeBean.redisPort == REDIS_PORT
prototypeBean.redisTimeout == REDIS_TIMEOUT
}

}

// tag::configuration[]
Expand All @@ -76,7 +79,7 @@ class GrailsLegacyConfig {

@Bean
GrailsMicronautBeanProcessor widgetProcessor() {
GrailsMicronautBeanProcessor
return GrailsMicronautBeanProcessor
.builder()
.addByType(Widget)
.addByType('someInterface', SomeInterface)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
*/
package com.agorapulse.micronaut.grails

import groovy.transform.CompileDynamic
import spock.lang.Specification

/**
* Tests for property translating customizer.
*/
@CompileDynamic
class PropertyTranslatingCustomizerSpec extends Specification {

void 'custom replacements works'() {
Expand All @@ -36,10 +38,10 @@ class PropertyTranslatingCustomizerSpec extends Specification {
.build()

then:
customizer.getAlternativeNames(null).isEmpty()
customizer.getAlternativeNames('').isEmpty()
customizer.getAlternativeNames('foo.bar').isEmpty()
customizer.getAlternativeNames('foo.gar').isEmpty()
customizer.getAlternativeNames(null).empty
customizer.getAlternativeNames('').empty
customizer.getAlternativeNames('foo.bar').empty
customizer.getAlternativeNames('foo.gar').empty
customizer.getAlternativeNames('foo.baz') == ['bar.baz', 'baz'] as Set<String>
customizer.getAlternativeNames('baz') == ['foo.baz'] as Set<String>
}
Expand All @@ -49,9 +51,9 @@ class PropertyTranslatingCustomizerSpec extends Specification {
PropertyTranslatingCustomizer customizer = PropertyTranslatingCustomizer.none()

then:
customizer.getAlternativeNames('foo.bar').isEmpty()
customizer.getAlternativeNames('foo.baz').isEmpty()
customizer.getAlternativeNames('baz').isEmpty()
customizer.getAlternativeNames('foo.bar').empty
customizer.getAlternativeNames('foo.baz').empty
customizer.getAlternativeNames('baz').empty
}

void 'standard replacements works'() {
Expand All @@ -62,7 +64,7 @@ class PropertyTranslatingCustomizerSpec extends Specification {
.build()

then:
customizer.getAlternativeNames('redis.timeout').isEmpty()
customizer.getAlternativeNames('redis.timeout').empty
customizer.getAlternativeNames('redis.port') == ['grails.redis.port'] as Set<String>
customizer.getAlternativeNames('micronaut.redis.port') == ['grails.redis.port', 'grails.micronaut.redis.port'] as Set<String>
customizer.getAlternativeNames('micronaut.server.url') == ['grails.server.url', 'grails.micronaut.server.url'] as Set<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.agorapulse.micronaut.grails
import com.agorapulse.micronaut.amazon.awssdk.sns.SimpleNotificationService
import com.agorapulse.micronaut.amazon.awssdk.sns.SimpleNotificationServiceConfiguration
import com.agorapulse.micronaut.amazon.awssdk.sqs.SimpleQueueService
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import io.micronaut.inject.qualifiers.Qualifiers
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -33,6 +34,7 @@ import spock.lang.Specification
/**
* Tests for micronaut Spring bean processor.
*/
@CompileDynamic
@ContextConfiguration(classes = [GrailsSimpleNotificationServiceConfig, MicronautGrailsConfiguration])
@TestPropertySource('classpath:com/agorapulse/micronaut/grails/SimpleNotificationServiceConfigurationSpec.properties')
class SimpleNotificationServiceConfigurationSpec extends Specification {
Expand All @@ -52,6 +54,7 @@ class SimpleNotificationServiceConfigurationSpec extends Specification {
configuration.android
configuration.android.arn == ARN
}

}

@CompileStatic
Expand All @@ -60,7 +63,7 @@ class GrailsSimpleNotificationServiceConfig {

@Bean
MicronautBeanImporter myImporter() {
MicronautBeanImporter.create()
return MicronautBeanImporter.create()
.customize(PropertyTranslatingCustomizer
.builder()
.replacePrefix('aws.sns', 'grails.plugin.awssdk.sns')
Expand Down

0 comments on commit 896fb86

Please sign in to comment.