From 83d84f607986815f89466ed75c3a0b12708be5b7 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Wed, 21 Dec 2016 20:53:33 +1300 Subject: [PATCH] #14 - Remove agent loading feature for spring boot as it has been moved to ebean-spring-agent --- pom.xml | 89 +++---------------- .../boot/EbeanAgentAutoConfiguration.java | 69 -------------- src/main/resources/META-INF/spring.factories | 2 - .../boot/EbeanAgentAutoConfigurationTest.java | 35 -------- src/test/java/org/unenhanced/Boondoggle.java | 11 --- src/test/java/org/unenhanced/Wotsit.java | 11 --- 6 files changed, 11 insertions(+), 206 deletions(-) delete mode 100644 src/main/java/io/ebean/spring/boot/EbeanAgentAutoConfiguration.java delete mode 100644 src/main/resources/META-INF/spring.factories delete mode 100644 src/test/java/io/ebean/spring/boot/EbeanAgentAutoConfigurationTest.java delete mode 100644 src/test/java/org/unenhanced/Boondoggle.java delete mode 100644 src/test/java/org/unenhanced/Wotsit.java diff --git a/pom.xml b/pom.xml index 0fa0f500f..5baf9772b 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ org.slf4j slf4j-api - [1.7,) + 1.7.21 provided @@ -41,22 +41,6 @@ provided - - - io.ebean - ebean-agent - [10,) - runtime - true - - - - org.avaje - avaje-agentloader - 2.1.2 - true - - org.springframework @@ -71,13 +55,6 @@ - - org.springframework.boot - spring-boot-autoconfigure - ${spring.boot.version} - provided - - org.springframework @@ -117,64 +94,20 @@ + - io.ebean - ebean-maven-plugin - 10.1.1 - - - main - process-test-classes - - target/test-classes - org.example.** - debug=1 - - - enhance - - - - - - maven-surefire-plugin - 2.18.1 + io.repaint.maven + tiles-maven-plugin + 2.8 + true - - false + + io.ebean.tile:enhancement:2.1 + - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - io.ebean - ebean-maven-plugin - [1,) - - enhance - - - - - - - - - - - - + + diff --git a/src/main/java/io/ebean/spring/boot/EbeanAgentAutoConfiguration.java b/src/main/java/io/ebean/spring/boot/EbeanAgentAutoConfiguration.java deleted file mode 100644 index d9970a77a..000000000 --- a/src/main/java/io/ebean/spring/boot/EbeanAgentAutoConfiguration.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.ebean.spring.boot; - -import org.avaje.agentloader.AgentLoader; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.autoconfigure.AutoConfigureOrder; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; -import org.springframework.core.PriorityOrdered; - - -/** - * Loads the Ebean enhancement agent early in the Spring Boot startup process, - * if it is present on the classpath. - *

- * Note that using this mechanism is only recommended for development; - * production applications should ideally be enhanced at build time, or at least - * load the agent via the javaagent JVM option. When the agent is - * loaded at runtime via this class, any entity classes that have already been - * loaded won't be enhanced and will fail to work correctly. - *

- * For unit tests and similar cases where Spring Boot auto-configuration may not - * be active, loading of the agent can be triggered manually via - * {@link #enable()}. - */ -@Configuration -@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) -@ConditionalOnClass(AgentLoader.class) -public class EbeanAgentAutoConfiguration implements BeanFactoryPostProcessor, PriorityOrdered { - - public EbeanAgentAutoConfiguration() { - load(); // Spring has already evaluated the @ConditionalOnClass - } - - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - // We're not actually doing anything with the BeanFactory, but implementing - // BeanFactoryPostProcessor ensures we get instantiated early, ideally - // before anybody has a chance to load any entity classes we want to - // enhance. - } - - @Override - public int getOrder() { - return Ordered.HIGHEST_PRECEDENCE; - } - - private static void load() { - AgentLoader.loadAgentFromClasspath("ebean-agent", "debug=1"); - } - - /** - * Loads the Ebean agent if the agent-loader and the agent itself are present - * on the classpath, or does nothing otherwise. - *

- * Do not call this method from a static initializer as this can lead to a JVM - * deadlock (the agent attach thread will attempt to acquire the class loader - * lock, which is held during static initialization). - */ - public static void enable() { - try { - load(); - } catch (NoClassDefFoundError e) { - /* ignored */ - } - } -} diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories deleted file mode 100644 index d4fedf3b0..000000000 --- a/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.ebean.spring.boot.EbeanAgentAutoConfiguration diff --git a/src/test/java/io/ebean/spring/boot/EbeanAgentAutoConfigurationTest.java b/src/test/java/io/ebean/spring/boot/EbeanAgentAutoConfigurationTest.java deleted file mode 100644 index bbd7bc81e..000000000 --- a/src/test/java/io/ebean/spring/boot/EbeanAgentAutoConfigurationTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.ebean.spring.boot; - -import io.ebean.bean.EntityBean; -import org.junit.Test; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.unenhanced.Boondoggle; -import org.unenhanced.Wotsit; -import static org.assertj.core.api.StrictAssertions.assertThat; - -@SpringBootTest(webEnvironment=WebEnvironment.NONE) -public class EbeanAgentAutoConfigurationTest extends AbstractJUnit4SpringContextTests { - - static { - // Validate our test setup. Agent should not be loaded yet, so 'Boondoggle' - // should have been enhanced neither at build time nor at load time. - assertThat(EntityBean.class.isAssignableFrom(Boondoggle.class)).isFalse(); - } - - @Configuration - @EnableAutoConfiguration - public static class Config { - /* no beans needed for this test */ - } - - @Test - public void testAgentIsWorking() { - // Wotsit is outside of the org.example package that's being enhanced - // at build time, so should be picked up by the agent only. - assertThat(EntityBean.class.isAssignableFrom(Wotsit.class)).isTrue(); - } -} diff --git a/src/test/java/org/unenhanced/Boondoggle.java b/src/test/java/org/unenhanced/Boondoggle.java deleted file mode 100644 index 0d23f258d..000000000 --- a/src/test/java/org/unenhanced/Boondoggle.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.unenhanced; - -import javax.persistence.Entity; -import javax.persistence.Id; - -// Not in org.example, i.e. not enhanced at build time -@Entity -public class Boondoggle { - @Id - public String name; -} diff --git a/src/test/java/org/unenhanced/Wotsit.java b/src/test/java/org/unenhanced/Wotsit.java deleted file mode 100644 index e2e723caf..000000000 --- a/src/test/java/org/unenhanced/Wotsit.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.unenhanced; - -import javax.persistence.Entity; -import javax.persistence.Id; - -// Not in org.example, i.e. not enhanced at build time -@Entity -public class Wotsit { - @Id - public String name; -}