description = 'Free Java library for displaying plots'

allprojects {
	group = 'de.erichseifert.gral'
	version = getVersionString()

	ext.inceptionYear = 2009
}

subprojects {
	apply plugin: 'java'
	sourceCompatibility = JavaVersion.VERSION_1_7
	targetCompatibility = JavaVersion.VERSION_1_7

	ext {
		owner1_id = 'eseifert'
		owner1_name = 'Erich Seifert'
		owner1_email = 'dev[at]erichseifert.de'
		owner2_id = 'mseifert'
		owner2_name = 'Michael Seifert'
		owner2_email = 'mseifert[at]error-reports.org'

		website = 'https://github.com/eseifert/gral/'
	}

	repositories {
		maven {
			url "https://plugins.gradle.org/m2/"
		}
	}
	dependencies {
		runtime 'de.erichseifert.vectorgraphics2d:VectorGraphics2D:0.13'
	}

	apply plugin: 'license'
	license {
		header(rootProject.file('config/license-header.txt'))
		strictCheck(true)
		mapping {
			java = 'SLASHSTAR_STYLE'
		}

		def currentYear = new GregorianCalendar().get(Calendar.YEAR)
		ext.year = "${inceptionYear}-${currentYear}"
		ext.owner1 = owner1_name
		ext.email1 = owner1_email
		ext.owner2 = owner2_name
		ext.email2 = owner2_email

		// Exlude certain file types from license checking
		// https://github.com/hierynomus/license-gradle-plugin/issues/9
	 	tasks.withType(nl.javadude.gradle.plugins.license.License).each { licenseTask ->
			licenseTask.exclude '**.properties'
		}
	}

	apply plugin: 'checkstyle'
	checkstyle.configFile = new File("${rootDir}/config/checkstyle.xml")

	apply plugin: 'pmd'
	pmd {
		// TODO: Dynamic dependency resolution possible?
		toolVersion = '5.0.5'
		ruleSets = ['java-basic']
		ignoreFailures = true
	}

	task sourceJar(type: Jar) {
		description = 'Assembles a jar archive containing the source code of the main classes.'
		group = 'Build'
		from sourceSets.main.allJava
		classifier 'sources'
	}
}

// Include the License Gradle plugin
buildscript {
	repositories {
		maven {
			url "https://plugins.gradle.org/m2/"
		}
	}

	dependencies {
		classpath 'gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.15.+'
	}
}

/*
 * This method must not be named getVersion, because it would
 * overwrite the implicit getter of the version property in the
 * current Project object.
 */
def getVersionString() {
	def out = new ByteArrayOutputStream()
	exec {
		commandLine('git', 'describe', '--tags', '--always')
		standardOutput = out
	}
	return out.toString().trim()
}
