Stephen McKamey avatar Stephen McKamey committed 6c727eb

moving all logging to SLF4J; piping SLF4J in maven-plugin to maven logger; reving to v0.4.0

Comments (0)

Files changed (10)

merge-builder/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>merge-builder</artifactId>
-	<version>0.3.1</version>
+	<version>0.4.0</version>
 	<packaging>jar</packaging>
 
 	<name>DUEL Merge Builder</name>
 
 		<cssless.version>0.3.3</cssless.version>
 		<closure.version>r1459</closure.version>
+		<slf4j.version>1.6.4</slf4j.version>
 		<junit.version>4.8.2</junit.version>
 		<jvm.version>1.6</jvm.version>
 	</properties>
 			<version>${closure.version}</version>
 		</dependency>
 
+		<!-- Logging API -->		
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>${slf4j.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-jdk14</artifactId>
+			<version>${slf4j.version}</version>
+			<scope>test</scope>
+		</dependency>
+
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>

merge-builder/src/main/java/org/duelengine/merge/LinkInterceptorCssFilter.java

 import java.io.IOException;
 import java.net.URI;
 import java.util.Map;
-import java.util.logging.Logger;
 
 import org.cssless.css.ast.*;
 import org.cssless.css.codegen.CssFilter;
 import org.cssless.css.parsing.CssLexer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class LinkInterceptorCssFilter implements CssFilter {
 
-	private final Logger log = Logger.getLogger(LinkInterceptorCssFilter.class.getCanonicalName());
+	private final Logger log = LoggerFactory.getLogger(LinkInterceptorCssFilter.class);
 	private final Map<String, String> linkMap;
 	private final URI context;
 
 
 				String valHash = this.linkMap.get(val);
 				if (valHash == null) {
-					log.warning("Missing CSS reference: "+val);
+					log.warn("Missing CSS reference: "+val);
 					break;
 				}
 
 				log.info("CSS url: "+val+" => "+valHash);
 
 			} else {
-				log.warning("Unexpected CSS url type: "+child.getNodeType());
+				log.warn("Unexpected CSS url type: "+child.getNodeType());
 			}
 		}
 		

merge-builder/src/main/java/org/duelengine/merge/MergeBuilder.java

 import java.io.*;
 import java.security.*;
 import java.util.*;
