Skip to content

Commit

Permalink
Updated java source/tests, jars, ruby source and gradle (#1)
Browse files Browse the repository at this point in the history
* Here it is!

* fix CHANGELOG, CONTRIBUTORS and Gemfile

* DissectorError is not registered with JRuby and its not part of JrJackson

* Found simple Index of bytes to be faster than KMP or Horspool
for small delims and source (in terms of String Search where
normally bigger needles are sought in bigger haystacks)

KMP

Benchmark                        Mode  Cnt  Score   Error  Units
DissectorBenchmark.aWarmupVLong  avgt   40  1.724 ± 0.010  us/op
DissectorBenchmark.bVLongDelims  avgt   40  1.808 ± 0.073  us/op
DissectorBenchmark.cLongDelims   avgt   40  1.479 ± 0.024  us/op
DissectorBenchmark.dOneDelim     avgt   40  1.312 ± 0.010  us/op
DissectorBenchmark.eTwoDelim     avgt   40  1.321 ± 0.007  us/op

IndexOfBytes

Benchmark                        Mode  Cnt  Score   Error  Units
DissectorBenchmark.aWarmupVLong  avgt   40  1.608 ± 0.048  us/op
DissectorBenchmark.bVLongDelims  avgt   40  1.559 ± 0.006  us/op
DissectorBenchmark.cLongDelims   avgt   40  1.437 ± 0.012  us/op
DissectorBenchmark.dOneDelim     avgt   40  1.408 ± 0.028  us/op
DissectorBenchmark.eTwoDelim     avgt   40  1.287 ± 0.004  us/op

* Moved the indexOf from BruteForce and IndexOfBytes to the Delim classes
Deleted BruteForce and IndexOfBytes

* handle the no delimiter case "%{a}%{b}-%{c}", "a" field -> "" value

* add new jar

* add field format validation for %{+&field} and %{&+field} definitions

* begin to add data type conversion (will not compile yet)

* complete data type conversion (Java side)

* whole bunch of renaming and reorg after chat with daniel mitterdorfer

* refactor triggered by review comments

* OK here are the changes from the review process

* rearranged and reformatted code according to IntelliJ defaults

* last few fixes for PR

* update build instructions to trigger travis build

* fix travis perhaps

* doh!

* damn devutils

* damn bundle exec

* maybe this will build on travis

* and again

* and again

* and again, more debug info

* OK so we have switched to RC1 and org.logstash

* add the check task to ensure JUnit tests run before the jar is created

* refactor travis yaml
  • Loading branch information
Guy Boertje committed Oct 15, 2016
1 parent 9bc2866 commit 00cd005
Show file tree
Hide file tree
Showing 48 changed files with 2,381 additions and 400 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -7,9 +7,9 @@ vendor
# build dirs
build
.gradle
gradle

# Intellij
.idea
*.iml
logstash-core-event-java.jar

gradle.properties
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,7 +1,8 @@
sudo: false
language: ruby
cache: bundler
jdk: oraclejdk8
rvm:
- jruby-1.7.23
- jruby-1.7.25
script:
- bundle exec rspec spec
- bundle exec rake travis_test
23 changes: 23 additions & 0 deletions BUILD_INSTRUCTIONS.md
@@ -0,0 +1,23 @@
These instructions are for the JAVA build NOT Ruby Gem build and publish.

#### History
This is a Logstash plugin with a large amount of Java code.

The Java source is dependent on the logstash-core jar and the logstash-core-event jar.
These jars can be found in the gems that are resolved via the `s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"` line in the gemspec.
So different versions of these gems can be installed as time goes by. The gradle build dependencies cannot refer to a static location and version.

These Rake tasks allow for Gradle to be dependent on Rubygems.
- `rake vendor` - this task calls "./gradlew vendor" but only after have done the "bundle_install" rake task
- `rake bundle_install` - this task calls `bundle install` then puts the output of `bundle show logstash-core` and `bundle show logstash-core-event` into the "gradle.properties" file.

#### Procedure
Each time a new gem version of `logstash-core-plugin-api` is released we need to run `rake vendor` to verify that any changes to the Java in logstash-core and logstash-core-event are still compatible with their usage in this plugin.

Run `rake vendor`

#### Travis
Travis is set to use `rake write_gradle_properties` before its build task

#### More Information
See the Gradle "vendor" task to understand how the the jar is generated.
7 changes: 2 additions & 5 deletions CHANGELOG.md
@@ -1,5 +1,2 @@
## 2.0.0
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
- Dependency on logstash-core update to 2.0

## 1.0.5
- Initial commit
3 changes: 1 addition & 2 deletions CONTRIBUTORS
Expand Up @@ -2,8 +2,7 @@ The following is a list of people who have contributed ideas, code, bug
reports, or in general have helped logstash along its way.

Contributors:
* Aaron Mildenstein (untergeek)
* Pier-Hugues Pellerin (ph)
* Guy Boertje [guyboertje]

Note: If you've sent us patches, bug reports, or otherwise contributed to
Logstash, and you aren't on the list above and want to be, please let us know
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
@@ -1,2 +1,3 @@
source 'https://rubygems.org'
gemspec
gemspec

3 changes: 3 additions & 0 deletions README.md
@@ -1,3 +1,6 @@
### NOTE
Please read BUILD_INSTRUCTIONS.md

# Logstash Plugin

[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-example.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-example)
Expand Down
57 changes: 57 additions & 0 deletions Rakefile
@@ -1 +1,58 @@
require "logstash/devutils/rake"

require 'rubygems'
require 'rubygems/package_task'
require 'fileutils'
require 'rspec/core/rake_task'

# Please read BUILD_INSTRUCTIONS.md

desc "Compile and vendor java into ruby"
task :vendor => [:bundle_install] do
sh("./gradlew check vendor")
puts "-------------------> vendored dissect jar via rake"
end

desc "Compile and vendor java into ruby for travis, its done bundle install already"
task :travis_vendor => [:write_gradle_properties] do
sh("./gradlew check vendor")
puts "-------------------> vendored dissect jar via rake"
end

desc "Do bundle install and write gradle.properties"
task :bundle_install do
`bundle install`
delete_create_gradle_properties
end

desc "Write gradle.properties" # used by travis
task :write_gradle_properties do
delete_create_gradle_properties
end

spec = Gem::Specification.load('logstash-filter-dissect.gemspec')
Gem::PackageTask.new(spec) do
desc 'Package gem'
task :package => [:vendor]
end

RSpec::Core::RakeTask.new(:spec)
task :check => [:vendor, :spec]

task :travis_test => [:travis_vendor, :spec]

def delete_create_gradle_properties
root_dir = File.dirname(__FILE__)
gradle_properties_file = "#{root_dir}/gradle.properties"
lsc_path = `bundle show logstash-core`
lsce_path = `bundle show logstash-core-event`
FileUtils.rm_f(gradle_properties_file)
File.open(gradle_properties_file, "w") do |f|
f.puts "logstashCoreGemPath=#{lsc_path}"
f.puts "logstashCoreEventGemPath=#{lsce_path}"
end
puts "-------------------> Wrote #{gradle_properties_file}"
puts `cat #{gradle_properties_file}`
end


1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
1.0.5
64 changes: 45 additions & 19 deletions build.gradle
@@ -1,3 +1,6 @@
import java.nio.file.Files
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING

buildscript {
repositories {
mavenLocal()
Expand All @@ -6,23 +9,28 @@ buildscript {
}
}

plugins {
id "me.champeau.gradle.jmh" version "0.3.1"
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}

apply plugin: 'java'
apply plugin: 'idea'

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
// options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}

apply plugin: 'java'
apply plugin: 'idea'

group = 'org.logstash.dissect'
version "${new File("VERSION").text.trim()}"
description = """Dissect Filter, a Logstash plugin - the Java parts"""

project.sourceCompatibility = 1.8

Expand All @@ -38,20 +46,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
extension 'jar'
}

task copyGemjar(type: Copy, dependsOn: sourcesJar) {
from project.jar
into project.file('lib/jars/')
}

task cleanGemjar {
delete fileTree(project.file('lib/jars/')) {
include '*.jar'
}
}

clean.dependsOn(cleanGemjar)
jar.finalizedBy(copyGemjar)

configurations.create('sources')
configurations.create('javadoc')
configurations.archives {
Expand Down Expand Up @@ -88,9 +82,13 @@ idea {
}
}

// logstashCoreGemPath and logstashCoreEventGemPath comes from the gradle.properties file
// the gradle.properties file is built by the Rake task bundle_install
// See BUILD_INSTRUCTIONS.md
dependencies {
provided 'org.jruby:jruby-core:1.7.22'
provided files('lib/logstash-core-event-java.jar')
provided 'org.jruby:jruby-core:1.7.25'
provided fileTree(dir: logstashCoreGemPath, include: '**/*.jar')
provided fileTree(dir: logstashCoreEventGemPath, include: '**/*.jar')
testCompile 'junit:junit:4.12'
}

Expand All @@ -100,4 +98,32 @@ task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}

