Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AS7-2164 Warn if CDI annotations present but no beans.xml

  • Loading branch information...
commit 93c2ba71c4f2cf092fe2544260f753b66e21baa1 1 parent 3c488fc
@esantana authored
View
167 weld/src/main/java/org/jboss/as/weld/CdiAnnotations.java
@@ -0,0 +1,167 @@
+/*
+ * 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 {
+ /**
+ * javax.decorator.Decorator CDI annotation.
+ */
+ DECORATOR(Constants.JAVAX_DECORATOR, "Decorator"),
+ /**
+ * javax.decorator.Delegate CDI annotation.
+ */
+ DELEGATE(Constants.JAVAX_DECORATOR, "Delegate"),
+ /**
+ * javax.enterprise.context.ApplicationScoped CDI annotation.
+ */
+ APP_SCOPED(Constants.JAVAX_ENT_CONTEXT, "ApplicationScoped"),
+ /**
+ * javax.enterprise.context.ConversationScoped CDI annotation.
+ */
+ CONV_SCOPED(Constants.JAVAX_ENT_CONTEXT, "ConversationScoped"),
+ /**
+ * javax.enterprise.context.RequestScoped CDI annotation.
+ */
+ REQ_SCOPED(Constants.JAVAX_ENT_CONTEXT, "RequestScoped"),
+ /**
+ * javax.enterprise.context.SessionScoped CDI annotation.
+ */
+ SESS_SCOPED(Constants.JAVAX_ENT_CONTEXT, "SessionScoped"),
+ /**
+ * javax.enterprise.context.NormalScope CDI annotation.
+ */
+ NORM_SCOPE(Constants.JAVAX_ENT_CONTEXT, "NormalScope"),
+ /**
+ * javax.enterprise.context.Dependent CDI annotation.
+ */
+ DEPENDENT(Constants.JAVAX_ENT_CONTEXT, "Dependent"),
+ /**
+ * javax.enterprise.event.Observes CDI annotation.
+ */
+ OBSERVES(Constants.JAVAX_ENT_EVT, "Observes"),
+ /**
+ * javax.enterprise.inject.Alternative CDI annotation.
+ */
+ ALTERNATIVE(Constants.JAVAX_ENT_INJ, "Alternative"),
+ /**
+ * javax.enterprise.inject.Any CDI annotation.
+ */
+ ANY(Constants.JAVAX_ENT_INJ, "Any"),
+ /**
+ * javax.enterprise.inject.Default CDI annotation.
+ */
+ DEFAULT(Constants.JAVAX_ENT_INJ, "Default"),
+ /**
+ * javax.enterprise.inject.Disposes CDI annotation.
+ */
+ DISPOSES(Constants.JAVAX_ENT_INJ, "Disposes"),
+ /**
+ * javax.enterprise.inject.Model CDI annotation.
+ */
+ MODEL(Constants.JAVAX_ENT_INJ, "Model"),
+ /**
+ * javax.enterprise.inject.New CDI annotation.
+ */
+ NEW(Constants.JAVAX_ENT_INJ, "New"),
+ /**
+ * javax.enterprise.inject.Produces CDI annotation.
+ */
+ PRODUCES(Constants.JAVAX_ENT_INJ, "Produces"),
+ /**
+ * javax.enterprise.inject.Specializes CDI annotation.
+ */
+ SPECIALIZES(Constants.JAVAX_ENT_INJ, "Specializes"),
+ /**
+ * javax.enterprise.inject.Stereotype CDI annotation.
+ */
+ STEREOTYPE(Constants.JAVAX_ENT_INJ, "Stereotype"),
+ /**
+ * javax.enterprise.inject.Typed CDI annotation.
+ */
+ TYPED(Constants.JAVAX_ENT_INJ, "Typed");
+
+ /**
+ * CDI annotation name.
+ */
+ private final String simpleName;
+
+ /**
+ * CDI annotation fully qualified name.
+ */
+ private final DotName dotName;
+
+ /**
+ * Constructor.
+ *
+ * @param prefix qualified name part
+ * @param simpleName simple class name
+ */
+ private CdiAnnotations(final DotName prefix, final String simpleName) {
+ this.simpleName = simpleName;
+ this.dotName = DotName.createComponentized(prefix, simpleName);
+ }
+
+ /**
+ * this can't go on the enum itself.
+ */
+ private static class Constants {
+ /**
+ * javax.decorator package.
+ */
+ public static final DotName JAVAX_DECORATOR = DotName.createSimple("javax.decorator");
+ /**
+ * javax.enterprise.context package.
+ */
+ public static final DotName JAVAX_ENT_CONTEXT = DotName.createSimple("javax.enterprise.context");
+
+ /**
+ * javax.enterprise.event package.
+ */
+ public static final DotName JAVAX_ENT_EVT = DotName.createSimple("javax.enterprise.event");
+
+ /**
+ * javax.enterprise.inject package.
+ */
+ public static final DotName JAVAX_ENT_INJ = DotName.createSimple("javax.enterprise.inject");
+ }
+
+ /**
+ * @return fully qualified name
+ */
+ public DotName getDotName() {
+ return dotName;
+ }
+
+ /**
+ * @return simple name
+ */
+ public String getSimpleName() {
+ return simpleName;
+ }
+
+}
View
66 weld/src/main/java/org/jboss/as/weld/deployment/CdiAnnotationMarker.java
@@ -0,0 +1,66 @@
+/*
+ * 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 final class CdiAnnotationMarker {
+ /**
+ * Boolean attachment key.
+ */
+ private static final AttachmentKey<Boolean> ATTACHMENT_KEY = AttachmentKey.create(Boolean.class);
+
+ /**
+ * Default constructor not visible.
+ */
+ private CdiAnnotationMarker() {
+ }
+
+ /**
+ * Mark the deployment as a CDI one.
+ *
+ * @param deployment to be marked
+ */
+ public static void mark(final DeploymentUnit deployment) {
+ if (deployment.getParent() != null) {
+ deployment.getParent().putAttachment(ATTACHMENT_KEY, true);
+ } else {
+ deployment.putAttachment(ATTACHMENT_KEY, true);
+ }
+ }
+
+ /**
+ * Return the information about the deployment regarding CDI.
+ *
+ * @param deploymentUnit to be verified
+ * @return true if the deployment is marked as a CDI one
+ */
+ public static boolean isCdiDeployment(final DeploymentUnit deploymentUnit) {
+ DeploymentUnit deployment = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
+ Boolean val = deployment.getAttachment(ATTACHMENT_KEY);
+ return val != null && val;
+ }
+}
View
54 weld/src/main/java/org/jboss/as/weld/deployment/CdiAnnotationProcessor.java
@@ -0,0 +1,54 @@
+/*
+ * 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.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;
+
+/**
+ * CdiAnnotationProcessor class. Used to verify the presence of CDI annotations.
+ */
+public class CdiAnnotationProcessor implements DeploymentUnitProcessor {
+ @Override
+ public void deploy(final 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()) {
+ CdiAnnotationMarker.mark(deploymentUnit);
+ return;
+ }
+ }
+
+ }
+
+ @Override
+ public void undeploy(final DeploymentUnit context) {
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.