Commit 902fd7ff authored by Christian Meyer's avatar Christian Meyer
Browse files

CHANGES file from git tags is part of simulation distribution

ZmtDeployPlugin.groovy
    moved code for obtaining changes from git to CreateChanges
ZmtSimulationPlugin.groovy
    adds createChangesFile task and its output to the distribution
    updated test
parent 13cd2e07
...@@ -11,7 +11,8 @@ import org.gradle.api.* ...@@ -11,7 +11,8 @@ import org.gradle.api.*
public class ZmtDeployPlugin implements Plugin<Project> { public class ZmtDeployPlugin implements Plugin<Project> {
private static final def CONFIGURE = { private static final def CONFIGURE = {
apply plugin: "org.hidetake.ssh" apply plugin: "org.hidetake.ssh"
apply plugin: "distribution"
remotes { remotes {
dochost { dochost {
host = determineCredentials.host host = determineCredentials.host
...@@ -20,46 +21,28 @@ public class ZmtDeployPlugin implements Plugin<Project> { ...@@ -20,46 +21,28 @@ public class ZmtDeployPlugin implements Plugin<Project> {
password = credentials.dochostPw password = credentials.dochostPw
} }
} }
task('deployZip') { task('deployZip') {
group = 'Upload' group = 'Upload'
description = 'Uploads zip distribution to dochost.' description = 'Uploads zip distribution to dochost.'
dependsOn distZip, determineCredentials dependsOn distZip, determineCredentials
}
doLast {
deployZip.doLast { println "\nConnecting to ${remotes.dochost.host}..."
println "\nConnecting to ${remotes.dochost.host}..." ssh.run {
ssh.run { session(remotes.dochost) {
session(remotes.dochost) { def remoteTargetDir = determineCredentials.wwwPath + 'dist'
def remoteTargetDir = determineCredentials.wwwPath + 'dist'
// create target directory on remote
// create target directory on remote execute "mkdir -p ${remoteTargetDir}"
execute "mkdir -p ${remoteTargetDir}"
put from: distZip.archivePath, into: remoteTargetDir
put from: distZip.archivePath, into: remoteTargetDir }
// create CHANGES file from git version list
put text: obtainVersionListFromGit(project), into: remoteTargetDir + '/CHANGES'
} }
} }
} }
} }
private static String obtainVersionListFromGit(Project project) {
def output = new ByteArrayOutputStream()
try {
project.exec {
commandLine 'git', 'tag', '-n99'
standardOutput = output
}
}
catch (org.gradle.process.internal.ExecException e) {
println "git tag for ${project.name} failed. Cannot obtain version list."
return ''
}
return output.toString().trim()
}
@Override @Override
void apply(Project project) { void apply(Project project) {
project.configure(project, CONFIGURE) project.configure(project, CONFIGURE)
......
package de.zmt.gradle; package de.zmt.gradle;
import org.gradle.api.* import org.gradle.api.*
import de.zmt.gradle.task.*;
/* /*
* Meta plugin applying all necessary plugins for ZMT simulations * Meta plugin applying all necessary plugins for ZMT simulations
...@@ -16,6 +17,14 @@ public class ZmtSimulationPlugin implements Plugin<Project> { ...@@ -16,6 +17,14 @@ public class ZmtSimulationPlugin implements Plugin<Project> {
apply(plugin: ZmtEclipsePlugin) apply(plugin: ZmtEclipsePlugin)
apply(plugin: ZmtLaunchConfigPlugin) apply(plugin: ZmtLaunchConfigPlugin)
apply(plugin: ZmtShortcutPlugin) apply(plugin: ZmtShortcutPlugin)
task('createChangesFile', type: CreateChanges) {
description = 'Creates a CHANGES file from git tags.'
}
distributions.main.contents {
from (project.createChangesFile)
}
} }
@Override @Override
......
package de.zmt.gradle.task;
import org.gradle.api.*;
import org.gradle.api.tasks.*;
public class CreateChanges extends DefaultTask {
@OutputFile
File outputFile = project.file("$project.buildDir/tmp/CHANGES")
@TaskAction
public void createChangesFile() {
try {
project.exec {
commandLine 'git', 'tag', '-n99'
standardOutput = new FileOutputStream(outputFile)
}
}
catch (org.gradle.process.internal.ExecException e) {
println "git tag for ${project.name} failed. Cannot obtain version list."
}
}
}
...@@ -3,6 +3,7 @@ package de.zmt.gradle ...@@ -3,6 +3,7 @@ package de.zmt.gradle
import org.gradle.api.* import org.gradle.api.*
import org.junit.* import org.junit.*
import org.gradle.testfixtures.ProjectBuilder import org.gradle.testfixtures.ProjectBuilder
import de.zmt.gradle.task.*;
import static org.junit.Assert.* import static org.junit.Assert.*
...@@ -22,6 +23,7 @@ class ZmtSimulationPluginTest { ...@@ -22,6 +23,7 @@ class ZmtSimulationPluginTest {
assertTrue(plugins.hasPlugin(ZmtEclipsePlugin.class)) assertTrue(plugins.hasPlugin(ZmtEclipsePlugin.class))
assertTrue(plugins.hasPlugin(ZmtLaunchConfigPlugin.class)) assertTrue(plugins.hasPlugin(ZmtLaunchConfigPlugin.class))
assertTrue(plugins.hasPlugin(ZmtShortcutPlugin.class)) assertTrue(plugins.hasPlugin(ZmtShortcutPlugin.class))
assertTrue(createChangesFile instanceof CreateChanges)
} }
project.evaluate() project.evaluate()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment