package com.jdroid.gradle.root.task;

import com.jdroid.gradle.commons.tasks.AbstractTask;
import com.jdroid.java.utils.StreamUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;


public class ProjectConfigValidationTask extends AbstractTask {

	public ProjectConfigValidationTask() {
		setDescription("Validates if the project configuration is up to date");
	}

	@Override
	protected void onExecute() {
		File rootDir = getProject().getRootDir();

		for (ProjectConfig projectConfig : ProjectConfig.values()) {
			if (projectConfig.isEnabled(getProject())) {
				try {
					log("Validating " + projectConfig.getTarget());
					File target = new File(rootDir, projectConfig.getTarget());
					boolean valid = target.exists();
					if (valid) {
						valid = StreamUtils.isEquals(getClass().getResourceAsStream(projectConfig.getSource()), new FileInputStream(target));
					}
					if (!valid) {
						throw new RuntimeException("The file [" + projectConfig.getTarget() + "] is not up to date");
					}
				} catch (FileNotFoundException e) {
					throw new RuntimeException(e);
				}
			}
		}
	}
}

@@ -127,16 +127,92 @@
 Utils;%0A%0A
+import org.gradle.api.GradleException;%0Aimport org.gradle.internal.jvm.Jvm;%0A%0A
 import j
@@ -224,16 +224,16 @@
 o.File;%0A
-
 import j
@@ -361,16 +361,76 @@
 Task %7B%0A%0A
+%09private static final String EXPECTED_JAVA_VERSION = %2211%22;%0A%0A
 %09public 
@@ -550,16 +550,16 @@
 verride%0A
-
 %09protect
@@ -580,16 +580,331 @@
 ute() %7B%0A
+%0A%09%09String javaVersion = Jvm.current().getJavaVersion().toString();%0A%09%09if (!javaVersion.equals(propertyResolver.getStringProp(%22EXPECTED_JAVA_VERSION%22, EXPECTED_JAVA_VERSION))) %7B%0A%09%09%09throw new GradleException(%22Wrong java version. Actual version: %22 + javaVersion + %22 %7C Expected version: %22 + EXPECTED_JAVA_VERSION);%0A%09%09%7D%0A%0A
 %09%09File r

Add java version validation