Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
build.gradle 5.43 KiB
apply plugin: 'asciidoctor'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'java'
apply plugin: 'jetty'
apply plugin: 'maven-publish'
apply plugin: 'vagrant'
apply plugin: 'war'
apply plugin: 'wrapper'

import org.apache.tools.ant.filters.FixCrLfFilter
import org.apache.tools.ant.filters.ReplaceTokens

group = 'it.unibz.inf.isochrones'
version = '1.1-SNAPSHOT'

description = 'PhD project of Nikolaus Krismer'

def getDate() {
    def date = new Date()
    def formattedDate = date.format('yyyyMMdd')
    return formattedDate
}

ext {
	defaultVersion = '0.3-SNAPSHOT'
	isRelease = false
//	vagrantDirString = System.properties['user.home'] + '/vagrantboxes/' + project.name.toLowerCase()
	vagrantDirString = '/media/data/VMs/vagrantboxes/' + project.name.toLowerCase()
	vagrantDir = file("$vagrantDirString")
}

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 {
	mavenCentral()
	maven { url "http://maven.geo-solutions.it" }
}

buildscript {
	apply from: 'http://www.krismer.de/files/checkstyle.gradle'

	repositories {
		jcenter()
		maven { url 'http://dl.bintray.com/content/aalmiray/asciidoctor'}
	}

	dependencies {
		classpath 'org.gradle.api.plugins:gradle-vagrant-plugin:0.2'
		classpath 'org.asciidoctor:asciidoctor-gradle-plugin:0.7.0'
	}
}

dependencies {
	compile group: 'org.postgresql', name: 'postgresql', version:'9.3-1100-jdbc41'
	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'
	compile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
	compile group: 'org.cometd.java', name: 'bayeux-api', version:'2.7+'
	compile group: 'org.cometd.java', name: 'cometd-java-server', version:'2.7+'
	compile group: 'org.cometd.javascript', name: 'cometd-javascript-jquery', version:'2.7+'
	compile(group: 'org.eclipse.jetty', name: 'jetty-servlets', version:'8+') {
		exclude(module: 'jetty-client')
	}
	compile group: 'org.json', name: 'json', version:'20131018'
	compile(group: 'org.postgis', name: 'postgis-jdbc', version:'1.3+') {
		exclude(module: 'postgis-stubs')
	}

	testCompile 'org.testng:testng:6+'
}

asciidoctor {
	backend = 'html5'
	sourceDir = file('doc')
	outputDir = file("$buildDir/docs/asciidoctor")
}

checkstyle {
	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'
		]
	}

	wtp {
		component {
			contextPath = '/isochrones'
		}

		facet {
			facet name: 'jst.web', version: '3.0'
			facet name: 'jst.java', version: '1.7'
		}
	}
}

publishing {
	publications {
		mavenJava(MavenPublication) {
			from components.java

			artifact javadocJar
			artifact sourcesJar
			artifact staticJar
			artifact war
		}
	}

	repositories {
		maven {
			credentials {
				username repositoryUsername
				password repositoryPassword
			}
			url repositoryPrefix + "${isRelease ? 'releases' : 'snapshots'}"
		}
	}
}

test {
	useTestNG()
}

vagrant {
	boxDir = vagrantDir
	provider = 'virtualbox'
}

vagrantDestroy.doFirst {
	if (!vagrantDir.isDirectory()) {
		throw new StopExecutionException()
	}
}

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

	classifier "javadoc"
}

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*'
}

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()

	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"
		vagrantDir.mkdirs()
	}

	sync {
		from files('etc/vagrant')
		into vagrantDir

		filter(FixCrLfFilter)
    	filter(ReplaceTokens, tokens: [db_username: 'niko', db_password: 'secretPhdPassword#2013!', shared_conf_dir: '/vagrant/conf'])
	}
}

vagrantUp.dependsOn(vagrantPrepare)

task jarAll(dependsOn: [jar, javadocJar, sourcesJar, staticJar])

task buildAll(dependsOn: [jarAll, build])