Skip to content

Commit

Permalink
Moved proxy bean to top level class, so it does not drag WeldFeature …
Browse files Browse the repository at this point in the history
…to native image. (#2906)
  • Loading branch information
tomas-langer authored Apr 1, 2021
1 parent 9b67ec7 commit 6bda22b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.integrations.graal.mp.nativeimage.extension;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Set;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;

/**
* Proxy used to initialize Weld.
* This class is a top level class so it does not add WeldFeature to the image.
*/
final class ProxyBean implements Bean<Object> {
// this is the bean class (producer class, or the type itself for managed beans)
private final Class<?> beanClass;
// the types of the produced bean (or
private final Set<Type> types;

ProxyBean(Class<?> beanClass, Set<Type> types) {
this.beanClass = beanClass;

this.types = types;
}

@Override
public Class<?> getBeanClass() {
return beanClass;
}

@Override
public Set<InjectionPoint> getInjectionPoints() {
return Collections.emptySet();
}

@Override
public boolean isNullable() {
return false;
}

@Override
public Object create(CreationalContext<Object> creationalContext) {
throw new IllegalStateException("This bean should not be created");
}

@Override
public void destroy(Object instance, CreationalContext<Object> creationalContext) {
}

@Override
public Set<Type> getTypes() {
return types;
}

@Override
public Set<Annotation> getQualifiers() {
return Set.of(Any.Literal.INSTANCE, Default.Literal.INSTANCE);
}

@Override
public Class<? extends Annotation> getScope() {
return ApplicationScoped.class;
}

@Override
public String getName() {
return beanClass.getName();
}

@Override
public Set<Class<? extends Annotation>> getStereotypes() {
return Collections.emptySet();
}

@Override
public boolean isAlternative() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates.
* Copyright (c) 2019, 2021 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
package io.helidon.integrations.graal.mp.nativeimage.extension;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.ArrayList;
Expand All @@ -32,12 +31,7 @@
import java.util.Set;
import java.util.function.Supplier;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
Expand Down Expand Up @@ -227,76 +221,6 @@ static List<WeldProxyConfig> weldProxyConfigurations(DuringSetupAccess access) {
}
}

/**
* Proxy used to initialize Weld.
*/
static final class ProxyBean implements Bean<Object> {
// this is the bean class (producer class, or the type itself for managed beans)
private final Class<?> beanClass;
// the types of the produced bean (or
private final Set<Type> types;

ProxyBean(Class<?> beanClass, Set<Type> types) {
this.beanClass = beanClass;

this.types = types;
}

@Override
public Class<?> getBeanClass() {
return beanClass;
}

@Override
public Set<InjectionPoint> getInjectionPoints() {
return Collections.emptySet();
}

@Override
public boolean isNullable() {
return false;
}

@Override
public Object create(CreationalContext<Object> creationalContext) {
throw new IllegalStateException("This bean should not be created");
}

@Override
public void destroy(Object instance, CreationalContext<Object> creationalContext) {
}

@Override
public Set<Type> getTypes() {
return types;
}

@Override
public Set<Annotation> getQualifiers() {
return Set.of(Any.Literal.INSTANCE, Default.Literal.INSTANCE);
}

@Override
public Class<? extends Annotation> getScope() {
return ApplicationScoped.class;
}

@Override
public String getName() {
return beanClass.getName();
}

@Override
public Set<Class<? extends Annotation>> getStereotypes() {
return Collections.emptySet();
}

@Override
public boolean isAlternative() {
return false;
}
}

private static class WeldProxyConfig {
// bean class
private final String beanClass;
Expand Down

0 comments on commit 6bda22b

Please sign in to comment.