Skip to content

Commit

Permalink
Replace native image system property with call to NativeDetector
Browse files Browse the repository at this point in the history
Closes gh-25303
  • Loading branch information
wilkinsona committed Feb 16, 2021
1 parent dcbc3a2 commit 55e3ca6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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 Down Expand Up @@ -29,6 +29,7 @@
import org.springframework.boot.context.event.SpringApplicationEvent;
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationListener;
import org.springframework.core.NativeDetector;
import org.springframework.core.annotation.Order;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
Expand Down Expand Up @@ -67,8 +68,7 @@ public class BackgroundPreinitializer implements ApplicationListener<SpringAppli
private static final boolean ENABLED;

static {
ENABLED = !Boolean.getBoolean(IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME)
&& System.getProperty("org.graalvm.nativeimage.imagecode") == null
ENABLED = !Boolean.getBoolean(IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME) && !NativeDetector.inNativeImage()
&& Runtime.getRuntime().availableProcessors() > 1;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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 Down Expand Up @@ -71,6 +71,7 @@
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.NativeDetector;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
Expand Down Expand Up @@ -110,8 +111,6 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
*/
public static final String DEFAULT_PROTOCOL = "org.apache.coyote.http11.Http11NioProtocol";

private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;

private File baseDirectory;

private List<Valve> engineValves = new ArrayList<>();
Expand Down Expand Up @@ -169,7 +168,7 @@ public TomcatServletWebServerFactory(String contextPath, int port) {

private static List<LifecycleListener> getDefaultLifecycleListeners() {
ArrayList<LifecycleListener> lifecycleListeners = new ArrayList<>();
if (!IN_NATIVE_IMAGE) {
if (!NativeDetector.inNativeImage()) {
AprLifecycleListener aprLifecycleListener = new AprLifecycleListener();
if (AprLifecycleListener.isAprAvailable()) {
lifecycleListeners.add(aprLifecycleListener);
Expand Down

0 comments on commit 55e3ca6

Please sign in to comment.