You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/09/25 23:03:31 UTC

svn commit: r449814 - in /myfaces: core/trunk/impl/src/main/java/org/apache/myfaces/config/ shared/trunk/core/src/main/java/org/apache/myfaces/shared/config/ tomahawk/trunk/examples/blank/src/main/webapp/WEB-INF/ tomahawk/trunk/examples/simple/src/main...

Author: mmarinschek
Date: Mon Sep 25 14:03:30 2006
New Revision: 449814

URL: http://svn.apache.org/viewvc?view=rev&rev=449814
Log:
fix for MYFACES-1423 : Log jar-files on startup

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
    myfaces/tomahawk/trunk/examples/blank/src/main/webapp/WEB-INF/web.xml
    myfaces/tomahawk/trunk/examples/simple/src/main/webapp/WEB-INF/web.xml
    myfaces/tomahawk/trunk/examples/tiles/src/main/webapp/WEB-INF/web.xml

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?view=diff&rev=449814&r1=449813&r2=449814
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java Mon Sep 25 14:03:30 2006
@@ -15,20 +15,12 @@
  */
 package org.apache.myfaces.config;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.*;
 
 import javax.faces.FacesException;
 import javax.faces.FactoryFinder;
@@ -103,7 +95,16 @@
     private ExternalContext _externalContext;
     private FacesConfigUnmarshaller _unmarshaller;
     private FacesConfigDispenser _dispenser;
-
+    private static final String JAR_EXTENSION = ".jar";
+    private static final String META_INF_MANIFEST_SUFFIX = "!/META-INF/MANIFEST.MF";
+    private static final String JAR_PREFIX = "jar:";
+
+    public static final String MYFACES_API_PACKAGE_NAME = "myfaces-api";
+    public static final String MYFACES_IMPL_PACKAGE_NAME = "myfaces-impl";
+    public static final String MYFACES_TOMAHAWK_PACKAGE_NAME = "tomahawk";
+    public static final String MYFACES_TOMAHAWK_SANDBOX_PACKAGE_NAME = "tomahawk-sandbox";
+    public static final String COMMONS_EL_PACKAGE_NAME = "commons-el";
+    public static final String JSP_API_PACKAGE_NAME = "jsp-api";
 
     public FacesConfigurator(ExternalContext externalContext)
     {
@@ -129,6 +130,11 @@
             feedClassloaderConfigurations();
             feedContextSpecifiedConfig();
             feedWebAppConfig();
+
+            if(log.isInfoEnabled())
+            {
+                logMetaInf();
+            }
         } catch (IOException e)
         {
             throw new FacesException(e);
@@ -153,6 +159,98 @@
         stream.close();
     }
 
