Skip to content

Commit

Permalink
WELD-1359 @priority not recognized on types added through BeforeBeanD…
Browse files Browse the repository at this point in the history
…iscovery.addAnnotatedType()
  • Loading branch information
jharting committed Mar 13, 2013
1 parent ffaba8d commit 1e8a94b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 6 deletions.
13 changes: 8 additions & 5 deletions impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
Expand Up @@ -83,6 +83,7 @@ public class BeanDeployer extends AbstractBeanDeployer<BeanDeployerEnvironment>

private final ResourceLoader resourceLoader;
private final SlimAnnotatedTypeStore annotatedTypeStore;
private final GlobalEnablementBuilder globalEnablementBuilder;

public BeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors, ServiceRegistry services) {
this(manager, ejbDescriptors, services, BeanDeployerEnvironmentFactory.newEnvironment(ejbDescriptors, manager));
Expand All @@ -92,6 +93,7 @@ public BeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors, Serv
super(manager, services, environment);
this.resourceLoader = manager.getServices().get(ResourceLoader.class);
this.annotatedTypeStore = manager.getServices().get(SlimAnnotatedTypeStore.class);
this.globalEnablementBuilder = manager.getServices().get(GlobalEnablementBuilder.class);
}

public BeanDeployer addClass(String className) {
Expand All @@ -100,7 +102,6 @@ public BeanDeployer addClass(String className) {
SlimAnnotatedType<?> type = loadAnnotatedType(clazz);
if (type != null) {
getEnvironment().addAnnotatedType(type);
processPriority(type);
}
}
return this;
Expand Down Expand Up @@ -133,13 +134,12 @@ private void processPriority(AnnotatedType<?> type) {
Priority priority = type.getAnnotation(Priority.class);
if (priority != null) {
int value = priority.value();
GlobalEnablementBuilder builder = getManager().getServices().get(GlobalEnablementBuilder.class);
if (type.isAnnotationPresent(Interceptor.class)) {
builder.addInterceptor(type.getJavaClass(), value);
globalEnablementBuilder.addInterceptor(type.getJavaClass(), value);
} else if (type.isAnnotationPresent(Decorator.class)) {
builder.addDecorator(type.getJavaClass(), value);
globalEnablementBuilder.addDecorator(type.getJavaClass(), value);
} else if (type.isAnnotationPresent(Alternative.class)) {
builder.addAlternative(type.getJavaClass(), value);
globalEnablementBuilder.addAlternative(type.getJavaClass(), value);
}
}
}
Expand Down Expand Up @@ -177,7 +177,10 @@ public void processAnnotatedTypes() {
classesToBeRemoved.add(annotatedType); // remove the original class
classesToBeAdded.add(event.getResultingAnnotatedType());
}
processPriority(event.getResultingAnnotatedType());
}
} else {
processPriority(annotatedType);
}
}
getEnvironment().removeAnnotatedTypes(classesToBeRemoved);
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
Expand All @@ -51,13 +52,16 @@ public static Archive<?> getDeployment() {
}

public static Archive<?> getWebArchive() {
JavaArchive thirdPartyLibrary = ShrinkWrap.create(JavaArchive.class).addClasses(ThirdPartyDecorator.class, ThirdPartyDecoratorExtension.class).addAsServiceProvider(Extension.class, ThirdPartyDecoratorExtension.class);

BeansXml beans = new BeansXml();
beans.decorators(LegacyDecorator1.class, LegacyDecorator2.class, LegacyDecorator3.class);
return ShrinkWrap
.create(WebArchive.class, "test.war")
.addClasses(DecoratedImpl.class, LegacyDecorator1.class, LegacyDecorator2.class, LegacyDecorator3.class,
WebApplicationGlobalDecorator.class, GlobalDecoratorOrderingTest.class, DecoratorRegisteringExtension.class)
.addAsWebInfResource(beans, "beans.xml").addAsServiceProvider(Extension.class, DecoratorRegisteringExtension.class);
.addAsWebInfResource(beans, "beans.xml").addAsServiceProvider(Extension.class, DecoratorRegisteringExtension.class)
.addAsLibrary(thirdPartyLibrary);
}

public static Archive<?> getSharedLibrary() {
Expand All @@ -73,6 +77,7 @@ public static Archive<?> getSharedLibrary() {
@Test
public void testDecoratorsInWebInfClasses() {
List<String> expected = new ArrayList<String>();
expected.add(ThirdPartyDecorator.class.getSimpleName());
expected.add(GloballyEnabledDecorator1.class.getSimpleName());
expected.add(ExtensionEnabledDecorator1.class.getSimpleName());
expected.add(GloballyEnabledDecorator4.class.getSimpleName());
Expand Down
@@ -0,0 +1,40 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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 org.jboss.weld.tests.decorators.ordering.global;

import java.util.List;

import javax.annotation.Priority;
import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.inject.Inject;

@Decorator
@Priority(1987)
public class ThirdPartyDecorator implements Decorated {

@Inject
@Delegate
private Decorated delegate;

@Override
public void getSequence(List<String> list) {
list.add(getClass().getSimpleName());
delegate.getSequence(list);
}

}
@@ -0,0 +1,29 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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 org.jboss.weld.tests.decorators.ordering.global;

import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;

public class ThirdPartyDecoratorExtension implements Extension {

void registerThirdPartyDecorator(@Observes BeforeBeanDiscovery event, BeanManager manager) {
event.addAnnotatedType(manager.createAnnotatedType(ThirdPartyDecorator.class), "ThirdPartyDecorator");
}
}

0 comments on commit 1e8a94b

Please sign in to comment.