Skip to content

Commit

Permalink
The inputs from powershell main instance are not sent to main class (#…
Browse files Browse the repository at this point in the history
…124)

* #92: upgrade to JNet 1.4.14

* #105: upgrade JNetPSCore and code adaptation

* #92 plus partial #122
  • Loading branch information
masesdevelopers authored Nov 15, 2022
1 parent c1219ca commit 3d3c0e9
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ launchSettings.json
/**/TEMP/
/**/packages/
/**/bin/
/**/binCLI/
/**/MASES.KNetPS/
/**/obj/
/**/jars/
Expand Down
2 changes: 1 addition & 1 deletion src/net/KNet/KNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<None Include="..\Documentation\articles\usage.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MASES.JNet" Version="1.4.12">
<PackageReference Include="MASES.JNet" Version="1.4.14">
<IncludeAssets>All</IncludeAssets>
<PrivateAssets>None</PrivateAssets>
</PackageReference>
Expand Down
20 changes: 19 additions & 1 deletion src/net/KNetCLI/KNetCLI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Common\Common.props" />
<PropertyGroup>
<OutputPath>..\..\..\bin\</OutputPath>
<OutputPath>..\..\..\binCLI\</OutputPath>
<PackageType>DotnetTool</PackageType>
<OutputType>Exe</OutputType>
<AssemblyName>MASES.KNetCLI</AssemblyName>
Expand All @@ -14,6 +14,24 @@
<PackageId>MASES.KNetCLI</PackageId>
<PackageReadmeFile>usageCLI.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup Condition="True">
<knetcli_jars Include="$(ProjectDir)\..\..\..\jars\*.*" />
<knetcli_config Include="$(ProjectDir)\..\..\config\*.*" />
<knetcli_kraft Include="$(ProjectDir)\..\..\config\kraft\*.*" />
</ItemGroup>

<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="@(knetcli_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(knetcli_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(knetcli_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
</Target>
<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
<Copy SourceFiles="@(knetcli_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(knetcli_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(knetcli_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
</Target>

<ItemGroup>
<None Include="..\Documentation\articles\usageCLI.md" Pack="true" PackagePath="\" />
</ItemGroup>
Expand Down
7 changes: 1 addition & 6 deletions src/net/KNetCLI/KNetCLI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
<file src="..\..\..\LICENSE" target="LICENSE" />
<file src="..\Common\JCOB128x128.png" target="" />
<file src="..\Documentation\articles\usageCLI.md" target="" />
<file src="..\..\..\jars\" target="tools\netcoreapp3.1\any\jars\" />
<file src="..\..\..\jars\" target="tools\net6.0\any\jars\" />
<file src="..\..\config\" target="tools\netcoreapp3.1\any\config\" />
<file src="..\..\config\" target="tools\net6.0\any\config\" />
<file src="..\..\..\bin\netcoreapp3.1\" target="tools\netcoreapp3.1\any\" />
<file src="..\..\..\bin\net6.0\" target="tools\net6.0\any\" />
<file src="..\..\..\binCLI\net6.0\" target="tools\net6.0\any\" />
</files>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* Refer to LICENSE for more information.
*/

using Java.Util.Function;
using MASES.JCOBridge.C2JBridge;
using MASES.JCOBridge.C2JBridge.JVMInterop;
using MASES.KNet.Clients.Consumer;
Expand Down
1 change: 0 additions & 1 deletion src/net/KNetPS/ClientCmdlet/InvokeSendCmdletCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using MASES.KNet.Clients.Producer;
using MASES.KNetPS.Cmdlet;
using System.Management.Automation;
using System.Reflection;

