Commit a0871070 authored by Christian Meyer's avatar Christian Meyer
Browse files

ZmtShortcutPlugin.groovy: adds shortcut to ./bin/launcher

    updated README
replaced CreateReadme with more generic CreateFile.groovy
    updated ZmtSimulationPlugin and test
added run-launcher, run-launcher.bat to resources
parent 10f906f6
......@@ -3,6 +3,7 @@ package de.zmt.gradle;
import org.gradle.api.*
import java.nio.file.*
import java.nio.file.attribute.PosixFilePermissions
import de.zmt.gradle.task.*;
/**
* Plugin for simulations based on zmt-core.
......@@ -13,7 +14,8 @@ import java.nio.file.attribute.PosixFilePermissions
public class ZmtShortcutPlugin implements Plugin<Project> {
private static final def SEPARATOR = '-'
private static final def SHORTCUT_PREFIX = 'run'
private static final def SHORTCUT_SUFFIX = 'with-gui'
private static final def SHORTCUT_LAUNCHER_SUFFIX = 'launcher'
private static final def SHORTCUT_GUI_SUFFIX = 'with-gui'
private static final def SUFFIX_WIN = '.bat'
private static final def TEMPLATE_ENGINE = new groovy.text.SimpleTemplateEngine()
......@@ -24,21 +26,40 @@ public class ZmtShortcutPlugin implements Plugin<Project> {
// create shortcuts
def shortcutDir = Files.createTempDirectory('shortcuts')
afterEvaluate {
def unixShortcut = createLauncherShortcut(project, SHORTCUT_PREFIX, SHORTCUT_SUFFIX, shortcutDir)
// TODO create task for doing that
def unixShortcut = createShortcut(project, SHORTCUT_PREFIX, SHORTCUT_GUI_SUFFIX, shortcutDir)
// set +x permissions if possible
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
Files.setPosixFilePermissions(unixShortcut, PosixFilePermissions.fromString('rwxr-xr-x'))
}
createLauncherShortcut(project, SHORTCUT_PREFIX, SHORTCUT_SUFFIX + SUFFIX_WIN, shortcutDir)
createShortcut(project, SHORTCUT_PREFIX, SHORTCUT_GUI_SUFFIX + SUFFIX_WIN, shortcutDir)
}
task('createLauncherShortcutUnix', type: CreateFile) {
resourceName = SHORTCUT_PREFIX + SEPARATOR + SHORTCUT_LAUNCHER_SUFFIX
clazz = ZmtShortcutPlugin.class
doLast {
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
Files.setPosixFilePermissions(outputDir.toPath().resolve(resourceName), PosixFilePermissions.fromString('rwxr-xr-x'))
}
}
}
task('createLauncherShortcutWin', type: CreateFile) {
resourceName = createLauncherShortcutUnix.resourceName + SUFFIX_WIN
clazz = ZmtShortcutPlugin.class
}
distributions.main.contents {
from (shortcutDir.toFile())
from (createLauncherShortcutUnix)
from (createLauncherShortcutWin)
}
}
/**
* Creates a launcher shortcut script. The template script is loaded
* Creates a shortcut script from template. The template script is loaded
* from given file name, processed to match the current project
* and saved to the given directory.
*
......@@ -48,7 +69,7 @@ public class ZmtShortcutPlugin implements Plugin<Project> {
* @param directory the directory where to save the resulting file
* @return the path to the resulting file
*/
private static Path createLauncherShortcut(Project project, String prefix, String suffix, Path directory) {
private static Path createShortcut(Project project, String prefix, String suffix, Path directory) {
def simClassName = ZmtLaunchConfigPlugin.findSimClassName(project)
// add sim name to shortcut
Path shortcut = Files.createFile(directory.resolve(prefix + SEPARATOR + simClassName + SEPARATOR + suffix))
......
......@@ -22,7 +22,8 @@ public class ZmtSimulationPlugin implements Plugin<Project> {
description = 'Creates a CHANGES file from git tags.'
}
task('createReadmeFile', type: CreateReadme) {
task('createReadmeFile', type: CreateFile) {
resourceName = 'README'
description = 'Creates the README file.'
}
......
package de.zmt.gradle.task;
import org.gradle.api.*;
import org.gradle.api.tasks.*;
/**
* Simple task that creates a file loaded from resource.
*/
public class CreateFile extends DefaultTask {
def resourceName
def clazz = CreateFile.class
@OutputDirectory
def outputDir = project.file("$project.buildDir/tmp/")
@TaskAction
public void createFile() {
outputDir.toPath().resolve(resourceName).append(clazz.getResourceAsStream(resourceName))
}
}
package de.zmt.gradle.task;
import org.gradle.api.*;
import org.gradle.api.tasks.*;
public class CreateReadme extends DefaultTask {
@OutputFile
File outputFile = project.file("$project.buildDir/tmp/README")
@TaskAction
public void createReadmeFile() {
outputFile.append(CreateReadme.class.getResourceAsStream('README'))
}
}
#!/usr/bin/env bash
##############################################################################
##
## shortcut for UN*X to launcher
## to be able to conveniently run the launcher from main directory
##
##############################################################################
./bin/launcher "$@"
@rem ##########################################################################
@rem
@rem shortcut for Windows to launcher
@rem to be able to conveniently run the launcher from main directory
@rem
@rem ##########################################################################
.\\bin\\launcher.bat %*
......@@ -7,10 +7,13 @@ Contents of distribution:
Libraries of simulations and those which they depend on.
README
this file
launch-with-gui
shortcut for running the launcher with the simulation in GUI-mode
run-<name>-with-gui
shortcut for running the launcher with the simulation named <name>
in GUI-mode
run-launcher
runs the launcher (just points to ./bin/launcher)
Run './bin/launcher --help' to see available options.
Run './run-launcher --help' to see available options.
Scripts come in Windows and Unix variants. Those for windows end with '.bat'.
......
......@@ -24,7 +24,7 @@ class ZmtSimulationPluginTest {
assertTrue(plugins.hasPlugin(ZmtLaunchConfigPlugin.class))
assertTrue(plugins.hasPlugin(ZmtShortcutPlugin.class))
assertTrue(createChangesFile instanceof CreateChanges)
assertTrue(createReadmeFile instanceof CreateReadme)
assertTrue(createReadmeFile instanceof CreateFile)
}
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