-import java.util.logging.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class MergeBuilder {
 
 	private static final String HASH_ALGORITHM = "SHA-1";
 	private static final String CHAR_ENCODING = "utf-8";
 
-	private final Logger log = Logger.getLogger(MergeBuilder.class.getCanonicalName());
+	private final Logger log = LoggerFactory.getLogger(MergeBuilder.class);
 	private final Map<String, Compactor> compactors;
 	private final Map<String, PlaceholderGenerator> placeholders;
 	private File webappDir;
 
 		PlaceholderGenerator generator = this.placeholders.get(getExtension(hashPath));
 		if (generator == null) {
-			log.warning("Cannot generate debug placeholder for "+debugPath);
+			log.warn("Cannot generate debug placeholder for "+debugPath);
 			return;
 		}
 
 
 			if (!outputFile.exists()) {
 				// file still missing, remove
-				log.severe(path+" failed to compact (output missing)");
+				log.error(path+" failed to compact (output missing)");
 				hashLookup.remove(path);
 
 			} else if (outputFile.length() < 1L) {
 				if (inputFile.length() < 1L) {
 					// special case for files which compact to empty
-					log.warning(path+" is an empty file");
+					log.warn(path+" is an empty file");
 
 					// remove from listings
 					hashLookup.remove(path);
 				} else {
 					// special case for files which compact to empty
-					log.warning(path+" compacted to an empty file (using original)");
+					log.warn(path+" compacted to an empty file (using original)");
 
 					// copy over original contents (as wasn't really empty)
 					new NullCompactor().compact(hashLookup, inputFile, outputFile, path);
 				String childPath = hashLookup.get(line);
 				if (childPath == null) {
 					// TODO: allow chaining of .merge files by ordering by dependency
-					log.warning("Missing merge reference: "+line);
+					log.warn("Missing merge reference: "+line);
 
 					// skip missing resources (will be reflected in hash)
 					continue;

merge-maven-plugin/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>merge-maven-plugin</artifactId>
-	<version>0.3.1</version>
+	<version>0.4.0</version>
 	<packaging>maven-plugin</packaging>
 
 	<name>DUEL Merge Maven Plugin</name>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
+		<slf4j.version>1.6.4</slf4j.version>
 		<maven.version>3.0.3</maven.version>
 		<junit.version>4.8.2</junit.version>
 		<jvm.version>1.6</jvm.version>
 			<artifactId>merge-builder</artifactId>
 			<version>${project.version}</version>
 		</dependency>
+
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>${slf4j.version}</version>
+		</dependency>
+
 		<dependency>
 			<groupId>org.apache.maven</groupId>
 			<artifactId>maven-core</artifactId>
 			<artifactId>maven-plugin-api</artifactId>
 			<version>${maven.version}</version>
 		</dependency>
+
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>

merge-maven-plugin/src/main/java/org/duelengine/merge/maven/MavenLoggerAdapter.java

+package org.duelengine.merge.maven;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.slf4j.helpers.MarkerIgnoringBase;
+
+@SuppressWarnings("serial")
+public class MavenLoggerAdapter extends MarkerIgnoringBase {
+
+	private final Log log;
+
+	public MavenLoggerAdapter(String name, Log log) {
+		this.name = name;
+		this.log = (log != null) ? log : new SystemStreamLog();
+	}
+
+	protected Log getLog() {
+		return log;
+	}
+	
+	@Override
+	public void debug(String msg) {
+		getLog().debug(msg);
+	}
+
+	@Override
+	public void debug(String format, Object arg1) {
+		debug(String.format(format, arg1));
+	}
+
+	@Override
+	public void debug(String format, Object[] arg1) {
+		debug(String.format(format, arg1));
+	}
+
+	@Override
+	public void debug(String msg, Throwable t) {
+		getLog().debug(msg, t);
+	}
+
+	@Override
+	public void debug(String format, Object arg1, Object arg2) {
+		debug(String.format(format, arg1, arg2));
+	}
+
+	@Override
+	public void error(String msg) {
+		getLog().error(msg);
+	}
+
+	@Override
+	public void error(String format, Object arg1) {
+		error(String.format(format, arg1));
+	}
+
+	@Override
+	public void error(String format, Object[] arg1) {
+		error(String.format(format, arg1));
+	}
+
+	@Override
+	public void error(String msg, Throwable t) {
+		getLog().error(msg, t);
+	}
+
+	@Override
+	public void error(String format, Object arg1, Object arg2) {
+		error(String.format(format, arg1, arg2));
+	}
+
+	@Override
+	public void info(String msg) {
+		getLog().info(msg);
+	}
+
+	@Override
+	public void info(String format, Object arg1) {
+		info(String.format(format, arg1));
+	}
+
+	@Override
+	public void info(String format, Object[] arg1) {
+		info(String.format(format, arg1));
+	}
+
+	@Override
+	public void info(String msg, Throwable t) {
+		getLog().info(msg, t);
+	}
+
+	@Override
+	public void info(String format, Object arg1, Object arg2) {
+		info(String.format(format, arg1, arg2));
+	}
+
+	@Override
+	public boolean isDebugEnabled() {
+		return getLog().isDebugEnabled();
+	}
+
+	@Override
+	public boolean isErrorEnabled() {
+		return getLog().isErrorEnabled();
+	}
+
+	@Override
+	public boolean isInfoEnabled() {
+		return getLog().isInfoEnabled();
+	}
+
+	@Override
+	public boolean isTraceEnabled() {
+		return false;
+	}
+
+	@Override
+	public boolean isWarnEnabled() {
+		return getLog().isWarnEnabled();
+	}
+
+	@Override
+	public void trace(String msg) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Object arg1) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Object[] arg1) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Throwable t) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Object arg1, Object arg2) {
+		// NOOP
+	}
+
+	@Override
+	public void warn(String msg) {
+		getLog().warn(msg);
+	}
+
+	@Override
+	public void warn(String format, Object arg1) {
+		warn(String.format(format, arg1));
+	}
+
+	@Override
+	public void warn(String format, Object[] arg1) {
+		warn(String.format(format, arg1));
+	}
+
+	@Override
+	public void warn(String msg, Throwable t) {
+		getLog().warn(msg, t);
+	}
+
+	@Override
+	public void warn(String format, Object arg1, Object arg2) {
+		warn(String.format(format, arg1, arg2));
+	}
+}

