Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

<properties>
<gpg.plugin.version>3.2.8</gpg.plugin.version>
<nexus.staging.plugin.version>1.7.0</nexus.staging.plugin.version>
<jboss.releases.repo.url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/
</jboss.releases.repo.url>
<jboss.snapshots.repo.url>https://repository.jboss.org/nexus/content/repositories/snapshots/
Expand Down
14 changes: 0 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@
<atinject.api.version>2.0.1</atinject.api.version>
<cdi.api.version>5.0.0</cdi.api.version>
<ejb.api.version>4.0.1</ejb.api.version>
<jaxrs.api.version>4.0.0</jaxrs.api.version>
<jpa.api.version>4.0.0-M6</jpa.api.version>
<jta.api.version>2.0.1</jta.api.version>
<interceptor.api.version>2.2.0</interceptor.api.version>
<servlet.api.version>6.1.0</servlet.api.version>
<validation.api.version>3.1.1</validation.api.version>
</properties>

<dependencyManagement>
Expand All @@ -115,12 +113,6 @@
<version>${jpa.api.version}</version>
</dependency>

<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${validation.api.version}</version>
</dependency>

<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
Expand Down Expand Up @@ -157,12 +149,6 @@
<version>${interceptor.api.version}</version>
</dependency>

<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jaxrs.api.version}</version>
</dependency>

<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
Expand Down
11 changes: 5 additions & 6 deletions weld-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

<dependencies>

