Skip to content

Commit fbbaf0c

Browse files
authored
Merge pull request #8 from smac89/master
Upgrade to gradle 5 and lots of other improvements
2 parents 3f47fb8 + b1a45ee commit fbbaf0c

File tree

15 files changed

+248
-268
lines changed

15 files changed

+248
-268
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
dist: trusty
12
language: java
23
sudo: false
34
jdk:
4-
- oraclejdk8
5+
- oraclejdk8
6+
- oraclejdk9
57
install: true
68
script: "./ci/travis.sh"
79
before_cache:
8-
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
10+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
911
cache:
1012
directories:
1113
- "$HOME/.gradle/caches/"

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ Please see the [Gradle Plugin Portal](https://plugins.gradle.org/plugin/io.netif
1515
### Extension Properties
1616
The plugin defines the following extension properties in the `flatbuffers` closure:
1717

18-
| Property | Type | Default Value | Required | Description |
19-
|-----------|--------|---------------|----------|----------------------------------------------------|
20-
| flatcPath | String | flatc | False | The path to the flatc compiler. |
21-
| language | String | null | False | The language to use when compiling the FlatBuffers.|
18+
|Property | Type | Default Value | Required | Description |
19+
|--------------|--------|---------------|----------|----------------------------------------------------|
20+
| flatcPath | String | flatc | False | The path to the flatc compiler. |
21+
| language | String | null | False | The language to use when compiling the FlatBuffers.|
22+
| flatBuffersVersion | String | 1.10.0 | False | The version of the java maven binaries to include. |
2223

2324
*Note:* Please see the [Supported Languages](#supported-languages) section for valid `language` values.
2425

build.gradle

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,40 @@
1-
buildscript {
2-
repositories {
3-
maven {
4-
url "https://plugins.gradle.org/m2/"
5-
}
6-
}
7-
dependencies {
8-
classpath "com.gradle.publish:plugin-publish-plugin:0.9.7"
9-
}
10-
}
11-
121
plugins {
13-
id 'com.gradle.build-scan' version '1.16'
2+
id 'groovy'
3+
id 'java-gradle-plugin'
4+
id 'com.gradle.plugin-publish' version "0.10.1"
145
id 'com.github.hierynomus.license' version '0.14.0'
156
}
167

17-
buildScan {
18-
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
19-
licenseAgree = 'yes'
20-
publishAlways()
21-
}
22-
23-
apply plugin: 'java-gradle-plugin'
24-
apply plugin: 'com.gradle.plugin-publish'
25-
apply plugin: 'groovy'
26-
278
repositories {
289
jcenter()
2910
}
3011

3112
dependencies {
32-
compile gradleApi()
33-
compile localGroovy()
34-
35-
testCompile gradleTestKit()
36-
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
37-
exclude module: 'groovy-all'
38-
}
13+
implementation 'org.codehaus.groovy:groovy:2.5.8'
14+
testImplementation('org.spockframework:spock-core:1.3-groovy-2.5')
3915
}
4016

4117
group = 'io.netifi'
42-
version = '1.0.5'
18+
version = '1.0.6'
4319

4420
pluginBundle {
4521
website = 'https://github.com/netifi/gradle-flatbuffers-plugin'
4622
vcsUrl = 'https://github.com/netifi/gradle-flatbuffers-plugin'
47-
description = 'Gradle plugin for generating code from Google FlatBuffers schemas.'
4823
tags = [ 'serialization', 'build', 'codegen' ]
4924

25+
plugins {
26+
flatBuffersPlugin {
27+
description = "Gradle plugin for generating code from Google FlatBuffers schemas."
28+
displayName = 'FlatBuffers Plugin'
29+
}
30+
}
31+
}
32+
33+
gradlePlugin {
5034
plugins {
5135
flatBuffersPlugin {
5236
id = 'io.netifi.flatbuffers'
53-
displayName = 'io.netifi.flatbuffers'
37+
implementationClass = 'io.netifi.flatbuffers.plugin.FlatBuffersPlugin'
5438
}
5539
}
5640
}
@@ -60,3 +44,8 @@ license {
6044
strictCheck true
6145
excludes([ "**/*.json", "**/*.html", "**/*.js" ])
6246
}
47+
48+
wrapper {
49+
gradleVersion = '5.6.4'
50+
distributionType = Wrapper.DistributionType.ALL
51+
}

ci/travis.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
# This script builds the project in Travis
3+
export GRADLE_OPTS="-Dorg.gradle.daemon=false"
34

45
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
56
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"

gradle/wrapper/gradle-wrapper.jar

2.21 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Jan 25 21:56:37 PST 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip

gradlew

Lines changed: 14 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
// settings.gradle
12
rootProject.name = 'gradle-flatbuffers-plugin'
2-

src/main/groovy/io/netifi/flatbuffers/plugin/FlatBuffersPlugin.groovy

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,84 +15,88 @@
1515
*/
1616
package io.netifi.flatbuffers.plugin
1717

18-
import io.netifi.flatbuffers.plugin.tasks.CleanFlatBuffers
18+
import groovy.transform.CompileStatic
1919
import io.netifi.flatbuffers.plugin.tasks.FlatBuffers
2020
import org.gradle.api.Plugin
2121
import org.gradle.api.Project
22-
import org.gradle.api.plugins.JavaPlugin
23-
import org.gradle.api.tasks.SourceSetContainer
24-
import org.gradle.plugins.ide.idea.IdeaPlugin
22+
import org.gradle.api.artifacts.Configuration
23+
import org.gradle.api.file.SourceDirectorySet
24+
import org.gradle.api.plugins.BasePlugin
25+
import org.gradle.api.plugins.JavaPluginConvention
26+
import org.gradle.api.tasks.Delete
27+
import org.gradle.api.tasks.SourceSet
28+
import org.gradle.plugins.ide.idea.model.IdeaModel
2529
import org.gradle.util.GUtil
2630

31+
import static org.gradle.api.plugins.JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME
32+
33+
@CompileStatic
2734
class FlatBuffersPlugin implements Plugin<Project> {
2835

2936
public static final String GROUP = 'FlatBuffers'
37+
public static final String FLAT_BUFFERS_EXTENSION_NAME = 'flatbuffers'
38+
39+
private FlatBuffersPluginExtension extension
40+
private Project project
3041

3142
@Override
3243
void apply(Project project) {
33-
project.extensions.create('flatbuffers', FlatBuffersPluginExtension.class)
44+
this.project = project
45+
configureProject()
46+
}
3447

35-
def fbTasks = []
36-
project.afterEvaluate({
37-
project.tasks.withType(FlatBuffers).each {
38-
fbTasks << it
39-
applySourceSets(project, it)
40-
reconfigurePlugins(project, it)
41-
}
48+
void configureProject() {
49+
extension = project.extensions.create(FLAT_BUFFERS_EXTENSION_NAME,
50+
FlatBuffersPluginExtension)
51+
project.pluginManager.apply(BasePlugin)
4252

43-
fbTasks.each {
44-
addCleanTask(project, it)
53+
project.afterEvaluate {
54+
project.tasks.withType(FlatBuffers).each {
55+
applySourceSets(it)
56+
reconfigurePlugins(it)
57+
addCleanTask(it)
4558
}
46-
4759
applyDependencies(project)
48-
})
60+
}
4961
}
5062

5163
/**
52-
* Adds a 'clean' task for any FlatBuffers tasks in the project.
64+
* Adds a 'clean' flatBuffers for any FlatBuffers tasks in the project.
5365
*
54-
* @param project Gradle project
55-
* @param task {@link FlatBuffers} task
66+
* @param flatBuffersTask {@link FlatBuffers} flatBuffers
5667
*/
57-
void addCleanTask(Project project, FlatBuffers task) {
58-
def taskName = 'clean' + GUtil.toCamelCase(task.name)
59-
project.tasks.create(taskName, CleanFlatBuffers) {
60-
outputDir = task.outputDir
68+
void addCleanTask(FlatBuffers flatBuffersTask) {
69+
def taskName = "clean${GUtil.toCamelCase(flatBuffersTask.name)}"
70+
project.tasks.create(name: taskName, type: Delete) { Delete task ->
71+
task.delete flatBuffersTask.outputDir
6172
}
6273
}
6374

6475
/**
6576
* Adds source sets for the FlatBuffers input and output directories.
6677
*
67-
* @param project Gradle project
6878
* @param task {@link FlatBuffers} task
6979
*/
70-
void applySourceSets(Project project, FlatBuffers task) {
71-
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets")
72-
73-
if (project.plugins.hasPlugin(JavaPlugin)) {
74-
if (!sourceSets.getByName("main").java.srcDirs.contains(task.getInputDir())) {
75-
sourceSets.getByName("main").java.srcDirs.add(task.getInputDir())
76-
}
77-
78-
if (!sourceSets.getByName("main").java.srcDirs.contains(task.getOutputDir())) {
79-
sourceSets.getByName("main").java.srcDirs.add(task.getOutputDir())
80+
void applySourceSets(FlatBuffers task) {
81+
project.pluginManager.withPlugin('java') {
82+
def javaPlugin = project.convention.getPlugin(JavaPluginConvention)
83+
def sourceSets = javaPlugin.sourceSets
84+
sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).java { SourceDirectorySet java ->
85+
java.srcDirs task.inputDir, task.outputDir
8086
}
8187
}
8288
}
8389

8490
/**
8591
* Reconfigures certain plugins to know about the FlatBuffers project structure.
8692
*
87-
* @param project Gradle project
8893
* @param task {@link FlatBuffers} task
8994
*/
90-
void reconfigurePlugins(Project project, FlatBuffers task) {
95+
void reconfigurePlugins(FlatBuffers task) {
9196
// Intellij specific configurations
92-
if (project.plugins.hasPlugin(IdeaPlugin)) {
93-
if (!project.idea.module.generatedSourceDirs.contains(task.outputDir)) {
94-
project.idea.module.generatedSourceDirs.add(task.outputDir)
95-
}
97+
project.pluginManager.withPlugin('idea') {
98+
def idea = project.extensions.getByType(IdeaModel)
99+
idea.module.generatedSourceDirs += task.outputDir
96100
}
97101
}
98102

@@ -103,11 +107,11 @@ class FlatBuffersPlugin implements Plugin<Project> {
103107
*/
104108
void applyDependencies(Project project) {
105109
// Java specific dependencies
106-
if (project.plugins.hasPlugin(JavaPlugin)) {
107-
project.dependencies {
108-
compile 'com.google.flatbuffers:flatbuffers-java:1.8.0'
110+
project.pluginManager.withPlugin('java') {
111+
project.configurations.getByName(IMPLEMENTATION_CONFIGURATION_NAME) { Configuration config ->
112+
def flatBufferVersion = "com.google.flatbuffers:flatbuffers-java:${extension.flatBuffersVersion ?: '1.10.0'}"
113+
config.dependencies.add(project.dependencies.create(flatBufferVersion))
109114
}
110115
}
111116
}
112-
113117
}

0 commit comments

Comments
 (0)