merge-maven-plugin/src/main/java/org/duelengine/merge/maven/MavenLoggerAdapterFactory.java

+package org.duelengine.merge.maven;
+
+import org.apache.maven.plugin.logging.Log;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.Logger;
+
+public class MavenLoggerAdapterFactory implements ILoggerFactory {
+
+	private static Log log;
+
+	static void setMavenLogger(Log log) {
+		MavenLoggerAdapterFactory.log = log;
+	}
+
+	@Override
+	public Logger getLogger(String name) {
+		return new MavenLoggerAdapter(name, log);
+	}
+}

merge-maven-plugin/src/main/java/org/duelengine/merge/maven/MergeMojo.java

-package org.duelengine.merge.maven;
-
-import java.util.Arrays;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.logging.Log;
-import org.duelengine.merge.*;
-
-/**
- * Generates client-side and server-side sources
- *
- * @goal merge
- * @phase generate-sources
- */
-public class MergeMojo extends AbstractMojo {
-
-	// http://maven.apache.org/ref/3.0.3/maven-model/maven.html#class_build
-
-	/**
-	 * Directory containing the webapp source.
-	 * 
-	 * @parameter default-value="${project.basedir}/src/main/webapp/"
-	 * @readonly
-	 * @required
-	 */
-	private String webappDir;
-
-	/**
-	 * Directory where webapp is output..
-	 * 
-	 * @parameter default-value="${project.build.directory}/${project.build.finalName}/"
-	 * @readonly
-	 * @required
-	 */
-	private String outputDir;
-
-	/**
-	 * File path of the generated resource map.
-	 * 
-	 * @parameter default-value="${project.build.outputDirectory}"
-	 * @readonly
-	 * @required
-	 */
-	private String resourcesDir;
-
-	/**
-	 * URL root path of CDN output.
-	 * 
-	 * @parameter default-value="/cdn/"
-	 */
-	private String cdnRoot;
-
-	/**
-	 * File name of the generated resource map.
-	 * 
-	 * @parameter default-value="cdn.properties"
-	 */
-	private String cdnMapFile;
-
-	/**
-	 * List of additional file extensions to hash and copy directly into CDN.
-	 * 
-	 * @parameter default-value=""
-	 */
-	private String cdnFiles;
-
-	public void execute()
-		throws MojoExecutionException {
-		
-		Log log = this.getLog();
-		log.info("\twebappDir="+this.webappDir);
-		log.info("\toutputDir="+this.outputDir);
-
-		if (this.cdnMapFile == null || this.cdnMapFile.isEmpty()) {
-			this.cdnMapFile = "/cdn.properties";
-		} else if (!this.cdnMapFile.startsWith("/")) {
-			this.cdnMapFile = '/'+this.cdnMapFile;
-		}
-		log.info("\tcdnMapFile="+this.resourcesDir+this.cdnMapFile);
-		log.info("\tcdnRoot="+this.cdnRoot);
-
-		String[] exts;
-		if (this.cdnFiles != null) {
-			exts = this.cdnFiles.split("[|,\\s]+");
-		} else {
-			exts = new String[0];
-		}
-
-		log.info("\tcdnFiles="+Arrays.toString(exts));
-
-		MergeBuilder merger = new MergeBuilder(exts);
-		merger.setWebAppDir(this.webappDir);
-		merger.setOutputDir(this.outputDir);
-
-		if (this.cdnRoot != null && !this.cdnRoot.isEmpty()) {
-			merger.setCDNRoot(this.cdnRoot);
-		}
-
-		merger.setCDNMapFile(this.resourcesDir+this.cdnMapFile);
-
-		try {
-			merger.execute();
-
-		} catch (Exception e) {
-			log.error(e);
-		}
-	}
-}
+package org.duelengine.merge.maven;
+
+import java.util.Arrays;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.duelengine.merge.MergeBuilder;
+
+/**
+ * Generates client-side and server-side sources
+ *
+ * @goal merge
+ * @phase generate-sources
+ */
+public class MergeMojo extends AbstractMojo {
+
+	// http://maven.apache.org/ref/3.0.3/maven-model/maven.html#class_build
+
+	/**
+	 * Directory containing the webapp source.
+	 * 
+	 * @parameter default-value="${project.basedir}/src/main/webapp/"
+	 * @readonly
+	 * @required
+	 */
+	private String webappDir;
+
+	/**
+	 * Directory where webapp is output..
+	 * 
+	 * @parameter default-value="${project.build.directory}/${project.build.finalName}/"
+	 * @readonly
+	 * @required
+	 */
+	private String outputDir;
+
+	/**
+	 * File path of the generated resource map.
+	 * 
+	 * @parameter default-value="${project.build.outputDirectory}"
+	 * @readonly
+	 * @required
+	 */
+	private String resourcesDir;
+
+	/**
+	 * URL root path of CDN output.
+	 * 
+	 * @parameter default-value="/cdn/"
+	 */
+	private String cdnRoot;
+
+	/**
+	 * File name of the generated resource map.
+	 * 
+	 * @parameter default-value="cdn.properties"
+	 */
+	private String cdnMapFile;
+
+	/**
+	 * List of additional file extensions to hash and copy directly into CDN.
+	 * 
+	 * @parameter default-value=""
+	 */
+	private String cdnFiles;
+
+	@Override
+	public void setLog(Log log) {
+		super.setLog(log);
+
+		MavenLoggerAdapterFactory.setMavenLogger(log);
+	};
+	
+	public void execute()
+		throws MojoExecutionException {
+		
+		Log log = this.getLog();
+
+		log.info("\twebappDir="+this.webappDir);
+		log.info("\toutputDir="+this.outputDir);
+
+		if (this.cdnMapFile == null || this.cdnMapFile.isEmpty()) {
+			this.cdnMapFile = "/cdn.properties";
+		} else if (!this.cdnMapFile.startsWith("/")) {
+			this.cdnMapFile = '/'+this.cdnMapFile;
+		}
+		log.info("\tcdnMapFile="+this.resourcesDir+this.cdnMapFile);
+		log.info("\tcdnRoot="+this.cdnRoot);
+
+		String[] exts;
+		if (this.cdnFiles != null) {
+			exts = this.cdnFiles.split("[|,\\s]+");
+		} else {
+			exts = new String[0];
+		}
+
+		log.info("\tcdnFiles="+Arrays.toString(exts));
+
+		MergeBuilder merger = new MergeBuilder(exts);
+		merger.setWebAppDir(this.webappDir);
+		merger.setOutputDir(this.outputDir);
+
+		if (this.cdnRoot != null && !this.cdnRoot.isEmpty()) {
+			merger.setCDNRoot(this.cdnRoot);
+		}
+
+		merger.setCDNMapFile(this.resourcesDir+this.cdnMapFile);
+
+		try {
+			merger.execute();
+
+		} catch (Exception e) {
+			log.error(e);
+		}
+	}
+}

