diff --git a/COMET-WebServices.sln b/COMET-WebServices.sln index 9fc317ff..5f1ef7a8 100644 --- a/COMET-WebServices.sln +++ b/COMET-WebServices.sln @@ -33,8 +33,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CDP4Authentication.Tests", "CDP4Authentication.Tests\CDP4Authentication.Tests.csproj", "{551D1D98-92D6-4391-ADB8-448BC9219330}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VersionFileCreator", "VersionFileCreator\VersionFileCreator.csproj", "{E941F9C0-139A-4DB7-9C98-32A320378DDB}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -77,10 +75,6 @@ Global {551D1D98-92D6-4391-ADB8-448BC9219330}.Debug|Any CPU.Build.0 = Debug|Any CPU {551D1D98-92D6-4391-ADB8-448BC9219330}.Release|Any CPU.ActiveCfg = Release|Any CPU {551D1D98-92D6-4391-ADB8-448BC9219330}.Release|Any CPU.Build.0 = Release|Any CPU - {E941F9C0-139A-4DB7-9C98-32A320378DDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E941F9C0-139A-4DB7-9C98-32A320378DDB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E941F9C0-139A-4DB7-9C98-32A320378DDB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E941F9C0-139A-4DB7-9C98-32A320378DDB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CometServer/CometServer.csproj b/CometServer/CometServer.csproj index 464ab572..f97d107e 100644 --- a/CometServer/CometServer.csproj +++ b/CometServer/CometServer.csproj @@ -4,6 +4,7 @@ Starion Group S.A. CometServer-CE 8.0.0-rc38 + 8.0.0-rc38 CDP4-COMET Services API Copyright © Starion Group S.A. AGPL-3.0-only @@ -56,34 +57,15 @@ - - <_StaticWebAssetEmbeddedProjectConfigurationCanonicalMetadata Remove="VERSION" /> - - - <_StaticWebAssetProjectConfigurationCanonicalMetadata Remove="VERSION" /> - - - - Always - - - - ../VersionFileCreator/bin/$(Configuration)/$(TargetFramework)/VersionFileCreator.dll - False - True - - - - - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/CometServer/Scripts/versionfilecreator.ps1 b/CometServer/Scripts/versionfilecreator.ps1 new file mode 100644 index 00000000..a4c4c7c0 --- /dev/null +++ b/CometServer/Scripts/versionfilecreator.ps1 @@ -0,0 +1,70 @@ +param ( + [string]$buildTarget, + [string]$publishDir +) + +# Ensure the build target is provided +if (-not $buildTarget) { + Write-Host "No build target provided. Exiting." + exit 1 +} + +# Set the path based on the build target +$binPath = if ($publishDir) { $publishDir } else { Join-Path -Path "bin" -ChildPath $buildTarget } + +# Path to the output file in the target build directory +$outputFile = Join-Path -Path $binPath -ChildPath "VERSION" + +# Echo the path of the VERSION file +Write-Host "The VERSION file will be created at: $outputFile" + +# Clear the content of the output file or create it if it doesn't exist +if (Test-Path $outputFile) { + Clear-Content $outputFile +} else { + New-Item -Path $outputFile -ItemType File | Out-Null +} + +# Normalize the bin path by ensuring it ends with a backslash +$binPath = [System.IO.Path]::GetFullPath($binPath) + [System.IO.Path]::DirectorySeparatorChar + +# Get the list of DLLs in the output directory and all subdirectories +$dlls = Get-ChildItem -Path $binPath -Filter *.dll -Recurse + +# Initialize lists for categorized DLLs +$cdp4CometDlls = @() +$otherDlls = @() + +foreach ($dll in $dlls) { + # Get the version information + $versionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($dll.FullName) + + # Get the relative path of the DLL starting from the output directory + $relativeDllPath = $dll.FullName.Substring($binPath.Length) + + # Prepare the output line + $outputLine = "$relativeDllPath $($versionInfo.FileVersion)" + + # Categorize DLLs + if ($dll.Name -match "(?i)cdp4|comet") { + $cdp4CometDlls += $outputLine + } else { + $otherDlls += $outputLine + } +} + +# Sort the other DLLs alphabetically +$otherDlls = $otherDlls | Sort-Object + +# Write the categorized DLLs to the VERSION file +Add-Content -Path $outputFile -Value "CDP4-COMET:" +Add-Content -Path $outputFile -Value "----------------" +$cdp4CometDlls | ForEach-Object { Add-Content -Path $outputFile -Value $_ } + +Add-Content -Path $outputFile -Value "" +Add-Content -Path $outputFile -Value "Dependencies:" +Add-Content -Path $outputFile -Value "----------------" +$otherDlls | ForEach-Object { Add-Content -Path $outputFile -Value $_ } + +# Confirm the creation of the VERSION file +Write-Host "Version information written to $outputFile in $binPath" diff --git a/CometServer/VERSION b/CometServer/VERSION deleted file mode 100644 index 8b20d4b3..00000000 --- a/CometServer/VERSION +++ /dev/null @@ -1,5 +0,0 @@ -CDP4Common.dll -CDP4Orm.dll -CDP4Authentication.dll -Authentication/CDP4Database/CDP4DatabaseAuthentication.dll -CometServer.dll diff --git a/Dockerfile b/Dockerfile index d1081552..f29f28fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,25 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env + +# Install PowerShell as a .NET Global Tool +RUN dotnet tool install --global PowerShell + +# Ensure that the global tools are in the PATH +ENV PATH="$PATH:/root/.dotnet/tools" + +# Create a symbolic link for 'powershell' to point to 'pwsh' +RUN ln -s /root/.dotnet/tools/pwsh /usr/bin/powershell + WORKDIR /app COPY CDP4Authentication CDP4Authentication COPY CDP4DatabaseAuthentication CDP4DatabaseAuthentication COPY CDP4WspDatabaseAuthentication CDP4WspDatabaseAuthentication COPY CDP4Orm CDP4Orm -COPY VersionFileCreator VersionFileCreator COPY CometServer CometServer RUN dotnet build CDP4DatabaseAuthentication -c Release RUN dotnet build CDP4WspDatabaseAuthentication -c Release RUN dotnet publish -r linux-x64 CometServer -c Release -o /app/CometServer/bin/Release/publish -COPY CometServer/bin/Release/linux-x64/VERSION /app/CometServer/bin/Release/publish/VERSION - FROM mcr.microsoft.com/dotnet/aspnet:8.0.7-alpine3.20 WORKDIR /app RUN mkdir /app/logs diff --git a/VersionFileCreator/Program.cs b/VersionFileCreator/Program.cs deleted file mode 100644 index 4b1b9299..00000000 --- a/VersionFileCreator/Program.cs +++ /dev/null @@ -1,165 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate -// -// This file is part of CDP4-COMET Webservices Community Edition. -// The CDP4-COMET Webservices Community Edition is the STARION implementation of ECSS-E-TM-10-25 Annex A and Annex C. -// -// The CDP4-COMET Webservices Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET Webservices Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace VersionFileCreator -{ - using System; - using System.Diagnostics; - using System.Diagnostics.CodeAnalysis; - using System.IO; - using System.Linq; - using System.Reflection; - - [ExcludeFromCodeCoverage] - internal class Program - { - /// - /// Main entry for the versionFileCreator, handles exception and notify the user in the output build window of visual studio - /// - /// Array containing all command line arguments - public static async Task Main(string[] args) - { - try - { - string path = null; - var consolePrefix = "VersionFileCreator =>"; - - Console.WriteLine($"{consolePrefix} Checking path variable."); - - if (args == null || !args.Any(Directory.Exists)) - { - path = Directory.GetCurrentDirectory(); - } - else - { - path = args.FirstOrDefault(Directory.Exists); - } - - Console.WriteLine($"{consolePrefix} Path: {path}"); - - var outputFolder = await GetOutputFolderFromArgs(args); - - Console.WriteLine($"{consolePrefix} Build configuration: {outputFolder}"); - - var versionFile = Path.Combine(path, outputFolder, "VERSION"); - Console.WriteLine($"{consolePrefix} Version file location: {versionFile}"); - - if (!File.Exists(versionFile)) - { - Console.WriteLine($"{consolePrefix} Version file {versionFile} was NOT FOUND."); - return -1; - } - - Console.WriteLine($"{consolePrefix} Version file {versionFile} was found."); - - var versionData = await File.ReadAllTextAsync(versionFile); - versionData = versionData.Replace("\r", ""); - var versionArray = versionData.Split("\n", StringSplitOptions.RemoveEmptyEntries); - - if (versionArray.Length == 0) - { - Console.WriteLine($"{consolePrefix} No version indicators found in {versionFile}."); - return -1; - } - - var newVersionArray = new string[versionArray.Length]; - var newVersionArrayCounter = 0; - - foreach (var versionRow in versionArray) - { - Console.WriteLine($"{consolePrefix} Find Version for file: {versionRow}"); - - var searchFile = Path.Combine(path, outputFolder, versionRow); - - if (!File.Exists(searchFile)) - { - Console.WriteLine($"{consolePrefix} File {searchFile} was NOT FOUND!."); - return -1; - } - - var fileVersion = QueryVersion(searchFile); - - newVersionArray[newVersionArrayCounter] = $"{Path.GetFileNameWithoutExtension(new FileInfo(searchFile).Name)}: {fileVersion}"; - - Console.WriteLine($"{consolePrefix} File {searchFile} version is {fileVersion}."); - - newVersionArrayCounter++; - } - - Console.WriteLine($"{consolePrefix} Writing version information to {versionFile}."); - await File.WriteAllTextAsync(versionFile, string.Join("\n", newVersionArray)); - Console.WriteLine($"{consolePrefix} Version information was written to {versionFile}."); - - return 0; - } - catch (Exception e) - { - Console.WriteLine($"{e}"); - return -1; - } - } - - /// - /// Gets the Build Configuration (Debug/Release) from the command line arguments - /// - /// The array of command line arguments - /// Build Configuration when found in arguments, otherwise null - private static async Task GetOutputFolderFromArgs(string[] args) - { - var configParameterPosition = Array.FindIndex(args, x => x.StartsWith("path:")); - - return - configParameterPosition >= 0 - ? args[configParameterPosition].Split(new[] { ':' }, StringSplitOptions.None)[1] - : null; - } - - /// - /// queries the version number from an assembly - /// - /// - /// The location of the - /// - /// - /// a string representation of the version of the assembly - /// - private static string QueryVersion(string assemblyPath) - { - var fileVersionInfo = FileVersionInfo.GetVersionInfo(assemblyPath); - var productVersion = fileVersionInfo.ProductVersion; - - if (productVersion != null) - { - var plusIndex = productVersion.IndexOf('+'); - - if (plusIndex != -1) - { - return productVersion.Substring(0, plusIndex); - } - } - - return productVersion ?? "unknown"; - } - } -} \ No newline at end of file diff --git a/VersionFileCreator/VersionFileCreator.csproj b/VersionFileCreator/VersionFileCreator.csproj deleted file mode 100644 index 7c49fc88..00000000 --- a/VersionFileCreator/VersionFileCreator.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Exe - net8.0 - Starion Group S.A. - VersionFileCreator - 1.0.0 - CDP4-COMET Version File Creator - Copyright © Starion Group S.A. - AGPL-3.0-only - Sam Gerené, Alex Vorobiev, Alexander van Delft - Debug;Release - enable - enable - latest - - -