Java Code Examples for org.springframework.instrument.classloading.LoadTimeWeaver

The following examples show how to use org.springframework.instrument.classloading.LoadTimeWeaver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.info("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			logger.info("Using a reflective load-time weaver for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example 2
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
	}
	catch (IllegalStateException ex) {
		logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
	}
	return null;
}
 
Example 3
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.info("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			logger.info("Using a reflective load-time weaver for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example 4
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
	}
	catch (IllegalStateException ex) {
		logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
	}
	return null;
}
 
Example 5
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.debug("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			if (logger.isDebugEnabled()) {
				logger.debug("Using reflective load-time weaver for class loader: " +
						this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
			}
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:spring-instrument-{version}.jar");
		}
	}
}
 
Example 6
@Nullable
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss.modules")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm.ws.classloader")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
	}
	catch (Exception ex) {
		if (logger.isInfoEnabled()) {
			logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
		}
	}
	return null;
}
 
Example 7
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example 8
Source Project: spring-analysis-note   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingDisabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example 9
Source Project: spring-analysis-note   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingAutodetect() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	// no expectations -> a class file transformer should NOT be added
	// because no META-INF/aop.xml is present on the classpath
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example 10
Source Project: spring-analysis-note   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingEnabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
}
 
Example 11
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.debug("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			if (logger.isDebugEnabled()) {
				logger.debug("Using reflective load-time weaver for class loader: " +
						this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
			}
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example 12
@Nullable
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
	String name = classLoader.getClass().getName();
	try {
		if (name.startsWith("org.apache.catalina")) {
			return new TomcatLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.glassfish")) {
			return new GlassFishLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("org.jboss.modules")) {
			return new JBossLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("com.ibm.ws.classloader")) {
			return new WebSphereLoadTimeWeaver(classLoader);
		}
		else if (name.startsWith("weblogic")) {
			return new WebLogicLoadTimeWeaver(classLoader);
		}
	}
	catch (Exception ex) {
		if (logger.isInfoEnabled()) {
			logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
		}
	}
	return null;
}
 
Example 13
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example 14
Source Project: java-technology-stack   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingDisabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example 15
Source Project: java-technology-stack   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingAutodetect() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	// no expectations -> a class file transformer should NOT be added
	// because no META-INF/aop.xml is present on the classpath
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example 16
Source Project: java-technology-stack   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 5 votes vote down vote up
@Test
public void enableLTW_withAjWeavingEnabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
}
 
Example 17
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example 18
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
Example 19
@Test
public void enableLTW_withAjWeavingDisabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example 20
@Test
public void enableLTW_withAjWeavingAutodetect() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	// no expectations -> a class file transformer should NOT be added
	// because no META-INF/aop.xml is present on the classpath
	verifyZeroInteractions(loadTimeWeaver);
}
 
Example 21
@Test
public void enableLTW_withAjWeavingEnabled() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
	ctx.refresh();
	LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
	verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
}
 
Example 22
Source Project: spring-analysis-note   Source File: AspectJWeavingEnabler.java    License: MIT License 4 votes vote down vote up
@Override
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
	this.loadTimeWeaver = loadTimeWeaver;
}
 
Example 23
Source Project: spring-analysis-note   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 4 votes vote down vote up
@Test
public void control() {
	GenericXmlApplicationContext ctx =
		new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml");
	ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
}
 
Example 24
Source Project: spring-analysis-note   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 4 votes vote down vote up
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
	return mock(LoadTimeWeaver.class);
}
 
Example 25
Source Project: spring-analysis-note   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 4 votes vote down vote up
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
	return mock(LoadTimeWeaver.class);
}
 
Example 26
Source Project: spring-analysis-note   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 4 votes vote down vote up
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
	return mock(LoadTimeWeaver.class);
}
 
Example 27
/**
 * Return the Spring LoadTimeWeaver to use for class instrumentation according
 * to the JPA class transformer contract.
 */
@Nullable
public LoadTimeWeaver getLoadTimeWeaver() {
	return this.loadTimeWeaver;
}
 
Example 28
Source Project: spring-analysis-note   Source File: SpringPersistenceUnitInfo.java    License: MIT License 4 votes vote down vote up
/**
 * Initialize this PersistenceUnitInfo with the LoadTimeWeaver SPI interface
 * used by Spring to add instrumentation to the current class loader.
 */
public void init(LoadTimeWeaver loadTimeWeaver) {
	Assert.notNull(loadTimeWeaver, "LoadTimeWeaver must not be null");
	this.loadTimeWeaver = loadTimeWeaver;
	this.classLoader = loadTimeWeaver.getInstrumentableClassLoader();
}
 
Example 29
Source Project: java-technology-stack   Source File: AspectJWeavingEnabler.java    License: MIT License 4 votes vote down vote up
@Override
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
	this.loadTimeWeaver = loadTimeWeaver;
}
 
Example 30
Source Project: java-technology-stack   Source File: EnableLoadTimeWeavingTests.java    License: MIT License 4 votes vote down vote up
@Test
public void control() {
	GenericXmlApplicationContext ctx =
		new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml");
	ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
}