Permalink
Browse files

Add publishSchema task

  • Loading branch information...
1 parent 70cb55e commit 522c0d1a4696c941dc36bd6210081e042efcd48f @cbeams cbeams committed Nov 9, 2010
Showing with 63 additions and 0 deletions.
  1. +63 −0 schema-publication.gradle
View
@@ -0,0 +1,63 @@
+apply from: "$rootDir/buildSrc/preconditions.gradle"
+
+checkForProps(taskPath: project.path + ':publishSchema',
+ requiredProps: ['sshHost', 'sshUsername', 'sshPrivateKey', 'remoteDocRoot'])
+
+configurations { scpAntTask }
+dependencies { scpAntTask("org.apache.ant:ant-jsch:1.8.1") }
+
+/**
+ * @author Chris Beams
+ */
+task publishSchema << {
+ def props = new Properties()
+ def file = new File("${projectDir}/src/main/resources/META-INF/spring.schemas")
+ if (file.exists()) {
+ file.withInputStream {
+ stream -> props.load(stream)
+ }
+ }
+
+ if (!props.size()) {
+ return
+ }
+
+ project.ant {
+ taskdef(name: 'scp',
+ classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
+ classpath: configurations.scpAntTask.asPath)
+ taskdef(name: 'sshexec',
+ classname: 'org.apache.tools.ant.taskdefs.optional.ssh.SSHExec',
+ classpath: configurations.scpAntTask.asPath)
+
+ for (def key : props.keySet()) {
+ // process only explicitly-versioned entries in the file
+ // we'll deal with symlinking to the latest released version
+ // later below
+ // e.g.:
+ // spring-integration-2.0.xsd
+ // but not:
+ // spring-integration.xsd
+ if (key =~ /\d\.xsd/) {
+ // key entries are formatted as http://www.springframework.org/schema/...
+ // strip the protocol and domain, leaving just the path from 'schema' on
+ def remotePath = key.substring(key.indexOf('schema/'))
+ sshexec(keyfile: sshPrivateKey,
+ host: sshHost,
+ username: sshUsername,
+ command: "mkdir -p `dirname ${remoteDocRoot}/${remotePath}`")
+ scp(keyfile: sshPrivateKey,
+ file: "src/main/resources/${props.get(key)}",
+ todir: "${sshUsername}@${sshHost}:${remoteDocRoot}/${remotePath}")
+ }
+ }
+ }
+
+ /*
+ def firstKey = props.keySet().iterator().next()
+ def path = firstKey.substring(firstKey.indexOf('schema/'))
+ def symlinkPath = (path =~ /-\d\.\d/).replaceFirst('')
+
+ println "sshexec ln -s wtf ${symlinkPath}"
+ */
+}

0 comments on commit 522c0d1

Please sign in to comment.