Search in sources :

Example 1 with ProjectStage

use of org.apache.deltaspike.core.api.projectstage.ProjectStage in project deltaspike by apache.

the class ClassDeactivationUtils method performProjectStageDependentCleanup.

private static void performProjectStageDependentCleanup() {
    ProjectStage currentProjectStage = ProjectStageProducer.getInstance().getProjectStage();
    if (previouslyDetectedProjectStage != currentProjectStage) {
        previouslyDetectedProjectStage = currentProjectStage;
        //don't use #clear to support parallel access to #isActivated (+ reset) without synchronization
        activationStatusCache = new ConcurrentHashMap<Class<? extends Deactivatable>, Boolean>();
        //#clear is ok here due to the handling in the synchronized method #initDeactivatableCacheFor
        classDeactivatorMap.clear();
    } else if (currentProjectStage == ProjectStage.UnitTest || currentProjectStage == ProjectStage.Development) {
        activationStatusCache = new ConcurrentHashMap<Class<? extends Deactivatable>, Boolean>();
    }
}
Also used : ProjectStage(org.apache.deltaspike.core.api.projectstage.ProjectStage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Deactivatable(org.apache.deltaspike.core.spi.activation.Deactivatable)

Example 2 with ProjectStage

use of org.apache.deltaspike.core.api.projectstage.ProjectStage in project deltaspike by apache.

the class ConfigResolver method getProjectStageAwarePropertyValue.

/**
     * Resolves the value configured for the given key in the current
     * {@link org.apache.deltaspike.core.api.projectstage.ProjectStage}.
     *
     * <p>
     * First, it will search for a value configured for the given key suffixed with the current ProjectStage (e.g.
     * 'myproject.myconfig.Production'), and in case this value is not found (null or empty), it will look up the given
     * key without any suffix.</p>
     *
     * <p>
     * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be
     * used to determine the ProjectStage itself.</p>
     *
     * @param key
     *
     * @return the value configured for {@code <given key>.<current project stage>}, or just the configured value of
     *         {@code <given key>} if the project-stage-specific value is not found (null or empty)
     *
     */
public static String getProjectStageAwarePropertyValue(String key) {
    ConfigResolverContext configResolverContext = new ConfigResolverContext().setProjectStageAware(true).setEvaluateVariables(true);
    ProjectStage ps = getProjectStage();
    String value = getPropertyValue(key + '.' + ps, configResolverContext);
    if (value == null) {
        value = getPropertyValue(key, configResolverContext);
    }
    return value;
}
Also used : ProjectStage(org.apache.deltaspike.core.api.projectstage.ProjectStage)

Example 3 with ProjectStage

use of org.apache.deltaspike.core.api.projectstage.ProjectStage in project deltaspike by apache.

the class ExcludeExtension method vetoBeans.

/**
     * Observer which is vetoing beans based on {@link Exclude}
     * @param processAnnotatedType observed event
     */
@SuppressWarnings("UnusedDeclaration")
protected void vetoBeans(@Observes ProcessAnnotatedType processAnnotatedType, BeanManager beanManager) {
    //we need to do it before the exclude logic to keep the @Exclude support for global alternatives
    if (isGlobalAlternativeActivated) {
        activateGlobalAlternatives(processAnnotatedType, beanManager);
    }
    if (isCustomProjectStageBeanFilterActivated) {
        vetoCustomProjectStageBeans(processAnnotatedType);
    }
    if (!isActivated) {
        return;
    }
    //TODO needs further discussions for a different feature CodiStartupBroadcaster.broadcastStartup();
    //also forces deterministic project-stage initialization
    ProjectStage projectStage = ProjectStageProducer.getInstance().getProjectStage();
    Exclude exclude = extractExcludeAnnotation(processAnnotatedType.getAnnotatedType().getJavaClass());
    if (exclude == null) {
        return;
    }
    if (!evalExcludeWithoutCondition(processAnnotatedType, exclude)) {
        //veto called already
        return;
    }
    if (!evalExcludeInProjectStage(processAnnotatedType, exclude, projectStage)) {
        //veto called already
        return;
    }
    if (!evalExcludeNotInProjectStage(processAnnotatedType, exclude, projectStage)) {
        //veto called already
        return;
    }
    evalExcludeWithExpression(processAnnotatedType, exclude);
}
Also used : Exclude(org.apache.deltaspike.core.api.exclude.Exclude) ProjectStage(org.apache.deltaspike.core.api.projectstage.ProjectStage)

Example 4 with ProjectStage

use of org.apache.deltaspike.core.api.projectstage.ProjectStage in project deltaspike by apache.

the class ProjectStageTest method testProjectStages.

@Test
public void testProjectStages() throws Exception {
    ProjectStage ps = ProjectStage.Development;
    Assert.assertNotNull(ps);
    ProjectStage psOther = ProjectStage.valueOf("CustomProjectStage");
    Assert.assertNotNull(psOther);
    psOther = TestProjectStages.CustomProjectStage;
    Assert.assertNotNull(psOther);
    ProjectStage psProd = ProjectStage.valueOf("Production");
    Assert.assertNotNull(psProd);
    ProjectStage[] values = ProjectStage.values();
    Assert.assertNotNull(values);
    Assert.assertTrue(values.length == 7);
}
Also used : ProjectStage(org.apache.deltaspike.core.api.projectstage.ProjectStage) Test(org.junit.Test)

Example 5 with ProjectStage

use of org.apache.deltaspike.core.api.projectstage.ProjectStage in project deltaspike by apache.

the class ProjectStageProducerTest method testProjectStageSetByEnvironment.

/**
     * Test a ProjectStage which got set by the <i>javax.faces.ProjectStage</i>
     */
@Test
public void testProjectStageSetByEnvironment() {
    String[] oldEnvVals = new String[ProjectStageProducer.CONFIG_SETTING_KEYS.length];
    for (int i = 0; i < ProjectStageProducer.CONFIG_SETTING_KEYS.length; i++) {
        String envName = ProjectStageProducer.CONFIG_SETTING_KEYS[i];
        oldEnvVals[i] = "" + System.getProperty(envName);
        // and also clean them now
        System.setProperty(ProjectStageProducer.CONFIG_SETTING_KEYS[i], "");
    }
    try {
        for (int i = 0; i < ProjectStageProducer.CONFIG_SETTING_KEYS.length; i++) {
            String envName = ProjectStageProducer.CONFIG_SETTING_KEYS[i];
            System.setProperty(envName, "SystemTest");
            ProjectStageProducer psp = ProjectStageProducer.getInstance();
            Assert.assertNotNull(psp);
            ProjectStageProducer.setProjectStage(null);
            ProjectStage ps = psp.getProjectStage();
            Assert.assertNotNull(ps);
            Assert.assertEquals(ps, ProjectStage.SystemTest);
            Assert.assertTrue(ps == ProjectStage.SystemTest);
            ProjectStageProducer.setProjectStage(null);
            System.setProperty(envName, "IntegrationTest");
            ps = psp.getProjectStage();
            Assert.assertNotNull(ps);
            Assert.assertEquals(ps, ProjectStage.IntegrationTest);
            Assert.assertTrue(ps == ProjectStage.IntegrationTest);
            System.setProperty(envName, "");
        }
    } finally {
        // restore the old env values
        for (int i = 0; i < ProjectStageProducer.CONFIG_SETTING_KEYS.length; i++) {
            System.setProperty(ProjectStageProducer.CONFIG_SETTING_KEYS[i], oldEnvVals[i]);
        }
    }
}
Also used : ProjectStageProducer(org.apache.deltaspike.core.util.ProjectStageProducer) ProjectStage(org.apache.deltaspike.core.api.projectstage.ProjectStage) Test(org.junit.Test)

Aggregations

ProjectStage (org.apache.deltaspike.core.api.projectstage.ProjectStage)6 Test (org.junit.Test)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Exclude (org.apache.deltaspike.core.api.exclude.Exclude)1 Deactivatable (org.apache.deltaspike.core.spi.activation.Deactivatable)1 ProjectStageProducer (org.apache.deltaspike.core.util.ProjectStageProducer)1