Skip to content

Commit

Permalink
Winduprule 886 (#780)
Browse files Browse the repository at this point in the history
* WINDUPRULE-886 Spring Boot DI rules updated to reflect new project structure

* WINDUPRULE-886 rebased and updated springboot-di-to-quarkus-00002-test iterable-filter to size=5
  • Loading branch information
PhilipCattanach committed Dec 14, 2022
1 parent 4be57c6 commit 88f3544
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
<when>
<or>
<xmlfile matches="//*/b:bean/@class">
<namespace prefix="b" uri="http://www.springframework.org/schema/beans"/>
<namespace prefix="b" uri="http://www.springframework.org/schema/beans"/>
</xmlfile>
<xmlfile matches="//*/c:annotation-config">
<namespace prefix="c" uri="http://www.springframework.org/schema/context"/>
<namespace prefix="c" uri="http://www.springframework.org/schema/context"/>
</xmlfile>
</or>
</when>
Expand All @@ -50,5 +50,31 @@
</hint>
</perform>
</rule>
<!-- WINDUPRULE-886 -->
<rule id="springboot-di-to-quarkus-00002">
<when>
<javaclass references="org.springframework.beans.factory.config.BeanFactoryPostProcessor">
<location>IMPLEMENTS_TYPE</location>
</javaclass>
<javaclass references="org.springframework.beans.factory.config.BeanPostProcessor">
<location>IMPLEMENTS_TYPE</location>
</javaclass>
<javaclass references="org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor">
<location>IMPLEMENTS_TYPE</location>
</javaclass>
<javaclass references="org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor">
<location>IMPLEMENTS_TYPE</location>
</javaclass>
<javaclass references="org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor">
<location>IMPLEMENTS_TYPE</location>
</javaclass>
</when>
<perform>
<hint title="Spring DI infrastructure classes not supported by Quarkus" effort="3" category-id="mandatory">
<message>Spring infrastructure classes (like `org.springframework.beans.factory.config.BeanPostProcessor` , `org.springframework.context.ApplicationContext` for example) will not be executed.</message>
<link title="Quarkus DI Guide - important technical note" href="https://quarkus.io/guides/spring-di#important-technical-note"/>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
System.out.println("Inside postProcessBeanFactory method.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CustomBeanPostProcessor.java
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class CustomBeanPostProcessor implements BeanPostProcessor
{
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
{
System.out.println("Called postProcessBeforeInitialization() for :" + beanName);
return bean;
}

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
{
System.out.println("Called postProcessAfterInitialization() for :" + beanName);
return bean;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;

public class CustomDestructionProcessor implements DestructionAwareBeanPostProcessor {

public CustomDestructionProcessor() {
log.info("DestructionAwareBeanPostProcessor In other bean Create before create");
}

/** The other bean is destroyed before it is destroyed. */
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
if (bean instanceof SimpleBean) {
log.info("{} About to be destroyed", beanName);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

public class CustomInstantiationProcessor implements InstantiationAwareBeanPostProcessor {

public CustomInstantiationProcessor() {
log.info("InstantiationAwareBeanPostProcessor In other bean Create before create");
}

/** Call before other bean instantiation */
@Override
public Object postProcessBeforeInstantiation(Class

beanClass, String beanName) throws BeansException {
if (beanClass.equals(SimpleBean.class)) {
log.info("{} About to instantiate", beanName);
}
return null;
}

/** After the other bean instantiation is called */
@Override
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
if (bean instanceof SimpleBean) {
log.info("{} Instantiation complete", beanName);
}
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;​
import java.lang.reflect.Constructor;​

public class CustomSmartInstantiationAwareBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor {
@Override
public Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {
System.out.println("CustomSmartInstantiationAwareBeanPostProcessor.predictBeanType,beanName:"+beanName);
return null; }

@Override
public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
System.out.println("CustomSmartInstantiationAwareBeanPostProcessor.determineCandidateConstructors,beanName:"+beanName);
return null; }​


@Override
public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
System.out.println("CustomSmartInstantiationAwareBeanPostProcessor.getEarlyBeanReference,beanName:"+beanName);
return null; }
}​
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
<fail message="[springboot-di-to-quarkus-extension] Test failure - springboot-di-to-quarkus-00001-test" />
</perform>
</rule>
<rule id="springboot-di-to-quarkus-00002-test">
<when>
<not>
<iterable-filter size="5">
<hint-exists message="Spring infrastructure classes*"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[springboot-di-to-quarkus-extension] SpringBoot infrastructure classes hint was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>

0 comments on commit 88f3544

Please sign in to comment.