Skip to content

Commit

Permalink
Avoid failing RunJosmTask when the current plugin does not require …
Browse files Browse the repository at this point in the history
…other plugins

The problem was, that the file `build/josm-custom-config/requiredPlugins.xml` was not generated. Because that file was required by the tasks of type `RunJosmTask`, these tasks failed.
The generation process of that file is now done in the task `writePluginConfig`, while the copying of the plugin *.jar files is now done by the task `updateJosmPlugins` instead of both `updateCurrentPlugin` and `updatePluginDependencies` (which both no longer exist).
  • Loading branch information
floscher committed Nov 7, 2017
1 parent 9f0aa0b commit ce57bfe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.openstreetmap.josm.gradle.plugin.setup
import org.gradle.api.Project
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.Sync
import org.gradle.api.tasks.TaskExecutionException

import org.openstreetmap.josm.gradle.plugin.RunJosmTask
Expand Down Expand Up @@ -50,9 +51,14 @@ class BasicTaskSetup extends AbstractSetup {
// All RunJosmTasks by default depend on this task.
pro.task(
[
description: 'Put all needed plugin *.jar files into the plugins directory. This task itself does nothing, but all tasks that copy the needed files (should) be set as dependencies of this task.'
type: Sync,
description: 'Put all needed plugin *.jar files into the plugins directory. This task copies files into the temporary JOSM home directory.'
],
'updateJosmPlugins'
'updateJosmPlugins',
{t ->
t.into "${pro.josm.tmpJosmHome}/plugins"
// the rest of the configuration (e.g. from where the files come, that should be copied) is done later (e.g. in the file `PluginTaskSetup.groovy`)
}
)
// Standard run-task
pro.task(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ class PluginTaskSetup extends AbstractSetup {

public void setup() {
pro.task(
[type: Copy],
'updatePluginDependencies',
[description: "Creates the configuration that tells JOSM which plugins to load (which is later automatically loaded by e.g. `runJosm`)"],
'writePluginConfig',
{t ->
doFirst {
t.doFirst {
def customConfig = new File("${pro.buildDir}/josm-custom-config/requiredPlugins.xml")
customConfig.parentFile.mkdirs()
customConfig.withWriter { out ->
pro.logger.lifecycle 'Write required plugins to {}…', customConfig.absolutePath
customConfig.withWriter ('UTF-8') { out ->
out.println """<?xml version="1.0" encoding="UTF-8"?>
<!-- No need to edit this file! -->
<!-- This file is being autogenerated (and **overwritten**!) by Gradle each time the task `updatePluginDependencies` runs. -->
<!-- This file is being autogenerated (and **overwritten**!) by Gradle each time the task `writePluginConfig` runs. -->
<!-- In order to add custom preferences, either edit \$buildDir/.josm/preferences.xml instead. Or create a custom config file next to this file and load it into JOSM via the command line argument - -load-preferences="..." -->
<!--See https://josm.openstreetmap.de/wiki/Help/Preferences/ImportExport for documentation on this format -->
<config>
Expand All @@ -39,16 +40,17 @@ class PluginTaskSetup extends AbstractSetup {
</preferences>
</config>"""
}
pro.logger.lifecycle 'Copy {} to {}…', source.files, destinationDir
}
pro.gradle.projectsEvaluated {
from pro.configurations.requiredPlugin
into "${pro.josm.tmpJosmHome}/plugins"
rename('(.*)-\\.jar', '$1.jar')
}
}
)

pro.tasks.updateJosmPlugins.dependsOn pro.tasks.writePluginConfig, pro.tasks.initJosmPrefs
pro.tasks.updateJosmPlugins.rename('(.*)-\\.jar', '$1.jar')
pro.gradle.projectsEvaluated {
pro.tasks.updateJosmPlugins.from pro.tasks.dist.outputs
pro.tasks.updateJosmPlugins.from pro.configurations.requiredPlugin.resolve()
}


def localDistPath = "${pro.buildDir}/localDist"
def localDistName = "${pro.archivesBaseName}-dev.${pro.jar.extension}"
Expand Down Expand Up @@ -121,20 +123,5 @@ class PluginTaskSetup extends AbstractSetup {
}
)
pro.tasks.jar.finalizedBy pro.tasks.dist

pro.task(
[type: Copy, description: 'Puts the plugin-JAR generated by the `jar`-task into `build/.josm/plugins`', dependsOn: [pro.tasks.dist, pro.tasks.initJosmPrefs, pro.tasks.updatePluginDependencies]],
'updateCurrentPlugin',
{t ->
doFirst {
pro.logger.lifecycle 'Copy {} to {}…', source.files, destinationDir
}
pro.updateJosmPlugins.dependsOn t
pro.gradle.projectsEvaluated {
from "${pro.buildDir}/dist"
into "${pro.josm.tmpJosmHome}/plugins"
}
}
)
}
}

0 comments on commit ce57bfe

Please sign in to comment.