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

ZmtLaunchPlugin.java: shortcuts are added to distribution

        to launch simulation with GUI
added run-with-gui, run-with-gui.bat
    the shortcut templates
parent b67efe38
......@@ -2,6 +2,11 @@ package de.zmt.gradle;
import org.gradle.api.*
import org.gradle.api.file.DuplicatesStrategy
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.attribute.PosixFilePermissions
import java.net.URL
import groovy.lang.Writable
/*
* Distribution plugin for simulations based on zmt.core
......@@ -9,14 +14,25 @@ import org.gradle.api.file.DuplicatesStrategy
* With this plugin the simulation's jar file, source, dependencies
* and the runtime dependencies are added to the distribution's lib
* folder.
* <p>
* Start scripts for the launcher are added and a shortcut for running
* the simulation in GUI mode.
*/
public class ZmtLaunchPlugin implements Plugin<Project> {
private static final def MAIN_CLASS_NAME = 'de.zmt.Main'
private static final def SHORTCUT_UNIX = 'run-with-gui'
private static final def SHORTCUT_WIN = 'run-with-gui.bat'
private static final def CONFIGURE = {
apply plugin: 'distribution'
def launcherProject = rootProject.ext.properties.get('launcherProject')
// create shortcuts
def shortcutDir = Files.createTempDirectory('shortcuts')
Path unixShortcut = createLauncherShortcut(project, SHORTCUT_UNIX, shortcutDir)
// set +x permissions for unix shortcut
Files.setPosixFilePermissions(unixShortcut, PosixFilePermissions.fromString('rwxr-xr-x'))
createLauncherShortcut(project, SHORTCUT_WIN, shortcutDir)
distributions {
main {
......@@ -27,6 +43,9 @@ public class ZmtLaunchPlugin implements Plugin<Project> {
from (project.sourceJar)
from (project.configurations.runtime)
}
from (shortcutDir.toFile())
// prevent adding duplicates
// e.g. when several projects depend on the same library
// otherwise they are added several times to archives
......@@ -35,6 +54,7 @@ public class ZmtLaunchPlugin implements Plugin<Project> {
}
}
def launcherProject = rootProject.ext.properties.get('launcherProject')
// if this project is the launcher
if (project.name == 'zmt-launcher') {
// make it an application
......@@ -103,6 +123,27 @@ public class ZmtLaunchPlugin implements Plugin<Project> {
}
}
private static final def TEMPLATE_ENGINE = new groovy.text.SimpleTemplateEngine()
/**
* Creates a launcher shortcut script. The template script is loaded
* from given file name, processed to match the current project
* and saved to the given directory.
*
* @param project the project
* @param filename the file name of the template and the resulting file
* @param directory the directory where to save the resulting file
* @return the path to the resulting file
*/
private static Path createLauncherShortcut(Project project, String filename, Path directory) {
Path shortcut = Files.createFile(directory.resolve(filename))
def binding = [projectName : project.name]
def templateUrl = ZmtLaunchPlugin.class.getResource(filename)
shortcut.append(TEMPLATE_ENGINE.createTemplate(templateUrl).make(binding))
return shortcut
}
@Override
void apply(Project project) {
project.configure(project, CONFIGURE)
......
#!/usr/bin/env bash
##############################################################################
##
## shortcut script for UN*X to launch with GUI
##
##############################################################################
./bin/launcher $projectName gui
@rem ##########################################################################
@rem
@rem shortcut script for Windows to launch with GUI
@rem
@rem ##########################################################################
.\\bin\\launcher.bat $projectName gui
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