Skip to content

Commit

Permalink
add built-in beans
Browse files Browse the repository at this point in the history
fixes #4
  • Loading branch information
jonasrutishauser committed Mar 5, 2018
1 parent ea98c10 commit 44b7d14
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.jboss.weld.bootstrap.spi.EEModuleDescriptor.ModuleType;
import org.jboss.weld.bootstrap.spi.Metadata;
import org.jboss.weld.bootstrap.spi.helpers.EEModuleDescriptorImpl;
import org.jboss.weld.bootstrap.spi.helpers.MetadataImpl;
import org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive;
import org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy;
import org.jboss.weld.environment.deployment.discovery.DiscoveryStrategyFactory;
Expand All @@ -67,6 +68,7 @@
import com.github.jonasrutishauser.cdi.maven.plugin.war.WarUtil;
import com.github.jonasrutishauser.cdi.maven.plugin.weld.EarDeployment;
import com.github.jonasrutishauser.cdi.maven.plugin.weld.JarsBeanArchiveScanner;
import com.github.jonasrutishauser.cdi.maven.plugin.weld.bootstrap.PredefinedBeansExtension;

public class EarUtil implements ArchiveUtil {

Expand All @@ -86,6 +88,7 @@ public EarUtil(ArchiverManager archiverManager) {
public Deployment createDeployment(CDI11Bootstrap bootstrap) {
ResourceLoader resourceLoader = new ClassLoaderResourceLoader(earClassloader);
Set<Metadata<Extension>> extensions = getExtensions(bootstrap);
extensions.add(MetadataImpl.from(new PredefinedBeansExtension()));
TypeDiscoveryConfiguration typeDiscoveryConfiguration = bootstrap.startExtensions(extensions);
return new EarDeployment(resourceLoader, bootstrap, getBeanDeploymentArchives(resourceLoader, bootstrap,
typeDiscoveryConfiguration.getKnownBeanDefiningAnnotations()), extensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import javax.enterprise.inject.spi.Extension;

Expand All @@ -40,6 +41,7 @@
import org.jboss.weld.bootstrap.spi.EEModuleDescriptor.ModuleType;
import org.jboss.weld.bootstrap.spi.Metadata;
import org.jboss.weld.bootstrap.spi.helpers.EEModuleDescriptorImpl;
import org.jboss.weld.bootstrap.spi.helpers.MetadataImpl;
import org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive;
import org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy;
import org.jboss.weld.environment.deployment.discovery.DiscoveryStrategyFactory;
Expand All @@ -50,6 +52,7 @@
import com.github.jonasrutishauser.cdi.maven.plugin.ear.EjbUtil;
import com.github.jonasrutishauser.cdi.maven.plugin.weld.WarBeanArchiveScanner;
import com.github.jonasrutishauser.cdi.maven.plugin.weld.WarDeployment;
import com.github.jonasrutishauser.cdi.maven.plugin.weld.bootstrap.PredefinedBeansExtension;

public class WarUtil implements ArchiveUtil {

Expand Down Expand Up @@ -102,7 +105,9 @@ private void init(File workDirectory, File warFile, ClassLoader parentClassloade

@Override
public Deployment createDeployment(CDI11Bootstrap bootstrap) {
Iterable<Metadata<Extension>> extensions = bootstrap.loadExtensions(warClassloader);
Set<Metadata<Extension>> extensions = StreamSupport
.stream(bootstrap.loadExtensions(warClassloader).spliterator(), false).collect(Collectors.toSet());
extensions.add(MetadataImpl.from(new PredefinedBeansExtension()));
TypeDiscoveryConfiguration typeDiscoveryConfiguration = bootstrap.startExtensions(extensions);
Set<WeldBeanDeploymentArchive> archives = createArchives(bootstrap,
typeDiscoveryConfiguration.getKnownBeanDefiningAnnotations());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.github.jonasrutishauser.cdi.maven.plugin.weld.bootstrap;

import java.security.Principal;
import java.util.Set;

import javax.enterprise.inject.Typed;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.ConstraintViolation;
import javax.validation.MessageInterpolator;
import javax.validation.ParameterNameProvider;
import javax.validation.TraversableResolver;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
import javax.validation.executable.ExecutableValidator;
import javax.validation.metadata.BeanDescriptor;

@Typed({Validator.class, ValidatorFactory.class, Principal.class, UserTransaction.class})
class Dummy implements Validator, ValidatorFactory, Principal, UserTransaction {

@Override
public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups) {
throw new UnsupportedOperationException();
}

@Override
public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups) {
throw new UnsupportedOperationException();
}

@Override
public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value,
Class<?>... groups) {
throw new UnsupportedOperationException();
}

@Override
public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
throw new UnsupportedOperationException();
}

@Override
public <T> T unwrap(Class<T> type) {
throw new UnsupportedOperationException();
}

@Override
public ExecutableValidator forExecutables() {
throw new UnsupportedOperationException();
}

@Override
public Validator getValidator() {
throw new UnsupportedOperationException();
}

@Override
public ValidatorContext usingContext() {
throw new UnsupportedOperationException();
}

@Override
public MessageInterpolator getMessageInterpolator() {
throw new UnsupportedOperationException();
}

@Override
public TraversableResolver getTraversableResolver() {
throw new UnsupportedOperationException();
}

@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
throw new UnsupportedOperationException();
}

@Override
public ParameterNameProvider getParameterNameProvider() {
throw new UnsupportedOperationException();
}

@Override
public void close() {
throw new UnsupportedOperationException();
}

@Override
public void begin() throws NotSupportedException, SystemException {
throw new UnsupportedOperationException();
}

@Override
public void commit()
throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SystemException {
throw new UnsupportedOperationException();
}

@Override
public void rollback() throws SystemException {
throw new UnsupportedOperationException();
}

@Override
public void setRollbackOnly() throws SystemException {
throw new UnsupportedOperationException();
}

@Override
public int getStatus() throws SystemException {
throw new UnsupportedOperationException();
}

@Override
public void setTransactionTimeout(int seconds) throws SystemException {
throw new UnsupportedOperationException();
}

@Override
public String getName() {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.jonasrutishauser.cdi.maven.plugin.weld.bootstrap;

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 PredefinedBeansExtension implements Extension {

void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager beanManager) {
event.addAnnotatedType(beanManager.createAnnotatedType(Dummy.class));
}

}
6 changes: 6 additions & 0 deletions src/test/projects/full/simple-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.validation.Validator;

@Dependent
public class TestImpl {

private final Foo foo;

@Inject
protected TestImpl(Foo foo) {
protected TestImpl(Foo foo, Validator validator) {
this.foo = foo;
}

Expand Down

0 comments on commit 44b7d14

Please sign in to comment.