Skip to content

Commit

Permalink
WFLY-476 Support for implicit bean archives
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting authored and bstansberry committed Jul 31, 2013
1 parent 861a9ce commit c1959b3
Show file tree
Hide file tree
Showing 53 changed files with 1,615 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public class WeldDeploymentMarker {
private static final AttachmentKey<Boolean> MARKER = AttachmentKey.create(Boolean.class);

/**
* Mark the top level deployment as being a weld deployment. If the deployment is not a top level deployment the parent is
* marked instead
* Mark this deployment and the top level deployment as being a weld deployment.
*
*/
public static void mark(DeploymentUnit unit) {
unit.putAttachment(MARKER, Boolean.TRUE);
if (unit.getParent() != null) {
mark(unit.getParent());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ public AttachmentKey<?> getPhaseKey() {
public static final int PARSE_EE_ANNOTATIONS = 0x2901;
public static final int PARSE_JAXRS_ANNOTATIONS = 0x2A00;
public static final int PARSE_CDI_ANNOTATIONS = 0x2A10;
public static final int PARSE_CDI_BEAN_DEFINING_ANNOTATIONS = 0x2A80;
public static final int PARSE_WELD_DEPLOYMENT = 0x2B00;
public static final int PARSE_WELD_IMPLICIT_DEPLOYMENT_DETECTION = 0x2C00;
public static final int PARSE_DATA_SOURCE_DEFINITION_ANNOTATION = 0x2D00;
public static final int PARSE_MAIL_SESSION_DEFINITION_ANNOTATION = 0x2D01;
public static final int PARSE_EJB_CONTEXT_BINDING = 0x2E00;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.as.test.integration.weld.deployment;

public class Alpha implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.jboss.as.test.integration.weld.deployment;

import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
*
* @author Martin Kouba
*/
@RunWith(Arquillian.class)
public class BeanDiscoveryTest {

@Deployment
public static WebArchive createTestArchive() {

// 1.1 version beans.xml with bean-discovery-mode of all
JavaArchive alpha = ShrinkWrap
.create(JavaArchive.class)
.addClass(Alpha.class)
.addAsManifestResource(newBeans11Descriptor("all"), "beans.xml");
// Empty beans.xml
JavaArchive bravo = ShrinkWrap.create(JavaArchive.class).addClass(Bravo.class)
.addAsManifestResource(new StringAsset(""), "beans.xml");
// No version beans.xml
JavaArchive charlie = ShrinkWrap
.create(JavaArchive.class)
.addClass(Charlie.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
// Bean defining annotation and no beans.xml
JavaArchive delta = ShrinkWrap.create(JavaArchive.class).addClass(Delta.class);
// Bean defining annotation and 1.1 version beans.xml with bean-discovery-mode of annotated
JavaArchive echo = ShrinkWrap
.create(JavaArchive.class)
.addClasses(Echo.class, EchoNotABean.class)
.addAsManifestResource(newBeans11Descriptor("annotated"), "beans.xml");
// Bean defining annotation and 1.1 version beans.xml with bean-discovery-mode of none
JavaArchive foxtrot = ShrinkWrap
.create(JavaArchive.class)
.addClass(Foxtrot.class)
.addAsManifestResource(newBeans11Descriptor("none"), "beans.xml");

// Archive which contains an extension and no beans.xml file
JavaArchive legacy = ShrinkWrap.create(JavaArchive.class).addClasses(LegacyExtension.class, LegacyAlpha.class,
LegacyBravo.class).addAsServiceProvider(Extension.class, LegacyExtension.class);

return ShrinkWrap.create(WebArchive.class).addClasses(BeanDiscoveryTest.class, VerifyingExtension.class)
.addAsServiceProvider(Extension.class, VerifyingExtension.class)
.addAsLibrary(ShrinkWrap.create(JavaArchive.class).addClass(Ping.class))
.addAsLibraries(alpha, bravo, charlie, delta, echo, foxtrot, legacy);
}

@Inject
private VerifyingExtension extension;

@Inject
private BeanManager manager;

@Test
public void testExplicitBeanArchiveModeAll(Alpha alpha) {
assertDiscoveredAndAvailable(alpha, Alpha.class);
}

@Test
public void testExplicitBeanArchiveEmptyDescriptor(Bravo bravo) {
assertDiscoveredAndAvailable(bravo, Bravo.class);
}

@Test
public void testExplicitBeanArchiveLegacyDescriptor(Charlie charlie) {
assertDiscoveredAndAvailable(charlie, Charlie.class);
}

@Test
public void testImplicitBeanArchiveNoDescriptor(Delta delta) {
assertDiscoveredAndAvailable(delta, Delta.class);
}

@Test
public void testImplicitBeanArchiveModeAnnotated(Echo echo) {
assertDiscoveredAndAvailable(echo, Echo.class);
assertNotDiscoveredAndNotAvailable(EchoNotABean.class);
}

@Test
public void testNoBeanArchiveModeNone() {
assertNotDiscoveredAndNotAvailable(Foxtrot.class);
}

@Test
public void testNotBeanArchiveExtension(LegacyAlpha legacyAlpha) {
assertDiscoveredAndAvailable(legacyAlpha, LegacyAlpha.class);
assertNotDiscoveredAndNotAvailable(LegacyBravo.class);
}

private <T extends Ping> void assertDiscoveredAndAvailable(T reference, Class<T> clazz) {
Assert.assertTrue(extension.getObservedAnnotatedTypes().contains(clazz));
Assert.assertNotNull(reference);
reference.pong();
manager.resolve(manager.getBeans(clazz));
}

private <T> void assertNotDiscoveredAndNotAvailable(Class<T> clazz) {
Assert.assertFalse(extension.getObservedAnnotatedTypes().contains(clazz));
Assert.assertTrue(manager.getBeans(clazz).isEmpty());
}

private static StringAsset newBeans11Descriptor(String mode) {
return new StringAsset("<beans bean-discovery-mode=\"" + mode + "\" version=\"1.1\"/>");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.as.test.integration.weld.deployment;

public class Bravo implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.as.test.integration.weld.deployment;

public class Charlie implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.as.test.integration.weld.deployment;

import javax.enterprise.context.RequestScoped;

@RequestScoped
public class Delta implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.as.test.integration.weld.deployment;

import javax.enterprise.context.RequestScoped;

@RequestScoped
public class Echo implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.as.test.integration.weld.deployment;

public class EchoNotABean implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.as.test.integration.weld.deployment;

import javax.enterprise.context.RequestScoped;

@RequestScoped
public class Foxtrot implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.as.test.integration.weld.deployment;

import javax.enterprise.context.RequestScoped;

@RequestScoped
public class LegacyAlpha implements Ping {

@Override
public void pong() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.as.test.integration.weld.deployment;

import javax.enterprise.context.RequestScoped;

@RequestScoped
public class LegacyBravo {

}
Loading

0 comments on commit c1959b3

Please sign in to comment.