[slf4j-dev] svn commit: r1174 - in slf4j/trunk: . integration integration/lib integration/src integration/src/main integration/src/main/java integration/src/test integration/src/test/java integration/src/test/java/org integration/src/test/java/org/slf4j slf4j-api/src/main/java/org/slf4j slf4j-api/src/main/java/org/slf4j/impl slf4j-site/src/site/pages

ceki at slf4j.org ceki at slf4j.org
Fri Oct 3 17:44:19 CEST 2008


Author: ceki
Date: Fri Oct  3 17:44:19 2008
New Revision: 1174

Added:
   slf4j/trunk/integration/   (props changed)
   slf4j/trunk/integration/build.xml
   slf4j/trunk/integration/lib/
   slf4j/trunk/integration/lib/junit-3.8.1.jar   (contents, props changed)
   slf4j/trunk/integration/lib/slf4j-simple-1.5.0.jar   (contents, props changed)
   slf4j/trunk/integration/lib/slf4j-simple-1.5.4-SNAPSHOT.jar   (contents, props changed)
   slf4j/trunk/integration/pom.xml
   slf4j/trunk/integration/src/
   slf4j/trunk/integration/src/main/
   slf4j/trunk/integration/src/main/java/
   slf4j/trunk/integration/src/test/
   slf4j/trunk/integration/src/test/java/
   slf4j/trunk/integration/src/test/java/org/
   slf4j/trunk/integration/src/test/java/org/slf4j/
   slf4j/trunk/integration/src/test/java/org/slf4j/VersionTest.java
Modified:
   slf4j/trunk/pom.xml
   slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java
   slf4j/trunk/slf4j-api/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
   slf4j/trunk/slf4j-site/src/site/pages/codes.html

Log:
- testing VERSION checks
- added a new module called "integration" for testing interactions between
  various SLF4J versions. This module uses Ant and relies on Ant's flexibility
  in providing different classpaths to various tasks (this is much harder to do 
  with Maven). The Ant build file is still invoked by Maven. Thus, integration tests
  are run at build time.

Added: slf4j/trunk/integration/build.xml
==============================================================================
--- (empty file)
+++ slf4j/trunk/integration/build.xml	Fri Oct  3 17:44:19 2008
@@ -0,0 +1,44 @@
+<project name="integration" default="testAll" basedir=".">
+
+	<echo message="compile classpath: ${compile_classpath}" />
+	<echo message="runtime classpath: ${runtime_classpath}" />
+	<echo message="test classpath:    ${test_classpath}" />
+	<echo message="plugin classpath:  ${plugin_classpath}" />
+	
+	<path id="path150">
+		<pathelement location="xtarget/classes/" />
+		<pathelement location="target/test-classes/" />
+		<pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" />
+		<pathelement location="./lib/slf4j-simple-1.5.0.jar" />
+	</path >
+
+
+	<!-- this is really very ugly, but it's the only way to circumvent
+  	     http://jira.codehaus.org/browse/MANTRUN-95
+	-->
+	<taskdef name="junit" classpath="${plugin_classpath};${compile_classpath}" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />
+
+
+	<target name="testAll">
+		<echo>Running unit tests via Ant</echo>
+		<echo>basedir=${basedir}</echo>
+		<echo>user.home=${user.home}</echo>
+		<mkdir dir="target/unit-reports" />
+
+		<junit printsummary="yes" fork="no" haltonfailure="yes">
+			<classpath refid="path150" />
+
+			<formatter type="plain" />
+			<batchtest fork="yes" todir="target/unit-reports">
+				<fileset dir="src/test/java">
+					<include name="**/VersionTest.java" />
+					<exclude name="**/XTests.java" />
+				</fileset>
+			</batchtest>
+		</junit>
+
+	</target>
+
+
+
+</project>
\ No newline at end of file

Added: slf4j/trunk/integration/lib/junit-3.8.1.jar
==============================================================================
Binary file. No diff available.

Added: slf4j/trunk/integration/lib/slf4j-simple-1.5.0.jar
==============================================================================
Binary file. No diff available.

Added: slf4j/trunk/integration/lib/slf4j-simple-1.5.4-SNAPSHOT.jar
==============================================================================
Binary file. No diff available.