task generateGemJarRequiresFile << {
File jars_file = file("lib/${project.name}_jars.rb")
jars_file.newWriter().withWriter { w ->
w << "# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n\n"
w << "require \'jar_dependencies\'\n"
configurations.runtime.allDependencies.each {
w << "require_jar(\'${it.group}\', \'${it.name}\', \'${it.version}\')\n"
}
w << "require_jar(\'${project.group}\', \'${project.name}\', \'${project.version}\')\n"
}
}

task vendor << {
String vendorPathPrefix = "vendor/jars"
configurations.runtime.allDependencies.each { dep ->
File f = configurations.runtime.filter { it.absolutePath.contains("${dep.group}/${dep.name}/${dep.version}") }.singleFile
String groupPath = dep.group.replaceAll('\\.', '/')
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${dep.name}/${dep.version}/${dep.name}-${dep.version}.jar")
newJarFile.mkdirs()
Files.copy(f.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
}
String projectGroupPath = project.group.replaceAll('\\.', '/')
File projectJarFile = file("${vendorPathPrefix}/${projectGroupPath}/${project.name}/${project.version}/${project.name}-${project.version}.jar")
projectJarFile.mkdirs()
Files.copy(file("$buildDir/libs/${project.name}-${project.version}.jar").toPath(), projectJarFile.toPath(), REPLACE_EXISTING)
println "-----------------> Vendored jar to: ${projectJarFile.getCanonicalPath()}"
}

vendor.dependsOn(jar, generateGemJarRequiresFile)
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
#Thu May 26 17:21:25 BST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-bin.zip
Binary file removed lib/jars/jruby-dissect-library.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions lib/jruby-dissect-library_jars.rb
@@ -0,0 +1,4 @@
# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.

require 'jar_dependencies'
require_jar('org.logstash.dissect', 'jruby-dissect-library', '1.0.5')

0 comments on commit 00cd005

Please sign in to comment.