diff --git a/weld/src/main/java/org/jboss/as/weld/CdiAnnotations.java b/weld/src/main/java/org/jboss/as/weld/CdiAnnotations.java new file mode 100644 index 0000000..6e4e8cf --- /dev/null +++ b/weld/src/main/java/org/jboss/as/weld/CdiAnnotations.java @@ -0,0 +1,74 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.weld; + +import org.jboss.jandex.DotName; + +/** + * Class that stores the {@link DotName}s of CDI annotations + * + */ +public enum CdiAnnotations { + DECORATOR(Constants.JAVAX_DECORATOR,"Decorator"), + DELEGATE(Constants.JAVAX_DECORATOR,"Delegate"), + APP_SCOPED(Constants.JAVAX_ENT_CONTEXT,"ApplicationScoped"), + CONV_SCOPED(Constants.JAVAX_ENT_CONTEXT,"ConversationScoped"), + REQ_SCOPED(Constants.JAVAX_ENT_CONTEXT,"RequestScoped"), + SESS_SCOPED(Constants.JAVAX_ENT_CONTEXT,"SessionScoped"), + NORM_SCOPE(Constants.JAVAX_ENT_CONTEXT,"NormalScope"), + DEPENDENT(Constants.JAVAX_ENT_CONTEXT,"Dependent"), + OBSERVES(Constants.JAVAX_ENT_EVT,"Observes"), + ALTERNATIVE(Constants.JAVAX_ENT_INJ,"Alternative"), + ANY(Constants.JAVAX_ENT_INJ,"Any"), + DEFAULT(Constants.JAVAX_ENT_INJ,"Default"), + DISPOSES(Constants.JAVAX_ENT_INJ,"Disposes"), + MODEL(Constants.JAVAX_ENT_INJ,"Model"), + NEW(Constants.JAVAX_ENT_INJ,"New"), + PRODUCES(Constants.JAVAX_ENT_INJ,"Produces"), + SPECIALIZES(Constants.JAVAX_ENT_INJ,"Specializes"), + STEREOTYPE(Constants.JAVAX_ENT_INJ,"Stereotype"), + TYPED(Constants.JAVAX_ENT_INJ,"Typed"); + + private final String simpleName; + private final DotName dotName; + + private CdiAnnotations(DotName prefix,String simpleName) { + this.simpleName = simpleName; + this.dotName = DotName.createComponentized(prefix, simpleName); + } + // this can't go on the enum itself + private static class Constants { + public static final DotName JAVAX_DECORATOR = DotName.createSimple("javax.decorator"); + public static final DotName JAVAX_ENT_CONTEXT = DotName.createSimple("javax.enterprise.context"); + public static final DotName JAVAX_ENT_EVT = DotName.createSimple("javax.enterprise.event"); + public static final DotName JAVAX_ENT_INJ = DotName.createSimple("javax.ws.rs.ext"); + } + + public DotName getDotName() { + return dotName; + } + + public String getSimpleName() { + return simpleName; + } + +} diff --git a/weld/src/main/java/org/jboss/as/weld/deployment/CdiAnnotationProcessor.java b/weld/src/main/java/org/jboss/as/weld/deployment/CdiAnnotationProcessor.java new file mode 100644 index 0000000..4540a31 --- /dev/null +++ b/weld/src/main/java/org/jboss/as/weld/deployment/CdiAnnotationProcessor.java @@ -0,0 +1,55 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.weld.deployment; + +import org.jboss.as.server.Services; +import org.jboss.as.server.deployment.Attachments; +import org.jboss.as.server.deployment.DeploymentPhaseContext; +import org.jboss.as.server.deployment.DeploymentUnit; +import org.jboss.as.server.deployment.DeploymentUnitProcessingException; +import org.jboss.as.server.deployment.DeploymentUnitProcessor; +import org.jboss.as.server.deployment.annotation.CompositeIndex; +import org.jboss.as.weld.CdiAnnotations; + +public class CdiAnnotationProcessor implements DeploymentUnitProcessor { + + @Override + public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { + final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); + + final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); + + for (final CdiAnnotations annotation : CdiAnnotations.values()) { + if (!index.getAnnotations(annotation.getDotName()).isEmpty()) { + CdiDeploymentMarker.mark(deploymentUnit); + phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, Services.JBOSS_MODULE_INDEX_SERVICE); + return; + } + } + + } + + @Override + public void undeploy(DeploymentUnit context) { + } + +} diff --git a/weld/src/main/java/org/jboss/as/weld/deployment/CdiDeploymentMarker.java b/weld/src/main/java/org/jboss/as/weld/deployment/CdiDeploymentMarker.java new file mode 100644 index 0000000..2191dee --- /dev/null +++ b/weld/src/main/java/org/jboss/as/weld/deployment/CdiDeploymentMarker.java @@ -0,0 +1,46 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.as.weld.deployment; + +import org.jboss.as.server.deployment.AttachmentKey; +import org.jboss.as.server.deployment.DeploymentUnit; + +/** + * Marker for CDI deployments + */ +public class CdiDeploymentMarker { + private static final AttachmentKey ATTACHMENT_KEY = AttachmentKey.create(Boolean.class); + + public static void mark(DeploymentUnit deployment) { + if (deployment.getParent() != null) { + deployment.getParent().putAttachment(ATTACHMENT_KEY, true); + } else { + deployment.putAttachment(ATTACHMENT_KEY, true); + } + } + + public static boolean isJaxrsDeployment(DeploymentUnit deploymentUnit) { + DeploymentUnit deployment = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent(); + Boolean val = deployment.getAttachment(ATTACHMENT_KEY); + return val != null && val; + } +}