Commit 7e5ed683 authored by Christian Meyer's avatar Christian Meyer
Browse files

formatter settings for Eclipse are added to simulation and library projects

added ZmtLaunchConfigPlugin.groovy
    plugin for adding eclipse launch configuration
    contains code formerly in ZmtEclipsePlugin
ZmtEclipsePlugin.groovy
    moved code for launch config creation to ZmtLaunchConfigPlugin
    adds gradle's eclipse plugin
ZmtJavaPlugin.groovy
    no longer adds gradle's eclipse plugin
ZmtLibraryPlugin.groovy
    adds ZmtEclipsePlugin
    updated test
ZmtSimultionPlugin.groovy
    adds ZmtLaunchConfigPlugin
    updated test
parent ca7d7465
......@@ -6,33 +6,15 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files
/*
* Eclipse Plugin for simulations based on zmt.core
/**
* Custom eclipse plugin for projects in zmt.core
* <p>
* With this plugin a launch configuration will be generated to launch the
* simulation in eclipse via launcher.
* With this script specific formatter settings are applied.
*/
class ZmtEclipsePlugin implements Plugin<Project> {
private static final def CONFIGURE = {
def launcherProject = rootProject.ext.properties.get('launcherProject')
def launchConfig = createLaunchConfigPath(project)
// need to have dependencies and stuff evaluated
afterEvaluate {
addDependencies(project, launcherProject)
}
// create launch configuration
tasks.eclipse.doLast {
launchConfig.text = createLaunchConfigText(project, launcherProject)
}
// delete launch configuration
tasks.cleanEclipse.doLast {
Files.deleteIfExists(launchConfig)
}
// add formatting properties into .settings/
apply plugin: 'eclipse'
eclipse.jdt.file.withProperties { properties ->
def formatterProperties = new Properties()
// load properties from file
......@@ -48,81 +30,6 @@ class ZmtEclipsePlugin implements Plugin<Project> {
void apply(Project project) {
project.configure(project, CONFIGURE)
}
/**
* Adds dependencies according to the availability of the
* launcher project.
*
* @param project the project
* @param launcherProject the launcher project
*/
private static void addDependencies(Project project, Project launcherProject) {
/* add runtime dependency for this project in launcher
* (if available) to make it executable in eclipse */
launcherProject?.afterEvaluate {
launcherProject.dependencies {
runtime(project) {
transitive = false
}
}
}
/* If launcher project is not available a runtime dependency
* for launcher is added to this project. */
if (launcherProject == null) {
project.dependencies {
runtime 'de.zmt:zmt-launcher:latest.release'
}
}
}
private static Path createLaunchConfigPath(Project project) {
def upperCaseName = project.name.substring(0, 1).toUpperCase()
upperCaseName += project.name.substring(1)
return project.projectDir.toPath().resolve("Run${upperCaseName}WithUI.launch")
}
/**
* Creates text of an eclipse configuration to launch current
* project with zmt-launcher. If the launcher project is
* <code>null</code> the configuration will point to the libary.
*
* @param project the project
* @param launcherProject the launcher project
* @return launch configuration text
*/
private static String createLaunchConfigText(Project project, Project launcherProject) {
// 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>"""
}
// ... 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>"""
}
}
......@@ -11,8 +11,6 @@ import org.gradle.api.tasks.bundling.Jar
class ZmtJavaPlugin implements Plugin<Project> {
private static final def CONFIGURE = {
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
dependencies {
......
package de.zmt.gradle;
import org.gradle.api.*
import org.gradle.api.artifacts.ProjectDependency
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files
/*
* Launch Configuration Plugin for simulations based on zmt.core
* <p>
* With this plugin a launch configuration will be generated to launch the
* simulation in eclipse via launcher.
*/
class ZmtLaunchConfigPlugin implements Plugin<Project> {
private static final def CONFIGURE = {
apply plugin: 'eclipse'
def launcherProject = rootProject.ext.properties.get('launcherProject')
def launchConfig = createLaunchConfigPath(project)
// need to have dependencies and stuff evaluated
afterEvaluate {
addDependencies(project, launcherProject)
}
// create launch configuration
tasks.eclipse.doLast {
launchConfig.text = createLaunchConfigText(project, launcherProject)
}
// delete launch configuration
tasks.cleanEclipse.doLast {
Files.deleteIfExists(launchConfig)
}
}
@Override
void apply(Project project) {
project.configure(project, CONFIGURE)
}
/**
* Adds dependencies according to the availability of the
* launcher project.
*
* @param project the project
* @param launcherProject the launcher project
*/
private static void addDependencies(Project project, Project launcherProject) {
/* add runtime dependency for this project in launcher
* (if available) to make it executable in eclipse */
launcherProject?.afterEvaluate {
launcherProject.dependencies {
runtime(project) {
transitive = false
}
}
}
/* If launcher project is not available a runtime dependency
* for launcher is added to this project. */
if (launcherProject == null) {
project.dependencies {
runtime 'de.zmt:zmt-launcher:latest.release'
}
}
}
private static Path createLaunchConfigPath(Project project) {
def upperCaseName = project.name.substring(0, 1).toUpperCase()
upperCaseName += project.name.substring(1)
return project.projectDir.toPath().resolve("Run${upperCaseName}WithUI.launch")
}
/**
* Creates text of an eclipse configuration to launch current
* project with zmt-launcher. If the launcher project is
* <code>null</code> the configuration will point to the libary.
*
* @param project the project
* @param launcherProject the launcher project
* @return launch configuration text
*/
private static String createLaunchConfigText(Project project, Project launcherProject) {
// 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>"""
}
// ... 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>"""
}
}
......@@ -12,6 +12,7 @@ public class ZmtLibraryPlugin implements Plugin<Project> {
apply(plugin: ZmtJavadocPlugin)
apply(plugin: ZmtDochostPlugin)
apply(plugin: ZmtPublishPlugin)
apply(plugin: ZmtEclipsePlugin)
}
@Override
......
......@@ -14,6 +14,7 @@ public class ZmtSimulationPlugin implements Plugin<Project> {
apply(plugin: ZmtLaunchPlugin)
apply(plugin: ZmtDeployPlugin)
apply(plugin: ZmtEclipsePlugin)
apply(plugin: ZmtLaunchConfigPlugin)
}
@Override
......
......@@ -18,6 +18,7 @@ class ZmtLibraryPluginTest {
assertTrue(plugins.hasPlugin(ZmtJavadocPlugin.class))
assertTrue(plugins.hasPlugin(ZmtDochostPlugin.class))
assertTrue(plugins.hasPlugin(ZmtPublishPlugin.class))
assertTrue(plugins.hasPlugin(ZmtEclipsePlugin.class))
}
project.evaluate()
......
......@@ -20,6 +20,7 @@ class ZmtSimulationPluginTest {
assertTrue(plugins.hasPlugin(ZmtLaunchPlugin.class))
assertTrue(plugins.hasPlugin(ZmtDeployPlugin.class))
assertTrue(plugins.hasPlugin(ZmtEclipsePlugin.class))
assertTrue(plugins.hasPlugin(ZmtLaunchConfigPlugin.class))
}
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