You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/02/10 17:44:59 UTC

svn commit: r908579 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: application/ApplicationImpl.java webapp/AbstractFacesInitializer.java

Author: jakobk
Date: Wed Feb 10 16:44:58 2010
New Revision: 908579

URL: http://svn.apache.org/viewvc?rev=908579&view=rev
Log:
MYFACES-2545 ProjectStage can be set via System Property and ProjectStage!=Production should create a log entry

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java?rev=908579&r1=908578&r2=908579&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java Wed Feb 10 16:44:58 2010
@@ -122,7 +122,11 @@
     // recives the runtime config instance during initializing
     private final static ThreadLocal<RuntimeConfig> initializingRuntimeConfig = new ThreadLocal<RuntimeConfig>();
 
+    // the name for the system property which specifies the current ProjectStage (see MYFACES-2545 for details)
+    public final static String PROJECT_STAGE_SYSTEM_PROPERTY_NAME = "faces.PROJECT_STAGE";
+    
     // MyFaces specific System Property to set the ProjectStage, if not present via the standard way
+    @Deprecated
     public final static String MYFACES_PROJECT_STAGE_SYSTEM_PROPERTY_NAME = "org.apache.myfaces.PROJECT_STAGE";
     
     @JSFWebConfigParam(defaultValue="false", expectedValues="true, false", since="2.0")
@@ -647,30 +651,51 @@
         if (_projectStage == null)
         {
             String stageName = null;
-            // Look for a JNDI environment entry under the key given by the
-            // value of
-            // ProjectStage.PROJECT_STAGE_JNDI_NAME (return type of
-            // java.lang.String).
-            try
+            
+            // try to obtain the ProjectStage from the system property
+            // faces.PROJECT_STAGE as proposed by Ed Burns
+            stageName = System.getProperty(PROJECT_STAGE_SYSTEM_PROPERTY_NAME);
+            
+            if (stageName == null)
             {
-                Context ctx = new InitialContext();
-                Object temp = ctx.lookup(ProjectStage.PROJECT_STAGE_JNDI_NAME);
-                if (temp != null)
+                // if not found check for the "old" System Property
+                // and print a warning message to the log (just to be 
+                // sure that everyone recognizes the change in the name).
+                stageName = System.getProperty(MYFACES_PROJECT_STAGE_SYSTEM_PROPERTY_NAME);
+                if (stageName != null)
                 {
-                    if (temp instanceof String)
-                    {
-                        stageName = (String) temp;
-                    }
-                    else
-                    {
-                        log.severe("JNDI lookup for key " + ProjectStage.PROJECT_STAGE_JNDI_NAME
-                                + " should return a java.lang.String value");
-                    }
+                    log.log(Level.WARNING, "The system property " + MYFACES_PROJECT_STAGE_SYSTEM_PROPERTY_NAME
+                            + " has been replaced by " + PROJECT_STAGE_SYSTEM_PROPERTY_NAME + "!"
+                            + " Please change your settings.");
                 }
             }
-            catch (NamingException e)
+            
+            if (stageName == null)
             {
-                // no-op
+                // Look for a JNDI environment entry under the key given by the
+                // value of ProjectStage.PROJECT_STAGE_JNDI_NAME (return type of
+                // java.lang.String).
+                try
+                {
+                    Context ctx = new InitialContext();
+                    Object temp = ctx.lookup(ProjectStage.PROJECT_STAGE_JNDI_NAME);
+                    if (temp != null)
+                    {
+                        if (temp instanceof String)
+                        {
+                            stageName = (String) temp;
+                        }
+                        else
+                        {
+                            log.severe("JNDI lookup for key " + ProjectStage.PROJECT_STAGE_JNDI_NAME
+                                    + " should return a java.lang.String value");
+                        }
+                    }
+                }
+                catch (NamingException e)
+                {
+                    // no-op
+                }
             }
 
             /*
@@ -683,15 +708,7 @@
                 stageName = context.getExternalContext().getInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME);
             }
 
-            /*
-             * If not found so far, let's try the Apache MyFaces extension (see MYFACES-2235)
-             */
-            if (stageName == null)
-            {
-                stageName = System.getProperty(MYFACES_PROJECT_STAGE_SYSTEM_PROPERTY_NAME);
-            }
-
-            // If a value is found found
+            // If a value is found
             if (stageName != null)
             {
                 /*
@@ -720,7 +737,7 @@
              * If not found, or any of the previous attempts to discover the enum constant value have failed, log a
              * descriptive error message, assign the value as ProjectStage.Production and return it.
              */
-
+            
             _projectStage = ProjectStage.Production;
         }
 

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java?rev=908579&r1=908578&r2=908579&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java Wed Feb 10 16:44:58 2010
@@ -26,6 +26,7 @@
 import javax.faces.FactoryFinder;
 import javax.faces.application.Application;
 import javax.faces.application.ApplicationFactory;
+import javax.faces.application.ProjectStage;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.FacesContextFactory;
@@ -107,6 +108,37 @@
             }
 
             dispatchInitDestroyEvent(servletContext, PostConstructApplicationEvent.class);
+            
+            // print out a very prominent log message if the project stage is != Production
+            if (!FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Production))
+            {
+                ProjectStage projectStage = FacesContext.getCurrentInstance().getApplication().getProjectStage();
+                StringBuilder message = new StringBuilder("\n\n");
+                message.append("*******************************************************************\n");
+                message.append("*** WARNING: JavaServer Faces is running in ");
+                message.append(projectStage.name().toUpperCase());        
+                message.append(" mode.");
+                int length = projectStage.name().length();
+                for (int i = 0; i < 11 - length; i++)
+                {
+                    message.append(" ");
+                }
+                message.append("   ***\n");
+                message.append("***                                         ");
+                for (int i = 0; i < length; i++)
+                {
+                    message.append("^");
+                }
+                for (int i = 0; i < 20 - length; i++)
+                {
+                    message.append(" ");
+                }
+                message.append("***\n");
+                message.append("*** Do NOT deploy to your live server(s) without changing this. ***\n");
+                message.append("*** See Application#getProjectStage() for more information.     ***\n");
+                message.append("*******************************************************************\n");
+                log.log(Level.WARNING, message.toString());
+            }
         } catch (Exception ex) {
             log.log(Level.SEVERE, "An error occured while initializing MyFaces: "
                       + ex.getMessage(), ex);