Introduce compiler reports

Signed-off-by: Dawid Pakuła <zulus@w3des.net>
diff --git a/build/pom.xml b/build/pom.xml
index 1d74261..1c3c77e 100644
--- a/build/pom.xml
+++ b/build/pom.xml
@@ -28,6 +28,7 @@
 	<properties>
 		<tycho-version>0.23.0</tycho-version>
 		<tycho-groupid>org.eclipse.tycho</tycho-groupid>
+		<antrun-version>1.7</antrun-version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<eclipse-repository-url>http://download.eclipse.org/releases/luna/</eclipse-repository-url>
 		<pack200>${java.home}/bin</pack200>
@@ -59,6 +60,7 @@
 	</pluginRepositories>
 
 	<build>
+
 		<plugins>
 			<plugin>
 				<groupId>org.eclipse.tycho</groupId>
@@ -129,6 +131,7 @@
 					</environments>
 				</configuration>
 			</plugin>
+
 		</plugins>
 	</build>
 
@@ -253,6 +256,55 @@
 				</plugins>
 			</build>
 		</profile>
+		<profile>
+			<id>reports</id>
+			<build>
+				<pluginManagement>
+					<plugins>
+						<plugin>
+							<groupId>${tycho-groupid}</groupId>
+							<artifactId>tycho-compiler-plugin</artifactId>
+							<version>${tycho-version}</version>
+							<configuration>
+								<logEnabled>true</logEnabled>
+								<logDirectory>${project.build.directory}/logfiles/</logDirectory>
+								<log>xml</log>
+								<showWarnings>true</showWarnings>
+							</configuration>
+						</plugin>
+					</plugins>
+				</pluginManagement>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-antrun-plugin</artifactId>
+						<version>${antrun-version}</version>
+						<inherited>false</inherited>
+						<executions>
+							<execution>
+								<id>generate-summary</id>
+								<phase>verify</phase>
+								<goals>
+									<goal>copy-resources</goal>
+								</goals>
+								<configuration>
+									<exportAntProperties>true</exportAntProperties>
+									<target>
+										<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 inheritRefs="true" antfile="${basedir}/postBuild.xml">
+											<target name="init" />
+										</ant>
+									</target>
+								</configuration>
+								
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
 	</profiles>
-
 </project>
