Skip to content
Snippets Groups Projects
build.gradle 9.66 KiB
Newer Older
apply plugin: 'asciidoctor'
apply plugin: 'eclipse-wtp'
apply plugin: 'findbugs'
Nikolaus Krismer's avatar
Nikolaus Krismer committed
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'jdepend'
apply plugin: 'js'
User expired's avatar
User expired committed
apply plugin: 'maven-publish'
apply plugin: 'war'
User expired's avatar
User expired committed
apply plugin: 'wrapper'
User expired's avatar
User expired committed
import org.apache.tools.ant.filters.FixCrLfFilter
import org.apache.tools.ant.filters.ReplaceTokens

group = 'it.unibz.inf.isochrone'
version = '0.2-SNAPSHOT'
description = 'PhD project of Nikolaus Krismer'
	def date = new Date()
	def formattedDate = date.format('yyyyMMdd')
	return formattedDate
	defaultVersion = '0.1-SNAPSHOT'
User expired's avatar
User expired committed
	isRelease = false
//	vagrantDirString = System.properties['user.home'] + '/vagrantboxes/' + project.name.toLowerCase()
//	vagrantDirString = '/media/data/VMs/vagrantboxes/' + project.name.toLowerCase()
//	vagrantDir = file("$vagrantDirString")
	vagrantDir = getProjectDir()
User expired's avatar
User expired committed
if (version.equalsIgnoreCase('unspecified')) {
	version = defaultVersion
} else if (!version.matches(~/[0-9\.]*(-SNAPSHOT)?/)) {
	println "Invalid version number '$version' given. Falling back to default!"
	version = defaultVersion
}

if (version.endsWith('-SNAPSHOT')) {
	println "Building SNAPSHOT version $version"
} else {
	isRelease = true;
	println "Building RELEASE version $version"
}

repositories {
User expired's avatar
User expired committed
	mavenCentral()
	maven { url "http://maven.geo-solutions.it" }
}

buildscript {
	apply from: 'http://www.krismer.de/files/checkstyle.gradle'
User expired's avatar
User expired committed
	repositories {
		jcenter()
		maven { url 'http://dl.bintray.com/content/aalmiray/asciidoctor'}
	}
User expired's avatar
User expired committed
	dependencies {
Nikolaus Krismer's avatar
Nikolaus Krismer committed
		classpath 'com.eriwen:gradle-js-plugin:1.9.0'
User expired's avatar
User expired committed
		classpath 'org.gradle.api.plugins:gradle-vagrant-plugin:0.2'
		classpath 'org.asciidoctor:asciidoctor-gradle-plugin:0.7.0'
	}
}

