Skip to content

Commit

Permalink
ApplicationClassInjector: No need to exclude auto configure classes…
Browse files Browse the repository at this point in the history
… for `Application`

Closes gh-635
  • Loading branch information
rainboyan committed Oct 7, 2024
1 parent adb76cf commit 65334c6
Showing 1 changed file with 2 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,8 @@ package org.grails.compiler.injection

import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.AnnotationNode
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.expr.ClassExpression
import org.codehaus.groovy.ast.stmt.Statement
import org.codehaus.groovy.classgen.GeneratorContext
import org.codehaus.groovy.control.SourceUnit
Expand Down Expand Up @@ -52,22 +50,11 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt
class ApplicationClassInjector implements GrailsArtefactClassInjector {

public static final String EXCLUDE_MEMBER = 'exclude'
public static final List<String> EXCLUDED_AUTO_CONFIGURE_CLASSES = new ArrayList<>()

ApplicationArtefactHandler applicationArtefactHandler = new ApplicationArtefactHandler()

private static final List<Integer> TRANSFORMED_INSTANCES = []

static {
ClassLoader classLoader = GrailsASTUtils.getClassLoader()
if (ClassUtils.isPresent('org.grails.plugins.datasource.DataSourceConnectionSourcesFactoryBean', classLoader)) {
EXCLUDED_AUTO_CONFIGURE_CLASSES.add('org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration')
}
if (ClassUtils.isPresent('org.grails.orm.hibernate.HibernateDatastore', classLoader)) {
EXCLUDED_AUTO_CONFIGURE_CLASSES.add('org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration')
}
}

@Override
String[] getArtefactTypes() {
[ApplicationArtefactHandler.TYPE] as String[]
Expand Down Expand Up @@ -99,16 +86,8 @@ class ApplicationClassInjector implements GrailsArtefactClassInjector {

ClassLoader classLoader = getClass().classLoader
if (ClassUtils.isPresent('org.springframework.boot.autoconfigure.SpringBootApplication', classLoader)) {
AnnotationNode springBootApplicationAnnotation = GrailsASTUtils.addAnnotationOrGetExisting(classNode,
GrailsASTUtils.addAnnotationOrGetExisting(classNode,
ClassHelper.make(classLoader.loadClass('org.springframework.boot.autoconfigure.SpringBootApplication')))

for (autoConfigureClassName in EXCLUDED_AUTO_CONFIGURE_CLASSES) {
if (ClassUtils.isPresent(autoConfigureClassName, classLoader)) {
ClassExpression autoConfigClassExpression =
new ClassExpression(ClassHelper.make(classLoader.loadClass(autoConfigureClassName)))
GrailsASTUtils.addExpressionToAnnotationMember(springBootApplicationAnnotation, EXCLUDE_MEMBER, autoConfigClassExpression)
}
}
}
}
}
Expand Down

0 comments on commit 65334c6

Please sign in to comment.