Skip to content

Commit 87f38d1

Browse files
committed
[PAXCDI-186] fixed regression for alternatives
1 parent 2a74c92 commit 87f38d1

File tree

7 files changed

+94
-4
lines changed

7 files changed

+94
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ops4j.pax.cdi.sample6;
2+
3+
4+
public interface MessageSource extends MessageProducer {
5+
6+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2015 Harald Wellmann.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.ops4j.pax.cdi.sample6.impl;
19+
20+
import javax.enterprise.inject.Alternative;
21+
22+
import org.ops4j.pax.cdi.sample6.MessageSource;
23+
24+
@Alternative
25+
public class AlternativeMessageSourceImpl implements MessageSource {
26+
27+
@Override
28+
public String getMessage() {
29+
return "Quod erat demonstrandum.";
30+
}
31+
}

pax-cdi-samples/pax-cdi-sample6/src/main/java/org/ops4j/pax/cdi/sample6/impl/MessageProducerImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@
1717
*/
1818
package org.ops4j.pax.cdi.sample6.impl;
1919

20+
import javax.inject.Inject;
21+
2022
import org.ops4j.pax.cdi.api.OsgiServiceProvider;
2123
import org.ops4j.pax.cdi.sample6.MessageProducer;
24+
import org.ops4j.pax.cdi.sample6.MessageSource;
2225

2326
@OsgiServiceProvider
2427
public class MessageProducerImpl implements MessageProducer {
2528

29+
@Inject
30+
private MessageSource source;
31+
2632
@Override
2733
public String getMessage() {
28-
return "Quod erat demonstrandum.";
34+
return source.getMessage();
2935
}
3036
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2015 Harald Wellmann.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.ops4j.pax.cdi.sample6.impl;
19+
20+
import org.ops4j.pax.cdi.sample6.MessageSource;
21+
22+
23+
public class MessageSourceImpl implements MessageSource {
24+
25+
@Override
26+
public String getMessage() {
27+
return "Tertium non datur.";
28+
}
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<beans xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
4+
<alternatives>
5+
<class>org.ops4j.pax.cdi.sample6.impl.AlternativeMessageSourceImpl</class>
6+
</alternatives>
7+
</beans>

pax-cdi-spi/src/main/java/org/ops4j/pax/cdi/spi/scan/BeanBundleFilter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
package org.ops4j.pax.cdi.spi.scan;
1919

2020
import java.net.URL;
21+
import java.util.ArrayList;
2122
import java.util.Dictionary;
2223
import java.util.HashMap;
24+
import java.util.List;
2325
import java.util.Map;
2426

2527
import org.ops4j.pax.cdi.spi.BeanBundles;
@@ -45,8 +47,9 @@ public boolean accept(Bundle providerBundle, String className) {
4547
return true;
4648
case NONE:
4749
return false;
50+
default:
51+
throw new IllegalArgumentException(descriptor.getBeanDiscoveryMode().toString());
4852
}
49-
return false;
5053
}
5154

5255
public BeanDescriptor findDescriptor(Bundle providerBundle) {
@@ -85,4 +88,12 @@ private boolean isWebBundle(Bundle bundle) {
8588
String contextPath = headers.get("Web-ContextPath");
8689
return (contextPath != null);
8790
}
91+
92+
public List<URL> getBeanDescriptors() {
93+
List<URL> urls = new ArrayList<>();
94+
for (BeanDescriptor descriptor : descriptorMap.values()) {
95+
urls.add(descriptor.getUrl());
96+
}
97+
return urls;
98+
}
8899
}

pax-cdi-spi/src/main/java/org/ops4j/pax/cdi/spi/scan/BeanScanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public Set<String> getBeanClasses() {
9494
* @return unmodifiable set
9595
*/
9696
public Set<URL> getBeanDescriptors() {
97-
// FIXME
98-
return Collections.emptySet();
97+
Set<URL> urls = new HashSet<>(filter.getBeanDescriptors());
98+
return Collections.unmodifiableSet(urls);
9999
}
100100

101101
/**

0 commit comments

Comments
 (0)