dependencies {
	providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
	providedCompile group: 'javax.websocket', name: 'javax.websocket-api', version:'1.0'

User expired's avatar
User expired committed
	compile group: 'commons-dbutils', name: 'commons-dbutils', version:'1.2'
	compile group: 'commons-httpclient', name: 'commons-httpclient', version:'3.1'
	compile(group: 'it.geosolutions', name: 'geoserver-manager', version:'1.5.2') {
		exclude(module: 'jcl-over-slf4j')
	compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.3.0'
	compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.3.0'
	compile group: 'com.google.code.findbugs', name: 'annotations', version: '2.0.3'
	compile group: 'com.tngtech.java', name: 'config-builder', version: '1.1'
	compile(group: 'org.postgis', name: 'postgis-jdbc', version:'1.3+') {
		exclude(module: 'postgis-stubs')
	}
	compile group: 'org.postgresql', name: 'postgresql', version:'9.3-1100-jdbc41'

	runtime 'org.slf4j:jcl-over-slf4j:1.7.5'
	runtime 'ch.qos.logback:logback-classic:1.0.13'
User expired's avatar
User expired committed

	testCompile 'org.testng:testng:6+'
	// adds support for compiler warnings generation
asciidoctor {
	backend = 'html5'
	sourceDir = file('doc')
User expired's avatar
User expired committed
	outputDir = file("$buildDir/docs/asciidoctor")
}

checkstyle {
	ignoreFailures = true
	showViolations = false
}

eclipse {
	project {
		buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'

		natures = [
			'net.sf.eclipsecs.core.CheckstyleNature',
			'org.springsource.ide.eclipse.gradle.core.nature',
			'org.eclipse.jem.workbench.JavaEMFNature',
			'org.eclipse.wst.common.modulecore.ModuleCoreNature',
			'org.eclipse.wst.common.project.facet.core.nature',
			'org.eclipse.jdt.core.javanature',
			'org.eclipse.wst.jsdt.core.jsNature'
		]
Nikolaus Krismer's avatar
Nikolaus Krismer committed

        file {
            withXml { xmlProvider ->
                Node project = xmlProvider.asNode()
                Node filteredResources = project.appendNode('filteredResources');

                Node filterGradle = filteredResources.appendNode('filter')
                filterGradle.appendNode('id', 1392635165065)
                filterGradle.appendNode('name', '')
                filterGradle.appendNode('type', 30)
                Node matcherGradle = filterGradle.appendNode('matcher')
                matcherGradle.appendNode('id', 'org.eclipse.ui.ide.multiFilter')
                matcherGradle.appendNode('arguments', '1.0-name-matches-false-false-.gradle')

                Node filterVagrant = filteredResources.appendNode('filter')
                filterVagrant.appendNode('id', 1392635165131)
                filterVagrant.appendNode('name', '')
                filterVagrant.appendNode('type', 30)
                Node matcherVagrant = filterVagrant.appendNode('matcher')
                matcherVagrant.appendNode('id', 'org.eclipse.ui.ide.multiFilter')
                matcherVagrant.appendNode('arguments', '1.0-name-matches-false-false-.vagrant')
            }
        }
	wtp {
User expired's avatar
User expired committed
		component {
			contextPath = '/isochrone'
			deployName = 'isochrone'
User expired's avatar
User expired committed
		facet {
			// when tomcat 8 becomes usable in eclipse this jst.web version should be set to 3.1
			//facet name: 'jst.web', version: '3.1'
			facet name: 'jst.web', version: '3.0'
User expired's avatar
User expired committed
			facet name: 'jst.java', version: '1.7'
			facet name: 'wst.jsdt.web', version: '1.0'
eclipse.classpath.file {
	// See: http://stackoverflow.com/questions/12836089/why-is-eclipse-not-attaching-3rd-party-libs-source-files-to-a-wtp-faceted-gradle
	// Chnanges eclipse classpath entries; otherwise no sources for 3rd party jars are shown
	withXml { xml ->
		def node = xml.asNode()
		node.remove( node.find { it.@path == 'org.eclipse.jst.j2ee.internal.web.container' } )
		node.appendNode( 'classpathentry', [ kind: 'con', path: 'org.eclipse.jst.j2ee.internal.web.container', exported: 'true'])
	}

	// See: http://forums.gradle.org/gradle/topics/eclipse_wtp_deploys_testcode_to_server_example_provided
	// Sets output folders for compiled classes and resources... otherwise test classes/resources would be deployed to wtp server
	whenMerged { cp ->
	    cp.entries.findAll { it.path.startsWith("src/main/") }*.output = "bin"
	    cp.entries.findAll { it.path.startsWith("src/test/") }*.output = "bin-test"
	}
findbugs {
	effort = "max"
	ignoreFailures = true
	toolVersion = '2.0.3'
User expired's avatar
User expired committed
publishing {
	publications {
		mavenJava(MavenPublication) {
			from components.java

			artifact javadocJar
			artifact sourcesJar
			artifact staticJar
User expired's avatar
User expired committed
		}
	}

	repositories {
		maven {
			credentials {
				username repositoryUsername
				password repositoryPassword
			}
			url repositoryPrefix + "${isRelease ? 'releases' : 'snapshots'}"
		}
	options {
		listeners << 'org.testng.reporters.XMLReporter'
	}

	//turn off Gradle's HTML report to avoid replacing the
	//reports generated by TestNG library:
	reports.junitXml.enabled = false
	reports.html.enabled = false
Nikolaus Krismer's avatar
Nikolaus Krismer committed

	ignoreFailures = true
test.doFirst {
	// TestNG XMLReporter does not create reportDir (but would fail without it)
	if (!project.testReportDir.isDirectory()) {
		project.testReportDir.mkdirs()
	}
}

User expired's avatar
User expired committed
	boxDir = vagrantDir
	provider = 'virtualbox'
}

User expired's avatar
User expired committed
vagrantDestroy.doFirst {
	if (!vagrantDir.isDirectory()) {
		throw new StopExecutionException()
	}
}

// Custom task definitions

task cleanTestResults(type: Delete) {
	// We only need the test reports... not the binary results
	delete project.testResultsDir
}

User expired's avatar
User expired committed
task javadocJar(type: Jar, dependsOn: javadoc) {
	description = 'Builds a jar file including javadoc'
	from javadoc.destinationDir

	classifier "javadoc"
}

Nikolaus Krismer's avatar
Nikolaus Krismer committed
task jsDoc(type:com.eriwen.gradle.js.tasks.JsDocTask) {
	source = fileTree(dir: 'src/main/webapp/js', include: '**/*.js', excludes: ['**/*.min.js', 'lib/**'])
	destinationDir = file("${buildDir}/docs/jsdoc")
Nikolaus Krismer's avatar
Nikolaus Krismer committed
}

task jsHint(type:com.eriwen.gradle.js.tasks.JsHintTask) {
	jshint.options = [browser: true, expr: true, jquery: true, latedef: 'nofunc', quotmark: 'single', unused: true, undef: true, wsh: true]
	jshint.predef = ['$': false, 'define': false, 'google': false, 'require': false]
	source = fileTree(dir: 'src/main/webapp/js', include: '**/*.js', exclude: ['**/*.min.js', 'lib/**'])
	dest = file("${buildDir}/reports/jshint/main.xml")
	reporter = 'checkstyle'
User expired's avatar
User expired committed
task sourcesJar(type: Jar, dependsOn: classes) {
	description = 'Builds a jar file including sources'
	from sourceSets.main.allSource

	classifier "sources"
}

task staticJar(type: Jar) {
	description = 'Builds a jar file including all libraries'
	from sourceSets.main.output
	from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

	manifest { attributes 'Main-Class': 'de.krismer.tnfp.TrackNumberFromPlaylist' }

	classifier "static"
}

task testSimple(type: Test, dependsOn: testClasses) {
	useTestNG()
	jvmArgs '-Xmx4096m'

	include '**/RunSimple*'
}

User expired's avatar
User expired committed
task vagrantExport(type: Zip) {
	description = 'Builds an archive file that contains the files, needed to create the vagrant box'

	from 'etc/vagrant'

	appendix = ''
	baseName = 'vagrantbox'
	classifier = ''
	version = getDate()
User expired's avatar
User expired committed

	filter(FixCrLfFilter)
	filter(ReplaceTokens, tokens: [db_username: 'myUser', db_password: 'myPassword'])
task vagrantPrepare << {
	description = 'Prepares the vagrant environment (creates directory, copies Vagrantfile, ...)'

	if (!vagrantDir.isDirectory()) {
		println "Creating directory $vagrantDir and copying content"
User expired's avatar
User expired committed
		vagrantDir.mkdirs()
		sync {
			from files('etc/vagrant')
			into vagrantDir
			filter(FixCrLfFilter)
			filter(ReplaceTokens, tokens: [db_username: 'niko', db_password: 'secretPhdPassword#2014!'])
tasks.jsDoc.dependsOn tasks.processResources
tasks.jsHint.dependsOn tasks.processResources
tasks.test.finalizedBy tasks.cleanTestResults
tasks.vagrantUp.dependsOn tasks.vagrantPrepare

// CI tasks
User expired's avatar
User expired committed
task jarAll(dependsOn: [jar, javadocJar, sourcesJar, staticJar])
task buildAll(dependsOn: [jarAll, build])
Nikolaus Krismer's avatar
Nikolaus Krismer committed
task daily(dependsOn: [asciidoctor, check, jsHint, javadoc, jsDoc, jarAll, war])