gradle-plugin-protobuf-0.9.2/000077500000000000000000000000001235704337500161235ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/.gitignore000066400000000000000000000001201235704337500201040ustar00rootroot00000000000000.gradle /**/gradle /**/build gradle-plugin-protobuf.i* gradle.properties /.idea gradle-plugin-protobuf-0.9.2/README.md000066400000000000000000000032641235704337500174070ustar00rootroot00000000000000# Protobuf Plugin for Gradle The Protobuf plugin provides protobuf compilation to your project. ## Latest Version ws.antonov.gradle.plugins:gradle-plugin-protobuf:0.9.1 - Available on Maven Central ## Usage To use the protobuf plugin, include in your build script: ```groovy apply plugin: 'protobuf' buildscript { repositories { mavenCentral() } dependencies { classpath 'ws.antonov.gradle.plugins:gradle-plugin-protobuf:0.9.1' } } // Optional - defaults to 'protoc' searching through your PATH protocPath = '/usr/local/bin/protoc' // Optional - defaults to value below extractedProtosDir = "${project.buildDir.path}/extracted-protos" // Optional - defaults to "${project.buildDir}/generated-sources/${sourceSet.name}" generatedFileDir = "${projectDir}/src" // This directory will get the current sourceSet.name appended to it. i.e. src/main or src/test // Optional - defaults to empty collection => [] // If entry separated by ':', will translate into 'protoc' argument '--plugin=protoc-gen-${values[0]}=${values[1]}' // If entry is anything else, will translate into 'protoc' argument '--plugin=protoc-gen-${it}=${project.projectDir}/protoc-gen-${it}' // // To execute the plugin, you either need to point to the full path, or have an executable shell script in the project main dir protobufCodeGenPlugins = ['foo:./protoc-gen-foo', 'bar'] dependencies { // If you have your protos archived in a tar file, you can specify that as a dependency // ... alternative archive types supported are: jar, tar, tar.gz, tar.bz2, zip protobuf files("lib/protos.tar.gz") // Different configuration fileSets are supported testProtobuf files("lib/protos.tar") } ``` gradle-plugin-protobuf-0.9.2/build.gradle000066400000000000000000000116351235704337500204100ustar00rootroot00000000000000import org.gradle.api.artifacts.maven.MavenDeployment println """\ Welcome to Gradle $gradle.gradleVersion - http://www.gradle.org Gradle home is set to: $gradle.gradleHomeDir Gradle user directory is set to: $gradle.gradleUserHomeDir Base directory: $projectDir Running script ${relativePath(buildFile)} """ apply plugin: 'idea' apply plugin: 'eclipse' apply plugin: 'groovy' apply plugin: 'maven' apply plugin: 'git' apply plugin: 'com.jfrog.bintray' apply plugin: 'signing' group = 'ws.antonov.gradle.plugins' version = '0.9.2' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'org.ajoberstar:gradle-git:0.1.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.5' } } test { //jvmArgs '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005' //debug true } repositories { mavenCentral() } dependencies { compile gradleApi() testCompile group: 'junit', name: 'junit', version: '4.8.1' compile localGroovy() } task wrapper(type: Wrapper) { gradleVersion = '1.12' } project.ext.set("signing.secretKeyRingFile", new File("${System.properties['user.home']}/.gnupg/secring.gpg")) task sourcesJar(type: Jar, dependsOn:classes) { classifier = 'sources' from sourceSets.main.allSource } task groovydocJar(type: Jar, dependsOn:groovydoc) { classifier = 'groovydoc' from groovydoc.destinationDir } artifacts { archives sourcesJar archives groovydocJar } signing { // required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") } sign configurations.archives } uploadArchives { repositories { mavenDeployer { beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { //repository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { authentication(userName: System.getProperty('nexusUser'), password: System.getProperty('nexusPassword')) } pom.project { name project.name description "Gradle build plugin to handle Protocol Buffers automated code generation and compilation" url "https://github.com/aantono/gradle-plugin-protobuf" licenses { license { name "New BSD License" url "http://www.opensource.org/licenses/bsd-license.php" } } developers { developer { id "aantono" name "Alex Antonov" email "alex@antonov.ws" } developer { id "valkolovos" name "Val Kolovos" email "valkolovos@yahoo.com" } developer { id "mleinartas" name "Michael Leinartas" email "mleinartas@gmail.com" } } scm { connection "scm:git:git://github.com/aantono/gradle-plugin-protobuf.git" developerConnection "scm:git:git@github.com:aantono/gradle-plugin-protobuf.git" url "https://github.com/aantono/gradle-plugin-protobuf" } } } } } bintray { user = System.getProperty('bintrayUser') key = System.getProperty('bintrayApiKey') configurations = ['archives'] //When uploading configuration files // - OR - //publications = ['mavenStuff'] //When uploading Maven-based publication files // - AND/OR - // filesSpec { //When uploading any arbitrary files ('filesSpec' is a standard Gradle CopySpec) // from 'arbitrary-files' // into 'standalone_files/level1' // rename '(.+)\\.(.+)', '$1-suffix.$2' // } dryRun = false //Whether to run this as dry-run, without deploying publish = true //If version should be auto published after an upload pkg { repo = 'maven' //userOrg = 'myorg' //An optional organization name when the repo belongs to one of the user's orgs name = 'gradle-plugin-protobuf' desc = 'Gradle Plugin for Google Protocol Buffers code generation/compilation.' websiteUrl = 'https://github.com/aantono/gradle-plugin-protobuf' issueTrackerUrl = 'https://github.com/aantono/gradle-plugin-protobuf/issues' vcsUrl = 'https://github.com/aantono/gradle-plugin-protobuf.git' licenses = ['GPL-3.0'] labels = ['gradle', 'protobuf', 'plugin'] publicDownloadNumbers = true attributes= ['gradle-plugin': 'protobuf:ws.antonov.gradle.plugins:gradle-plugin-protobuf'] //Optional package-level attributes //Optional version descriptor version { name = '0.9.2' //Bintray logical version name //desc = 'optional, version-specific description' vcsTag = '0.9.2' attributes = ['gradle-plugin': 'protobuf:ws.antonov.gradle.plugins:gradle-plugin-protobuf'] //Optional version-level attributes } } }gradle-plugin-protobuf-0.9.2/build.sh000077500000000000000000000000371235704337500175610ustar00rootroot00000000000000#!/bin/sh exec ./gradlew "$@" gradle-plugin-protobuf-0.9.2/src/000077500000000000000000000000001235704337500167125ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/000077500000000000000000000000001235704337500176365ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/000077500000000000000000000000001235704337500211635ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/000077500000000000000000000000001235704337500216145ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/000077500000000000000000000000001235704337500233005ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/gradle/000077500000000000000000000000001235704337500245365ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/gradle/plugins/000077500000000000000000000000001235704337500262175ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/gradle/plugins/protobuf/000077500000000000000000000000001235704337500300575ustar00rootroot00000000000000ProtobufCompile.groovy000066400000000000000000000050571235704337500343670ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/gradle/plugins/protobufpackage ws.antonov.gradle.plugins.protobuf import org.gradle.api.DefaultTask import org.gradle.api.InvalidUserDataException import org.gradle.api.tasks.Input import org.gradle.api.logging.LogLevel import org.gradle.api.tasks.TaskAction import org.gradle.util.CollectionUtils public class ProtobufCompile extends DefaultTask { @Input def includeDirs = [] String sourceSetName String destinationDir /** * Add a directory to protoc's include path. */ public void include(Object dir) { if (dir instanceof File) { includeDirs += dir } else { includeDirs += project.file(dir) } } @TaskAction def compile() { def plugins = project.convention.plugins.protobuf.protobufCodeGenPlugins def protoc = project.convention.plugins.protobuf.protocPath File destinationDir = project.file(destinationDir) def srcDirs = [project.file("src/${sourceSetName}/proto"), "${project.extractedProtosDir}/${sourceSetName}"] destinationDir.mkdirs() def dirs = CollectionUtils.join(" -I", srcDirs) logger.debug "ProtobufCompile using directories ${dirs}" logger.debug "ProtobufCompile using files ${inputs.sourceFiles.files}" def cmd = [ protoc ] cmd.addAll(srcDirs.collect {"-I${it}"}) //TODO: Figure out how to add variable to a task cmd.addAll(includeDirs*.path.collect {"-I${it}"}) cmd += "--java_out=${destinationDir}" // Handle code generation plugins if (plugins) { cmd.addAll(plugins.collect { def name = it if (it.indexOf(":") > 0) { name = it.split(":")[0] } "--${name}_out=${destinationDir}" }) cmd.addAll(plugins.collect { if (it.indexOf(":") > 0) { def values = it.split(":") "--plugin=protoc-gen-${values[0]}=${values[1]}" } else { "--plugin=protoc-gen-${it}=${project.projectDir}/protoc-gen-${it}" } }) } cmd.addAll inputs.sourceFiles.files logger.log(LogLevel.INFO, cmd.toString()) def output = new StringBuffer() Process result = cmd.execute() result.consumeProcessOutput(output, output) result.waitFor() if (result.exitValue() == 0) { logger.log(LogLevel.INFO, output.toString()) } else { throw new InvalidUserDataException(output.toString()) } } } ProtobufConvention.groovy000066400000000000000000000014261235704337500351150ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/gradle/plugins/protobufpackage ws.antonov.gradle.plugins.protobuf import org.gradle.api.Project class ProtobufConvention { def ProtobufConvention(Project project) { extractedProtosDir = "${project.buildDir.path}/extracted-protos" generatedFileDir = "${project.buildDir}/generated-sources" } def String protocPath = "protoc" /** * Directory to extract proto files into */ def String extractedProtosDir /** * Directory to save java files to */ def String generatedFileDir /** * List of code generation plugin names * -- Each name will be transformed into '--plugin=protoc-gen-' and '--_out=' * -- Names have to be unique */ def Set protobufCodeGenPlugins = Collections.emptySet() } ProtobufExtract.groovy000066400000000000000000000031151235704337500344020ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/gradle/plugins/protobufpackage ws.antonov.gradle.plugins.protobuf import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction /** * Created by aantonov on 5/19/14. */ class ProtobufExtract extends DefaultTask { File extractedProtosDir String configName @TaskAction def extract() { project.configurations[configName].files.each { file -> if (file.path.endsWith('.proto')) { ant.copy( file: file.path, toDir: extractedProtosDir ) //generateJavaTask.getSource().create(project.files(file)) } else if (file.path.endsWith('.jar') || file.path.endsWith('.zip')) { ant.unzip(src: file.path, dest: extractedProtosDir) } else { def compression if (file.path.endsWith('.tar')) { compression = 'none' } else if (file.path.endsWith('.tar.gz')) { compression = 'gzip' } else if (file.path.endsWith('.tar.bz2')) { compression = 'bzip2' } else { throw new GradleException( "Unsupported file type (${file.path}); handles only jar, tar, tar.gz & tar.bz2") } ant.untar( src: file.path, dest: extractedProtosDir, compression: compression) } } } } ProtobufPlugin.groovy000066400000000000000000000071471235704337500342370ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/groovy/ws/antonov/gradle/plugins/protobufpackage ws.antonov.gradle.plugins.protobuf import org.gradle.api.Action import org.gradle.api.InvalidUserDataException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.file.SourceDirectorySet import org.gradle.api.internal.file.DefaultSourceDirectorySet import org.gradle.api.logging.LogLevel import org.gradle.api.tasks.SourceSet import org.gradle.api.GradleException import org.gradle.tooling.UnsupportedVersionException import org.gradle.util.CollectionUtils class ProtobufPlugin implements Plugin { void apply(final Project project) { def gv = project.gradle.gradleVersion =~ "(\\d*)\\.(\\d*).*" if (!gv || !gv.matches() || gv.group(1) < "1" || (gv.group(1) == "1" && gv.group(2) < "12")) { //throw new UnsupportedVersionException println("You are using Gradle ${project.gradle.gradleVersion}: This version of the protobuf plugin requires minimum Gradle version 1.12") } project.apply plugin: 'java' project.convention.plugins.protobuf = new ProtobufConvention(project); project.sourceSets.all { SourceSet sourceSet -> def protobufConfigName = (sourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME) ? "protobuf" : sourceSet.getName() + "Protobuf") def generateJavaTaskName = sourceSet.getTaskName('generate', 'proto') project.tasks.create(generateJavaTaskName, ProtobufCompile) { description = "Compiles Proto source '${sourceSet.name}:proto'" inputs.source project.fileTree("src/${sourceSet.name}/proto") {include "**/*.proto"} inputs.source project.fileTree("${project.extractedProtosDir}/${sourceSet.name}") {include "**/*.proto"} outputs.dir getGeneratedSourceDir(project, sourceSet) //outputs.upToDateWhen {false} sourceSetName = sourceSet.name destinationDir = project.file(getGeneratedSourceDir(project, sourceSet)) } def generateJavaTask = project.tasks.getByName(generateJavaTaskName) project.configurations.create(protobufConfigName) { visible = false transitive = false extendsFrom = [] } def extractProtosTaskName = sourceSet.getTaskName('extract', 'proto') project.tasks.create(extractProtosTaskName, ProtobufExtract) { description = "Extracts proto files/dependencies specified by 'protobuf' configuration" //TODO: Figure out why the configuration can't be used as input. That makes declaring output invalid //inputs.files project.configurations[protobufConfigName].files //outputs.dir "${project.extractedProtosDir}/${sourceSet.name}" extractedProtosDir = project.file("${project.extractedProtosDir}/${sourceSet.name}") configName = protobufConfigName } def extractProtosTask = project.tasks.getByName(extractProtosTaskName) generateJavaTask.dependsOn(extractProtosTask) sourceSet.java.srcDir getGeneratedSourceDir(project, sourceSet) String compileJavaTaskName = sourceSet.getCompileTaskName("java"); Task compileJavaTask = project.tasks.getByName(compileJavaTaskName); compileJavaTask.dependsOn(generateJavaTask) } } private getGeneratedSourceDir(Project project, SourceSet sourceSet) { def generatedSourceDir = project.convention.plugins.protobuf.generatedFileDir return "${generatedSourceDir}/${sourceSet.name}" } } gradle-plugin-protobuf-0.9.2/src/main/resources/000077500000000000000000000000001235704337500216505ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/resources/META-INF/000077500000000000000000000000001235704337500230105ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/resources/META-INF/gradle-plugins/000077500000000000000000000000001235704337500257255ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/src/main/resources/META-INF/gradle-plugins/protobuf.properties000066400000000000000000000001071235704337500317010ustar00rootroot00000000000000implementation-class=ws.antonov.gradle.plugins.protobuf.ProtobufPlugin gradle-plugin-protobuf-0.9.2/testProject/000077500000000000000000000000001235704337500204315ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/build.gradle000066400000000000000000000026031235704337500227110ustar00rootroot00000000000000println """\ Welcome to Gradle $gradle.gradleVersion - http://www.gradle.org Gradle home is set to: $gradle.gradleHomeDir Gradle user directory is set to: $gradle.gradleUserHomeDir Base directory: $projectDir Running script ${relativePath(buildFile)} """ buildscript { dependencies { classpath files("../build/libs/gradle-plugin-protobuf-0.9.2.jar") } } apply plugin: 'protobuf' repositories { mavenCentral() } dependencies { compile group: 'com.google.protobuf', name: 'protobuf-java', version: '2.5.0' protobuf files("lib/protos.tar.gz") //protobuf files("ext/test1.proto", "ext/test2.proto") protobuf fileTree("ext/") { //exclude 'more.proto' } testProtobuf files("lib/protos.tar.gz") testCompile 'junit:junit:4.7' } group = 'ws.antonov.gradle.plugins.protobuf.test' version = '1.0' manifest.mainAttributes(provider: 'gradle') protocPath = '/usr/local/bin/protoc' //protobufCodeGenPlugins = ['foo:./protoc-gen-foo'] task printDeps(dependsOn: build) << { configurations.each { println it } sourceSets.each { println it.getCompileTaskName("proto") } sourceSets.each { println it.getCompileTaskName("java") } sourceSets.each { println it } println tasks['generateProto'].source println tasks['compileJava'].source println project.buildDir println project.buildDir.path } task wrapper(type: Wrapper) { gradleVersion = '1.12' } gradle-plugin-protobuf-0.9.2/testProject/build.sh000077500000000000000000000000371235704337500220670ustar00rootroot00000000000000#!/bin/sh exec ./gradlew "$@" gradle-plugin-protobuf-0.9.2/testProject/ext/000077500000000000000000000000001235704337500212315ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/ext/more.proto000066400000000000000000000001401235704337500232530ustar00rootroot00000000000000message MoreMsg { optional string bar = 1; } message Foo { optional string stuff = 1; }gradle-plugin-protobuf-0.9.2/testProject/ext/test1.proto000066400000000000000000000003161235704337500233560ustar00rootroot00000000000000/** * Created with IntelliJ IDEA. * User: aantonov * Date: 1/17/13 * Time: 3:44 PM * To change this template use File | Settings | File Templates. */ message Test1Msg { optional string bar = 1; }gradle-plugin-protobuf-0.9.2/testProject/ext/test2.proto000066400000000000000000000000611235704337500233540ustar00rootroot00000000000000message Test2Msg { optional string bar = 1; }gradle-plugin-protobuf-0.9.2/testProject/lib/000077500000000000000000000000001235704337500211775ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/lib/protos.tar.gz000066400000000000000000000005061235704337500236550ustar00rootroot00000000000000‹ C¦NíÓÍN„0ðjbŒÜõ<ñ°å£6ônLtÞ6•°+ PB‹ãÝGðY|: â×êf=ˆÆøÿ%“ÒR`ÊdlY°‘qΓ8¦~”ïÇg$„ŒE‰P â"Œ¸dX§5V5.¥*«+}½jߺûÃ9^Æ?ºúû3cÛùܯmõßpÿCFÑêúIð¦þÜÕ_ò0aÄGÈåƒ^¶µ·Í6;Q)žÓ º5¶ã"pq碛?|í•GÓéÙpÙ=qïbiËÆëúnªK¿Ti£Ke3㧪É,»ñº,R]´eE‡D“~¡È«ÌMÅÄ»ý†³Cßÿãvÿúþç±\êÿXúÿ'”™1j‘Ñq¡®è©étms]©‚ŒmòjA—ªZÎûílà3`|r©(gradle-plugin-protobuf-0.9.2/testProject/src/000077500000000000000000000000001235704337500212205ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/src/main/000077500000000000000000000000001235704337500221445ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/src/main/java/000077500000000000000000000000001235704337500230655ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/src/main/java/Foo.java000066400000000000000000000000321235704337500244460ustar00rootroot00000000000000public class Foo { } gradle-plugin-protobuf-0.9.2/testProject/src/main/proto/000077500000000000000000000000001235704337500233075ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/src/main/proto/sample.proto000066400000000000000000000004011235704337500256500ustar00rootroot00000000000000option java_package = "com.example.tutorial"; option java_outer_classname = "OuterSample"; option java_multiple_files = true; message Msg { optional string foo = 1; optional SecondMsg blah = 2; } message SecondMsg { optional int32 blah = 1; } gradle-plugin-protobuf-0.9.2/testProject/src/main/proto/test.proto000066400000000000000000000006441235704337500253570ustar00rootroot00000000000000package ws.antonov.protobuf.test; message TestMessage { required int32 id = 1; optional string name = 2; } message AnotherMessage { repeated string names = 1; optional DataPayload data = 2; message DataPayload { optional string payload = 1; } } message Item { required string name = 1; optional string value = 2; } message DataMap { repeated Item data_items = 1 [experimental_map_key="name"]; }gradle-plugin-protobuf-0.9.2/testProject/src/test/000077500000000000000000000000001235704337500221775ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/src/test/java/000077500000000000000000000000001235704337500231205ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/src/test/java/FooTest.java000066400000000000000000000001551235704337500253470ustar00rootroot00000000000000import junit.framework.TestCase; public class FooTest extends TestCase { public void testNothing() {} } gradle-plugin-protobuf-0.9.2/testProject/src/test/proto/000077500000000000000000000000001235704337500233425ustar00rootroot00000000000000gradle-plugin-protobuf-0.9.2/testProject/src/test/proto/test.proto000066400000000000000000000000301235704337500253770ustar00rootroot00000000000000message MsgTest { }