merge-maven-plugin/src/main/java/org/slf4j/impl/StaticLoggerBinder.java

+package org.slf4j.impl;
+
+import org.duelengine.merge.maven.MavenLoggerAdapterFactory;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.LoggerFactory;
+import org.slf4j.spi.LoggerFactoryBinder;
+
+/**
+ * The binding of {@link LoggerFactory} class with an actual instance of
+ * {@link ILoggerFactory} is performed using information returned by this class.
+ */
+public class StaticLoggerBinder implements LoggerFactoryBinder {
+
+	/**
+	 * The unique instance of this class.
+	 * 
+	 */
+	private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
+	
+	/**
+	 * Return the singleton of this class.
+	 * 
+	 * @return the StaticLoggerBinder singleton
+	 */
+	public static final StaticLoggerBinder getSingleton() {
+		return SINGLETON;
+	}
+
+	/**
+	 * Declare the version of the SLF4J API this implementation is compiled
+	 * against. The value of this field is usually modified with each release.
+	 */
+	// to avoid constant folding by the compiler, this field must *not* be final
+	public static String REQUESTED_API_VERSION = "1.6";	 // !final
+	
+	private static final String loggerFactoryClassStr = MavenLoggerAdapterFactory.class.getName();
+
+	/**
+	 * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
+	 * method should always be the same object
+	 */
+	private final ILoggerFactory loggerFactory;
+	
+	private StaticLoggerBinder() {
+		loggerFactory = new MavenLoggerAdapterFactory();
+	}
+	
+	public ILoggerFactory getLoggerFactory() {
+		return loggerFactory;
+	}
+	
+	public String getLoggerFactoryClassStr() {
+		return loggerFactoryClassStr;
+	}		
+}

