You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2010/04/04 13:12:28 UTC
svn commit: r930664 - in /myfaces/extensions/cdi/trunk/core:
api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/
api/src/test/ api/src/test/java/ api/src/test/java/org/
api/src/test/java/org/apache/ api/src/test/java/org/apache/m...
Author: struberg
Date: Sun Apr 4 11:12:27 2010
New Revision: 930664
URL: http://svn.apache.org/viewvc?rev=930664&view=rev
Log:
EXTCDI-7 EXTCDI-19 EXTCDI-19 EXTCDI-18
since I'm not able to commit single files without getting a weird error in fuuu.. SVN
I had to commit the whole bunch at once :(
Added:
myfaces/extensions/cdi/trunk/core/api/src/test/
myfaces/extensions/cdi/trunk/core/api/src/test/java/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/ProjectStageTest.java
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/TestProjectStages.java
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/tools/
myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/tools/DefaultAnnotationTest.java
myfaces/extensions/cdi/trunk/core/api/src/test/resources/
myfaces/extensions/cdi/trunk/core/api/src/test/resources/META-INF/
myfaces/extensions/cdi/trunk/core/api/src/test/resources/META-INF/services/
myfaces/extensions/cdi/trunk/core/api/src/test/resources/META-INF/services/org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder
myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageActivationExtension.java
myfaces/extensions/cdi/trunk/core/impl/src/main/resources/META-INF/
myfaces/extensions/cdi/trunk/core/impl/src/main/resources/META-INF/services/
myfaces/extensions/cdi/trunk/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/ProjectStageActivationExtensionTest.java
myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/
myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailService.java
myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceImpl.java
myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceMockImpl.java
myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/utils/
myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/utils/ContainerTestBase.java
myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/
myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/beans.xml
myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/services/
myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Modified:
myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStage.java
myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStageActivated.java
myfaces/extensions/cdi/trunk/core/impl/src/main/config/beans.xml
myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageProducer.java
Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStage.java?rev=930664&r1=930663&r2=930664&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStage.java (original)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStage.java Sun Apr 4 11:12:27 2010
@@ -55,28 +55,33 @@ import java.util.logging.Logger;
* </p>
*
* <p>Adding a new ProjectStage is done via the
- * {@link java.util.ServiceLoader} mechanism.</p>
+ * {@link java.util.ServiceLoader} mechanism. A class deriving from {@link ProjectStage}
+ * must be provided and used for creating a single static instance of it. The name of
+ * the class should be the name of the ProjectStage prefixed with 'C',
+ * e.g. "CUnitTest"</p>
*
* <p>Custom ProjectStages can be implemented by writing anonymous ProjectStage
* members into a registered {@link ProjectStageHolder} as shown in the following
* sample:</p>
* <pre>
* package org.apache.myfaces.extensions.cdi.test.api.projectstage;
- * public class MyProjectStages implements ProjectStageHolder
- * {
- * public static final ProjectStage MyOwnProjectStage = new ProjectStage("MyOwnProjectStage") {};
- * public static final ProjectStage MyOtherProjectStage = new ProjectStage("MyOtherProjectStage") {};
- * }
+ * public class MyProjectStages implements ProjectStageHolder {
+ * public static final class CMyOwnProjectStage extends ProjectStage {};
+ * public static final CMyOwnProjectStage MyOwnProjectStage = new CMyOwnProjectStage();
+ *
+ * public static final class CMyOtherProjectStage extends ProjectStage {};
+ * public static final CMyOtherProjectStage MyOtherProjectStage = new CMyOtherProjectStage();
+ * }
* </pre>
* <p>For activating those projectstages, you have to register this ProjectStageHolder class
* to get picked up via the java.util.ServiceLoader mechanism. Simply create a file
* <pre>
- * META-INF/services/org.apache.myfaces.extensions.cdi.api.projectstage.ProjectStageHolder
+ * META-INF/services/org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder
* </pre>
* which contains the fully qualified class name of custom ProjectStageHolder implementation:
* <pre>
* # this class now get's picked up by java.util.ServiceLoader
- * org.apache.myfaces.extensions.cdi.test.api.projectstage.MyProjectStages
+ * org.apache.myfaces.extensions.cdi.core.test.api.projectstage.MyProjectStages
* </pre>
* </p>
* <p>You can use your own ProjectStages exactly the same way as all the ones provided
@@ -137,16 +142,15 @@ public abstract class ProjectStage imple
/**
* The protected constructor will register the given ProjectStage via its name.
* The name is returned by the {@link #toString()} method of the ProjectStage.
- *
- * @param psNameIn the name of the ProjectStage which should get registered.
*/
- protected ProjectStage(String psNameIn)
+ protected ProjectStage()
{
- this.psName = psNameIn;
+ String psNameIn = this.getClass().getSimpleName();
+ psName = psNameIn.substring(1);
if (!projectStages.containsKey(psNameIn))
{
- projectStages.put(psNameIn, this);
+ projectStages.put(psName, this);
}
else
{
@@ -178,27 +182,34 @@ public abstract class ProjectStage imple
}
- public static final ProjectStage UnitTest = new ProjectStage("UnitTest")
+ public static final class CUnitTest extends ProjectStage
{
};
+ public static final CUnitTest UnitTest = new CUnitTest();
+
- public static final ProjectStage Development = new ProjectStage("Development")
+ public static final class CDevelopment extends ProjectStage
{
};
+ public static final CDevelopment Development = new CDevelopment();
- public static final ProjectStage SystemTest = new ProjectStage("SystemTest")
+ public static final class CSystemTest extends ProjectStage
{
};
+ public static final CSystemTest SystemTest = new CSystemTest();
- public static final ProjectStage IntegrationTest = new ProjectStage("IntegrationTest")
+ public static final class CIntegrationTest extends ProjectStage
{
};
+ public static final CIntegrationTest IntegrationTest = new CIntegrationTest();
- public static final ProjectStage Staging = new ProjectStage("Staging")
+ public static final class CStaging extends ProjectStage
{
};
+ public static final CStaging Staging = new CStaging();
- public static final ProjectStage Production = new ProjectStage("Production")
+ public static final class CProduction extends ProjectStage
{
};
+ public static final CProduction Production = new CProduction();
}
Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStageActivated.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStageActivated.java?rev=930664&r1=930663&r2=930664&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStageActivated.java (original)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/projectstage/ProjectStageActivated.java Sun Apr 4 11:12:27 2010
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
* <p>Example Usage:</p>
* <pre>
* @Alternative
- * @ProjectStageActivated({ProjectStage.Development.class, ProjectStage.UnitTest.class})
+ * @ProjectStageActivated({ProjectStage.CDevelopment.class, ProjectStage.CUnitTest.class})
* @ApplicationScoped
* public class MockMailServiceImpl implements MailService {...}
* </pre>
Added: myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/ProjectStageTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/ProjectStageTest.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/ProjectStageTest.java (added)
+++ myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/ProjectStageTest.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,48 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.myfaces.extensions.cdi.core.test.api.projectstage;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Test for {@link org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage}
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class ProjectStageTest {
+
+ @Test
+ public void testProjectStages() throws Exception
+ {
+ ProjectStage ps = ProjectStage.Development;
+ Assert.assertNotNull(ps);
+
+ ProjectStage psOther = ProjectStage.valueOf("AnotherProjectStage");
+ Assert.assertNotNull(psOther);
+
+ ProjectStage psProd = ProjectStage.valueOf("Production");
+ Assert.assertNotNull(psProd);
+
+ ProjectStage[] values = ProjectStage.values();
+ Assert.assertNotNull(values);
+ Assert.assertTrue(values.length == 7);
+ }
+}
Added: myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/TestProjectStages.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/TestProjectStages.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/TestProjectStages.java (added)
+++ myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/projectstage/TestProjectStages.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,33 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.myfaces.extensions.cdi.core.test.api.projectstage;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder;
+
+/**
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class TestProjectStages implements ProjectStageHolder
+{
+ public static final class CAnotherProjectStage extends ProjectStage
+ {
+ };
+ public static final CAnotherProjectStage AnotherProjectStage = new CAnotherProjectStage();
+}
Added: myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/tools/DefaultAnnotationTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/tools/DefaultAnnotationTest.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/tools/DefaultAnnotationTest.java (added)
+++ myfaces/extensions/cdi/trunk/core/api/src/test/java/org/apache/myfaces/extensions/cdi/core/test/api/tools/DefaultAnnotationTest.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,54 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.myfaces.extensions.cdi.core.test.api.tools;
+
+import java.lang.annotation.Annotation;
+import org.apache.myfaces.extensions.cdi.core.api.tools.annotate.DefaultAnnotation;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class DefaultAnnotationTest {
+
+ @Test
+ public void testDefaultAnnotationCache() throws Exception
+ {
+ Annotation ann1a = DefaultAnnotation.of(MyAnnotation1.class);
+ Assert.assertNotNull(ann1a);
+
+ Annotation ann1b = DefaultAnnotation.of(MyAnnotation1.class);
+ Assert.assertNotNull(ann1b);
+
+ Assert.assertTrue(ann1a == ann1b);
+
+ MyAnnotation2 ann2 = (MyAnnotation2) DefaultAnnotation.of(MyAnnotation2.class);
+ Assert.assertNotNull(ann2);
+ Assert.assertTrue(ann2.qualifier() == MyAnnotation1.class);
+ }
+
+
+ public static @interface MyAnnotation1
+ {
+ }
+
+ public static @interface MyAnnotation2
+ {
+ Class<? extends Annotation> qualifier() default MyAnnotation1.class;
+ }
+}
Added: myfaces/extensions/cdi/trunk/core/api/src/test/resources/META-INF/services/org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/test/resources/META-INF/services/org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/test/resources/META-INF/services/org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder (added)
+++ myfaces/extensions/cdi/trunk/core/api/src/test/resources/META-INF/services/org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder Sun Apr 4 11:12:27 2010
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Test file to register a test ProjectStageHolder which contains
+# a few additional ProjectStages
+org.apache.myfaces.extensions.cdi.core.test.api.projectstage.TestProjectStages
Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/config/beans.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/config/beans.xml?rev=930664&r1=930663&r2=930664&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/config/beans.xml (original)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/config/beans.xml Sun Apr 4 11:12:27 2010
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans/>
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageActivationExtension.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageActivationExtension.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageActivationExtension.java (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageActivationExtension.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.impl.projectstage;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageActivated;
+
+
+/**
+ * <p>This class implements the logic for handling
+ * {@link ProjectStageActivated} annotations.</p>
+ * <p>We simply listen for all annotated types to get scanned, and
+ * if it has a {@link ProjectStageActivated} annotation but the
+ * the current {@link ProjectStage} is not in the list, we simply
+ * veto that bean.</p>
+ *
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class ProjectStageActivationExtension implements Extension
+{
+
+ private ProjectStage projectStage = null;
+
+ protected ProjectStage getProjectStage()
+ {
+ if (projectStage == null)
+ {
+ // we have to do this manually since we don't have any
+ // injection mechanism in place at this point since
+ // the CDI container has not yet been started...
+ ProjectStageProducer psp = new ProjectStageProducer();
+ psp.determineProjectStage();
+ projectStage = psp.getProjectStage();
+ }
+ return projectStage;
+ }
+
+ /**
+ * Check if the {@link javax.enterprise.inject.spi.AnnotatedType} is an @Alternative and
+ * is not disabled for the current {@link ProjectStage}.
+ */
+ protected void vetoAlternativeTypes(@Observes ProcessAnnotatedType<Object> pat)
+ {
+ if (pat.getAnnotatedType().getJavaClass().isAnnotationPresent(ProjectStageActivated.class))
+ {
+ Class<? extends ProjectStage>[] activatedIn =
+ pat.getAnnotatedType().getJavaClass().getAnnotation(ProjectStageActivated.class).value();
+ if (isInProjectStage(activatedIn))
+ {
+ return;
+ }
+
+ // otherwise this alternative shall not get used
+ pat.veto();
+ }
+ }
+
+ private boolean isInProjectStage(Class<? extends ProjectStage>[] activatedIn)
+ {
+ if (activatedIn != null && activatedIn.length > 0)
+ {
+ ProjectStage ps = getProjectStage();
+ for (Class<? extends ProjectStage> activated : activatedIn)
+ {
+ if (ps.getClass().equals(activated))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+}
Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageProducer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageProducer.java?rev=930664&r1=930663&r2=930664&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageProducer.java (original)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/projectstage/ProjectStageProducer.java Sun Apr 4 11:12:27 2010
@@ -75,6 +75,14 @@ public class ProjectStageProducer
private final static Logger log = Logger.getLogger(ProjectStageProducer.class.getName());
/**
+ * ProjectStageProducers must only be created by subclassing producers
+ */
+ protected ProjectStageProducer()
+ {
+
+ }
+
+ /**
* The detected ProjectStage
*/
private static ProjectStage projectStage;
@@ -151,6 +159,8 @@ public class ProjectStageProducer
/**
* Read the configuration from the stated places.
* This can be overloaded to implement own lookup mechanisms.
+ *
+ * This will only determine the ProjectStage if it is not yet set.
*/
@Inject
public void determineProjectStage()
Added: myfaces/extensions/cdi/trunk/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension Sun Apr 4 11:12:27 2010
@@ -0,0 +1,36 @@
+#####################################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#####################################################################################
+
+#####################################################################################
+# This service configuration contains all available CODI extensions but in a
+#
+# DISABLED (commented-out)
+#
+# status.
+# Please copy over this file to your own project and enable the extensions as needed.
+#
+# We choose to do it that way since there is no option to later disable Services with
+# the underlying java.util.ServiceLoader mechanism.
+#####################################################################################
+
+# support for @ProjectStageActivated
+#org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageActivationExtension
+
+# myfaces-codi BeanManager provider
+#org.apache.myfaces.extensions.cdi.core.api.manager.BeanManagerProvider
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/ProjectStageActivationExtensionTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/ProjectStageActivationExtensionTest.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/ProjectStageActivationExtensionTest.java (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/ProjectStageActivationExtensionTest.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.test.impl.projectstage;
+
+import org.apache.myfaces.extensions.cdi.core.test.impl.projectstage.testbeans.MyMailService;
+import org.apache.myfaces.extensions.cdi.core.test.impl.projectstage.testbeans.MyMailServiceMockImpl;
+import org.apache.myfaces.extensions.cdi.core.test.utils.ContainerTestBase;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class ProjectStageActivationExtensionTest extends ContainerTestBase
+{
+ @Test
+ public void testProjectStageActivationExtension()
+ {
+ MyMailService mailSvc = getBeanInstance(MyMailService.class);
+ Assert.assertNotNull(mailSvc);
+
+ Assert.assertTrue(mailSvc instanceof MyMailServiceMockImpl);
+ }
+}
Added: myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailService.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailService.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailService.java (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailService.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,29 @@
+package org.apache.myfaces.extensions.cdi.core.test.impl.projectstage.testbeans;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Test mailservice interface
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public interface MyMailService {
+
+ public void sendMail(String mailTo, String text);
+
+}
Added: myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceImpl.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceImpl.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceImpl.java (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceImpl.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.test.impl.projectstage.testbeans;
+
+/**
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class MyMailServiceImpl implements MyMailService
+{
+
+ public void sendMail(String mailTo, String text) {
+ // do some real mail sending
+ }
+}
Added: myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceMockImpl.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceMockImpl.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceMockImpl.java (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/projectstage/testbeans/MyMailServiceMockImpl.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.test.impl.projectstage.testbeans;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageActivated;
+
+import javax.enterprise.inject.Alternative;
+
+/**
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+@Alternative
+@ProjectStageActivated({ProjectStage.CUnitTest.class})
+public class MyMailServiceMockImpl implements MyMailService
+{
+
+ public void sendMail(String mailTo, String text) {
+ // do some mock mail sending
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/utils/ContainerTestBase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/utils/ContainerTestBase.java?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/utils/ContainerTestBase.java (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/utils/ContainerTestBase.java Sun Apr 4 11:12:27 2010
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.core.test.utils;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+import org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageProducer;
+import org.apache.webbeans.cditest.CdiTestContainer;
+import org.apache.webbeans.cditest.CdiTestContainerLoader;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class ContainerTestBase
+{
+
+ protected Logger log;
+ protected static volatile CdiTestContainer containerStarter;
+ protected static volatile int containerRefCount = 0;
+
+ /**
+ * Returns an instance of the given class.
+ *
+ * @param <T>
+ * Type of Bean
+ * @param clazz
+ * Class of Bean
+ * @param qualifiers
+ * List of qualifiers
+ * @return Bean instance
+ */
+ protected <T> T getBeanInstance(Class<T> clazz, Annotation... qualifiers)
+ {
+ return containerStarter.getInstance(clazz, qualifiers);
+ }
+
+ /**
+ * Starts container or clean contextual instances before each test.
+ *
+ * @throws Exception in case of severe problem
+ */
+ @BeforeMethod
+ public final void setUp() throws Exception
+ {
+ log = Logger.getLogger(this.getClass().getName());
+ containerRefCount++;
+
+ if (containerStarter == null)
+ {
+ ProjectStageProducer.setProjectStage(ProjectStage.UnitTest);
+
+ containerStarter = CdiTestContainerLoader.getCdiContainer();
+ containerStarter.bootContainer();
+ }
+ else
+ {
+ cleanInstances();
+ }
+ }
+
+ @BeforeClass
+ public final void beforeClass() throws Exception
+ {
+ setUp();
+ }
+ /**
+ * Shuts down container.
+ * @throws Exception in case of severe problem
+ */
+ @AfterMethod
+ public final void tearDown() throws Exception
+ {
+ containerRefCount--;
+ }
+
+ public final void cleanInstances() throws Exception
+ {
+ containerStarter.stopContexts();
+ containerStarter.startContexts();
+ }
+
+ public void finalize() throws Throwable
+ {
+ if (containerStarter != null)
+ {
+ containerStarter.shutdownContainer();
+ containerStarter = null;
+ }
+
+ super.finalize();
+ }
+}
Added: myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/beans.xml?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/beans.xml (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/beans.xml Sun Apr 4 11:12:27 2010
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans>
+ <alternatives>
+ <class>org.apache.myfaces.extensions.cdi.core.test.impl.projectstage.testbeans.MyMailServiceMockImpl</class>
+ </alternatives>
+</beans>
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension?rev=930664&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension (added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension Sun Apr 4 11:12:27 2010
@@ -0,0 +1,36 @@
+#####################################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#####################################################################################
+
+#####################################################################################
+# This service configuration contains all available CODI extensions but in a
+#
+# DISABLED (commented-out)
+#
+# status.
+# Please copy over this file to your own project and enable the extensions as needed.
+#
+# We choose to do it that way since there is no option to later disable Services with
+# the underlying java.util.ServiceLoader mechanism.
+#####################################################################################
+
+# support for @ProjectStageActivated
+org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageActivationExtension
+
+# myfaces-codi BeanManager provider
+org.apache.myfaces.extensions.cdi.core.api.manager.BeanManagerProvider