You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/01/24 23:07:18 UTC

svn commit: r1235524 - in /tapestry/tapestry5/branches/5.3: md5.gradle ssh.gradle

Author: hlship
Date: Tue Jan 24 22:07:18 2012
New Revision: 1235524

URL: http://svn.apache.org/viewvc?rev=1235524&view=rev
Log:
Ah, another couple of missing files. Looks like I'll never learn.

Added:
    tapestry/tapestry5/branches/5.3/md5.gradle
    tapestry/tapestry5/branches/5.3/ssh.gradle

Added: tapestry/tapestry5/branches/5.3/md5.gradle
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.3/md5.gradle?rev=1235524&view=auto
==============================================================================
--- tapestry/tapestry5/branches/5.3/md5.gradle (added)
+++ tapestry/tapestry5/branches/5.3/md5.gradle Tue Jan 24 22:07:18 2012
@@ -0,0 +1,25 @@
+import java.security.MessageDigest
+
+class GenMD5 extends SourceTask {
+
+  def outputDir
+
+  @OutputDirectory
+  File getOutputDir() { project.file(outputDir) }
+
+  @TaskAction
+  void writeMD5s() {
+
+    source.each { file ->
+      MessageDigest digest = MessageDigest.getInstance("MD5")
+
+      digest.update(file.bytes)
+
+      def checksum = new BigInteger(1, digest.digest()).toString(16).padLeft(32, "0")
+
+      new File(outputDir, file.name + ".md5").text = checksum
+    }
+  }
+}
+
+project.GenMD5 = GenMD5.class

Added: tapestry/tapestry5/branches/5.3/ssh.gradle
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.3/ssh.gradle?rev=1235524&view=auto
==============================================================================
--- tapestry/tapestry5/branches/5.3/ssh.gradle (added)
+++ tapestry/tapestry5/branches/5.3/ssh.gradle Tue Jan 24 22:07:18 2012
@@ -0,0 +1,124 @@
+project.Scp = Scp.class
+project.SshExec = SshExec.class
+project.SshTask = SshTask.class
+
+configurations {
+  sshAntTask
+}
+
+dependencies {
+  sshAntTask "org.apache.ant:ant-jsch:1.8.2"
+}
+
+tasks.withType(SshTask) {
+  sshAntClasspath = configurations.sshAntTask
+}
+
+class SshTask extends DefaultTask {
+  @InputFiles
+  FileCollection sshAntClasspath
+
+  @Input
+  String host
+
+  @Input
+  String userName
+
+  @Input
+  String password
+
+  boolean verbose = false
+
+  private boolean antInited = false
+
+  protected initAnt() {
+    if (!antInited) {
+      ant.taskdef(name: 'scp',
+        classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
+        classpath: sshAntClasspath.asPath,
+        loaderref: 'ssh')
+      ant.taskdef(name: 'sshexec',
+        classname: 'org.apache.tools.ant.taskdefs.optional.ssh.SSHExec',
+        classpath: sshAntClasspath.asPath,
+        loaderref: 'ssh')
+      antInited = true
+    }
+  }
+
+  protected withInfoLogging(Closure action) {
+    def oldLogLevel = logging.level
+    logging.level = [LogLevel.INFO, oldLogLevel].min()
+    try {
+      action()
+    } finally {
+      if (oldLogLevel) {
+        logging.level = oldLogLevel
+      }
+    }
+  }
+
+  def scpFile(source, destination) {
+    initAnt()
+    withInfoLogging {
+      ant.scp(localFile: project.files(source).singleFile, remoteToFile: "${userName}@${host}:${destination}", password: password, verbose: verbose)
+    }
+  }
+
+  def scpDir(source, destination) {
+    initAnt()
+    withInfoLogging {
+      ant.sshexec(host: host, username: userName, password: password, command: "mkdir -p ${destination}")
+      ant.scp(remoteTodir: "${userName}@${host}:${destination}", password: password, verbose: verbose) {
+        project.files(source).addToAntBuilder(ant, "fileSet", FileCollection.AntType.FileSet)
+      }
+    }
+  }
+
+  def ssh(Object... commandLine) {
+    initAnt()
+    withInfoLogging {
+      ant.sshexec(host: host, username: userName, password: password, command: commandLine.join(' '))
+    }
+  }
+}
+
+class Scp extends SshTask {
+  @InputFiles @SkipWhenEmpty source
+  @Input destination
+  boolean isDir = false
+
+  @TaskAction
+  void doActions() {
+    if (isDir) {
+      scpDir(source, destination)
+      return
+    }
+
+    project.files(source).each { doFile(it) }
+  }
+
+  void doFile(File file) {
+
+    if (file.directory) {
+      file.eachFile { doFile(it) }
+    } else {
+      scpFile(file, destination)
+    }
+  }
+}
+
+class SshExec extends SshTask {
+  @Input
+  List<String[]> commandLines = []
+
+  void commandLine(String... commandLine) {
+    commandLines << commandLine
+  }
+
+  @TaskAction
+  void doActions() {
+    commandLines.each { commandLine ->
+      ssh(* commandLine)
+    }
+  }
+}
\ No newline at end of file