Ensure a unique plugin logger is instatiated per model/generator combination.

Change-Id: I5805d7e93c7932cf2d3debe6b66b86293148faa6
diff --git a/core/org.eclipse.tigerstripe.api/pom.xml b/core/org.eclipse.tigerstripe.api/pom.xml
index f4895b0..b08ef97 100644
--- a/core/org.eclipse.tigerstripe.api/pom.xml
+++ b/core/org.eclipse.tigerstripe.api/pom.xml
@@ -26,6 +26,16 @@
 			<groupId>com.thoughtworks.qdox</groupId>

 			<artifactId>qdox</artifactId>

 			<version>1.6.3</version>

+			<exclusions>

+				<exclusion>

+					<groupId>jmock</groupId>

+					<artifactId>jmock</artifactId>

+				</exclusion>

+				<exclusion>

+					<groupId>junit</groupId>

+					<artifactId>junit</artifactId>

+				</exclusion>

+			</exclusions>

 		</dependency>

 		<dependency>

 			<groupId>org.apache.velocity</groupId>

diff --git a/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/plugins/PluginLogger.java b/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/plugins/PluginLogger.java
index f6716ae..4b1d362 100644
--- a/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/plugins/PluginLogger.java
+++ b/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/plugins/PluginLogger.java
@@ -41,7 +41,7 @@
  */
 public class PluginLogger {
 
-	public final static String DEFAULT_PATH = "pluginLog.log";
+	public static final String DEFAULT_PATH = "pluginLog.log";
 
 	private static final String LOG4J_FQCN = PluginLog.class.getName();
 	
@@ -89,10 +89,8 @@
 			throws TigerstripeException {
 
 		try {
-			String tigerstripeLoggerID = PluginLogger.class.getCanonicalName();
-
 			String outputPath = getOutputPath(pluginConfig, config);
-			File outputFile = new File(outputPath);
+			boolean logExists = new File(outputPath).exists();
 			// the current time (to the nearest millisecond) is used as a
 			// unique ID for this process's logfile entries (in case there are
 			// multiple processes using the same logfile...
@@ -104,20 +102,21 @@
 			String conversionPattern = "%-5p %C [%d{dd-MMM-yyyy HH:mm:ss.SSS}] - %m ["
 					+ logStartTime + "]%n";
 			PatternLayout patternLayout = new PatternLayout(conversionPattern);
-			boolean outputFileExists = false;
-			if (outputFile.exists())
-				outputFileExists = true;
 			RollingFileAppender appender = new RollingFileAppender(
 					patternLayout, outputPath);
 			appender.setMaxBackupIndex(maxNumBackupLogs);
-			logger = Logger.getLogger(tigerstripeLoggerID);
+            // Every project/plugin combo needs its own unique logger ID,
+            // otherwise multi-threaded generation may resolve to same logger object
+			String loggerId = pluginConfig.getProjectHandle().getName() + ":" + pluginConfig.getPluginName();
+			logger = Logger.getLogger(loggerId);
 			logger.removeAllAppenders();
-			if (outputFileExists)
+			if (logExists) {
 				appender.rollOver();
+			}
 			logger.addAppender(appender);
 			logger.setAdditivity(false);
 			logger.setLevel(toLevel(pluginConfig.getCurrentLogLevel()));
-
+			
 			logInitialized = true;
 		} catch (IOException e) {
 		    throw new TigerstripeException(
diff --git a/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/plugins/PluginLog.java b/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/plugins/PluginLog.java
index 8e76515..483d425 100644
--- a/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/plugins/PluginLog.java
+++ b/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/plugins/PluginLog.java
@@ -30,69 +30,76 @@
  * 
  */
 public class PluginLog {
-    
-    private PluginLogger pluginLogger;
-    
-    
-    public PluginLog() {
-        this.pluginLogger = new PluginLogger();    
+
+    private static final ThreadLocal<PluginLogger> LOGGER = new ThreadLocal<>();
+
+    private PluginLog() {
+        // Static class, do not instantiate
     }
     
-    
-    public void log(LogLevel level, String message, Throwable e) {
-            log(level, message, e);
-	}
+    public static void setThreadAwarePluginLogger(PluginLogger logger) {
+        LOGGER.set(logger);
+    }
 
-	 /**
-     * Reported statuses are displayed in generation results dialog. 
+    public static void log(LogLevel level, String message, Throwable e) {
+        PluginLogger logger = LOGGER.get();
+        if (logger != null) {
+            logger.log(level, message, e);
+        }
+    }
+
+    /**
+     * Reported statuses are displayed in generation results dialog.
      */
-    public void reportStatus(IStatus status) {
-            pluginLogger.reportStatus( status);
+    public static void reportStatus(IStatus status) {
+        PluginLogger logger = LOGGER.get();
+        if (logger != null) {
+            logger.reportStatus(status);
+        }
     }
-	
-	public void log(LogLevel level, String message) {
-		log(level, message, null);
-	}
 
-	public void logError(String message, Throwable e) {
-		log(LogLevel.ERROR, message, e);
-	}
+    public static void log(LogLevel level, String message) {
+        log(level, message, null);
+    }
 
-	public void logError(String message) {
-		logError(message, null);
-	}
+    public static void logError(String message, Throwable e) {
+        log(LogLevel.ERROR, message, e);
+    }
 
-	public void logWarning(String message, Throwable e) {
-		log(LogLevel.WARNING, message, e);
-	}
+    public static void logError(String message) {
+        logError(message, null);
+    }
 
-	public void logWarning(String message) {
-		logWarning(message, null);
-	}
+    public static void logWarning(String message, Throwable e) {
+        log(LogLevel.WARNING, message, e);
+    }
 
-	public void logInfo(String message, Throwable e) {
-		log(LogLevel.INFO, message, e);
-	}
+    public static void logWarning(String message) {
+        logWarning(message, null);
+    }
 
-	public void logInfo(String message) {
-		logInfo(message, null);
-	}
+    public static void logInfo(String message, Throwable e) {
+        log(LogLevel.INFO, message, e);
+    }
 
-	public void logDebug(String message, Throwable e) {
-		log(LogLevel.DEBUG, message, e);
-	}
+    public static void logInfo(String message) {
+        logInfo(message, null);
+    }
 
-	public void logDebug(String message) {
-		logDebug(message, null);
-	}
+    public static void logDebug(String message, Throwable e) {
+        log(LogLevel.DEBUG, message, e);
+    }
 
-	public void logTrace(String message, Throwable e) {
-		log(LogLevel.TRACE, message, e);
-	}
+    public static void logDebug(String message) {
+        logDebug(message, null);
+    }
 
-	public void logTrace(String message) {
-		logTrace(message, null);
-	}
-	
+    public static void logTrace(String message, Throwable e) {
+        log(LogLevel.TRACE, message, e);
+    }
+
+    public static void logTrace(String message) {
+        logTrace(message, null);
+    }
 
 }
diff --git a/core/org.eclipse.tigerstripe.core/pom.xml b/core/org.eclipse.tigerstripe.core/pom.xml
index bb8b151..8dce366 100644
--- a/core/org.eclipse.tigerstripe.core/pom.xml
+++ b/core/org.eclipse.tigerstripe.core/pom.xml
@@ -17,6 +17,12 @@
 			<groupId>org.eclipse.tigerstripe</groupId>

 			<artifactId>tigerstripe-api</artifactId>

 			<version>${project.version}</version>

+			<exclusions>

+				<exclusion>

+					<groupId>ant</groupId>

+					<artifactId>ant</artifactId>

+				</exclusion>

+			</exclusions>

 		</dependency>

 		<dependency>

 			<groupId>org.slf4j</groupId>

@@ -24,24 +30,14 @@
 			<version>${slf4j.version}</version>

 		</dependency>

 		<dependency>

-			<groupId>org.apache.velocity</groupId>

-			<artifactId>velocity</artifactId>

-			<version>1.5</version>

-		</dependency>

-		<dependency>

 			<groupId>org.dom4j</groupId>

 			<artifactId>dom4j</artifactId>

-			<version>2.0.0</version>

+			<version>2.1.1</version>

 		</dependency>

 		<dependency>

 			<groupId>org.apache.ant</groupId>

 			<artifactId>ant</artifactId>

-			<version>1.10.1</version>

-		</dependency>

-		<dependency>

-			<groupId>commons-digester</groupId>

-			<artifactId>commons-digester</artifactId>

-			<version>1.7</version>

+			<version>1.10.5</version>

 		</dependency>

 	</dependencies>

 </project>
\ No newline at end of file
diff --git a/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/core/generation/BaseM1Generator.java b/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/core/generation/BaseM1Generator.java
index 1b1ad47..8b469c3 100644
--- a/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/core/generation/BaseM1Generator.java
+++ b/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/core/generation/BaseM1Generator.java
@@ -45,6 +45,7 @@
 import org.eclipse.tigerstripe.workbench.plugins.EPluggablePluginNature;

 import org.eclipse.tigerstripe.workbench.plugins.IPluginReport;

 import org.eclipse.tigerstripe.workbench.plugins.LogLevel;

+import org.eclipse.tigerstripe.workbench.plugins.PluginLog;

 import org.eclipse.tigerstripe.workbench.project.IAdvancedProperties;

 import org.eclipse.tigerstripe.workbench.project.IDependency;

 import org.eclipse.tigerstripe.workbench.project.IPluginConfig;

@@ -499,6 +500,7 @@
 

             PluginLogger pluginLogger = new PluginLogger();

             pluginLogger.setUpForRun(ref, config);

+            PluginLog.setThreadAwarePluginLogger(pluginLogger);

 

             PluginRunStatus pluginResult = new PluginRunStatus(ref, project, project.getActiveFacet(),

                     ref.getLabel());

@@ -553,6 +555,7 @@
                 result.add(pluginResult);

                 ref.getRuntime().logTraceMessage("Tearing down logger for generator: "

                         + ref.toString());

+                PluginLog.setThreadAwarePluginLogger(null);

                 pluginLogger.tearDown();

             }

         }

diff --git a/core/pom.xml b/core/pom.xml
index e56f166..d828711 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -3,25 +3,25 @@
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 
-	<parent>
-		<groupId>org.eclipse.tigerstripe</groupId>
-		<artifactId>org.eclipse.tigerstripe.parent</artifactId>
-		<version>0.11.0-SNAPSHOT</version>
-	</parent>
-	
+	<groupId>org.eclipse.tigerstripe</groupId>
 	<artifactId>tigerstripe-core-parent</artifactId>
+	<version>0.11.0-SNAPSHOT</version>
 	<packaging>pom</packaging>
-	<name>Tigerstripe Core Parent POM</name>
+	<name>Tigerstripe Core Parent</name>
 
 	<properties>
+		<!-- Build properties -->
+		<java.version>1.8</java.version>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
+
 		<!-- Dependency versions -->
-		<slf4j.version>1.7.25</slf4j.version>
+		<slf4j.version>1.7.26</slf4j.version>
 
 		<!-- Plugin versions -->
 		<build-helper.version>3.0.0</build-helper.version>
-
-		<!-- Build config -->
-		<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
+		<compiler-plugin.version>3.8.0</compiler-plugin.version>
+		<jar-plugin.version>3.1.1</jar-plugin.version>
 	</properties>
 	
 	<modules>
@@ -30,40 +30,25 @@
 	</modules>
 	
 	<build>
-		<plugins>		
-			<plugin>
-				<!-- 
-					Make the version available for reference by plugins and documentation for resource filtering.
-					Ex. ${release.majorVersion}.${release.minorVersion}.${release.incrementalVersion} 
-				-->
-				<groupId>org.codehaus.mojo</groupId>
-				<artifactId>build-helper-maven-plugin</artifactId>
-				<version>${build-helper.version}</version>
-				<executions>
-					<execution>
-						<id>populate-version-details</id>
-						<goals>
-							<goal>parse-version</goal>
-						</goals>
-						<configuration>
-							<propertyPrefix>release</propertyPrefix>
-						</configuration>
-					</execution>
-				</executions>
-			</plugin>
-		</plugins>
-
 		<pluginManagement>
 			<plugins>
 				<plugin>
+					<artifactId>maven-compiler-plugin</artifactId>
+					<version>${compiler-plugin.version}</version>
+					<configuration>
+						<source>${java.version}</source>
+						<target>${java.version}</target>
+					</configuration>
+				</plugin>
+				<plugin>
 					<groupId>org.apache.maven.plugins</groupId>
 					<artifactId>maven-jar-plugin</artifactId>
-					<version>3.1.1</version>
+					<version>${jar-plugin.version}</version>
 					<configuration>
 						<archive>
 							<manifestEntries>
 								<!-- Used by tigerstripe core to show version information in Eclipse and in newly generated files. -->
-								<Bundle-Version>${release.majorVersion}.${release.minorVersion}.${release.incrementalVersion}.${maven.build.timestamp}</Bundle-Version>
+								<Bundle-Version>${bundleVersion}</Bundle-Version>
 							</manifestEntries>
 						</archive>
 					</configuration>
@@ -72,4 +57,44 @@
 		</pluginManagement>
 	</build>
 
+	<profiles>
+		<profile>
+			<id>release-profile</id>
+			<properties>
+				<bundleVersion>${project.version}</bundleVersion>
+			</properties>
+		</profile>
+		<profile>
+			<id>set-bundle-version</id>
+			<activation>
+				<activeByDefault>true</activeByDefault>
+			</activation>
+			<properties>
+				<bundleVersion>${release.majorVersion}.${release.minorVersion}.${release.incrementalVersion}.${maven.build.timestamp}</bundleVersion>
+			</properties>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.codehaus.mojo</groupId>
+						<artifactId>build-helper-maven-plugin</artifactId>
+						<version>${build-helper.version}</version>
+						<executions>
+							<execution>
+								<id>populate-version-details</id>
+								<phase>validate</phase>
+								<goals>
+									<goal>parse-version</goal>
+								</goals>
+								<configuration>
+									<propertyPrefix>release</propertyPrefix>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+
+
 </project>