merge-maven-plugin/src/main/java/org/slf4j/impl/StaticMDCBinder.java

+package org.slf4j.impl;
+
+import org.slf4j.helpers.NOPMDCAdapter;
+import org.slf4j.spi.MDCAdapter;
+
+/**
+ * This implementation is bound to {@link NOPMDCAdapter}.
+ */
+public class StaticMDCBinder {
+
+	/**
+	 * The unique instance of this class.
+	 */
+	public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
+
+	private StaticMDCBinder() {
+	}
+	
+	/**
+	 * Currently this method always returns an instance of 
+	 * {@link StaticMDCBinder}.
+	 */
+	public MDCAdapter getMDCA() {
+		 return new NOPMDCAdapter();
+	}
+	
+	public String	 getMDCAdapterClassStr() {
+		return NOPMDCAdapter.class.getName();
+	}
+}

merge-maven-plugin/src/main/java/org/slf4j/impl/StaticMarkerBinder.java

+package org.slf4j.impl;
+
+import org.slf4j.IMarkerFactory;
+import org.slf4j.MarkerFactory;
+import org.slf4j.helpers.BasicMarkerFactory;
+import org.slf4j.spi.MarkerFactoryBinder;
+
+/**
+ * 
+ * The binding of {@link MarkerFactory} class with an actual instance of 
+ * {@link IMarkerFactory} is performed using information returned by this class. 
+ */
+public class StaticMarkerBinder implements MarkerFactoryBinder {
+
+	/**
+	 * The unique instance of this class.
+	 */
+	public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
+	
+	final IMarkerFactory markerFactory = new BasicMarkerFactory();
+	
+	private StaticMarkerBinder() {
+	}
+	
+	/**
+	 * Currently this method always returns an instance of 
+	 * {@link BasicMarkerFactory}.
+	 */
+	public IMarkerFactory getMarkerFactory() {
+		return markerFactory;
+	}
+	
+	/**
+	 * Currently, this method returns the class name of
+	 * {@link BasicMarkerFactory}.
+	 */
+	public String getMarkerFactoryClassStr() {
+		return BasicMarkerFactory.class.getName();
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.