Added: slf4j/trunk/integration/pom.xml
==============================================================================
--- (empty file)
+++ slf4j/trunk/integration/pom.xml	Fri Oct  3 17:44:19 2008
@@ -0,0 +1,98 @@
+<project 
+ xmlns="http://maven.apache.org/POM/4.0.0" 
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<parent>
+		<groupId>org.slf4j</groupId>
+		<artifactId>slf4j-parent</artifactId>
+    	<version>1.5.4-SNAPSHOT</version>
+	</parent>
+	
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>org.slf4j</groupId>
+	<artifactId>integration</artifactId>
+	<packaging>jar</packaging>
+	<name>SLF4J Integration tests</name>
+
+	<url>http://www.slf4j.org</url>
+  <description>SLF4J integration tests</description>
+
+  <dependencies>
+	  <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+		</dependency>
+
+    <!-- declaration to cimcumvent  http://jira.codehaus.org/browse/MANTRUN-95 -->
+    <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>3.8.1</version>
+    </dependency>
+    <!-- declaration to cimcumvent  http://jira.codehaus.org/browse/MANTRUN-95 -->
+    <dependency>
+      <groupId>ant</groupId>
+      <artifactId>ant-junit</artifactId>
+      <version>1.6.5</version>    
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.2</version>
+        <dependencies>
+          <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+          </dependency>
+          <dependency>
+            <groupId>ant</groupId>
+            <artifactId>ant-junit</artifactId>
+            <version>1.6.5</version>    
+          </dependency>
+        </dependencies>
+        <executions>
+          <execution>
+            <id>ant-test</id>
+            <phase>package</phase>
+            <configuration>
+              <tasks>      
+                <property name="currentVersion" value="${version}" />
+                <property name="compile_classpath" refid="maven.compile.classpath"/>
+                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
+                <property name="test_classpath" refid="maven.test.classpath"/>
+                <property name="plugin_classpath" refid="maven.plugin.classpath"/>
+                <ant antfile="${basedir}/build.xml"/>
+              </tasks>
+            </configuration>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <forkMode>once</forkMode>
+          <reportFormat>plain</reportFormat>
+          <trimStackTrace>false</trimStackTrace>
+          <excludes>
+            <exclude>**/*Test.java</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+    </plugins>
+
+
+  </build>
+
+</project>
\ No newline at end of file

Added: slf4j/trunk/integration/src/test/java/org/slf4j/VersionTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/integration/src/test/java/org/slf4j/VersionTest.java	Fri Oct  3 17:44:19 2008
@@ -0,0 +1,24 @@
+package org.slf4j;
+
+import junit.framework.TestCase;
+
+public class VersionTest extends TestCase {
+
+  public VersionTest(String name) {
+    super(name);
+  }
+
+  protected void setUp() throws Exception {
+    super.setUp();
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  
+  public void test() throws Exception  {
+    Logger logger = LoggerFactory.getLogger(this.getClass());
+    logger.info("hello world");
+  }
+}

Modified: slf4j/trunk/pom.xml
==============================================================================
--- slf4j/trunk/pom.xml	(original)
+++ slf4j/trunk/pom.xml	Fri Oct  3 17:44:19 2008
@@ -23,16 +23,17 @@
 
 	<modules>
 		<module>slf4j-api</module>
-    <module>slf4j-simple</module>
+    <module>slf4j-simple</module>  
     <module>slf4j-nop</module>
 		<module>slf4j-jdk14</module>
     <module>slf4j-log4j12</module>
     <module>slf4j-jcl</module>
-    <module>slf4j-ext</module>
+    <module>slf4j-ext</module>  
     <module>jcl-over-slf4j</module>
     <module>jcl104-over-slf4j</module>
     <module>log4j-over-slf4j</module>
     <module>jul-to-slf4j</module>
+    <module>integration</module>
     <module>slf4j-site</module>
     <module>slf4j-migrator</module>
   </modules>

Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java	(original)
+++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java	Fri Oct  3 17:44:19 2008
@@ -26,10 +26,10 @@
 
 import org.slf4j.helpers.Util;
 import org.slf4j.impl.StaticLoggerBinder;
- 
+
 /**
  * The <code>LoggerFactory</code> is a utility class producing Loggers for
- * various logging APIs, most notably for log4j, logback and JDK 1.4 logging. 
+ * various logging APIs, most notably for log4j, logback and JDK 1.4 logging.
  * Other implementations such as {@link org.slf4j.impl.NOPLogger NOPLogger} and
  * {@link org.slf4j.impl.SimpleLogger SimpleLogger} are also supported.
  * 
@@ -50,34 +50,44 @@
   static final String NO_STATICLOGGERBINDER_URL = "http://www.slf4j.org/codes.html#StaticLoggerBinder";
   static final String NULL_LF_URL = "http://www.slf4j.org/codes.html#null_LF";
   static final String VERSION_MISMATCH = "http://www.slf4j.org/codes.html#version_mismatch";
-  
+
   static private final String EXPECTED_VERSION = "1.5.4-SNAPSHOT";
-   
+
   // private constructor prevents instantiation
   private LoggerFactory() {
   }
 
-
   static {
-    try { 
+    try {
       String actualVer = StaticLoggerBinder.VERSION;
-      if(!EXPECTED_VERSION.equals(actualVer)) {
-        Util.reportFailure("Actual version "+actualVer+" differs from expected version "+EXPECTED_VERSION);
-        Util.reportFailure("See "+VERSION_MISMATCH+" for further details.");
+      if (!EXPECTED_VERSION.equals(actualVer)) {
+        Util.reportFailure("The version " + actualVer
+            + " of your slf4j-binding differs from " + EXPECTED_VERSION
+            + ", the expected version.");
+        Util.reportFailure("See " + VERSION_MISMATCH + " for further details.");
       }
-    } catch(Exception e) {
-     e.printStackTrace();
+    } catch (java.lang.NoSuchFieldError nsfe) {
+      Util
+          .reportFailure("The version of your slf4j-binding is probably older than 1.5.4, and differs from "
+              + EXPECTED_VERSION + ", the expected version.");
+      Util.reportFailure("See " + VERSION_MISMATCH + " for further details.");
+    } catch (Throwable e) {
+      Util
+          .reportFailure("An unexpected problem occured while checking the version of your slf4j-binding");
+      e.printStackTrace();
     }
-    
-    try { 
+
+    try {
       loggerFactory = StaticLoggerBinder.SINGLETON.getLoggerFactory();
-    } catch(NoClassDefFoundError ncde) {
+    } catch (NoClassDefFoundError ncde) {
       String msg = ncde.getMessage();
-      if(msg != null && msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1) {
-        Util.reportFailure("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
-        Util.reportFailure("See "+NO_STATICLOGGERBINDER_URL+" for further details.");
-        
-      } 
+      if (msg != null && msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1) {
+        Util
+            .reportFailure("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
+        Util.reportFailure("See " + NO_STATICLOGGERBINDER_URL
+            + " for further details.");
+
+      }
       throw ncde;
     } catch (Exception e) {
       // we should never get here
@@ -91,12 +101,14 @@
    * bound {@link ILoggerFactory} instance.
    * 
    * @param name
-   *          The name of the logger.
+   *                The name of the logger.
    * @return logger
    */
   public static Logger getLogger(String name) {
-    if(loggerFactory == null) {
-      throw new IllegalStateException("Logging factory implementation cannot be null. See also "+NULL_LF_URL);
+    if (loggerFactory == null) {
+      throw new IllegalStateException(
+          "Logging factory implementation cannot be null. See also "
+              + NULL_LF_URL);
     }
     return loggerFactory.getLogger(name);
   }
@@ -106,12 +118,14 @@
    * the statically bound {@link ILoggerFactory} instance.
    * 
    * @param clazz
-   *          the returned logger will be named after clazz
+   *                the returned logger will be named after clazz
    * @return logger
    */
   public static Logger getLogger(Class clazz) {
-    if(loggerFactory == null) {
-      throw new IllegalStateException("Logging factory implementation cannot be null. See also "+NULL_LF_URL);
+    if (loggerFactory == null) {
+      throw new IllegalStateException(
+          "Logging factory implementation cannot be null. See also "
+              + NULL_LF_URL);
     }
     return loggerFactory.getLogger(clazz.getName());
   }
@@ -119,8 +133,8 @@
   /**
    * Return the {@link ILoggerFactory} instance in use.
    * 
-   * <p>ILoggerFactory instance is bound with this class at compile
-   * time.
+   * <p>
+   * ILoggerFactory instance is bound with this class at compile time.
    * 
    * @return the ILoggerFactory instance in use
    */

Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/impl/StaticLoggerBinder.java	(original)
+++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/impl/StaticLoggerBinder.java	Fri Oct  3 17:44:19 2008
@@ -47,7 +47,8 @@
    * Version tag used to check compatibility. The value of this field is
    * modified in each release. 
    */
-  public static final String VERSION = "1.5.4-SNAPSHOT";
+  // to avoid constant folding by the compiler, VERSION field should *not* be final
+  public static String VERSION = "1.5.4-SNAPSHOT";  // !final
   
   private StaticLoggerBinder() {
     throw new UnsupportedOperationException("This code should have never made it into the jar");

Modified: slf4j/trunk/slf4j-site/src/site/pages/codes.html
==============================================================================
--- slf4j/trunk/slf4j-site/src/site/pages/codes.html	(original)
+++ slf4j/trunk/slf4j-site/src/site/pages/codes.html	Fri Oct  3 17:44:19 2008
@@ -173,6 +173,9 @@
     matches that of the slf4j binding.
     </p>
 
+    <p>At initialization time, if SLF4J suspects that there may be a
+    mismatch problem, it emits a warning about the said mismatch.
+    </p>
 
 </div>
 </body>



More information about the slf4j-dev mailing list