import java.nio.file.Files import static java.nio.file.StandardCopyOption.REPLACE_EXISTING apply plugin: 'java' apply plugin: 'idea' apply plugin: 'maven-publish' apply plugin: 'maven' apply plugin: "distribution" group 'net.doyl.logstash.codec.json' version "${file("VERSION").text.trim()}" description = "JSON codec for Java-based Logstash pipelines" def licenses = ['WTFPL'] // list of SPDX license IDs def longDescription = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using \$LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" def authors = ['Jordan Doyle'] def email = ['jordan@doyle.la'] def homepage = "http://www.elastic.co/guide/en/logstash/current/index.html" def pluginType = "codec" def pluginClass = "JavaJson" def pluginName = "java_json" // must match the @LogstashPlugin annotation in the main plugin class def pluginFullName = "logstash-" + pluginType + "-" + pluginName buildscript { repositories { mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "com.github.jengelman.gradle.plugins:shadow:5.0.0" } } repositories { mavenCentral() } apply plugin: 'com.github.johnrengelman.shadow' shadowJar { classifier = null } dependencies { implementation "org.apache.logging.log4j:log4j-api:2.11.2" implementation "com.google.guava:guava:28.0-jre" implementation "com.fasterxml.jackson.core:jackson-core:2.9.9" implementation "com.fasterxml.jackson.core:jackson-databind:2.9.9" implementation "com.fasterxml.jackson.core:jackson-annotations:2.9.9" implementation "com.fasterxml.jackson.datatype:jackson-datatype-guava:2.9.9" implementation fileTree(dir: "../logstash", include: "**/logstash-core-?.?.?.jar") testCompile 'junit:junit:4.12' testCompile 'org.jruby:jruby-complete:9.1.13.0' } tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } task vendor(dependsOn: shadowJar) { doLast { String vendorPathPrefix = "vendor/jar-dependencies" 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) } } task generateRubySupportFiles() { doLast { File gemspecFile = file(pluginFullName + ".gemspec") gemspecFile.write("# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n") gemspecFile.append("PLUGIN_VERSION = File.read(File.expand_path(File.join(File.dirname(__FILE__), \"VERSION\"))).strip unless defined?(PLUGIN_VERSION)\n") gemspecFile.append("\n") gemspecFile.append("Gem::Specification.new do |s|\n") gemspecFile.append(" s.name = '" + pluginFullName + "'\n") gemspecFile.append(" s.version = PLUGIN_VERSION\n") gemspecFile.append(" s.licenses = ['" + String.join("', '", licenses) + "']\n") gemspecFile.append(" s.summary = '" + project.description + "'\n") gemspecFile.append(" s.description = '" + longDescription + "'\n") gemspecFile.append(" s.authors = ['" + String.join("', '", authors) + "']\n") gemspecFile.append(" s.email = ['" + String.join("', '", email) + "']\n") gemspecFile.append(" s.homepage = '" + homepage + "'\n") gemspecFile.append(" s.require_paths = ['lib', 'vendor/jar-dependencies']\n") gemspecFile.append("\n") gemspecFile.append(" s.files = Dir[\"lib/**/*\",\"*.gemspec\",\"*.md\",\"CONTRIBUTORS\",\"Gemfile\",\"LICENSE\",\"NOTICE.TXT\", \"vendor/jar-dependencies/**/*.jar\", \"vendor/jar-dependencies/**/*.rb\", \"VERSION\", \"docs/**/*\"]\n") gemspecFile.append("\n") gemspecFile.append(" # Special flag to let us know this is actually a logstash plugin\n") gemspecFile.append(" s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => '" + pluginType + "'}\n") gemspecFile.append("\n") gemspecFile.append(" # Gem dependencies\n") gemspecFile.append(" s.add_runtime_dependency \"logstash-core-plugin-api\", \">= 1.60\", \"<= 2.99\"\n") gemspecFile.append(" s.add_runtime_dependency 'jar-dependencies'\n") gemspecFile.append(" s.add_development_dependency 'logstash-devutils'\n") gemspecFile.append("end\n") String moduleName = pluginType.substring(0, 1).toUpperCase() + pluginType.substring(1) + "s" File pluginRb = file("lib/logstash/" + pluginType + "s/" + pluginName + ".rb") Files.createDirectories(pluginRb.toPath().getParent()) pluginRb.write("# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n") pluginRb.append("# encoding: utf-8\n") pluginRb.append("require \"logstash/" + pluginType + "s/base\"\n") pluginRb.append("require \"logstash/namespace\"\n") pluginRb.append("require \"plugin_jars\"\n") pluginRb.append("require \"java\"\n") pluginRb.append("\n") pluginRb.append("def net() Java::Net; end\n") pluginRb.append("\n") pluginRb.append("class LogStash::" + moduleName + "::" + pluginClass + " < LogStash::" + moduleName + "::Base\n") pluginRb.append(" config_name \"" + pluginName + "\"\n") pluginRb.append("\n") pluginRb.append(" def self.javaClass() " + project.group + "." + pluginClass + ".java_class; end\n") pluginRb.append("end\n") File pluginJarsRb = file("lib/plugin_jars.rb") pluginJarsRb.write("# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n") pluginJarsRb.append("# encoding: utf-8\n") pluginJarsRb.append("\n") pluginJarsRb.append("require 'jar_dependencies'\n") pluginJarsRb.append("require_jar('" + project.group + "', '" + pluginFullName + "', '" + version +"')\n") } } task buildGem(dependsOn: [vendor, generateRubySupportFiles]) { doLast { print "building gem" } }