From e26aa8d59fa06d7cc068cdeeff8691de767bdc07 Mon Sep 17 00:00:00 2001 From: Peter Ng Date: Sun, 29 May 2016 22:22:01 +0800 Subject: [PATCH] Add C# protobuf code gen support --- .gitignore | 383 +++++++++++++++++- .../gradle/ProtobufCSharpConvention.groovy | 17 + .../gradle/ProtobufConfigurator.groovy | 7 +- .../plugins/ProtobufCSharpPlugin.groovy | 82 ++++ .../gradle/plugins/ProtobufPlugin.groovy | 3 + .../com.google.protobuf.csharp.properties | 1 + .../plugins/ProtobufCSharpPluginTest.groovy | 62 +++ testProjectCSharp/Sample.csproj | 72 ++++ testProjectCSharp/Sample.sln | 22 + testProjectCSharp/build.gradle | 48 +++ testProjectCSharp/lib/protos.tar.gz | Bin 0 -> 210 bytes testProjectCSharp/packages.config | 4 + testProjectCSharp/src/main/proto/sample.proto | 12 + .../src/main/protocolbuffers/more.proto | 9 + .../src/protocolbuffers/proto/messages.proto | 138 +++++++ 15 files changed, 855 insertions(+), 5 deletions(-) create mode 100644 src/main/groovy/com/google/protobuf/gradle/ProtobufCSharpConvention.groovy create mode 100644 src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufCSharpPlugin.groovy create mode 100644 src/main/resources/META-INF/gradle-plugins/com.google.protobuf.csharp.properties create mode 100644 src/test/groovy/com/google/plugins/ProtobufCSharpPluginTest.groovy create mode 100644 testProjectCSharp/Sample.csproj create mode 100644 testProjectCSharp/Sample.sln create mode 100644 testProjectCSharp/build.gradle create mode 100644 testProjectCSharp/lib/protos.tar.gz create mode 100644 testProjectCSharp/packages.config create mode 100644 testProjectCSharp/src/main/proto/sample.proto create mode 100644 testProjectCSharp/src/main/protocolbuffers/more.proto create mode 100644 testProjectCSharp/src/protocolbuffers/proto/messages.proto diff --git a/.gitignore b/.gitignore index 622b605f..b37ec17b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,380 @@ + +# Created by https://www.gitignore.io/api/gradle,visualstudio,intellij,eclipse + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml + + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + + +### Gradle ### .gradle -/**/build -protobuf-gradle-plugin.i* -gradle.properties -/.idea +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufCSharpConvention.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufCSharpConvention.groovy new file mode 100644 index 00000000..591cfbd2 --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufCSharpConvention.groovy @@ -0,0 +1,17 @@ +package com.google.protobuf.gradle + +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.tasks.SourceSet +import org.gradle.api.internal.tasks.DefaultSourceSetContainer + +class ProtobufCSharpConvention { + def ProtobufCSharpConvention(DefaultSourceSetContainer sourceSets) { + csharpSourceSets = sourceSets + } + + def final DefaultSourceSetContainer csharpSourceSets + + public NamedDomainObjectContainer csharpSourceSets(Closure closure) { + return csharpSourceSets.configure(closure); + } +} diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufConfigurator.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufConfigurator.groovy index e69605c2..6f7d580c 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufConfigurator.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufConfigurator.groovy @@ -153,7 +153,12 @@ public class ProtobufConfigurator { extends GenerateProtoTaskCollection { public Collection ofSourceSet(String sourceSet) { return all().findAll { task -> - task.sourceSet.name == sourceSet + task.sourceSet.name == sourceSet && !task.name.endsWith('CSharp') + } + } + public Collection ofCSharpSourceSet(String sourceSet) { + return all().findAll { task -> + task.sourceSet.name == sourceSet && task.name.endsWith('CSharp') } } } diff --git a/src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufCSharpPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufCSharpPlugin.groovy new file mode 100644 index 00000000..763200e2 --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufCSharpPlugin.groovy @@ -0,0 +1,82 @@ +package com.google.protobuf.gradle.plugins + +import com.google.protobuf.gradle.ProtobufCSharpConvention +import com.google.protobuf.gradle.TaskGenerator +import com.google.protobuf.gradle.Utils +import javafx.concurrent.Task +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer + +import org.gradle.internal.reflect.Instantiator +import org.gradle.api.internal.file.SourceDirectorySetFactory +import org.gradle.api.internal.tasks.DefaultSourceSetContainer + +import javax.inject.Inject + +class ProtobufCSharpPlugin implements Plugin { + + private final Instantiator instantiator + private Project project + private DefaultSourceSetContainer sourceSets + + @Inject + ProtobufCSharpPlugin(Instantiator instantiator) { + this.instantiator = instantiator; + } + + void apply(final Project project) { + this.project = project + + project.apply plugin: 'com.google.protobuf.base' + + sourceSets = instantiator.newInstance(DefaultSourceSetContainer.class, project.fileResolver, project.tasks, instantiator, + project.services.get(SourceDirectorySetFactory.class)); + sourceSets.create('main') + + project.convention.plugins.csharpProtobuf = new ProtobufCSharpConvention(sourceSets); + + Utils.setupSourceSets(project, sourceSets, 'CSharp') + } + + /** + * Adds Protobuf-related tasks to the project. + */ + void addProtoTasks() { + sourceSets.all { sourceSet -> + addTasksForSourceSet(sourceSet) + } + } + + /** + * Performs after task are added and configured + */ + void afterTaskAdded() { + linkGenerateProtoTasksToCompile() + } + + /** + * Creates Protobuf tasks for a sourceSet + */ + private addTasksForSourceSet(final SourceSet sourceSet) { + def generateProtoTask = TaskGenerator.addGenerateProtoTask(project, sourceSet.name, [sourceSet], 'CSharp') + generateProtoTask.sourceSet = sourceSet + generateProtoTask.doneInitializing() + generateProtoTask.builtins { + csharp {} + } + + def extractProtosTask = TaskGenerator.maybeAddExtractProtosTask(project, sourceSet.name, 'CSharp') + generateProtoTask.dependsOn(extractProtosTask) + } + + private linkGenerateProtoTasksToCompile() { + def compileTasks = project.tasks.findAll { it.class.name.startsWith 'com.ullink.Msbuild' } + sourceSets.each { sourceSet -> + project.protobuf.generateProtoTasks.ofCSharpSourceSet(sourceSet.name).each { generateProtoTask -> + compileTasks.each { it.dependsOn(generateProtoTask) } + } + } + } +} diff --git a/src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufPlugin.groovy index 72c3c1a3..5d8e075b 100644 --- a/src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/plugins/ProtobufPlugin.groovy @@ -39,11 +39,13 @@ import org.gradle.api.plugins.AppliedPlugin class ProtobufPlugin implements Plugin { // any one of these plugins should be sufficient to proceed with applying this plugin private static final List javaPluginOptions = ['java'] + private static final List csharpPluginOptions = ['msbuild'] private static final List androidPluginOptions = ['com.android.application', 'com.android.library', 'android', 'android-library'] + private List pluginsApplied = []; private Project project; @@ -56,6 +58,7 @@ class ProtobufPlugin implements Plugin { // has been applied then we will assume that none of prerequisite plugins were specified and we will // throw an Exception to alert the user of this configuration issue. applyWithPrerequisitePlugin(javaPluginOptions, 'com.google.protobuf.java') + applyWithPrerequisitePlugin(csharpPluginOptions, 'com.google.protobuf.csharp') applyWithPrerequisitePlugin(androidPluginOptions, 'com.google.protobuf.android') project.afterEvaluate { diff --git a/src/main/resources/META-INF/gradle-plugins/com.google.protobuf.csharp.properties b/src/main/resources/META-INF/gradle-plugins/com.google.protobuf.csharp.properties new file mode 100644 index 00000000..995a5288 --- /dev/null +++ b/src/main/resources/META-INF/gradle-plugins/com.google.protobuf.csharp.properties @@ -0,0 +1 @@ +implementation-class=com.google.protobuf.gradle.plugins.ProtobufCSharpPlugin \ No newline at end of file diff --git a/src/test/groovy/com/google/plugins/ProtobufCSharpPluginTest.groovy b/src/test/groovy/com/google/plugins/ProtobufCSharpPluginTest.groovy new file mode 100644 index 00000000..69edf6e3 --- /dev/null +++ b/src/test/groovy/com/google/plugins/ProtobufCSharpPluginTest.groovy @@ -0,0 +1,62 @@ +package com.google.protobuf.gradle.plugins + +import com.google.protobuf.gradle.GenerateProtoTask +import com.google.protobuf.gradle.ProtobufExtract +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.TaskOutcome +import org.junit.Rule +import org.junit.rules.TemporaryFolder +import spock.lang.Specification + +class ProtobufCSharpPluginTest extends Specification { + + @Rule + final TemporaryFolder tempDir = new TemporaryFolder() + + def "Applying com.google.protobuf.csharp adds corresponding task to project"() { + given: "a basic project with com.google.protobuf.csharp" + Project project = ProjectBuilder.builder().build() + project.apply plugin: 'com.google.protobuf.csharp' + + when: "project evaluated" + project.evaluate() + + then: "generate tasks added" + assert project.tasks.generateProtoCSharp instanceof GenerateProtoTask + assert project.tasks.extractProtoCSharp instanceof ProtobufExtract + } + + def "Custom sourceSet should get its own GenerateProtoTask"() { + given: "a basic project with com.google.protobuf.csharp" + Project project = ProjectBuilder.builder().build() + project.apply plugin: 'com.google.protobuf.csharp' + + when: "adding custom sourceSet nano" + project.csharpSourceSets.create('nano') + + and: "project evaluated" + project.evaluate() + + then: "tasks for nano added" + assert project.tasks.generateNanoProtoCSharp instanceof GenerateProtoTask + assert project.tasks.extractNanoProtoCSharp instanceof ProtobufExtract + } + + // MSBuild 14 / Mono has to be installed for testing + def "testProjectCSharp should be successfully executed"() { + given: "project from testProjectCSharp" + def projectDir = tempDir.newFolder() + ProtobufPluginTestHelper.copyTestProject('testProjectCSharp', projectDir) + + when: "build is invoked" + def result = GradleRunner.create() + .withProjectDir(projectDir) + .withArguments('build') + .build() + + then: "it succeed" + result.task(":msbuild").outcome == TaskOutcome.SUCCESS + } +} \ No newline at end of file diff --git a/testProjectCSharp/Sample.csproj b/testProjectCSharp/Sample.csproj new file mode 100644 index 00000000..5b9076cd --- /dev/null +++ b/testProjectCSharp/Sample.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {7524C00C-2DC2-435E-9AC9-8034CA12AD83} + Library + Properties + Sample + Sample + v4.5 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + + + packages\Google.Protobuf.3.0.0-beta3\lib\dotnet\Google.Protobuf.dll + True + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testProjectCSharp/Sample.sln b/testProjectCSharp/Sample.sln new file mode 100644 index 00000000..8c22d41c --- /dev/null +++ b/testProjectCSharp/Sample.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample.csproj", "{7524C00C-2DC2-435E-9AC9-8034CA12AD83}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7524C00C-2DC2-435E-9AC9-8034CA12AD83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7524C00C-2DC2-435E-9AC9-8034CA12AD83}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7524C00C-2DC2-435E-9AC9-8034CA12AD83}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7524C00C-2DC2-435E-9AC9-8034CA12AD83}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/testProjectCSharp/build.gradle b/testProjectCSharp/build.gradle new file mode 100644 index 00000000..5f6253bd --- /dev/null +++ b/testProjectCSharp/build.gradle @@ -0,0 +1,48 @@ +// A sample CSharp project + +buildscript { + dependencies { + classpath "com.ullink.gradle:gradle-msbuild-plugin:2.14" + classpath "com.ullink.gradle:gradle-nuget-plugin:2.14" + } + repositories { + mavenCentral() + jcenter() + } +} + +apply plugin: 'msbuild' +apply plugin: 'nuget' +apply plugin: 'com.google.protobuf' + +dependencies { + protobufCSharp files("lib/protos.tar.gz") +} + +protobuf { + protoc { + artifact = 'com.google.protobuf:protoc:3.0.0-beta-3' + } + generateProtoTasks { + ofCSharpSourceSet('protocolbuffers')*.builtins { + csharp { + option 'file_extension=.g.cs' + } + } + } +} + +msbuild { + solutionFile = 'Sample.sln' +} + +csharpSourceSets { + protocolbuffers { + proto { + srcDir 'src/main/protocolbuffers' + } + } +} + +msbuild.dependsOn nugetRestore +build.finalizedBy msbuild \ No newline at end of file diff --git a/testProjectCSharp/lib/protos.tar.gz b/testProjectCSharp/lib/protos.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..a6193a2054b248bf136af474cc62e9e855bff73e GIT binary patch literal 210 zcmV;@04@I?iwFQ?*sfIo1MShx3IZV*g<;oT#YY!V+KkO2+H@xd(-f7(=s-Vo?^(18 zYB#m$eKzu`;K7r2hmq=;$tq`*DNW%_m1k=w);#u~lpQ-)I9KLX}W>Xyslq1~r_FK^rno|GT@uk1_zMV^$HUedhy^Zw&0 zB!85d3?BU#gQ?cLI!52rGT-`@T(o2{wd>HxB7fCP>{MU%uY&^s00000000000000` MHzNE4jsPeC0L1lVvj6}9 literal 0 HcmV?d00001 diff --git a/testProjectCSharp/packages.config b/testProjectCSharp/packages.config new file mode 100644 index 00000000..cb70682e --- /dev/null +++ b/testProjectCSharp/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/testProjectCSharp/src/main/proto/sample.proto b/testProjectCSharp/src/main/proto/sample.proto new file mode 100644 index 00000000..171826a9 --- /dev/null +++ b/testProjectCSharp/src/main/proto/sample.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +option csharp_namespace = "Google.Protobuf.Msg"; + +message Msg { + string foo = 1; + SecondMsg blah = 2; +} + +message SecondMsg { + int32 blah = 1; +} diff --git a/testProjectCSharp/src/main/protocolbuffers/more.proto b/testProjectCSharp/src/main/protocolbuffers/more.proto new file mode 100644 index 00000000..3c893810 --- /dev/null +++ b/testProjectCSharp/src/main/protocolbuffers/more.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +message MoreMsg { + string bar = 1; +} + +message Foo { + string stuff = 1; +} \ No newline at end of file diff --git a/testProjectCSharp/src/protocolbuffers/proto/messages.proto b/testProjectCSharp/src/protocolbuffers/proto/messages.proto new file mode 100644 index 00000000..44ea78fa --- /dev/null +++ b/testProjectCSharp/src/protocolbuffers/proto/messages.proto @@ -0,0 +1,138 @@ + +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Message definitions to be used by integration test service definitions. + +syntax = "proto3"; + +package grpc.testing; + +option java_package = "nano"; + +// The type of payload that should be returned. +enum PayloadType { + // Compressable text format. + COMPRESSABLE = 0; + + // Uncompressable binary format. + UNCOMPRESSABLE = 1; + + // Randomly chosen from all other formats defined in this enum. + RANDOM = 2; +} + +// A block of data, to simply increase gRPC message size. +message Payload { + // The type of data in body. + PayloadType type = 1; + // Primary contents of payload. + bytes body = 2; +} + +// Unary request. +message SimpleRequest { + // Desired payload type in the response from the server. + // If response_type is RANDOM, server randomly chooses one from other formats. + PayloadType response_type = 1; + + // Desired payload size in the response from the server. + // If response_type is COMPRESSABLE, this denotes the size before compression. + int32 response_size = 2; + + // Optional input payload sent along with the request. + Payload payload = 3; + + // Whether SimpleResponse should include username. + bool fill_username = 4; + + // Whether SimpleResponse should include OAuth scope. + bool fill_oauth_scope = 5; +} + +// Unary response, as configured by the request. +message SimpleResponse { + // Payload to increase message size. + Payload payload = 1; + // The user the request came from, for verifying authentication was + // successful when the client expected it. + string username = 2; + // OAuth scope. + string oauth_scope = 3; +} + +message SimpleContext { + string value = 1; +} + +// Client-streaming request. +message StreamingInputCallRequest { + // Optional input payload sent along with the request. + Payload payload = 1; + + // Not expecting any payload from the response. +} + +// Client-streaming response. +message StreamingInputCallResponse { + // Aggregated size of payloads received from the client. + int32 aggregated_payload_size = 1; +} + +// Configuration for a particular response. +message ResponseParameters { + // Desired payload sizes in responses from the server. + // If response_type is COMPRESSABLE, this denotes the size before compression. + int32 size = 1; + + // Desired interval between consecutive responses in the response stream in + // microseconds. + int32 interval_us = 2; +} + +// Server-streaming request. +message StreamingOutputCallRequest { + // Desired payload type in the response from the server. + // If response_type is RANDOM, the payload from each response in the stream + // might be of different types. This is to simulate a mixed type of payload + // stream. + PayloadType response_type = 1; + + // Configuration for each expected response message. + repeated ResponseParameters response_parameters = 2; + + // Optional input payload sent along with the request. + Payload payload = 3; +} + +// Server-streaming response, as configured by the request and parameters. +message StreamingOutputCallResponse { + // Payload to increase response size. + Payload payload = 1; +}