Skip to content

Commit

Permalink
Remove SpEL from Jafu samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Apr 9, 2020
1 parent 61a6757 commit f150589
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 28 deletions.
37 changes: 31 additions & 6 deletions spring-graal-native-samples/jafu-webmvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,43 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.fu</groupId>
<artifactId>spring-fu-jafu</artifactId>
<version>0.3.0.M2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>graal-hotspot-library</artifactId>
<version>20.0.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.fu</groupId>
<artifactId>spring-fu-jafu</artifactId>
<version>0.3.0.M2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.jafu;


import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ServletWebServerApplicationContextWithoutSpel;

@TargetClass(className = "org.springframework.boot.SpringApplication")
public final class Target_SpringApplication {

// Use the application context without SpEL and avoid reflection
@Substitute
protected ConfigurableApplicationContext createApplicationContext() {
return new ServletWebServerApplicationContextWithoutSpel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,6 @@
"allDeclaredConstructors": true,
"allDeclaredMethods": true
},
{
"name": "org.springframework.web.context.ConfigurableWebApplicationContext",
"allDeclaredConstructors": true,
"allDeclaredMethods": true
},
{
"name": "org.springframework.web.context.WebApplicationContext",
"allDeclaredConstructors": true,
"allDeclaredMethods": true
},
{
"name": "org.springframework.context.ConfigurableApplicationContext",
"allDeclaredConstructors": true
},
{
"name": "org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory$StaticResourceConfigurer",
"allDeclaredConstructors": true,
Expand All @@ -97,11 +83,6 @@
"allDeclaredConstructors": true,
"allDeclaredMethods": true
},
{
"name": "org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext",
"allDeclaredConstructors": true,
"allDeclaredMethods": true
},
{
"name": "org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor",
"allDeclaredConstructors": true,
Expand Down
3 changes: 3 additions & 0 deletions spring-graal-native-samples/jafu/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ cd target/native-image
jar -xvf ../$JAR >/dev/null 2>&1
cp -R META-INF BOOT-INF/classes

# Avoids clashing substitutions from this project deps and the feature deps
rm BOOT-INF/lib/svm-20.*.jar

LIBPATH=`find BOOT-INF/lib | tr '\n' ':'`
CP=BOOT-INF/classes:$LIBPATH:$FEATURE

Expand Down
22 changes: 22 additions & 0 deletions spring-graal-native-samples/jafu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,34 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.fu</groupId>
<artifactId>spring-fu-jafu</artifactId>
<version>0.3.0.M2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>graal-hotspot-library</artifactId>
<version>20.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.jafu;


import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContextWithoutSpel;

@TargetClass(className = "org.springframework.boot.SpringApplication")
public final class Target_SpringApplication {

// Use the application context without SpEL and avoid reflection
@Substitute
protected ConfigurableApplicationContext createApplicationContext() {
return new GenericApplicationContextWithoutSpel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.springframework.context.support;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.support.ResourceEditorRegistrar;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader;

// Skip StandardBeanExpressionResolver and LoadTimeWeaver
public class GenericApplicationContextWithoutSpel extends GenericApplicationContext {

@Override
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
// Tell the internal bean factory to use the context's class loader etc.
beanFactory.setBeanClassLoader(getClassLoader());
beanFactory.addPropertyEditorRegistrar(new ResourceEditorRegistrar(this, getEnvironment()));

// Configure the bean factory with context callbacks.
beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this));
beanFactory.ignoreDependencyInterface(EnvironmentAware.class);
beanFactory.ignoreDependencyInterface(EmbeddedValueResolverAware.class);
beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class);
beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class);
beanFactory.ignoreDependencyInterface(MessageSourceAware.class);
beanFactory.ignoreDependencyInterface(ApplicationContextAware.class);

// BeanFactory interface not registered as resolvable type in a plain factory.
// MessageSource registered (and found for autowiring) as a bean.
beanFactory.registerResolvableDependency(BeanFactory.class, beanFactory);
beanFactory.registerResolvableDependency(ResourceLoader.class, this);
beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this);
beanFactory.registerResolvableDependency(ApplicationContext.class, this);

// Register early post-processor for detecting inner beans as ApplicationListeners.
beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(this));

// Register default environment beans.
if (!beanFactory.containsLocalBean(ENVIRONMENT_BEAN_NAME)) {
beanFactory.registerSingleton(ENVIRONMENT_BEAN_NAME, getEnvironment());
}
if (!beanFactory.containsLocalBean(SYSTEM_PROPERTIES_BEAN_NAME)) {
beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, getEnvironment().getSystemProperties());
}
if (!beanFactory.containsLocalBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) {
beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, getEnvironment().getSystemEnvironment());
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.springframework.internal.svm;

import java.util.function.BooleanSupplier;

public class RemoveSpelSupport implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
return Boolean.valueOf(System.getProperty("spring.graal.remove-spel-support", "false"));
}

}

0 comments on commit f150589

Please sign in to comment.