namespace MASES.KNetPS.ClientCmdlet
{
Expand Down
58 changes: 2 additions & 56 deletions src/net/KNetPS/Cmdlet/KNetPSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,12 @@
* Refer to LICENSE for more information.
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNetPSCore;
using MASES.JNetPSCore.Cmdlet;
using MASES.KNet;
using System;
using System.Management.Automation;
using System.Reflection;

namespace MASES.KNetPS.Cmdlet
{
/// <summary>
/// Base class to be extended in derived projects for all PS cmdlet which needs the core active
/// </summary>
public abstract class KNetPSCmdlet<TCore> : PSCmdlet
where TCore : KNetCore<TCore>
{
// This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
protected override void BeginProcessing()
{
WriteVerbose("Begin of JNetPSCmdlet");
WriteVerbose(MyInvocation.Line);
}

// This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
protected sealed override void ProcessRecord()
{
if (!JNetPSHelper<TCore>.InstanceCreated)
{
WriteWarning("Engine was not started, cannot execute the command");
return;
}

try
{
ProcessCommand();
}
catch (TypeInitializationException tinite)
{
WriteError(new ErrorRecord(tinite, tinite.Source, ErrorCategory.InvalidOperation, tinite));
}
catch (TargetInvocationException tie)
{
WriteError(new ErrorRecord(tie.InnerException, tie.InnerException.Source, ErrorCategory.InvalidOperation, tie.InnerException));
}
catch (JCOBridge.C2JBridge.JVMInterop.JavaException je)
{
var newEx = je.Convert();
WriteError(new ErrorRecord(newEx, newEx.Source, ErrorCategory.InvalidOperation, newEx));
}
}

protected abstract void ProcessCommand();

// This method will be called once at the end of pipeline execution; if no input is received, this method is not called
protected override void EndProcessing()
{
WriteVerbose("End of JNetPSCmdlet");
}
}

public abstract class KNetPSCmdlet : KNetPSCmdlet<KNetCore>
public abstract class KNetPSCmdlet : JNetPSCmdlet<KNetCore>
{
}
}
11 changes: 5 additions & 6 deletions src/net/KNetPS/Cmdlet/KafkaClassToRunCmdletCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNetPSCore;
using MASES.KNet;
using MASES.KNetPS;
using System;
Expand All @@ -26,8 +27,8 @@

namespace MASES.KNetPS.Cmdlet
{
public class KafkaClassToRunCmdletCommandBase<T> : StartKNetPSCmdletCommandBase<T>
where T : KafkaClassToRunCmdletCommandBase<T>
public class KafkaClassToRunCmdletCommandBase<TCmdlet> : StartKNetPSCmdletCommandBase<TCmdlet>
where TCmdlet : KafkaClassToRunCmdletCommandBase<TCmdlet>
{
[Parameter(
ValueFromPipeline = true,
Expand All @@ -38,10 +39,8 @@ public class KafkaClassToRunCmdletCommandBase<T> : StartKNetPSCmdletCommandBase<
protected override void OnBeforeCreateGlobalInstance()
{
base.OnBeforeCreateGlobalInstance();
var t = typeof(T);
if (!t.IsDefined(typeof(CmdletAttribute), false)) throw new PSInvalidOperationException("Missing Cmdlet attribute");
var attribute = t.GetCustomAttributes(typeof(CmdletAttribute), false).First() as CmdletAttribute;
KNetPSHelper<KNetCore>.SetClassToRun(attribute.NounName);
var nounName = JNetPSHelper.NounName<TCmdlet>();
KNetPSHelper<KNetCore>.SetClassToRun(nounName);
}

protected override void OnAfterCreateGlobalInstance()
Expand Down
2 changes: 0 additions & 2 deletions src/net/KNetPS/Cmdlet/StartKNetPSCmdletCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* Refer to LICENSE for more information.
*/

using MASES.JNetPSCore.Cmdlet;
using MASES.KNet;
using System.Management.Automation;

namespace MASES.KNetPS.Cmdlet
Expand Down
1 change: 0 additions & 1 deletion src/net/KNetPS/Cmdlet/StartKNetPSCmdletCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

using MASES.JNetPSCore.Cmdlet;
using MASES.KNet;
using MASES.KNetPS;
using System.Management.Automation;

namespace MASES.KNetPS.Cmdlet
Expand Down
20 changes: 10 additions & 10 deletions src/net/KNetPS/KNetPS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
</PropertyGroup>

<ItemGroup Condition="True">
<jnetps_jars Include="$(ProjectDir)\..\..\..\jars\*.*" />
<jnetps_config Include="$(ProjectDir)\..\..\config\*.*" />
<jnetps_kraft Include="$(ProjectDir)\..\..\config\kraft\*.*" />
<knetps_jars Include="$(ProjectDir)\..\..\..\jars\*.*" />
<knetps_config Include="$(ProjectDir)\..\..\config\*.*" />
<knetps_kraft Include="$(ProjectDir)\..\..\config\kraft\*.*" />
</ItemGroup>

<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="@(jnetps_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(jnetps_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(jnetps_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
<Copy SourceFiles="@(knetps_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(knetps_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(knetps_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
</Target>
<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
<Copy SourceFiles="@(jnetps_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(jnetps_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(jnetps_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
<Copy SourceFiles="@(knetps_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(knetps_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(knetps_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
</Target>

<ItemGroup>
<ProjectReference Include="..\KNet\KNet.csproj">
<!--<IncludeAssets>All</IncludeAssets>-->
<!--<PrivateAssets>None</PrivateAssets>-->
</ProjectReference>
<PackageReference Include="MASES.JNetPSCore" Version="1.4.12" />
<PackageReference Include="MASES.JNetPSCore" Version="1.4.14" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
11 changes: 6 additions & 5 deletions src/net/KNetPS/KNetPSHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Refer to LICENSE for more information.
*/

using MASES.JNetPSCore;
using MASES.KNet;

namespace MASES.KNetPS
Expand All @@ -25,14 +26,14 @@ namespace MASES.KNetPS
/// </summary>
public static class KNetPSHelper<TClass> where TClass : KNetCore<TClass>
{
public static void SetClassToRun(string classToRun) { typeof(TClass).BaseType.GetProperty(nameof(KNetCore.ApplicationClassToRun)).SetValue(null, classToRun); }
public static void SetClassToRun(string classToRun) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetCore.ApplicationClassToRun), classToRun); }

public static void SetJarRootPath(string jarRootPath) { typeof(TClass).BaseType.GetProperty(nameof(KNetCore.ApplicationJarRootPath)).SetValue(null, jarRootPath); }
public static void SetJarRootPath(string jarRootPath) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetCore.ApplicationJarRootPath), jarRootPath); }

public static void SetLog4JPath(string log4JPath) { typeof(TClass).BaseType.GetProperty(nameof(KNetCore.ApplicationLog4JPath)).SetValue(null, log4JPath); }
public static void SetLog4JPath(string log4JPath) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetCore.ApplicationLog4JPath), log4JPath); }

public static void SetLogPath(string logPath) { typeof(TClass).BaseType.GetProperty(nameof(KNetCore.ApplicationLogPath)).SetValue(null, logPath); }
public static void SetLogPath(string logPath) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetCore.ApplicationLogPath), logPath); }

public static void SetScalaVersion(string scalaVersion) { typeof(TClass).BaseType.GetProperty(nameof(KNetCore.ApplicationScalaVersion)).SetValue(null, scalaVersion); }
public static void SetScalaVersion(string scalaVersion) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetCore.ApplicationScalaVersion), scalaVersion); }
}
}

0 comments on commit 3d3c0e9

Please sign in to comment.