Skip to content

Commit

Permalink
Further improve Gradle build, update installation instructions (#6)
Browse files Browse the repository at this point in the history
* Further improve Gradle build, update installation instructions

* update installation and building instructions in `README.md` to include new tasks (like `runJosm`)
* update versions of Gradle plugins `nexus-staging` and `spotless`, remove `download` plugin
* automate activation of the plugin and starting of JOSM when running `installPlugin`
* move configuration of JOSM and its manifest to `build.gradle` (if there's no Ant build, that's the preferred method)
* distribute the Atlas dependency inside the release *.jar

* Let Travis CI also check, if compilation against the minimum compatible JOSM version is possible

Also put the version back to `gradle.properties`, because `build.sh` depends on it.
  • Loading branch information
floscher authored and matthieun committed Feb 14, 2018
1 parent a24a778 commit 4e7243d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi

if [ "$TRAVIS_PULL_REQUEST" != "false" ];
then
./gradlew clean build
./gradlew clean build minJosmVersionClasses
else
./gradlew clean build
./gradlew clean build minJosmVersionClasses
fi
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,37 @@ You must be on JOSM v12712 or later for the latest build to work.

## Installation

### Build

Clone the project and edit the build.gradle to change the josm version to your JOSM's version:

```
project.ext.josmVersion = '13367'
Each time you run
```bash
./gradlew installPlugin
```
the plugin is built if needed. The resulting \*.jar file is activated for your already installed JOSM instance.
This task then fires up that JOSM instance and you can use the plugin right away.

Then run:
After that you can start JOSM however you want, the plugin will still be installed. You'd only have to repeat this, when you want to later update to a newer version of the plugin.

```
gradle downloadJosm
```
## Development

and
### Launch a clean JOSM instance

When you run
```bash
./gradlew runJosm
```
gradle installPlugin
```
a clean JOSM instance is fired up containing only the `josm-atlas` plugin.

### Launch
You do **not** have to have JOSM already installed for this: Gradle will download a JOSM executable and run that.

Open JOSM and navigate to your Plugin Preferences.
A new `JOSM_HOME` directory is created (separate from any existing ones). It persists between calls to this task, but can be cleared using the `cleanJosm` task.

Edit > Preferences > Plugins
### Build

Type `josm-atlas` into the search box and select the plugin.
Run
```bash
./gradlew build
```
to start a full build.

## Contributing

To contribute to the project, see the [contributing guidelines](https://github.com/osmlab/atlas/blob/dev/CONTRIBUTING.md)
To contribute to the project, see the [contributing guidelines](https://github.com/osmlab/atlas/blob/dev/CONTRIBUTING.md)
83 changes: 53 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
buildscript {
dependencies {
classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.4.0'
}
}

plugins {
id 'org.openstreetmap.josm' version '0.3.2'
id "de.undercouch.download" version "3.2.0"
id 'com.diffplug.gradle.spotless' version '3.9.0'
// Used to promote a staging release build
// https://github.com/Codearte/gradle-nexus-staging-plugin
// gradle closeAndReleaseRepository
id "io.codearte.nexus-staging" version "0.8.0"

id 'java'
id 'checkstyle'
id 'maven'
id 'maven-publish'
id 'signing'
id 'idea'
}

project.ext.pluginName = 'josm-atlas'
// corresponds to POM description/group
description = "Atlas Library"
group = 'org.openstreetmap.atlas'

archivesBaseName = 'josm-atlas'
josm { // see https://floscher.github.io/gradle-josm-plugin/kdoc/v0.3.2/gradle-josm-plugin/org.openstreetmap.josm.gradle.plugin.config/-josm-plugin-extension
josmCompileVersion '13367'
manifest { // see https://floscher.github.io/gradle-josm-plugin/kdoc/v0.3.2/gradle-josm-plugin/org.openstreetmap.josm.gradle.plugin.config/-josm-manifest
author = 'James Gage'
canLoadAtRuntime = true
description = 'Allows you to view an Atlas file as a layer.'
iconPath = 'images/dialogs/world-3.png'
mainClass = 'org.openstreetmap.atlas.AtlasReader'
minJosmVersion = '12712'
website = new URL('https://github.com/osmlab/josm-atlas')
}
}

apply from: 'dependencies.gradle'
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "com.diffplug.gradle.spotless"
apply plugin: 'idea'

sourceCompatibility=1.8
targetCompatibility=1.8
Expand All @@ -42,14 +52,12 @@ idea {

spotless {
java {
importOrder(['static java', 'static javax', 'static org', 'static com', 'static scala', 'java', 'javax', 'org', 'com', 'scala'])
importOrder 'static java', 'static javax', 'static org', 'static com', 'static scala', 'java', 'javax', 'org', 'com', 'scala'
removeUnusedImports()
eclipse().configFile 'config/format/code_format.xml'
}
}

// corresponds to POM description
description = "Atlas Library"

// This is to skip the tasks for which there is a skip<TaskName>=true environment variable
def skippedTaskNames = System.getenv().findAll { key, value ->
Expand Down Expand Up @@ -85,7 +93,7 @@ configurations

dependencies
{
compile packages.atlas
packIntoJar packages.atlas
}

tasks.withType(Test) {
Expand All @@ -108,14 +116,11 @@ artifacts
archives /*javadocJar,*/ sourcesJar
}


/**
* JOSM SPECIFIC TASKS
*/
import de.undercouch.gradle.tasks.download.Download
import org.gradle.internal.os.OperatingSystem


/**
* This task installs the plugin in your system's JOSM plugins directory.
*
Expand All @@ -124,22 +129,40 @@ import org.gradle.internal.os.OperatingSystem
* On macOS:
*
* ~/Library/JOSM/plugins/
*/
task installPlugin(type: Copy, dependsOn: jar) {
*/
task installPlugin(type: Copy) {
def destStr
if(OperatingSystem.current().isMacOsX()) {
destStr = "${System.getProperty('user.home')}/Library/JOSM/plugins"
} else if(OperatingSystem.current().isWindows()) {
destStr = "${System.getenv()['APPDATA']}/JOSM/plugins"
} else {
} else if (new File("${System.getProperty('user.home')}/.josm").exists()) {
destStr = "${System.getProperty('user.home')}/.josm/plugins"
} else {
destStr = "${System.getProperty('user.home')}/.local/share/JOSM/plugins"
}
println("Plugin JAR Archive Path: " + jar.archivePath)
println("Plugin JAR Destination Path: " + destStr)
from jar.archivePath
logger.lifecycle("Plugin JAR Archive Path: " + dist.outputs.files.asFileTree.files[0])
logger.lifecycle("Plugin JAR Destination Path: " + destStr)
from tasks.dist
into destStr
rename {
pluginName + '.jar'
project.afterEvaluate {
finalizedBy activatePlugin
}
}

/**
* Starts a JOSM instance and activates the plugin if it's not already active.
*
* The difference to the `runJosm` task is that there a completely clean instance is started up and a temporary JOSM_HOME is used.
* Here your default JOSM_HOME is used and you have to have JOSM already installed.
*/
task activatePlugin(type: Exec, dependsOn: installPlugin) {
def configFile = new File(buildDir, "addPluginConfig.xml")
doFirst {
configFile.withWriter { out ->
out.print "<?xml version=\"1.0\" encoding=\"UTF-8\"?><config><preferences operation=\"append\"><list key=\"plugins\"><entry value=\"${project.archivesBaseName}\"/></list></preferences></config>"
}
}
executable 'josm'
args '--load-preferences=' + configFile.toURI().toURL().toString()
}
12 changes: 0 additions & 12 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
group=org.openstreetmap.atlas
version=4.0.0-SNAPSHOT

plugin.class=org.openstreetmap.atlas.AtlasReader
plugin.compile.version=13367
plugin.description=Allows you to view an Atlas file as a layer.
plugin.main.version=12712
plugin.author=James Gage
plugin.canloadatruntime=true
# plugin.early=false
plugin.icon=images/dialogs/world-3.png
# plugin.requires=
# plugin.stage=50

maven2_url=https://oss.sonatype.org/service/local/staging/deploy/maven2/
snapshot_url=https://oss.sonatype.org/content/repositories/snapshots/
project_name="JOSM plugin to view Atlas files"
Expand Down

0 comments on commit 4e7243d

Please sign in to comment.