You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/04/27 12:42:58 UTC
svn commit: r1097075 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/config/ test/java/org/apache/myfaces/config/
Author: lofwyr
Date: Wed Apr 27 10:42:57 2011
New Revision: 1097075
URL: http://svn.apache.org/viewvc?rev=1097075&view=rev
Log:
MYFACES-3107: FacesConfigurator doesn't recognize Tobago
- change log statement to have the same (and more clear) look for "found" and "not found" artifacts.
- simplify the regexp, which wasn't detecting "alpha" in the version number
- fix log.isWarnInfoEnabled inside of log.isInfoEnabled
- remove inner class Version, because no functionallity is used
- test was rewritten
- separate this logging functionallity into a separate class
Added:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/LogMetaInfUtilsTestCase.java
- copied, changed from r1091758, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/FacesConfiguratorTestCase.java
Removed:
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/FacesConfiguratorTestCase.java
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java?rev=1097075&r1=1097074&r2=1097075&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java Wed Apr 27 10:42:57 2011
@@ -107,6 +107,8 @@ public class DefaultFacesConfigurationMe
// apply the ordering and sorting algorithm
orderAndFeedArtifacts(dispenser, appConfigResources, webAppFacesConfig);
+ LogMetaInfUtils.logMetaInf();
+
return dispenser;
}
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?rev=1097075&r1=1097074&r2=1097075&view=diff
==============================================================================
--- 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 Wed Apr 27 10:42:57 2011
@@ -98,16 +98,12 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Configures everything for a given context. The FacesConfigurator is independent of the concrete implementations that
@@ -144,59 +140,6 @@ public class FacesConfigurator
private static long lastUpdate;
- 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_TOMAHAWK12_PACKAGE_NAME = "tomahawk12";
- public static final String MYFACES_ORCHESTRA_PACKAGE_NAME = "myfaces-orchestra-core";
- public static final String MYFACES_ORCHESTRA12_PACKAGE_NAME = "myfaces-orchestra-core12";
- public static final String MYFACES_TRINIDAD_API_PACKAGE_NAME = "trinidad-api";
- public static final String MYFACES_TRINIDAD_IMPL_PACKAGE_NAME = "trinidad-impl";
- public static final String MYFACES_TOBAGO_PACKAGE_NAME = "tobago";
- public static final String MYFACES_TOMAHAWK_SANDBOX_PACKAGE_NAME = "tomahawk-sandbox";
- public static final String MYFACES_TOMAHAWK_SANDBOX12_PACKAGE_NAME = "tomahawk-sandbox12";
- public static final String MYFACES_TOMAHAWK_SANDBOX15_PACKAGE_NAME = "tomahawk-sandbox15";
- public static final String COMMONS_EL_PACKAGE_NAME = "commons-el";
- public static final String JSP_API_PACKAGE_NAME = "jsp-api";
-
- private static final String[] ARTIFACTS_IDS =
- {
- MYFACES_API_PACKAGE_NAME, MYFACES_IMPL_PACKAGE_NAME,
- MYFACES_TOMAHAWK_PACKAGE_NAME, MYFACES_TOMAHAWK12_PACKAGE_NAME,
- MYFACES_TOMAHAWK_SANDBOX_PACKAGE_NAME, MYFACES_TOMAHAWK_SANDBOX12_PACKAGE_NAME,
- MYFACES_TOMAHAWK_SANDBOX15_PACKAGE_NAME,
- MYFACES_ORCHESTRA_PACKAGE_NAME, MYFACES_ORCHESTRA12_PACKAGE_NAME,
- MYFACES_TRINIDAD_API_PACKAGE_NAME, MYFACES_TRINIDAD_IMPL_PACKAGE_NAME,
- MYFACES_TOBAGO_PACKAGE_NAME,
- COMMONS_EL_PACKAGE_NAME, JSP_API_PACKAGE_NAME
- };
-
- /**
- * Regular expression used to extract the jar information from the
- * files present in the classpath.
- * <p>The groups found with the regular expression are:</p>
- * <ul>
- * <li>Group 6: file path (required)</li>
- * <li>Group 7: artifact id (required)</li>
- * <li>Group 8: major version (required)</li>
- * <li>Group 10: minor version (optional)</li>
- * <li>Group 12: maintenance version (optional)</li>
- * <li>Group 14: extra version (optional)</li>
- * <li>Group 15: SNAPSHOT marker (optional)</li>
- * </ul>
- */
- public static final String REGEX_LIBRARY = "((jar)?(besjar)?(wsjar)?(zip)?)?:(file:.*/(.+)-" +
- "(\\d+)(\\.(\\d+)(\\.(\\d+)(\\.(\\d+))?)?)?(-SNAPSHOT)?" +
- "\\.jar)!/META-INF/MANIFEST.MF";
- private static final Pattern REGEX_LIBRARY_PATTERN = Pattern.compile(REGEX_LIBRARY);
- private static final int REGEX_LIBRARY_FILE_PATH = 6;
- private static final int REGEX_LIBRARY_ARTIFACT_ID = 7;
- private static final int REGEX_LIBRARY_MAJOR_VERSION = 8;
- private static final int REGEX_LIBRARY_MINOR_VERSION = 10;
- private static final int REGEX_LIBRARY_MAINTENANCE_VERSION = 12;
- private static final int REGEX_LIBRARY_EXTRA_VERSION = 14;
- private static final int REGEX_LIBRARY_SNAPSHOT_MARKER = 15;
-
public FacesConfigurator(ExternalContext externalContext)
{
if (externalContext == null)
@@ -470,99 +413,6 @@ public class FacesConfigurator
lastUpdate = System.currentTimeMillis();
}
- /**
- * This method performs part of the factory search outlined in section 10.2.6.1.
- */
- @SuppressWarnings("unchecked")
- protected void logMetaInf()
- {
- try
- {
- Map<String, List<JarInfo>> libs = new HashMap<String, List<JarInfo>>(30);
-
- Iterator<URL> it = ClassUtils.getResources("META-INF/MANIFEST.MF", this);
- while (it.hasNext())
- {
- URL url = it.next();
- Matcher matcher = REGEX_LIBRARY_PATTERN.matcher(url.toString());
- if (matcher.matches())
- {
- // We have a valid JAR
- String artifactId = matcher.group(REGEX_LIBRARY_ARTIFACT_ID);
- List<JarInfo> versions = libs.get(artifactId);
- if (versions == null)
- {
- versions = new ArrayList<JarInfo>(2);
- libs.put(artifactId, versions);
- }
-
- String path = matcher.group(REGEX_LIBRARY_FILE_PATH);
-
- Version version = new Version(matcher.group(REGEX_LIBRARY_MAJOR_VERSION),
- matcher.group(REGEX_LIBRARY_MINOR_VERSION),
- matcher.group(REGEX_LIBRARY_MAINTENANCE_VERSION),
- matcher.group(REGEX_LIBRARY_EXTRA_VERSION),
- matcher.group(REGEX_LIBRARY_SNAPSHOT_MARKER));
-
- JarInfo newInfo = new JarInfo(path, version);
- if (!versions.contains(newInfo))
- {
- versions.add(newInfo);
- }
- }
- }
-
- if (log.isLoggable(Level.INFO))
- {
- if (log.isLoggable(Level.WARNING))
- {
- for (String artifactId : ARTIFACTS_IDS)
- {
- List<JarInfo> versions = libs.get(artifactId);
- if (versions != null && versions.size() > 1)
- {
- StringBuilder builder = new StringBuilder(1024);
- builder.append("You are using the library: ");
- builder.append(artifactId);
- builder.append(" in different versions; first (and probably used) version is: ");
- builder.append(versions.get(0).getVersion());
- builder.append(" loaded from: ");
- builder.append(versions.get(0).getUrl());
- builder.append(", but also found the following versions: ");
-
- boolean needComma = false;
- for (int i = 1; i < versions.size(); i++)
- {
- JarInfo info = versions.get(i);
- if (needComma)
- {
- builder.append(", ");
- }
-
- builder.append(info.getVersion());
- builder.append(" loaded from: ");
- builder.append(info.getUrl());
-
- needComma = true;
- }
-
- log.warning(builder.toString());
- }
- }
- }
-
- for (String artifactId : ARTIFACTS_IDS)
- {
- startLib(artifactId, libs);
- }
- }
- }
- catch (Throwable e)
- {
- throw new FacesException(e);
- }
- }
-
private List<String> getConfigFilesList() {
String configFiles = _externalContext.getInitParameter(FacesServlet.CONFIG_FILES_ATTR);
List<String> configFilesList = new ArrayList<String>();
@@ -629,21 +479,6 @@ public class FacesConfigurator
}
}
- private void startLib(String artifactId, Map<String, List<JarInfo>> libs)
- {
- List<JarInfo> versions = libs.get(artifactId);
- if (versions == null)
- {
- log.info("MyFaces-package : " + artifactId + " not found.");
- }
- else
- {
- JarInfo info = versions.get(0);
- log.info("Starting up MyFaces-package : " + artifactId + " in version : "
- + info.getVersion() + " from path : " + info.getUrl());
- }
- }
-
private void configureApplication()
{
Application application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
@@ -828,7 +663,7 @@ public class FacesConfigurator
}
log.warning("The SystemEvent source type for "+systemEventClass.getName() + " could not be detected, either register it manually or use a constructor argument for auto detection, defaulting now to java.lang.Object");
return "java.lang.Object";
- };
+ }
protected RuntimeConfig getRuntimeConfig()
@@ -1026,247 +861,6 @@ public class FacesConfigurator
return LifecycleFactory.DEFAULT_LIFECYCLE;
}
- /*
- * public static class VersionInfo { private String artifactId; private List<JarInfo> jarInfos;
- *
- * public VersionInfo(String artifactId) { this.artifactId = artifactId; }
- *
- * public String getArtifactId() { return packageName; }
- *
- * public void addJarInfo(Matcher matcher) { if (jarInfos == null) { jarInfos = new ArrayList<JarInfo>(); }
- *
- * String path = matcher.group(1);
- *
- * Version version = new Version(matcher.group(3), matcher.group(5), matcher.group(7), matcher.group(9),
- * matcher.group(10));
- *
- * jarInfos.add(new JarInfo(path, version)); }
- *
- * public String getLastVersion() { if (jarInfos == null) return null; if (jarInfos.size() == 0) return null;
- *
- * return ""; //return 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 ""; //return
- * 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 jarInfos.get(0).getUrl();
- *
- * } }
- */
- private static class JarInfo implements Comparable<JarInfo>
- {
- private String url;
- private Version version;
-
- public JarInfo(String url, Version version)
- {
- this.url = url;
- this.version = version;
- }
-
- public Version getVersion()
- {
- return version;
- }
-
- public String getUrl()
- {
- return url;
- }
-
- public int compareTo(JarInfo info)
- {
- return version.compareTo(info.version);
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (o == this)
- {
- return true;
- }
- else if (o instanceof JarInfo)
- {
- JarInfo other = (JarInfo) o;
- return version.equals(other.version);
- }
- else
- {
- return false;
- }
- }
-
- @Override
- public int hashCode()
- {
- return version.hashCode();
- }
- }
-
- static class Version implements Comparable<Version>
- {
- // we have to use Long here, because the version number
- // could be something like 20060714150240 and this value
- // exceeds an Integer (see MYFACES-2686)
- private Long[] parts;
-
- private boolean snapshot;
-
- public Version(String major, String minor, String maintenance, String extra, String snapshot)
- {
- parts = new Long[4];
- parts[0] = Long.valueOf(major);
-
- if (minor != null)
- {
- parts[1] = Long.valueOf(minor);
-
- if (maintenance != null)
- {
- parts[2] = Long.valueOf(maintenance);
-
- if (extra != null)
- {
- parts[3] = Long.valueOf(extra);
- }
- }
- }
-
- this.snapshot = snapshot != null;
- }
-
- public int compareTo(Version v)
- {
- for (int i = 0; i < parts.length; i++)
- {
- Long left = parts[i];
- Long right = v.parts[i];
- if (left == null)
- {
- if (right == null)
- {
- break;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- if (right == null)
- {
- return 1;
- }
- else if (left < right)
- {
- return -1;
- }
- else if (left > right)
- {
- return 1;
- }
- }
- }
-
- if (snapshot)
- {
- return v.snapshot ? 0 : -1;
- }
- else
- {
- return v.snapshot ? 1 : 0;
- }
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (o == this)
- {
- return true;
- }
- else if (o instanceof Version)
- {
- Version other = (Version) o;
- if (snapshot != other.snapshot)
- {
- return false;
- }
-
- for (int i = 0; i < parts.length; i++)
- {
- Long thisPart = parts[i];
- Long otherPart = other.parts[i];
- if (thisPart == null ? otherPart != null : !thisPart.equals(otherPart))
- {
- return false;
- }
- }
-
- return true;
- }
- else
- {
- return false;
- }
- }
-
- @Override
- public int hashCode()
- {
- int hash = 0;
- for (Long part : parts)
- {
- if (part != null)
- {
- hash ^= part.hashCode();
- }
- }
-
- hash ^= Boolean.valueOf(snapshot).hashCode();
-
- return hash;
- }
-
- @Override
- public String toString()
- {
- StringBuilder builder = new StringBuilder();
- builder.append(parts[0]);
- for (int i = 1; i < parts.length; i++)
- {
- Long val = parts[i];
- if (val != null)
- {
- builder.append('.').append(val);
- }
- }
-
- if (snapshot)
- {
- builder.append("-SNAPSHOT");
- }
-
- return builder.toString();
- }
- }
-
private void handleSerialFactory()
{
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java?rev=1097075&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java Wed Apr 27 10:42:57 2011
@@ -0,0 +1,229 @@
+/*
+ * 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.config;
+
+import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+import javax.faces.FacesException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+class LogMetaInfUtils {
+
+ private static final Logger log = Logger.getLogger(LogMetaInfUtils.class.getName());
+
+ /**
+ * Regular expression used to extract the jar information from the
+ * files present in the classpath.
+ * <p>The groups found with the regular expression are:</p>
+ * <ul>
+ * <li>Group 2: file path</li>
+ * <li>Group 3: artifact id</li>
+ * <li>Group 4: version</li>
+ * </ul>
+ * The regexp is searching in the file name to the first - followed by a digit to split artifact name and version.
+ */
+ public static final String REGEX_LIBRARY
+ = "(jar|besjar|wsjar|zip)"
+ + ":(file:.*/((myfaces|tomahawk|trinidad|tobago|commons\\-el|jsp\\-api)[\\w\\-\\_]+?)"
+ + "-(\\d+.*)\\.jar)!/META-INF/MANIFEST.MF";
+ private static final Pattern REGEX_LIBRARY_PATTERN = Pattern.compile(REGEX_LIBRARY);
+
+ private static final int REGEX_LIBRARY_FILE_PATH = 2;
+ private static final int REGEX_LIBRARY_ARTIFACT_ID = 3;
+ private static final int REGEX_LIBRARY_VERSION = 5;
+
+ /**
+ * This method performs part of the factory search outlined in section 10.2.6.1.
+ */
+ @SuppressWarnings("unchecked")
+ protected static void logMetaInf()
+ {
+ if (!log.isLoggable(Level.WARNING)) {
+ return;
+ }
+
+ try
+ {
+ Map<String, List<JarInfo>> libs = new HashMap<String, List<JarInfo>>(30);
+
+ Iterator<URL> it = ClassUtils.getResources("META-INF/MANIFEST.MF", LogMetaInfUtils.class);
+ while (it.hasNext())
+ {
+ URL url = it.next();
+ addJarInfo(libs, url);
+ }
+
+ final List<String> keys = new ArrayList(libs.keySet());
+ Collections.sort(keys);
+
+ if (log.isLoggable(Level.WARNING))
+ {
+ for (String artifactId : keys)
+ {
+ List<JarInfo> versions = libs.get(artifactId);
+ if (versions != null && versions.size() > 1)
+ {
+ StringBuilder builder = new StringBuilder(1024);
+ builder.append("You are using the library: ");
+ builder.append(artifactId);
+ builder.append(" in different versions; first (and probably used) version is: ");
+ builder.append(versions.get(0).getVersion());
+ builder.append(" loaded from: ");
+ builder.append(versions.get(0).getUrl());
+ builder.append(", but also found the following versions: ");
+
+ boolean needComma = false;
+ for (int i = 1; i < versions.size(); i++)
+ {
+ JarInfo info = versions.get(i);
+ if (needComma)
+ {
+ builder.append(", ");
+ }
+
+ builder.append(info.getVersion());
+ builder.append(" loaded from: ");
+ builder.append(info.getUrl());
+
+ needComma = true;
+ }
+
+ log.warning(builder.toString());
+ }
+ }
+ }
+
+ if (log.isLoggable(Level.INFO))
+ {
+ for (String artifactId : keys)
+ {
+ logArtifact(artifactId, libs);
+ }
+ }
+ }
+ catch (Throwable e)
+ {
+ throw new FacesException(e);
+ }
+ }
+
+ protected static void addJarInfo(Map<String, List<JarInfo>> libs, URL url) {
+ Matcher matcher = REGEX_LIBRARY_PATTERN.matcher(url.toString());
+ if (matcher.matches())
+ {
+ // We have a valid JAR
+ String artifactId = matcher.group(REGEX_LIBRARY_ARTIFACT_ID);
+ List<JarInfo> versions = libs.get(artifactId);
+ if (versions == null)
+ {
+ versions = new ArrayList<JarInfo>(1);
+ libs.put(artifactId, versions);
+ }
+
+ String path = matcher.group(REGEX_LIBRARY_FILE_PATH);
+
+ String version = matcher.group(REGEX_LIBRARY_VERSION);
+
+ JarInfo newInfo = new JarInfo(path, version);
+ if (!versions.contains(newInfo))
+ {
+ versions.add(newInfo);
+ }
+ }
+ }
+
+ private static void logArtifact(String artifactId, Map<String, List<JarInfo>> libs)
+ {
+ List<JarInfo> versions = libs.get(artifactId);
+ if (versions == null)
+ {
+ log.info("Artifact '" + artifactId + "' was not found.");
+ }
+ else
+ {
+ JarInfo info = versions.get(0);
+ log.info("Artifact '" + artifactId + "' was found in version '"
+ + info.getVersion() + "' from path '" + info.getUrl() + "'");
+ }
+ }
+
+
+ protected static class JarInfo implements Comparable<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 String getUrl()
+ {
+ return url;
+ }
+
+ public int compareTo(JarInfo info)
+ {
+ return version.compareTo(info.version);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (o == this)
+ {
+ return true;
+ }
+ else if (o instanceof JarInfo)
+ {
+ JarInfo other = (JarInfo) o;
+ return version.equals(other.version);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return version.hashCode();
+ }
+ }
+
+}
Copied: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/LogMetaInfUtilsTestCase.java (from r1091758, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/FacesConfiguratorTestCase.java)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/LogMetaInfUtilsTestCase.java?p2=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/LogMetaInfUtilsTestCase.java&p1=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/FacesConfiguratorTestCase.java&r1=1091758&r2=1097075&rev=1097075&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/FacesConfiguratorTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/config/LogMetaInfUtilsTestCase.java Wed Apr 27 10:42:57 2011
@@ -16,76 +16,66 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.myfaces.config;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+package org.apache.myfaces.config;
-import org.apache.myfaces.config.FacesConfigurator.Version;
import org.apache.myfaces.test.base.AbstractJsfTestCase;
-public class FacesConfiguratorTestCase extends AbstractJsfTestCase
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class LogMetaInfUtilsTestCase extends AbstractJsfTestCase
{
- public FacesConfiguratorTestCase(String name)
+ public LogMetaInfUtilsTestCase(String name)
{
super(name);
}
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public static final String REGEX_LIBRARY = "((jar)?(besjar)?(wsjar)?(zip)?)?:(file:.*/(.+)-" +
- "(\\d+)(\\.(\\d+)(\\.(\\d+)(\\.(\\d+))?)?)?(-SNAPSHOT)?" +
- "\\.jar)!/META-INF/MANIFEST.MF";
-
-
public void testVersionNumber() throws Exception
{
- Pattern pattern = Pattern.compile(REGEX_LIBRARY);
- List<Version> l = new ArrayList<Version>();
- l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-collections-3.jar!/META-INF/MANIFEST.MF"));
- l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-codec-1.3.jar!/META-INF/MANIFEST.MF"));
- l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-beanutils-1.7.0.jar!/META-INF/MANIFEST.MF"));
- l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-beanutils-1.7.0.6.jar!/META-INF/MANIFEST.MF"));
- l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/commons-beanutils-1.7.0-SNAPSHOT.jar!/META-INF/MANIFEST.MF"));
- l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/tomahawk12-1.1.10-SNAPSHOT.jar!/META-INF/MANIFEST.MF"));
- l.add(testJar(pattern, "jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/ProjetBidonJSF/WEB-INF/lib/tomahawk-sandbox12-1.1.10.jar!/META-INF/MANIFEST.MF"));
-
- assertEquals(new Version("3", null, null, null, null), l.get(0) );
- assertEquals(new Version("1", "3", null, null, null), l.get(1) );
- assertEquals(new Version("1", "7", "0", null, null), l.get(2) );
- assertEquals(new Version("1", "7", "0", "6", null), l.get(3) );
- assertEquals(new Version("1", "7", "0", null, "SNAPSHOT"), l.get(4) );
- assertEquals(new Version("1", "1", "10", null, "SNAPSHOT"), l.get(5) );
- assertEquals(new Version("1", "1", "10", null, null), l.get(6) );
- Collections.sort(l);
+ // tests single digits
+ // tests more digits
+ // tests alpha
+ // tests SNAPSHOT
+ // tests digits in artifact names
+
+ Map<String, List<LogMetaInfUtils.JarInfo>> libs = new HashMap<String, List<LogMetaInfUtils.JarInfo>>(30);
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/C:/.../WEB-INF/lib/myfaces-api-1.2.11-SNAPSHOT.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/C:/.../WEB-INF/lib/myfaces-api-2.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/C:/.../WEB-INF/lib/tomahawk12-1.1.10-SNAPSHOT.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/G:/.../WEB-INF/lib/tomahawk-facelets-taglib-1.0.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/C:/.../WEB-INF/lib/tomahawk-sandbox12-1.1.10.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/home/.../tobago-core/1.5.0-alpha-3-SNAPSHOT/tobago-core-1.5.0-alpha-3-SNAPSHOT.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/home/.../tobago-core/1.0.35/tobago-core-1.0.35.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("jar:file:/home/.../other/1.0/other-1.0.jar!/META-INF/MANIFEST.MF"));
+ LogMetaInfUtils.addJarInfo(libs, new URL("file:/opt/project/tobago/tobago-example/tobago-example-demo/target/tobago-example-demo/WEB-INF/lib/slf4j-log4j12-1.6.1.jar"));
+
+ final List<LogMetaInfUtils.JarInfo> mf = libs.get("myfaces-api");
+ assertEquals(2, mf.size());
+ assertEquals("1.2.11-SNAPSHOT", mf.get(0).getVersion());
+ assertEquals("2", mf.get(1).getVersion());
+
+ final List<LogMetaInfUtils.JarInfo> tk12 = libs.get("tomahawk12");
+ assertEquals(1, tk12.size());
+ assertEquals("1.1.10-SNAPSHOT", tk12.get(0).getVersion());
+
+ final List<LogMetaInfUtils.JarInfo> tksb = libs.get("tomahawk-sandbox12");
+ assertEquals(1, tksb.size());
+ assertEquals("1.1.10", tksb.get(0).getVersion());
+
+ final List<LogMetaInfUtils.JarInfo> tobago = libs.get("tobago-core");
+ assertEquals(2, tobago.size());
+ assertEquals("1.5.0-alpha-3-SNAPSHOT", tobago.get(0).getVersion());
+ assertEquals("1.0.35", tobago.get(1).getVersion());
+
+ final List<LogMetaInfUtils.JarInfo> other = libs.get("other");
+ assertNull(other);
+
+ final List<LogMetaInfUtils.JarInfo> slf = libs.get("slf4j-log4j12");
+ assertNull(slf);
}
-
- private static Version testJar(Pattern pattern, String libName)
- {
- Matcher matcher = pattern.matcher(libName);
-
- if (matcher.matches())
- {
- Version version = new Version(matcher.group(8), matcher.group(10), matcher.group(12), matcher.group(14),
- matcher.group(15));
- return version;
- }
-
- return null;
- }
}