<dependency>
<groupId>jakarta.cdi</groupId>
<artifactId>jakarta.cdi-el-api</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
Expand Down Expand Up @@ -55,12 +60,6 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>jakarta.ejb</groupId>
<artifactId>jakarta.ejb-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public abstract class SingletonProvider {
*/
private static volatile SingletonProvider INSTANCE;

private static final String DEFAULT_SCOPE_FACTORY = RegistrySingletonProvider.class.getName();

/**
* Returns a singleton instance of this class.
*
Expand Down Expand Up @@ -76,12 +74,7 @@ protected SingletonProvider() {
* Initialize with the default instance
*/
private static void initializeWithDefaultScope() {
try {
Class<?> aClass = Class.forName(DEFAULT_SCOPE_FACTORY);
INSTANCE = (SingletonProvider) aClass.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
INSTANCE = new RegistrySingletonProvider();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
*/
package org.jboss.weld.bootstrap.api.helpers;

import java.util.AbstractMap;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.bootstrap.api.ServiceRegistry;

Expand All @@ -28,19 +36,46 @@ private ServiceRegistries() {
}

/**
* Returns an unmodifiable version of provided {@link ServiceRegistry} where any attempt to add a service results in an
* exception
* Returns a view of the provided {@link ServiceRegistry} that prevents adding, removing or replacing registrations.
* Changes made through the original registry remain visible. Service cleanup operations are still delegated.
*
* @param serviceRegistry service registry to process
* @return unmodifiable variant
*/
public static ServiceRegistry unmodifiableServiceRegistry(final ServiceRegistry serviceRegistry) {
Map<Class<? extends Service>, Service> services = Collections.unmodifiableMap(new AbstractMap<>() {
@Override
public Set<Entry<Class<? extends Service>, Service>> entrySet() {
return serviceRegistry.entrySet();
}
});
return new ForwardingServiceRegistry() {

public <S extends Service> void add(java.lang.Class<S> type, S service) {
@Override
public <S extends Service> void add(Class<S> type, S service) {
throw new UnsupportedOperationException("This service registry is unmodifiable");
}

@Override
public <S extends Service> S addIfAbsent(Class<S> type, S service) {
throw new UnsupportedOperationException("This service registry is unmodifiable");
}

@Override
public void addAll(Collection<Entry<Class<? extends Service>, Service>> services) {
throw new UnsupportedOperationException("This service registry is unmodifiable");
}

@Override
public Set<Entry<Class<? extends Service>, Service>> entrySet() {
return services.entrySet();
}

@Override
public Iterator<Service> iterator() {
return services.values().iterator();
}

@Override
protected ServiceRegistry delegate() {
return serviceRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,12 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (obj instanceof Map<?, ?>) {
return services.equals(obj);
} else {
return false;
}
return this == obj || obj instanceof SimpleServiceRegistry
&& services.equals(((SimpleServiceRegistry) obj).services);
}

public Iterator<Service> iterator() {
return new ValueIterator<Class<? extends Service>, Service>() {

@Override
protected Iterator<Entry<Class<? extends Service>, Service>> delegate() {
return services.entrySet().iterator();
}

};
}

private abstract static class ValueIterator<K, V> implements Iterator<V> {

protected abstract Iterator<Entry<K, V>> delegate();

public boolean hasNext() {
return delegate().hasNext();
}

public V next() {
return delegate().next().getValue();
}

public void remove() {
delegate().remove();
}

return services.values().iterator();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Represents the value of the <code>bean-discovery-mode</code> attribute within <code>beans.xml</code>. If a
* <code>beans.xml</code> file does not contain the <code>bean-discovery-mode</code> attribute, the value defaults to
* {@link BeanDiscoveryMode#ALL}.
* {@link BeanDiscoveryMode#ANNOTATED}.
*
* @author Jozef Hartinger
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,9 @@ public interface Deployment {
/**
* Specifies the extensions this deployment should call observer methods on.
*
* JSR-299 specifies that extensions should be loaded using <a
* href="http://download.oracle.com/javase/1.5.0/docs/guide/jar/jar.html#Service%20Provider" >Service Providers from the JAR
* File specification</a>
*
* Weld delegates this task to the container, allowing the container to programatically alter the extensions registered. To
* load extensions, the container could use the {@link ServiceLoader} available in the JDK (since Java 6). In pre Java 6
* environments, the container must provide the ServiceLoader itself. We provide an example Service Loader <a
* href="http://gist.github.com/540594">here</a>.
* CDI extensions are registered as service providers for {@link Extension}.
* Weld delegates loading to the container, allowing it to programmatically alter the registered extensions.
* The container can use {@link ServiceLoader} to discover extension providers.
*
* @return the extensions to call observer methods on, or an empty list if there are no observers
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ public interface WeldManager extends BeanManager, ELAwareBeanManager, Serializab
*
* Note that for each scope, there might be more than one {@link Context}, but there can be at most one active at a time.
*
* The default implementation returns a snapshot of the active contexts.
*
* @return Collection of all currently active {@link Context}s
*/
default Collection<Context> getActiveContexts() {
return getScopes().stream()
.filter(this::isContextActive)
.map(this::getContext)
.collect(Collectors.toSet());
.collect(Collectors.toUnmodifiableSet());
}

/**
Expand All @@ -243,6 +245,8 @@ default Collection<Context> getActiveContexts() {
* This method can therefore return an incomplete view of all active contexts as not every context implements
* {@link WeldAlterableContext}.
*
* The default implementation returns a snapshot of the active contexts implementing {@link WeldAlterableContext}.
*
* @return Collection of all active contexts implementing {@link WeldAlterableContext}
*/
default Collection<WeldAlterableContext> getActiveWeldAlterableContexts() {
Expand All @@ -251,18 +255,7 @@ default Collection<WeldAlterableContext> getActiveWeldAlterableContexts() {
.map(this::getContext)
.filter(t -> t instanceof WeldAlterableContext)
.map(t -> (WeldAlterableContext) t)
.collect(Collectors.toSet());
.collect(Collectors.toUnmodifiableSet());
}

/**
* Obtains all {@linkplain Context context objects}, active and inactive, for the given
* {@linkplain jakarta.enterprise.context scope}.
* <p>
* This feature is planned to be added into specification as part of
* <a href="https://github.com/jakartaee/cdi/issues/628">this issue</a>.
*
* @param scopeType the {@linkplain jakarta.enterprise.context scope}; must not be {@code null}
* @return immutable collection of {@linkplain Context context objects}; never {@code null}, but may be empty
*/
Collection<Context> getContexts(Class<? extends Annotation> scopeType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jboss.weld.bootstrap.api.test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.expectThrows;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.bootstrap.api.helpers.ServiceRegistries;
import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
import org.testng.annotations.Test;

public class ServiceRegistriesTest {

@Test
public void unmodifiableRegistryRejectsAllRegistrationChanges() {
ServiceRegistry backing = new SimpleServiceRegistry();
Service original = () -> {
};
Service replacement = () -> {
};
backing.add(Service.class, original);
ServiceRegistry view = ServiceRegistries.unmodifiableServiceRegistry(backing);

expectThrows(UnsupportedOperationException.class, () -> view.add(Service.class, replacement));
expectThrows(UnsupportedOperationException.class, () -> view.addIfAbsent(Service.class, replacement));
expectThrows(UnsupportedOperationException.class, () -> view.addIfAbsent(MockService.class, new MockService() {
}));
expectThrows(UnsupportedOperationException.class,
() -> view.addAll(List.of(Map.entry(Service.class, replacement))));
expectThrows(UnsupportedOperationException.class, () -> view.entrySet().clear());
expectThrows(UnsupportedOperationException.class,
() -> view.entrySet().iterator().next().setValue(replacement));
Iterator<Map.Entry<Class<? extends Service>, Service>> entries = view.entrySet().iterator();
entries.next();
expectThrows(UnsupportedOperationException.class, entries::remove);
Iterator<Service> services = view.iterator();
assertSame(services.next(), original);
expectThrows(UnsupportedOperationException.class, services::remove);
assertFalse(services.hasNext());
assertSame(backing.get(Service.class), original);
assertEquals(backing.entrySet().size(), 1);
}

@Test
public void unmodifiableRegistryRemainsLiveAndDelegatesCleanup() {
ServiceRegistry backing = new SimpleServiceRegistry();
ServiceRegistry view = ServiceRegistries.unmodifiableServiceRegistry(backing);
Set<Map.Entry<Class<? extends Service>, Service>> entries = view.entrySet();
AtomicBoolean cleaned = new AtomicBoolean();
Service service = () -> cleaned.set(true);
backing.add(Service.class, service);
assertSame(view.get(Service.class), service);
assertEquals(entries.size(), 1);
view.cleanup();
assertTrue(cleaned.get());
}
}
Loading
Loading