Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lang/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ endif (SNAPPY_FOUND)

add_definitions (${Boost_LIB_DIAGNOSTIC_DEFINITIONS})

add_definitions (-DAVRO_VERSION="${AVRO_VERSION_MAJOR}.${AVRO_VERSION_MINOR}.${AVRO_VERSION_PATCH}")

include_directories (api ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS})

set (AVRO_SOURCE_FILES
Expand Down
15 changes: 10 additions & 5 deletions lang/c++/impl/avrogencpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -810,23 +810,28 @@ int main(int argc, char **argv) {
const string NO_UNION_TYPEDEF("no-union-typedef");

po::options_description desc("Allowed options");
desc.add_options()("help,h", "produce help message")("include-prefix,p", po::value<string>()->default_value("avro"),
desc.add_options()("help,h", "produce help message")("version,V", "produce version information")("include-prefix,p", po::value<string>()->default_value("avro"),
"prefix for include headers, - for none, default: avro")("no-union-typedef,U", "do not generate typedefs for unions in records")("namespace,n", po::value<string>(), "set namespace for generated code")("input,i", po::value<string>(), "input file")("output,o", po::value<string>(), "output file to generate");

po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);

if (vm.count(IN_FILE) == 0 || vm.count(OUT_FILE) == 0) {
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
return 0;
}

if (vm.count("help")) {
std::cout << desc << std::endl;
if (vm.count("version")) {
std::cout << AVRO_VERSION << std::endl;
return 0;
}

if (vm.count(IN_FILE) == 0 || vm.count(OUT_FILE) == 0) {
std::cout << desc << std::endl;
return 1;
}

string ns = vm.count(NS) > 0 ? vm[NS].as<string>() : string();
string outf = vm.count(OUT_FILE) > 0 ? vm[OUT_FILE].as<string>() : string();
string inf = vm.count(IN_FILE) > 0 ? vm[IN_FILE].as<string>() : string();
Expand Down
3 changes: 1 addition & 2 deletions lang/csharp/src/apache/codegen/Avro.codegen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
unless framework is explicitly specified with 'dotnet tool install'
https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-tool-install
-->
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>$(DefaultExeTargetFrameworks)</TargetFrameworks>
<AssemblyName>avrogen</AssemblyName>
<RootNamespace>Avro.codegen</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\Avro.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
19 changes: 15 additions & 4 deletions lang/csharp/src/apache/codegen/AvroGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Avro
{
Expand All @@ -39,6 +40,15 @@ public static int Main(string[] args)
return 0;
}

if (args.Contains("--version") || args.Contains("-V"))
{
// Print version information
// Note: Use InformationalVersion attributre
// It is capable to include semver prerelease information label (if prerelease), e.g. 1.x.y-beta.z
Console.WriteLine(typeof(AvroGenTool).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
return 0;
}

// Parse command line arguments
bool? isProtocol = null;
string inputFile = null;
Expand Down Expand Up @@ -135,10 +145,11 @@ static void Usage()
" avrogen -p <protocolfile> <outputdir> [--namespace <my.avro.ns:my.csharp.ns>]\n" +
" avrogen -s <schemafile> <outputdir> [--namespace <my.avro.ns:my.csharp.ns>]\n\n" +
"Options:\n" +
" -h --help Show this screen.\n" +
" --namespace Map an Avro schema/protocol namespace to a C# namespace.\n" +
" The format is \"my.avro.namespace:my.csharp.namespace\".\n" +
" May be specified multiple times to map multiple namespaces.\n",
" -h --help Show this screen.\n" +
" -V --version Show version.\n" +
" --namespace Map an Avro schema/protocol namespace to a C# namespace.\n" +
" The format is \"my.avro.namespace:my.csharp.namespace\".\n" +
" May be specified multiple times to map multiple namespaces.\n",
AppDomain.CurrentDomain.FriendlyName);
}

Expand Down
33 changes: 0 additions & 33 deletions lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs

This file was deleted.

24 changes: 21 additions & 3 deletions lang/csharp/src/apache/test/AvroGen/AvroGenToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
* limitations under the License.
*/
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Reflection;
using NUnit.Framework;

namespace Avro.Test.AvroGen
Expand Down Expand Up @@ -51,6 +49,26 @@ public void CommandLineHelp(params string[] args)
Assert.That(result.StdErr, Is.Empty);
}

[TestCase("--version")]
[TestCase("-V")]
public void CommandLineVersion(params string[] args)
{
AvroGenToolResult result = AvroGenHelper.RunAvroGenTool(args);

Assert.That(result.ExitCode, Is.EqualTo(0));
Assert.That(result.StdOut, Is.Not.Empty);
Assert.That(result.StdErr, Is.Empty);

// Check if returned version is SemVer 2.0 compliant
Assert.That(result.StdOut[0], Does.Match(Utils.VersionTests.SemVerRegex));

// Returned version must be the same as the avrogen tool assembly's version
Assert.That(result.StdOut[0], Is.EqualTo(typeof(AvroGenTool).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion));

// Returned version must be the same as the avro library assembly's version
Assert.That(result.StdOut[0], Is.EqualTo(typeof(Schema).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion));
}

[TestCase("-p")]
[TestCase("-s")]
[TestCase("-p", "whatever.avpr")]
Expand Down
55 changes: 55 additions & 0 deletions lang/csharp/src/apache/test/Utils/VersionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Reflection;
using NUnit.Framework;

namespace Avro.Test.Utils
{
public class VersionTests
{
// SemVer2.0 regex
public static string SemVerRegex = @"^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$";

[Test]
public void VersionTest()
{
// Avro library's assembly
Assembly assembly = typeof(Schema).Assembly;

// Note: InformationalVersion contains pre-release tag if available (e.g. 1.x.y-beta.z)
string libraryVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;

// Check version is SmeVer 2.0 compliant
Assert.That(libraryVersion, Does.Match(SemVerRegex));
}

[Test]
public void MandatoryAttributesTest()
{
// Avro library's assembly
Assembly assembly = typeof(Schema).Assembly;

Assert.That(assembly.GetCustomAttribute<AssemblyCompanyAttribute>(), Is.Not.Null);
Assert.That(assembly.GetCustomAttribute<AssemblyDescriptionAttribute>(), Is.Not.Null);
Assert.That(assembly.GetCustomAttribute<AssemblyFileVersionAttribute>(), Is.Not.Null);
Assert.That(assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(), Is.Not.Null);
Assert.That(assembly.GetCustomAttribute<AssemblyProductAttribute>(), Is.Not.Null);
}
}
}