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

ZmtLaunchConfigPlugin.java: using template files for launch configs

        instead of hard-coded string
added runWithUI-external, runWithUI-project.launch templates
parent a90613e9
......@@ -13,6 +13,10 @@ import java.nio.file.Files
* simulation in eclipse via launcher.
*/
class ZmtLaunchConfigPlugin implements Plugin<Project> {
private static final def TEMPLATE_ENGINE = new groovy.text.SimpleTemplateEngine()
private static final def LAUNCH_CONFIG_PROJECT_FILENAME = 'runWithUI-project.launch'
private static final def LAUNCH_CONFIG_EXTERNAL_FILENAME = 'runWithUI-external.launch'
private static final def CONFIGURE = {
apply plugin: 'eclipse'
......@@ -34,7 +38,7 @@ class ZmtLaunchConfigPlugin implements Plugin<Project> {
Files.deleteIfExists(launchConfig)
}
}
@Override
void apply(Project project) {
project.configure(project, CONFIGURE)
......@@ -73,36 +77,16 @@ class ZmtLaunchConfigPlugin implements Plugin<Project> {
* @return launch configuration text
*/
private static String createLaunchConfigText(Project project, Project launcherProject) {
def binding = [projectName : project.name, projectDir : project.projectDir]
def templateFilename = LAUNCH_CONFIG_EXTERNAL_FILENAME
// if project is available, return launch config pointing to it
if (launcherProject != null) {
return """<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
<launchConfiguration type=\"org.eclipse.jdt.launching.localJavaApplication\">
<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_PATHS\">
<listEntry value=\"${launcherProject.projectDir}/src/main/java/de/zmt/Main.java\"/>
</listAttribute>
<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_TYPES\">
<listEntry value=\"1\"/>
</listAttribute>
<stringAttribute key=\"org.eclipse.jdt.launching.MAIN_TYPE\" value=\"de.zmt.Main\"/>
<stringAttribute key=\"org.eclipse.jdt.launching.PROGRAM_ARGUMENTS\" value=\"$project.name gui\"/>
<stringAttribute key=\"org.eclipse.jdt.launching.PROJECT_ATTR\" value=\"$launcherProject.name\"/>
<stringAttribute key=\"org.eclipse.jdt.launching.WORKING_DIRECTORY\" value=\"\${workspace_loc:$project.name}\"/>
</launchConfiguration>"""
binding.put('launcherProjectName', launcherProject.name)
binding.put('launcherProjectDir', launcherProject.projectDir)
templateFilename = LAUNCH_CONFIG_PROJECT_FILENAME
}
// ... otherwise return config pointing to launcher library
return """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="${project.projectDir}"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.zmt.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="$project.name gui"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="$project.name"/>
</launchConfiguration>"""
def templateUrl = ZmtLaunchConfigPlugin.class.getResource(LAUNCH_CONFIG_PROJECT_FILENAME)
return TEMPLATE_ENGINE.createTemplate(templateUrl).make(binding)
}
}
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="${projectDir}"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.zmt.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="${projectName} gui"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="${projectName}"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="${launcherProjectDir}/src/main/java/de/zmt/Main.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.zmt.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="${projectName} gui"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="${launcherProjectName}"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="\${workspace_loc:${projectName}}"/>
</launchConfiguration>
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