import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact
import org.gradle.api.artifacts.PublishArtifact
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.Configuration
import org.gradle.api.internal.artifacts.dsl.dependencies.ModuleDependencyFactory
import org.gradle.api.internal.AsmBackedClassGenerator
import groovy.swing.SwingBuilder
import javax.swing.*
import java.awt.Dimension
import groovy.beans.Bindable
import java.util.regex.Pattern
import java.util.Properties
defaultTasks 'showGui'
apply plugin: 'war'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
project.convention.plugins.addoninfo = new AddOnInfo()
task generateAddOnInfo {
outputFile = new File(buildDir, 'tmp/war/META-INF/addon-info.xml')
afterEvaluate {
inputs.properties project.convention.plugins.addoninfo.properties
outputs.file outputFile
}
doLast {
def props = project.convention.plugins.addoninfo.properties
if (props.any { key, value -> value != null }) {
def text = '\r\n'
props.each { key, value ->
if (value) text += " <$key>$value$key>\r\n"
}
text += ''
outputFile.parentFile.mkdirs()
outputFile.text = text
}
else
outputFile.delete()
}
}
war {
dependsOn generateAddOnInfo
inputs.files generateAddOnInfo.outputFile, 'LICENSE.txt'
// lower-case'ify the war name to simplify usage in a web browser (which is case-sensitive)
archiveName = war.baseName.toLowerCase() + '.war'
// include addon-info.xml in binary
from(generateAddOnInfo.outputFile) {
into 'META-INF'
}
// include license in binary
from('LICENSE.txt') {
into 'WEB-INF'
}
}
// not intended to be used directly. This is the default task for the script. This allows
// the user to "double-click" on 'gradlew' and have the GUI launch.
task showGui(description: 'Starts a graphical user interface for the build') << {
org.gradle.gradleplugin.userinterface.swing.standalone.BlockingApplication.launchAndBlock();
}
// Helper method to get the installation root directory of the server. This method will either
// return whatever is in the 'serverRootDir' property (if it's set) ...
File getServerDir() {
if (!hasProperty('serverRootDir')) {
serverRootDir = null
Properties props = new Properties()
File optionsFile = new File('build.options')
if (optionsFile.exists()) {
optionsFile.withReader { props.load(it) }
serverRootDir = props.getProperty('serverRootDir')
}
if (serverRootDir == null) {
File dir = pickServerDir()
if (dir == null)
throw new Exception("""serverRootDir property (path to webctrl install directory) not set.
Please set the serverRootDir property on the command line (-PserverRootDir=
) or in the userHome/.gradle/gradle.properties file.""")
serverRootDir = dir.absolutePath.replaceAll('\\\\', '/')
props.setProperty('serverRootDir', serverRootDir)
optionsFile.withWriter { props.store(it, null) }
}
}
return new File(serverRootDir)
}
// Helper methods to get the directory in which to deploy webapps (add-ons).
File getDeployLoc() { new File(getServerDir(), 'webserver/webapps/'+war.baseName.toLowerCase()) }
// task that deletes the .war (and exploded dir) from the webserver
task cleanDeploy(description: 'Deletes the war from the webserver', overwrite: true, type:Delete)
cleanDeploy.doFirst { delete getDeployLoc() }
// task that builds and deploys the .war to the webserver
task deploy(description: 'Deploys the war to the webserver', type: Sync, dependsOn:war) {
doFirst {
println "Deploying $war.baseName to ${getDeployLoc().canonicalPath}"
}
from zipTree(war.archivePath)
into { getDeployLoc() }
}
// have build tell you where the archive was put!
build.doLast {
println "War created as ${war.archivePath}"
}
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-3'
jarFile = file('wrapper/gradle-wrapper.jar')
archiveBase = Wrapper.PathBase.GRADLE_USER_HOME
}
File pickServerDir() {
def serverDir = null;
def builder = new SwingBuilder()
builder.registerBeanFactory('folderChooser', com.jidesoft.swing.FolderChooser)
builder.build {
frame(id: 'mainframe', title:'Pick Server Root Dir', defaultCloseOperation:JFrame.EXIT_ON_CLOSE, size:[440,440], locationRelativeTo: null, show: true) {
panel(border: emptyBorder(10)) {
boxLayout axis: BoxLayout.Y_AXIS
panel {
boxLayout axis: BoxLayout.X_AXIS
label text: 'In order to deploy the add-on to the server (and to run some tests), the build needs to know where the root directory of the server is located.'
}
rigidArea size: new Dimension(0, 10)
panel {
boxLayout axis: BoxLayout.Y_AXIS
panel {
boxLayout axis: BoxLayout.X_AXIS
label text: 'Server root dir:'
hglue()
}
rigidArea size: new Dimension(0, 5)
panel {
boxLayout axis: BoxLayout.X_AXIS
folderChooser id: 'driverDirChooser', currentDirectory: new File('.'), navigationFieldVisible: false, controlButtonsAreShown: false, availableButtons: 0, recentListVisible: false
hglue()
}
}
rigidArea size: new Dimension(0, 10)
panel {
boxLayout axis: BoxLayout.X_AXIS
hglue()
button text: 'Accept', actionPerformed: {
serverDir = builder.driverDirChooser.selectedFolder
dispose()
}
hglue()
button text: 'Cancel', actionPerformed: {
dispose()
}
hglue()
}
}
}
}
// block until the gui is closed
while (builder.mainframe.isVisible()) {
Thread.sleep(100)
}
return serverDir
}
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.6'
languageLevel = '1.6'
}
}
buildscript {
repositories { mavenRepo url: 'http://download.java.net/maven/2/' }
dependencies { classpath group: 'com.jidesoft', name: 'jide-oss', version: '2.9.0' }
}
// Support for addon-info.xml
class AddOnInfo {
def String name
def String description
def String version
def String vendor
void info(Closure c) {
c.setDelegate(this)
c.setResolveStrategy Closure.DELEGATE_ONLY
c()
}
Map getProperties() {
[ name:name, description:description, version:version, vendor:vendor ]
}
}