You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/03/30 06:17:44 UTC
[avro] branch branch-1.11 updated: AVRO-3435: Add --version to avrogen tool (#1583)
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/branch-1.11 by this push:
new ed37da7 AVRO-3435: Add --version to avrogen tool (#1583)
ed37da7 is described below
commit ed37da7d3296d5997ff42eed3f26c6c3fb450821
Author: Zoltan Csizmadia <zc...@gmail.com>
AuthorDate: Wed Mar 30 01:16:46 2022 -0500
AVRO-3435: Add --version to avrogen tool (#1583)
* Add version to avrogen
* Use DefaultExeTargetFrameworks from common.props
* Add version to avrogencpp
* Remove file version check
Co-authored-by: Zoltan Csizmadia <Cs...@valassis.com>
(cherry picked from commit 4fc9e2369d620f36eabdd5d6e1f36dd45e37c458)
---
lang/c++/CMakeLists.txt | 2 +
lang/c++/impl/avrogencpp.cc | 15 ++++--
lang/csharp/src/apache/codegen/Avro.codegen.csproj | 3 +-
lang/csharp/src/apache/codegen/AvroGen.cs | 19 ++++++--
.../src/apache/codegen/Properties/AssemblyInfo.cs | 33 -------------
.../src/apache/test/AvroGen/AvroGenToolTests.cs | 24 ++++++++--
lang/csharp/src/apache/test/Utils/VersionTests.cs | 55 ++++++++++++++++++++++
7 files changed, 104 insertions(+), 47 deletions(-)
diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index 4a37931..b02aea2 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -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
diff --git a/lang/c++/impl/avrogencpp.cc b/lang/c++/impl/avrogencpp.cc
index c287bbd..01c4cdb 100644
--- a/lang/c++/impl/avrogencpp.cc
+++ b/lang/c++/impl/avrogencpp.cc
@@ -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();
diff --git a/lang/csharp/src/apache/codegen/Avro.codegen.csproj b/lang/csharp/src/apache/codegen/Avro.codegen.csproj
index 371d2d7..ad49521 100644
--- a/lang/csharp/src/apache/codegen/Avro.codegen.csproj
+++ b/lang/csharp/src/apache/codegen/Avro.codegen.csproj
@@ -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>
diff --git a/lang/csharp/src/apache/codegen/AvroGen.cs b/lang/csharp/src/apache/codegen/AvroGen.cs
index cb01671..4b401a3 100644
--- a/lang/csharp/src/apache/codegen/AvroGen.cs
+++ b/lang/csharp/src/apache/codegen/AvroGen.cs
@@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
namespace Avro
{
@@ -39,6 +40,15 @@ namespace Avro
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;
@@ -135,10 +145,11 @@ namespace Avro
" 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);
}
diff --git a/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs b/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs
deleted file mode 100644
index 6175167..0000000
--- a/lang/csharp/src/apache/codegen/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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 System.Runtime.InteropServices;
-
-[assembly: AssemblyTitle("Avro.codegen")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Apache")]
-[assembly: AssemblyProduct("Avro.codegen")]
-[assembly: AssemblyCopyright("Copyright © Apache 2013")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-[assembly: ComVisible(false)]
-[assembly: Guid("3C23DD33-DD4F-42B1-B71F-8F9C86929E58")]
-[assembly: AssemblyVersion("0.9.0.0")]
-[assembly: AssemblyFileVersion("0.9.0.0")]
\ No newline at end of file
diff --git a/lang/csharp/src/apache/test/AvroGen/AvroGenToolTests.cs b/lang/csharp/src/apache/test/AvroGen/AvroGenToolTests.cs
index a5a46b4..c1433bc 100644
--- a/lang/csharp/src/apache/test/AvroGen/AvroGenToolTests.cs
+++ b/lang/csharp/src/apache/test/AvroGen/AvroGenToolTests.cs
@@ -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
@@ -51,6 +49,26 @@ namespace Avro.Test.AvroGen
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")]
diff --git a/lang/csharp/src/apache/test/Utils/VersionTests.cs b/lang/csharp/src/apache/test/Utils/VersionTests.cs
new file mode 100644
index 0000000..7492230
--- /dev/null
+++ b/lang/csharp/src/apache/test/Utils/VersionTests.cs
@@ -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);
+ }
+ }
+}