Skip to content

Commit

Permalink
Merge pull request #8 from smac89/master
Browse files Browse the repository at this point in the history
Upgrade to gradle 5 and lots of other improvements
  • Loading branch information
gregwhitaker authored Jan 11, 2020
2 parents 3f47fb8 + b1a45ee commit fbbaf0c
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 268 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
dist: trusty
language: java
sudo: false
jdk:
- oraclejdk8
- oraclejdk8
- oraclejdk9
install: true
script: "./ci/travis.sh"
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
directories:
- "$HOME/.gradle/caches/"
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ Please see the [Gradle Plugin Portal](https://plugins.gradle.org/plugin/io.netif
### Extension Properties
The plugin defines the following extension properties in the `flatbuffers` closure:

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

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

Expand Down
53 changes: 21 additions & 32 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,56 +1,40 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.9.7"
}
}

plugins {
id 'com.gradle.build-scan' version '1.16'
id 'groovy'
id 'java-gradle-plugin'
id 'com.gradle.plugin-publish' version "0.10.1"
id 'com.github.hierynomus.license' version '0.14.0'
}

buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
publishAlways()
}

apply plugin: 'java-gradle-plugin'
apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'groovy'

repositories {
jcenter()
}

dependencies {
compile gradleApi()
compile localGroovy()

testCompile gradleTestKit()
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
implementation 'org.codehaus.groovy:groovy:2.5.8'
testImplementation('org.spockframework:spock-core:1.3-groovy-2.5')
}

group = 'io.netifi'
version = '1.0.5'
version = '1.0.6'

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

plugins {
flatBuffersPlugin {
description = "Gradle plugin for generating code from Google FlatBuffers schemas."
displayName = 'FlatBuffers Plugin'
}
}
}

gradlePlugin {
plugins {
flatBuffersPlugin {
id = 'io.netifi.flatbuffers'
displayName = 'io.netifi.flatbuffers'
implementationClass = 'io.netifi.flatbuffers.plugin.FlatBuffersPlugin'
}
}
}
Expand All @@ -60,3 +44,8 @@ license {
strictCheck true
excludes([ "**/*.json", "**/*.html", "**/*.js" ])
}

wrapper {
gradleVersion = '5.6.4'
distributionType = Wrapper.DistributionType.ALL
}
1 change: 1 addition & 0 deletions ci/travis.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# This script builds the project in Travis
export GRADLE_OPTS="-Dorg.gradle.daemon=false"

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Jan 25 21:56:37 PST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
25 changes: 14 additions & 11 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
Expand Down Expand Up @@ -28,16 +28,16 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -154,16 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// settings.gradle
rootProject.name = 'gradle-flatbuffers-plugin'

Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,88 @@
*/
package io.netifi.flatbuffers.plugin

import io.netifi.flatbuffers.plugin.tasks.CleanFlatBuffers
import groovy.transform.CompileStatic
import io.netifi.flatbuffers.plugin.tasks.FlatBuffers
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.SourceSet
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.util.GUtil

import static org.gradle.api.plugins.JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME

@CompileStatic
class FlatBuffersPlugin implements Plugin<Project> {

public static final String GROUP = 'FlatBuffers'
public static final String FLAT_BUFFERS_EXTENSION_NAME = 'flatbuffers'

private FlatBuffersPluginExtension extension
private Project project

@Override
void apply(Project project) {
project.extensions.create('flatbuffers', FlatBuffersPluginExtension.class)
this.project = project
configureProject()
}

def fbTasks = []
project.afterEvaluate({
project.tasks.withType(FlatBuffers).each {
fbTasks << it
applySourceSets(project, it)
reconfigurePlugins(project, it)
}
void configureProject() {
extension = project.extensions.create(FLAT_BUFFERS_EXTENSION_NAME,
FlatBuffersPluginExtension)
project.pluginManager.apply(BasePlugin)

fbTasks.each {
addCleanTask(project, it)
project.afterEvaluate {
project.tasks.withType(FlatBuffers).each {
applySourceSets(it)
reconfigurePlugins(it)
addCleanTask(it)
}

applyDependencies(project)
})
}
}

/**
* Adds a 'clean' task for any FlatBuffers tasks in the project.
* Adds a 'clean' flatBuffers for any FlatBuffers tasks in the project.
*
* @param project Gradle project
* @param task {@link FlatBuffers} task
* @param flatBuffersTask {@link FlatBuffers} flatBuffers
*/
void addCleanTask(Project project, FlatBuffers task) {
def taskName = 'clean' + GUtil.toCamelCase(task.name)
project.tasks.create(taskName, CleanFlatBuffers) {
outputDir = task.outputDir
void addCleanTask(FlatBuffers flatBuffersTask) {
def taskName = "clean${GUtil.toCamelCase(flatBuffersTask.name)}"
project.tasks.create(name: taskName, type: Delete) { Delete task ->
task.delete flatBuffersTask.outputDir
}
}

/**
* Adds source sets for the FlatBuffers input and output directories.
*
* @param project Gradle project
* @param task {@link FlatBuffers} task
*/
void applySourceSets(Project project, FlatBuffers task) {
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets")

if (project.plugins.hasPlugin(JavaPlugin)) {
if (!sourceSets.getByName("main").java.srcDirs.contains(task.getInputDir())) {
sourceSets.getByName("main").java.srcDirs.add(task.getInputDir())
}

if (!sourceSets.getByName("main").java.srcDirs.contains(task.getOutputDir())) {
sourceSets.getByName("main").java.srcDirs.add(task.getOutputDir())
void applySourceSets(FlatBuffers task) {
project.pluginManager.withPlugin('java') {
def javaPlugin = project.convention.getPlugin(JavaPluginConvention)
def sourceSets = javaPlugin.sourceSets
sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).java { SourceDirectorySet java ->
java.srcDirs task.inputDir, task.outputDir
}
}
}

/**
* Reconfigures certain plugins to know about the FlatBuffers project structure.
*
* @param project Gradle project
* @param task {@link FlatBuffers} task
*/
void reconfigurePlugins(Project project, FlatBuffers task) {
void reconfigurePlugins(FlatBuffers task) {
// Intellij specific configurations
if (project.plugins.hasPlugin(IdeaPlugin)) {
if (!project.idea.module.generatedSourceDirs.contains(task.outputDir)) {
project.idea.module.generatedSourceDirs.add(task.outputDir)
}
project.pluginManager.withPlugin('idea') {
def idea = project.extensions.getByType(IdeaModel)
idea.module.generatedSourceDirs += task.outputDir
}
}

Expand All @@ -103,11 +107,11 @@ class FlatBuffersPlugin implements Plugin<Project> {
*/
void applyDependencies(Project project) {
// Java specific dependencies
if (project.plugins.hasPlugin(JavaPlugin)) {
project.dependencies {
compile 'com.google.flatbuffers:flatbuffers-java:1.8.0'
project.pluginManager.withPlugin('java') {
project.configurations.getByName(IMPLEMENTATION_CONFIGURATION_NAME) { Configuration config ->
def flatBufferVersion = "com.google.flatbuffers:flatbuffers-java:${extension.flatBuffersVersion ?: '1.10.0'}"
config.dependencies.add(project.dependencies.create(flatBufferVersion))
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
*/
package io.netifi.flatbuffers.plugin

import groovy.transform.CompileStatic

@CompileStatic
class FlatBuffersPluginExtension {

String flatcPath

String language

String flatBuffersVersion = '1.10.0'
}
Loading

0 comments on commit fbbaf0c

Please sign in to comment.