+    /**
+     * This method performs part of the factory search outlined in section 10.2.6.1.
+     */
+    protected void logMetaInf()
+    {
+        try
+        {
+            List li = new ArrayList();
+            li.add(new VersionInfo(MYFACES_API_PACKAGE_NAME));
+            li.add(new VersionInfo(MYFACES_IMPL_PACKAGE_NAME));
+            li.add(new VersionInfo(MYFACES_TOMAHAWK_PACKAGE_NAME));
+            li.add(new VersionInfo(MYFACES_TOMAHAWK_SANDBOX_PACKAGE_NAME));
+
+            Iterator it = ClassUtils.getResources("META-INF/MANIFEST.MF",
+                                                  this);
+            while (it.hasNext())
+            {
+                URL url = (URL)it.next();
+
+                for (int i = 0; i < li.size(); i++)
+                {
+                    VersionInfo versionInfo = (VersionInfo) li.get(i);
+                    checkJar(versionInfo, url);
+                }
+            }
+
+            for (int i = 0; i < li.size(); i++)
+            {
+                VersionInfo versionInfo = (VersionInfo) li.get(i);
+
+                if(versionInfo.getUsedVersion()!=null)
+                {
+                    if(log.isInfoEnabled())
+                    {
+                        log.info("Starting up MyFaces-package : "+versionInfo.getPackageName()+" in version : "
+                                +versionInfo.getUsedVersion()+" from path : "+versionInfo.getUsedVersionPath());
+                    }
+                }
+                else
+                {
+                    if(log.isInfoEnabled())
+                    {
+                        log.info("MyFaces-package : "+versionInfo.getPackageName()+" not found.");
+                    }
+                }
+            }
+        }
+        catch (Throwable e)
+        {
+            throw new FacesException(e);
+        }
+    }
+
+    private static void checkJar(VersionInfo versionInfo, URL path)
+    {
+        int index;
+
+        String version = versionInfo.getLastVersion();
+
+        String pathString = path.toString();
+
+        pathString = pathString.substring(JAR_PREFIX.length(),pathString.length()-META_INF_MANIFEST_SUFFIX.length());
+
+        File file = new File(pathString);
+
+        String fileName = file.getName();
+
+        if(fileName.endsWith(JAR_EXTENSION) && (index=fileName.indexOf(versionInfo.getPackageName()))!=-1)
+        {
+            String newVersion = fileName.substring(
+                    Math.min(index+versionInfo.getPackageName().length()+1,fileName.length()-1),
+                    Math.max(fileName.length()-JAR_EXTENSION.length(),0));
+
+            if(version == null)
+            {
+                versionInfo.addJarInfo(pathString,newVersion);
+                return;
+            }
+            else if(version.equals(newVersion))
+            {
+                versionInfo.addJarInfo(pathString, version);
+            }
+
+
+            log.error("You are using the MyFaces-package : "+versionInfo.getPackageName() +
+                    " in different versions; first (and probably used) version is : "+versionInfo.getUsedVersion() +", currently encountered version is : "+newVersion+
+                    ". This will cause undesired behaviour. Please clean out your class-path." +
+                    " The first encountered version is loaded from : "+versionInfo.getUsedVersionPath()+". The currently encountered version is loaded from : "+
+                    path);
+        }
+    }
+
 
     /**
      * This method performs part of the factory search outlined in section 10.2.6.1.
@@ -668,5 +766,110 @@
         }
 
         return LifecycleFactory.DEFAULT_LIFECYCLE;
+    }
+
+    public static class VersionInfo
+    {
+        private String packageName;
+        private List jarInfos;
+
+        public VersionInfo(String packageName)
+        {
+
+            this.packageName = packageName;
+        }
+
+        public String getPackageName()
+        {
+            return packageName;
+        }
+
+        public void setPackageName(String packageName)
+        {
+            this.packageName = packageName;
+        }
+
+        public void addJarInfo(String path, String version)
+        {
+            if(jarInfos == null)
+            {
+                jarInfos = new ArrayList();
+            }
+
+            jarInfos.add(new JarInfo(path, version));
+        }
+
+        public String getLastVersion()
+        {
+            if(jarInfos == null)
+                return null;
+            if(jarInfos.size()==0)
+                return null;
+
+            return ((JarInfo) jarInfos.get(jarInfos.size()-1)).getVersion();
+        }
+
+        /**Probably, the first encountered version will be used.
+         *
+         * @return probably used version
+         */
+        public String getUsedVersion()
+        {
+
+            if(jarInfos == null)
+                return null;
+            if(jarInfos.size()==0)
+                return null;
+
+            return ((JarInfo) jarInfos.get(0)).getVersion();
+        }
+
+        /**Probably, the first encountered version will be used.
+         *
+         * @return probably used classpath
+         */
+        public String getUsedVersionPath()
+        {
+
+            if(jarInfos == null)
+                return null;
+            if(jarInfos.size()==0)
+                return null;
+
+            return ((JarInfo) jarInfos.get(0)).getUrl();
+
+        }
+    }
+
+    public static class JarInfo
+    {
+        private String url;
+        private String version;
+
+        public JarInfo(String url, String version)
+        {
+            this.url = url;
+            this.version = version;
+        }
+
+        public String getVersion()
+        {
+            return version;
+        }
+
+        public void setVersion(String version)
+        {
+            this.version = version;
+        }
+
+        public String getUrl()
+        {
+            return url;
+        }
+
+        public void setUrl(String url)
+        {
+            this.url = url;
+        }
     }
 }

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java?view=diff&rev=449814&r1=449813&r2=449814
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java Mon Sep 25 14:03:30 2006
@@ -80,14 +80,15 @@
     private boolean _readonlyAsDisabledForSelect;
 
     private static final boolean TOMAHAWK_AVAILABLE;
+    private static final boolean MYFACES_IMPL_AVAILABLE;
+    private static final boolean RI_IMPL_AVAILABLE;
     
     static
     {
     	boolean tomahawkAvailable;
     	try
 		{
-			ClassUtils
-					.classForName("org.apache.myfaces.webapp.filter.ExtensionsFilter");
+			ClassUtils.classForName("org.apache.myfaces.webapp.filter.ExtensionsFilter");
 			tomahawkAvailable = true;
 		}
 		catch (ClassNotFoundException e)
@@ -96,6 +97,36 @@
 		}
 		TOMAHAWK_AVAILABLE = tomahawkAvailable;
     }