diff --git a/build/postBuild.xml b/build/postBuild.xml
new file mode 100644
index 0000000..27d26df
--- /dev/null
+++ b/build/postBuild.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Check" default="init" basedir=".">
+	<target name="init">
+		<xmlproperty file="pom.xml" prefix="pom_file" collapseattributes="true" semanticattributes="true"/>
+		<script language="javascript">
+		<![CDATA[
+		var modules = project.getProperty('pom_file.project.modules.module').split(',');
+		function echo(mess) {
+			var e = project.createTask('echo');
+			e.setMessage(mess);
+			e.perform();
+		}
+		var counts = {
+			bundles : {
+				totalBundles : 0,
+				totalWarnings : 0,
+				totalErrors : 0,
+				totalAccess : 0,
+				totaldiscouragedAccessWarningCount : 0,
+				totalforbiddenAccessWarningCount : 0
+			},
+			tests : {
+				totalBundles : 0,
+				totalWarnings : 0,
+				totalErrors : 0,
+				totalAccess : 0,
+				totaldiscouragedAccessWarningCount : 0,
+				totalforbiddenAccessWarningCount : 0
+			}
+		};
+		for (var i in modules) {
+			var logs = project.createDataType('fileset');
+			logs.setDir(new java.io.File(modules[i]));
+			logs.setIncludes('**/target/logfiles/*.xml');
+			var ds = logs.getDirectoryScanner(project);
+		    var srcFiles = ds.getIncludedFiles();
+				
+			for (var a in srcFiles) {
+				var basedir  = logs.getDir(project);
+		        var filename = srcFiles[a];
+		        var file = new java.io.File(basedir, filename), bundleDir = file.getParentFile().getParentFile().getParentFile(), tests = false;
+				if (bundleDir.getName().indexOf('.test') != -1) { 
+					tests = true;
+				}
+				var curr = tests ? counts.tests : counts.bundles;
+				curr.totalBundles++;
+				var dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(), dBuilder = dbFactory.newDocumentBuilder(), doc = dBuilder.parse(file)
+				var sources = doc.getElementsByTagName('sources');
+				if (sources.getLength() == 0) {
+					continue;
+				}
+				sources = sources.item(0).getElementsByTagName('source');
+				for (var p = 0; p < sources.getLength();p++) {
+					var main = sources.item(p).getElementsByTagName('problems');
+					if(main.getLength() == 0) {
+						continue;
+					}
+					var problems = main.item(0).getElementsByTagName('problem');	
+					for (var n = 0; n < problems.getLength(); n++) {
+						var problemId = problems.item(n).getAttribute('problemId');
+						if (problemId = 'ForbiddenReference') {
+							curr.totalforbiddenAccessWarningCount++;
+							curr.access++;
+						} else if (problemId == 'DiscouragedReference') {
+							curr.totaldiscouragedAccessWarningCount++;
+							curr.access++;
+						}
+						var problemSeverity = problems.item(n).getAttribute('severity');
+						if(problemSeverity == "WARNING") {
+							curr.totalWarnings++;
+						} else if (problemSeverity =="ERROR") {
+							curr.totalErrors++;
+						}
+					}
+				}
+			}
+		
+		}
+		function prepareXml(fileName, settings) {
+			var docFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
+			docBuilder = docFactory.newDocumentBuilder();
+			doc = docBuilder.newDocument();
+			rootElement = doc.createElement("compileSummary");
+			doc.appendChild(rootElement);
+			for (var varName in settings) {
+				var item = doc.createElement('summaryItem');
+				var name = doc.createElement('name'), value = doc.createElement('value');
+				name.appendChild(doc.createTextNode(varName));
+				value.appendChild(doc.createTextNode(settings[varName]));
+				item.appendChild(name);
+				item.appendChild(value);
+				
+				rootElement.appendChild(item);
+			}
+		
+			// write the content into xml file
+			transformerFactory = javax.xml.transform.TransformerFactory.newInstance();
+			transformer = transformerFactory.newTransformer();
+			source = new javax.xml.transform.dom.DOMSource(doc);
+			var dir = new java.io.File('update.site/target/repository/logs');
+			dir.mkdirs();
+			var resFile = new java.io.File(dir, fileName);
+			if (resFile.exists()) {	
+				resFile.delete();
+			}
+			result = new javax.xml.transform.stream.StreamResult(resFile);
+		
+			transformer.transform(source, result);
+		}
+		prepareXml('compilelogsSummary.xml', counts.bundles);
+		prepareXml('testcompilelogsSummary.xml', counts.tests);
+		]]>
+		</script>
+	</target>
+	<target name="loop">
+		<echo>${module}</echo>
+		
+		<fileset dir="${module}">
+		<include name="**/logfiles/*.xml"/>
+		</fileset>
+	</target>
+</project>
\ No newline at end of file
diff --git a/build/site/pom.xml b/build/site/pom.xml
index 757a629..0b0bbb2 100644
--- a/build/site/pom.xml
+++ b/build/site/pom.xml
@@ -12,7 +12,7 @@
 		<tycho-version>0.23.0</tycho-version>
 		<tycho-groupid>org.eclipse.tycho</tycho-groupid>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-		<dltk-repository-url>file://${basedir}/../../../update.site/target/site/</dltk-repository-url>
+		<dltk-repository-url>file://${basedir}/../../update.site/target/site/</dltk-repository-url>
 		<eclipse-repository-url>http://download.eclipse.org/releases/luna/</eclipse-repository-url>
 	</properties>
 
diff --git a/build/site/site/template/index.php.template b/build/site/site/template/index.php.template
index d14f9dd..3b93fbd 100644
--- a/build/site/site/template/index.php.template
+++ b/build/site/site/template/index.php.template
@@ -60,7 +60,7 @@
         //eval($code);
 }
 
-/*$filename = "testcompilelogsSummary.xml";
+$filename = "testcompilelogsSummary.xml";
 $prefix = "test_";
 $compileSummary = simplexml_load_file($filename);
 foreach ($compileSummary->summaryItem as $summaryItem) {
@@ -69,7 +69,7 @@
         ${$prefix . $name} = $value;
         //echo "<br />code: " . $code;
         //eval($code);
-}*/
+}
 
 
 ?>