blob: e7f6a9fb9055cb7e3ee25c8870c1983c45a6a65e [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Apache S4 Application Build File
*
* Use this script to buils and package S4 apps.
*
* Run 'gradle install' on the s4 project to publish to your local maven repo.
*
* TODO: This should probably be distributed as an s4 plugin for Gradle.
* TODO: There seem to be to be similarities with the war and jetty plugins. (war -> s4r, jetty -> s4Run).
* We should make it easy to test the app from this script by a running a test task that starts and stops
* an s4 server. See: http://www.gradle.org/releases/1.0-milestone-3/docs/userguide/userguide_single.html#war_plugin
*
* This is an interesting discussion:
* http://gradle.1045684.n5.nabble.com/Exclude-properties-file-from-war-td3365147.html
*
*/
/* Set the destination where we want to install the apps. */
//s4AppInstallDir = "/tmp/s4Apps" // TODO: decide how to standarize dirs, use env var?
project.ext["appClassName"] = hasProperty('appClass')? "$appClass": "UNDEFINED"
project.ext["appName"] = hasProperty('appName')? "$appName": "UNDEFINED"
project.ext["s4Version"] = '0.6.0-incubating'
description = 'Apache S4 App'
archivesBaseName = "$project.name"
distRootFolder = "$archivesBaseName-${-> version}"
// Append the suffix 'SNAPSHOT' when the build is not for release.
version = new Version(major: 0, minor: 0, bugfix: 0, isRelease: false)
group = 'org.apache.s4'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
/* Set Java version. */
sourceCompatibility = 1.6
targetCompatibility = 1.6
/* All project libraries must be defined here. */
project.ext["libraries"] = [
guava: 'com.google.guava:guava:12.0.1',
gson: 'com.google.code.gson:gson:1.6',
guice: 'com.google.inject:guice:3.0',
guice_assist: 'com.google.inject.extensions:guice-assistedinject:3.0',
kryo: 'com.googlecode:kryo:1.04',
netty: 'org.jboss.netty:netty:3.2.5.Final',
mockito_core: 'org.mockito:mockito-core:1.9.0',
commons_config: 'commons-configuration:commons-configuration:1.6',
commons_codec: 'commons-codec:commons-codec:1.4',
commons_coll: 'net.sourceforge.collections:collections-generic:4.01', // Use this lib until the commons collection with Generics is released.
slf4j: 'org.slf4j:slf4j-api:1.6.1',
logback_core: 'ch.qos.logback:logback-core:0.9.29',
logback_classic: 'ch.qos.logback:logback-classic:0.9.29',
zk: 'org.apache.zookeeper:zookeeper:3.3.1',
jcip: 'net.jcip:jcip-annotations:1.0',
junit: 'junit:junit:4.10',
zkclient: 'com.github.sgroschupf:zkclient:0.1',
diezel: 'net.ericaro:diezel-maven-plugin:1.0.0-beta-4',
jcommander: 'com.beust:jcommander:1.25',
gradle_base_services: 'org.gradle:gradle-base-services:1.0',
gradle_core: 'org.gradle:gradle-core:1.0',
gradle_tooling_api: 'org.gradle:gradle-tooling-api:1.0',
gradle_wrapper: 'org.gradle:gradle-wrapper:1.0'
]
dependencies {
compile project(":s4-base")
compile project(":s4-comm")
compile project(":s4-core")
/* Logging. */
compile( libraries.slf4j )
compile( libraries.logback_core )
compile( libraries.logback_classic )
/* Commons. */
compile( libraries.commons_config )
compile( libraries.commons_coll )
/* Misc. */
compile( libraries.jcip )
compile ( libraries.zkclient)
/* Testing. */
testCompile( libraries.junit )
}
// Set the manifest attributes for the S4 archive here. ('S4-App-Class': gets set by the s4r task)
manifest.mainAttributes(
provider: 'gradle',
'Implementation-Url': 'http://incubator.apache.org/projects/s4.html',
'Implementation-Version': version,
'Implementation-Vendor': 'Apache S4',
'Implementation-Vendor-Id': 's4app',
'S4-App-Class':'',
'S4-Version': s4Version
)
project.ext["appDependencies"] = ( configurations.compile )
// external dependencies will be available in the /lib directory of the s4r
task copyDependenciesToLib(type: Copy) {
into project.libsDir.path+"/lib"
from configurations.runtime
}
// app jar will be available from the /app directory of the s4r
task buildProjectJar() {
dependsOn jar {
destinationDir file(project.libsDir.path + "/app")
from sourceSets.main.output
}
}
/* This task will extract all the class files and create a fat jar. We set the manifest and the extension to make it an S4 archive file. */
// TODO: exclude schema files as needed (not critical) see: http://forums.gradle.org/gradle/topics/using_gradle_to_fat_jar_a_spring_project
// TODO: exclude s4 platform jars
task s4r(type: Jar) {
dependsOn cleanCopyDependenciesToLib, copyDependenciesToLib, cleanBuildProjectJar, buildProjectJar
from { project.libsDir }
manifest = project.manifest
baseName = appName
extension = 's4r'
exclude '*.s4r'
println ( hasProperty("appClass") ? "$appClass" : "UNDEFINED")
manifest.mainAttributes('S4-App-Class': appClassName)
}
/* List the artifacts that will br added to the s4 archive (and explode if needed). */
s4r << {
appDependencies.each { File file -> println 'Adding to s4 archive: ' + file.name }
configurations.archives.allArtifacts.files.each { File file -> println 'Adding to s4 archive: ' + file.name }
/* This is for debugging. */
//configurations.s4All.each { File file -> println 's4All: ' + file.name }
//deployableDependencies.each { File file -> println 'Deploy: ' + file.name }
// more debugging statements.
//sourceSets.main.compileClasspath.each { File file -> println 'compileClasspath: ' + file.name }
}
/* Parse source file to get the app classname so we can use it in the manifest.
* TODO: Use a real Java parser. (This is not skippong comments for example.)
*/
def getAppClassname(file) {
def classname = "UNKNOWN"
def lines= file.readLines()
def packageName=""
for(line in lines) {
def pn = line =~ /.*package\s+([\w\.]+)\s*;.*/
if(pn) {
packageName = pn[0][1] + "."
}
def an = line =~ /.*public\s+class\s+(\w+)\s+extends.+App.*\{/
if (an) {
classname = packageName + an[0][1]
println "Found app class name: " + classname
break
}
}
classname
}
class Version {
int major
int minor
int bugfix
boolean isRelease
String toString() {
"$major.$minor.$bugfix${isRelease ? '' : '-SNAPSHOT'}"
}
}