| /** |
| * 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. |
| */ |
| |
| |
| 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' |
| project.ext["archivesBaseName"] = "$project.name" |
| project.ext["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' |
| apply plugin:'application' |
| |
| /* Set Java version. */ |
| sourceCompatibility = 1.6 |
| targetCompatibility = 1.6 |
| |
| repositories { |
| mavenCentral() |
| mavenLocal() |
| mavenRepo name: "gson", url: "http://google-gson.googlecode.com/svn/mavenrepo" |
| |
| /* Add lib dir as a repo. Some jar files that are not available |
| in a public repo are distributed in the lib dir. */ |
| flatDir name: 'libDir', dirs: "$rootDir/lib" |
| } |
| |
| /* All project libraries must be defined here. */ |
| project.ext["libraries"] = [ |
| // for instance, adding twitter4j 2.2.5 will be: |
| //twitter4j_core: 'org.twitter4j:twitter4j-core:2.2.5' |
| // http://mvnrepository.com/ is a good source |
| // if you need to use a different repository, please specify it in the above "repositories" block |
| |
| // you always need the s4 libraries for building your app |
| s4_base: 'org.apache.s4:s4-base:'+ s4Version, |
| s4_comm: 'org.apache.s4:s4-comm:'+ s4Version, |
| s4_core: 'org.apache.s4:s4-core:'+ s4Version |
| ] |
| |
| |
| dependencies { |
| |
| /* S4 Platform. We only need the API, not the transitive dependencies. */ |
| |
| compile (libraries.s4_base) |
| compile (libraries.s4_comm) |
| compile (libraries.s4_core) |
| |
| // if you need to use the twitter4j lib defined above, you must reference it here as a dependency |
| // compile (libraries.twitter4j_core) |
| |
| |
| } |
| |
| // 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' |
| 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 { println 'Adding to s4 archive: ' + it.name } |
| |
| checkAppClass() |
| } |
| |
| task cp << { |
| description='Dumps the classpath for running a class from this project, into a \'classpath.txt\' file in the current directory' |
| new File("classpath.txt").write(sourceSets.main.output.classesDir.path + File.pathSeparator + <s4_install_dir> + '/lib/*' + File.pathSeparator + <s4_install_dir> + '/subprojects/s4-tools/build/install/s4-tools/lib/*') |
| } |
| |
| /*Check whether the defined appClass exists and extends App*/ |
| void checkAppClass() { |
| |
| def loader = this.getClass().getClassLoader() |
| |
| def jardir = new File( project.libsDir.path,'lib' ) |
| def jars = jardir.listFiles().findAll { it.name.endsWith('.jar') } |
| jars.each { |
| loader.addURL(it.toURI().toURL()) |
| } |
| |
| def appJar = project.libsDir.path+"/app/"+"$project.name"+".jar" |
| loader.addURL(new URL("file://"+appJar)) |
| |
| def userClass = Class.forName(appClassName, true, this.getClass().getClassLoader()) |
| def appClass = Class.forName('org.apache.s4.core.App', true, this.getClass().getClassLoader()) |
| |
| if (!(appClass.isAssignableFrom(userClass))){ |
| throw new InvalidUserDataException("App class " + appClassName + " does not extend org.apache.s4.core.App") |
| } |
| |
| } |
| |