Commit 76150a93 authored by Christian Meyer's avatar Christian Meyer
Browse files

ZmtEclipsePlugin.groovy: fixed adding project dependency to launcher project

    launch configuration for launcher library is created if project
        is not available
    cleanup
parent aede3239
......@@ -2,6 +2,9 @@ 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
/*
* Eclipse Plugin for simulations based on zmt.core
......@@ -10,62 +13,23 @@ import org.gradle.api.artifacts.ProjectDependency
* simulation in eclipse via launcher.
*/
class ZmtEclipsePlugin implements Plugin<Project> {
private static final def LAUNCHER_PROJECT_NAME = 'zmt-launcher'
private static final def CONFIGURE = {
def launcherProject = rootProject.ext.properties.get('launcherProject')
def launchConfig = createLaunchConfigPath(project)
// need to have dependencies and stuff evaluated
afterEvaluate {
// also generate eclipse files in dependencies
configurations.compile.dependencies.withType(ProjectDependency.class).each {
// need to evaluate dependencies first
evaluationDependsOn(it.dependencyProject.path)
if (it.dependencyProject.plugins.hasPlugin('eclipse')) {
tasks.eclipse.dependsOn(it.dependencyProject.tasks.eclipse)
tasks.cleanEclipse.dependsOn(
it.dependencyProject.tasks.cleanEclipse)
}
}
// ... and for launcher
tasks.eclipse.dependsOn(':LAUNCHER_PROJECT_NAME:eclipse')
tasks.cleanEclipse.dependsOn(':LAUNCHER_PROJECT_NAME:cleanEclipse')
/* add runtime dependency for this project in launcher
to make it executable in eclipse */
Project launcherProject = findProject(':LAUNCHER_PROJECT_NAME')
launcherProject?.afterEvaluate {
launcherProject.dependencies {
runtime(project) {
transitive = false
}
}
}
addDependencies(project, launcherProject)
}
def upperCaseName = name.substring(0, 1).toUpperCase()
upperCaseName += name.substring(1)
def launchConfigFileName = "Run${upperCaseName}WithUI.launch"
// create launch configuration
tasks.eclipse.doLast {
def launchConfig = new File(launchConfigFileName)
// eclipse generated launch configuration with project name in it
launchConfig.text = """<?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=\"/$LAUNCHER_PROJECT_NAME/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=\"$LAUNCHER_PROJECT_NAME\"/>
<stringAttribute key=\"org.eclipse.jdt.launching.WORKING_DIRECTORY\" value=\"\${workspace_loc:$project.name}\"/>
</launchConfiguration>"""
launchConfig.text = createLaunchConfigText(project, launcherProject)
}
// delete launch configuration
tasks.cleanEclipse.doLast {
new File(launchConfigFileName).delete()
Files.delete(launchConfig)
}
}
......@@ -73,6 +37,81 @@ 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>"""
}
}
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