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: 1 addition & 1 deletion .github/workflows/generateclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
DOTNET_CreateDumpVerboseDiagnostics: 1
DOTNET_EnableCrashReport: 1
JCOBRIDGE_LicensePath: ${{ secrets.JCOBRIDGE_ENCODED_2_5_21 }}
JNet_Version: 2.5.12
JNet_Version: 2.5.13
PDFBox_Version: 3.0.5
FONTCACHE_FOLDER: ${{ github.workspace }}\fontcache

Expand Down
2 changes: 1 addition & 1 deletion src/jvm/netpdf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<maven.compiler.target>11</maven.compiler.target>
<classpathfile>${basedir}/classpathfile.classpath</classpathfile>
<mavenSkipMain>false</mavenSkipMain> <!-- set mavenSkipMain to true to avoid source compilation: use directive in command-line -->
<jnetVersion>2.5.12.0</jnetVersion>
<jnetVersion>2.5.13.0</jnetVersion>
<pdfBoxVersion>3.0.5</pdfBoxVersion>
<netpdfversion>3.0.4.0</netpdfversion>
<jcobridgepath>../../../bin/net8.0/JCOBridge.jar</jcobridgepath>
Expand Down
4 changes: 4 additions & 0 deletions src/net/Common/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup Condition="True">
<netpdf_jars Include="$(ProjectDir)\..\..\..\jars\**\*.*" />
<netpdf_config Include="$(ProjectDir)\..\..\config\**\*.*" />
</ItemGroup>
<ItemGroup Condition="'$(NETPDF_DOCKER_BUILD_ACTIONS)' != 'true'">
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/net/NetPDF/InternalConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace MASES.NetPDF
class CLIParam
{
// CommonArgs
public const string ClassToRun = "ClassToRun";
public const string CommonLoggingConfiguration = "CommonLoggingConfiguration";
public const string LogPath = "LogPath";
public const string FontCachePath = "FontCachePath";
Expand Down
12 changes: 4 additions & 8 deletions src/net/NetPDF/NetPDF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
<PropertyGroup Condition="'$(GITHUB_SIMPLIFIED_GENERATION)' == 'true'">
<DefineConstants>$(DefineConstants);NETPDF_SIMPLIFIED_GENERATION</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="True">
<netpdf_jars Include="$(ProjectDir)\..\..\..\jars\*.*" />
<netpdf_config Include="$(ProjectDir)\..\..\config\*.*" />
</ItemGroup>
<Target Name="CopyCustomContent" AfterTargets="AfterBuild" Condition="'$(GITHUB_ACTIONS)' != 'true' Or '$(GITHUB_TEST_PREPARATION)' == 'true'">
<Copy SourceFiles="@(netpdf_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(netpdf_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(netpdf_jars)" DestinationFolder="$(OutDir)\jars\%(RecursiveDir)" />
<Copy SourceFiles="@(netpdf_config)" DestinationFolder="$(OutDir)\config\%(RecursiveDir)" />
</Target>
<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish" Condition="'$(GITHUB_ACTIONS)' != 'true' Or '$(GITHUB_TEST_PREPARATION)' == 'true'">
<Copy SourceFiles="@(netpdf_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(netpdf_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(netpdf_jars)" DestinationFolder="$(OutDir)\jars\%(RecursiveDir)" />
<Copy SourceFiles="@(netpdf_config)" DestinationFolder="$(OutDir)\config\%(RecursiveDir)" />
</Target>
<ItemGroup>
<None Include="mases.netpdf.targets" Pack="true" PackagePath="build" />
Expand Down
46 changes: 0 additions & 46 deletions src/net/NetPDF/NetPDFCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public override IEnumerable<IArgumentMetadata> CommandLineArguments
var lst = new List<IArgumentMetadata>(base.CommandLineArguments);
lst.AddRange(new IArgumentMetadata[]
{
new ArgumentMetadata<string>()
{
Name = CLIParam.ClassToRun,
Help = "The class to be instantiated from CLI.",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.CommonLoggingConfiguration,
Expand Down Expand Up @@ -95,7 +90,6 @@ protected override string[] ProcessCommandLine()
{
var result = base.ProcessCommandLine();

_classToRun = ParsedArgs.Get<string>(CLIParam.ClassToRun);
_commonLoggingPath = ParsedArgs.Get<string>(CLIParam.CommonLoggingConfiguration);
if (!Path.IsPathRooted(_commonLoggingPath)) // it is not a full path
{
Expand All @@ -114,37 +108,6 @@ protected override string[] ProcessCommandLine()
_usePureJavaCMYKConversion = ParsedArgs.Exist(CLIParam.UsePureJavaCMYKConversion);
return result;
}
/// <summary>
/// Prepare <see cref="MainClassToRun"/> property
/// </summary>
/// <param name="className">The class to search</param>
/// <exception cref="ArgumentException">If <paramref name="className"/> does not have a corresponding implemented <see cref="Type"/></exception>
protected virtual void PrepareMainClassToRun(string className)
{
if (string.IsNullOrWhiteSpace(className)) return;
var invariantLowClassName = className.ToLowerInvariant();
Type type = null;
foreach (var item in typeof(NetPDFCore<>).Assembly.ExportedTypes)
{
if (item.Name.ToLowerInvariant() == invariantLowClassName
|| item.FullName.ToLowerInvariant() == invariantLowClassName)
{
type = item;
break;
}
}
MainClassToRun = type ?? throw new ArgumentException($"Requested class {className} is not a valid class name.");
}

/// <summary>
/// Sets the <see cref="Type"/> to be invoked at startup
/// </summary>
public static Type MainClassToRun { get; protected set; }

/// <summary>
/// Sets the global value of class to run
/// </summary>
public static string ApplicationClassToRun { get; set; }

/// <summary>
/// Sets the global value of log4j path
Expand All @@ -166,15 +129,6 @@ protected virtual void PrepareMainClassToRun(string className)
/// </summary>
public static bool? ApplicationUsePureJavaCMYKConversion { get; set; }

/// <summary>
/// value can be overridden in subclasses
/// </summary>
protected string _classToRun;
/// <summary>
/// The class to run in CLI version
/// </summary>
public virtual string ClassToRun { get { return ApplicationClassToRun ?? _classToRun; } }

string _commonLoggingPath;
/// <summary>
/// The log4j folder
Expand Down
18 changes: 6 additions & 12 deletions src/net/NetPDFCLI/NetPDFCLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageType>DotnetTool</PackageType>
<OutputType>Exe</OutputType>
<AssemblyName>MASES.NetPDFCLI</AssemblyName>
<RootNamespace>MASES.NetPDFCLI</RootNamespace>
<RootNamespace>MASES.NetPDF.CLI</RootNamespace>
<Title>NetPDF command line interface - .NET suite for PDFBox™</Title>
<Description>Command line interface of .NET suite for PDFBox™. NetPDF is a comprehensive suite of libraries and tools to use PDFBox™ and .NET side-by-side.</Description>
<Product>NetPDFCLI</Product>
Expand All @@ -16,26 +16,20 @@
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
</PropertyGroup>

<ItemGroup Condition="True">
<netpdfcli_jars Include="$(ProjectDir)\..\..\..\jars\*.*" />
<netpdfcli_config Include="$(ProjectDir)\..\..\config\*.*" />
</ItemGroup>

<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="@(netpdfcli_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(netpdfcli_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(netpdf_jars)" DestinationFolder="$(OutDir)\jars\%(RecursiveDir)" />
<Copy SourceFiles="@(netpdf_config)" DestinationFolder="$(OutDir)\config\%(RecursiveDir)" />
</Target>
<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
<Copy SourceFiles="@(netpdfcli_jars)" DestinationFolder="$(OutDir)\jars" />
<Copy SourceFiles="@(netpdfcli_config)" DestinationFolder="$(OutDir)\config" />
<Copy SourceFiles="@(netpdf_jars)" DestinationFolder="$(OutDir)\jars\%(RecursiveDir)" />
<Copy SourceFiles="@(netpdf_config)" DestinationFolder="$(OutDir)\config\%(RecursiveDir)" />
</Target>

<ItemGroup>
<None Include="..\..\documentation\articles\usageCLI.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.14.0" />
<PackageReference Include="MASES.JNetCLICore" Version="2.5.13" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
188 changes: 12 additions & 176 deletions src/net/NetPDFCLI/NetPDFCLICore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,208 +18,44 @@

using MASES.CLIParser;
using MASES.JNet;
using MASES.NetPDF;
using MASES.JNet.Specific.CLI;
using System;
using System.Collections.Generic;
using System.IO;

namespace MASES.NetPDFCLI
namespace MASES.NetPDF.CLI
{
/// <summary>
/// Overridable implementation of <see cref="NetPDFCore{T}"/>
/// </summary>
public class NetPDFCLICore<T> : NetPDFCore<T>
where T : NetPDFCLICore<T>
{
class CLIParam
{
// ReflectorArgs
public static string[] Interactive = new string[] { "Interactive", "i" };
public static string[] NoLogo = new string[] { "NoLogo", "nl" };
public static string[] Script = new string[] { "Script", "s" };
public static string[] JarList = new string[] { "JarList", "jl" };
public static string[] NamespaceList = new string[] { "NamespaceList", "nl" };
public static string[] ImportList = new string[] { "ImportList", "il" };
}

static bool _Interactive;
public static bool Interactive => _Interactive;

static bool _NoLogo;
public static bool NoLogo => _NoLogo;

static string _Script;
public static string Script => _Script;

static IEnumerable<string> _JarList;
public static IEnumerable<string> JarList => _JarList;

static IEnumerable<string> _NamespaceList;
public static IEnumerable<string> NamespaceList => _NamespaceList;

static IEnumerable<string> _ImportList;
public static IEnumerable<string> ImportList => _ImportList;

/// <inheritdoc cref="JNetCoreBase{T}.CommandLineArguments"/>
public override IEnumerable<IArgumentMetadata> CommandLineArguments => base.CommandLineArguments.SetCLICommandLineArguments();
/// <summary>
/// Public ctor
/// </summary>
public NetPDFCLICore()
{
foreach (var item in ImportList)
{
ImportPackage(item);
}
}

public override IEnumerable<IArgumentMetadata> CommandLineArguments
{
get
{
var lst = new List<IArgumentMetadata>(base.CommandLineArguments);
lst.AddRange(new IArgumentMetadata[]
{
new ArgumentMetadata<string>()
{
Name = CLIParam.Interactive[0],
ShortName = CLIParam.Interactive[1],
Type = ArgumentType.Single,
Help = "Activate an interactive shell",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.NoLogo[0],
ShortName = CLIParam.NoLogo[1],
Type = ArgumentType.Single,
Help = "Do not display initial informative string",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.Script[0],
ShortName = CLIParam.Script[1],
Type = ArgumentType.Double,
Help = "Run the script code and exit, the argument is the path to the file containing the script",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.JarList[0],
ShortName = CLIParam.JarList[1],
Type = ArgumentType.Double,
Help = "A CSV list of JAR to be used or folders containing the JARs",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.NamespaceList[0],
ShortName = CLIParam.NamespaceList[1],
Type = ArgumentType.Double,
Help = "A CSV list of namespace to be used for interactive shell, JNet/NetPDF namespaces are added automatically",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.ImportList[0],
ShortName = CLIParam.ImportList[1],
Type = ArgumentType.Double,
Help = "A CSV list of import to be used",
},
});
return lst;
}
this.InitCLI();
}

protected override string[] ProcessCommandLine()
{
var result = base.ProcessCommandLine(); // returns the filtered args till now

if (string.IsNullOrWhiteSpace(_classToRun) && result != null && result.Length > 0)
return this.ProcessCLIParsedArgs(result, settingsCallback: (className) =>
{
// try to use first argument as ClassToRun
_classToRun = result[0];
int remaining = result.Length - 1;
if (remaining != 0)
switch (className)
{
string[] tmp_result = new string[remaining];
Array.Copy(result, 1, tmp_result, 0, remaining); // remove first argument
result = tmp_result;
default:
ApplicationInitialHeapSize = ApplicationHeapSize = Environment.Is64BitOperatingSystem ? "512G" : "256M";
break;
}
}

_Interactive = ParsedArgs.Exist(CLIParam.Interactive[0]);
_NoLogo = ParsedArgs.Exist(CLIParam.NoLogo[0]);

_Script = ParsedArgs.Get<string>(CLIParam.Script[0]);

List<string> jarList = new List<string>();
if (ParsedArgs.Exist(CLIParam.JarList[0]))
{
var jars = ParsedArgs.Get<string>(CLIParam.JarList[0]).Split(',', ';');
jarList.AddRange(jars);
}
_JarList = jarList;

List<string> namespaceList = new List<string>();

var jnetAssembly = typeof(JNetCoreBase<>).Assembly;
foreach (var item in jnetAssembly.GetExportedTypes())
{
if (item.IsPublic)
{
if (!namespaceList.Contains(item.Namespace)) namespaceList.Add(item.Namespace);
}
}
var netpdfAssembly = typeof(NetPDFCore<>).Assembly;
foreach (var item in netpdfAssembly.GetExportedTypes())
{
if (item.IsPublic)
{
if (!namespaceList.Contains(item.Namespace)) namespaceList.Add(item.Namespace);
}
}
if (ParsedArgs.Exist(CLIParam.NamespaceList[0]))
{
var namespaces = ParsedArgs.Get<string>(CLIParam.JarList[0]).Split(',', ';');
foreach (var item in namespaces)
{
if (!namespaceList.Contains(item)) namespaceList.Add(item);
}
}
_NamespaceList = namespaceList;

List<string> importList = new List<string>();
if (ParsedArgs.Exist(CLIParam.ImportList[0]))
{
var imports = ParsedArgs.Get<string>(CLIParam.JarList[0]).Split(',', ';');
foreach (var item in imports)
{
if (!importList.Contains(item)) importList.Add(item);
}
}
_ImportList = importList;

PrepareMainClassToRun(ClassToRun);

switch (ClassToRun?.ToLowerInvariant())
{

default:
ApplicationHeapSize ??= "256M";
break;
}

return result;
});
}

/// <inheritdoc cref="JNetCoreBase{T}.PathToParse"/>
protected override IList<string> PathToParse
{
get
{
var lst = base.PathToParse;
foreach (var item in _JarList)
{
lst.Add(Path.GetFullPath(item));
}
return lst;
}
}
protected override IList<string> PathToParse => base.PathToParse.SetCLIPathToParse();
}

/// <summary>
Expand Down
Loading
Loading