+
+    static
+    {
+    	boolean myfacesImplAvailable;
+    	try
+		{
+			ClassUtils.classForName("org.apache.myfaces.application.ApplicationImpl");
+			myfacesImplAvailable = true;
+		}
+		catch (ClassNotFoundException e)
+		{
+			myfacesImplAvailable = false;
+		}
+		MYFACES_IMPL_AVAILABLE = myfacesImplAvailable;
+    }
+
+    static
+    {
+    	boolean riImplAvailable;
+    	try
+		{
+			ClassUtils.classForName("com.sun.faces.application.ApplicationImpl");
+			riImplAvailable = true;
+		}
+		catch (ClassNotFoundException e)
+		{
+			riImplAvailable = false;
+		}
+		RI_IMPL_AVAILABLE = riImplAvailable;
+    }
     
     public static MyfacesConfig getCurrentInstance(ExternalContext extCtx)
     {
@@ -135,6 +166,27 @@
             	log.info("Tomahawk jar not available. Autoscrolling, DetectJavascript, AddResourceClass and CheckExtensionsFilter are disabled now.");
             }
         }
+
+        if(RI_IMPL_AVAILABLE)
+        {
+            if(log.isInfoEnabled())
+            {
+                log.info("Starting up Tomahawk on the RI-JSF-Implementation.");
+            }
+        }
+
+        if(MYFACES_IMPL_AVAILABLE)
+        {
+            if(log.isInfoEnabled())
+            {
+                log.info("Starting up Tomahawk on the MyFaces-JSF-Implementation");
+            }
+        }
+
+        if(RI_IMPL_AVAILABLE && MYFACES_IMPL_AVAILABLE)
+        {
+            log.error("Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.");
+        }
                 
         return myfacesConfig;
     }
@@ -218,6 +270,21 @@
     public boolean isReadonlyAsDisabledForSelect()
     {
         return _readonlyAsDisabledForSelect;
+    }
+
+    public boolean isTomahawkAvailable()
+    {
+        return TOMAHAWK_AVAILABLE;
+    }
+
+    public boolean isMyfacesImplAvailable()
+    {
+        return MYFACES_IMPL_AVAILABLE;
+    }
+
+    public boolean isRiImplAvailable()
+    {
+        return RI_IMPL_AVAILABLE;
     }
 
     /**

Modified: myfaces/tomahawk/trunk/examples/blank/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/blank/src/main/webapp/WEB-INF/web.xml?view=diff&rev=449814&r1=449813&r2=449814
==============================================================================
--- myfaces/tomahawk/trunk/examples/blank/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tomahawk/trunk/examples/blank/src/main/webapp/WEB-INF/web.xml Mon Sep 25 14:03:30 2006
@@ -157,7 +157,7 @@
   </servlet>
   <servlet>
     <servlet-name>SourceCodeServlet</servlet-name>
-    <servlet-class>org.apache.myfaces.shared.util.servlet.SourceCodeServlet</servlet-class>
+    <servlet-class>org.apache.myfaces.shared_tomahawk.util.servlet.SourceCodeServlet</servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/WEB-INF/web.xml?view=diff&rev=449814&r1=449813&r2=449814
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/webapp/WEB-INF/web.xml Mon Sep 25 14:03:30 2006
@@ -119,7 +119,7 @@
     <param-name>org.apache.myfaces.RESOURCE_VIRTUAL_PATH</param-name>
     <param-value>/faces/extensionResource</param-value>
   </context-param>
-  
+
   <filter>
     <filter-name>extensionsFilter</filter-name>
     <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
@@ -160,7 +160,7 @@
   </servlet>
   <servlet>
     <servlet-name>SourceCodeServlet</servlet-name>
-    <servlet-class>org.apache.myfaces.shared.util.servlet.SourceCodeServlet</servlet-class>
+    <servlet-class>org.apache.myfaces.shared_tomahawk.util.servlet.SourceCodeServlet</servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>

Modified: myfaces/tomahawk/trunk/examples/tiles/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/tiles/src/main/webapp/WEB-INF/web.xml?view=diff&rev=449814&r1=449813&r2=449814
==============================================================================
--- myfaces/tomahawk/trunk/examples/tiles/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tomahawk/trunk/examples/tiles/src/main/webapp/WEB-INF/web.xml Mon Sep 25 14:03:30 2006
@@ -167,7 +167,7 @@
   </servlet>
   <servlet>
     <servlet-name>SourceCodeServlet</servlet-name>
-    <servlet-class>org.apache.myfaces.shared.util.servlet.SourceCodeServlet</servlet-class>
+    <servlet-class>org.apache.myfaces.shared_tomahawk.util.servlet.SourceCodeServlet</servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>