From ae127ca7142171edbadfd31c25dc111f0f9e399d Mon Sep 17 00:00:00 2001 From: "Denis Kuzmin [ GitHub/3F ]" Date: Sat, 2 Jan 2021 18:24:27 +0300 Subject: [PATCH] Implemented `-no-mgr` key: - Do not use manager for automatic restore the remote package. --- Manager/batch/.compressor | 2 +- Manager/batch/Manager.bat | 110 ++++++++++--------- Manager/batch/tests.bat | 11 +- Manager/batch/tests.targets | 10 +- Wizard/DllExportCfgTask.cs | 12 ++ Wizard/DxpOptType.cs | 39 +++++++ Wizard/Extensions/XProjectExtension.cs | 27 +++++ Wizard/IWizardConfig.cs | 5 + Wizard/Project.cs | 134 +++++------------------ Wizard/UI/SimpleConfFormater.cs | 1 + Wizard/Wizard.csproj | 1 + Wizard/net.r_eg.DllExport.Wizard.targets | 2 + 12 files changed, 193 insertions(+), 161 deletions(-) create mode 100644 Wizard/DxpOptType.cs diff --git a/Manager/batch/.compressor b/Manager/batch/.compressor index 94d88ba..1919890 100644 --- a/Manager/batch/.compressor +++ b/Manager/batch/.compressor @@ -92,7 +92,7 @@ var vdict = gencomb(cdict, 2, (int i) => { return char.IsLetter(cdict[i]) || cdict[i] == '_'; }); // to skip processing for: - var exvar = new[] { "__p_call", "__dxp_pv", "wMgrArgs", "wPkgVer", "wProxy", "wSlnDir", "wPkgPath", "wMetaLib", "wMetaCor", "wDxpTarget", "wAction", "wSlnFile", "wRootPath", "ngserver" }; + var exvar = new[] { "__p_call", "__dxp_pv", "wMgrArgs", "wPkgVer", "wProxy", "wDxpOpt", "wSlnDir", "wPkgPath", "wMetaLib", "wMetaCor", "wDxpTarget", "wAction", "wSlnFile", "wRootPath", "ngserver" }; const string VNAME = "[a-z_][a-z_0-9]+"; const string VERS = "[Minified version]"; diff --git a/Manager/batch/Manager.bat b/Manager/batch/Manager.bat index 3d34672..4443d01 100644 --- a/Manager/batch/Manager.bat +++ b/Manager/batch/Manager.bat @@ -1,6 +1,6 @@ @echo off & echo Incomplete script. Compile it first via 'build.bat' - github.com/3F/DllExport 1>&2 & exit /B 1 -:: Copyright (c) 2016-2020 Denis Kuzmin [ x-3F@outlook.com ] +:: Copyright (c) 2016-2021 Denis Kuzmin [x-3F@outlook.com] github/3F :: https://github.com/3F/DllExport @@ -83,6 +83,11 @@ set "buildInfoFile=build_info.txt" set "fManager=!dpnx0!" set "wRootPath=!cd!" +:: - +:: bitwise parameters + +set /a wDxpOpt=0 + :: - set "dxpDebug=" @@ -121,7 +126,7 @@ goto commands echo. @echo .NET DllExport $-version-$ @echo Copyright (c) 2009-2015 Robert Giesecke -@echo Copyright (c) 2016-2020 Denis Kuzmin [ x-3F@outlook.com ] GitHub/3F +@echo Copyright (c) 2016-2021 Denis Kuzmin ^ github/3F echo. echo MIT License @echo https://github.com/3F/DllExport @@ -131,60 +136,61 @@ echo. @echo Usage: DllExport [args to DllExport] [args to GetNuTool] [args to hMSBuild] echo ------ echo. -echo Arguments: -echo ---------- -echo -action {type} - Specified action for Wizard. Where {type}: -echo * Configure - To configure DllExport for specific projects. -echo * Update - To update pkg reference for already configured projects. -echo * Restore - To restore configured DllExport. -echo * Export - To export configured projects data. -echo * Recover - To re-configure projects via predefined/exported data. -echo * Unset - To unset all data from specified projects. -echo * Upgrade - Aggregates an Update action with additions for upgrading. +echo Arguments +echo --------- +echo -action {type} - Specified action for Wizard. Where {type}: +echo * Configure - To configure DllExport for specific projects. +echo * Update - To update pkg reference for already configured projects. +echo * Restore - To restore configured DllExport. +echo * Export - To export configured projects data. +echo * Recover - To re-configure projects via predefined/exported data. +echo * Unset - To unset all data from specified projects. +echo * Upgrade - Aggregates an Update action with additions for upgrading. echo. -echo -sln-dir {path} - Path to directory with .sln files to be processed. -echo -sln-file {path} - Optional predefined .sln file to be processed. -echo -metalib {path} - Relative path to meta library. -echo -metacor {path} - Relative path to meta core library. -echo -dxp-target {path} - Relative path to entrypoint wrapper of the main core. -echo -dxp-version {num} - Specific version of DllExport. Where {num}: -echo * Versions: 1.6.6 ... -echo * Keywords: -echo `actual` - Unspecified local/latest remote version; -echo ( Only if you know what you are doing ) +echo -sln-dir {path} - Path to directory with .sln files to be processed. +echo -sln-file {path} - Optional predefined .sln file to be processed. +echo -metalib {path} - Relative path to meta library. +echo -metacor {path} - Relative path to meta core library. +echo -dxp-target {path} - Relative path to entrypoint wrapper of the main core. +echo -dxp-version {num} - Specific version of DllExport. Where {num}: +echo * Versions: 1.7.3 ... +echo * Keywords: +echo `actual` - Unspecified local/latest remote version; +echo ( Only if you know what you are doing ) echo. -echo -msb {path} - Full path to specific msbuild. -echo -hMSBuild {args} - Access to hMSBuild tool (packed) https://github.com/3F/hMSBuild -echo -packages {path} - A common directory for packages. -echo -server {url} - Url for searching remote packages. -echo -proxy {cfg} - To use proxy. The format: [usr[:pwd]@]host[:port] -echo -pkg-link {uri} - Direct link to package from the source via specified URI. -echo -force - Aggressive behavior, e.g. like removing pkg when updating. -echo -mgr-up - Updates this manager to version from '-dxp-version'. -echo -wz-target {path} - Relative path to entrypoint wrapper of the main wizard. -echo -pe-exp-list {module} - To list all available exports from PE32/PE32+ module. -echo -eng - Try to use english language for all build messages. -echo -GetNuTool {args} - Access to GetNuTool (integrated) https://github.com/3F/GetNuTool -echo -debug - To show additional information. -echo -version - Displays version for which (together with) it was compiled. -echo -build-info - Displays actual build information from selected DllExport. -echo -help - Displays this help. Aliases: -help -h +echo -msb {path} - Full path to specific msbuild. +echo -hMSBuild {args} - Access to hMSBuild tool (packed) https://github.com/3F/hMSBuild +echo -packages {path} - A common directory for packages. +echo -server {url} - Url for searching remote packages. +echo -proxy {cfg} - To use proxy. The format: [usr[:pwd]@]host[:port] +echo -pkg-link {uri} - Direct link to package from the source via specified URI. +echo -force - Aggressive behavior, e.g. like removing pkg when updating. +echo -no-mgr - Do not use %~nx0 for automatic restore the remote package. +echo -mgr-up - Updates %~nx0 to version from '-dxp-version'. +echo -wz-target {path} - Relative path to entrypoint wrapper of the main wizard. +echo -pe-exp-list {module} - To list all available exports from PE32/PE32+ module. +echo -eng - Try to use english language for all build messages. +echo -GetNuTool {args} - Access to GetNuTool (integrated) https://github.com/3F/GetNuTool +echo -debug - To show additional information. +echo -version - Displays version for which (together with) it was compiled. +echo -build-info - Displays actual build information from selected DllExport. +echo -help - Displays this help. Aliases: -help -h echo. -echo Flags: -echo ------ +echo Flags +echo ----- echo __p_call - To use the call-type logic when invoking %~nx0 echo. -echo Samples: -echo -------- -echo DllExport -action Configure -force -pkg-link http://host/v1.6.6.nupkg -echo DllExport -action Restore -sln-file "Conari.sln" -echo DllExport -proxy guest:1234@10.0.2.15:7428 -action Configure +echo Samples +echo ------- +echo DllExport -action Configure -force -pkg-link http://host/v1.7.3.nupkg +echo DllExport -action Restore -sln-file "Conari.sln" +echo DllExport -proxy guest:1234@10.0.2.15:7428 -action Configure echo. -echo DllExport -mgr-up -dxp-version 1.6.6 -echo DllExport -action Upgrade -dxp-version 1.6.6 +echo DllExport -mgr-up -dxp-version 1.7.3 +echo DllExport -action Upgrade -dxp-version 1.7.3 echo. -echo DllExport -GetNuTool /p:ngpackages="Conari;regXwild" -echo DllExport -pe-exp-list bin\Debug\regXwild.dll +echo DllExport -GetNuTool /p:ngpackages="Conari;regXwild" +echo DllExport -pe-exp-list bin\Debug\regXwild.dll goto endpoint @@ -279,6 +285,11 @@ set key=!arg[%idx%]! set kForce=1 + goto continue + ) else if [!key!]==[-no-mgr] ( + + set /a wDxpOpt^|=1 + goto continue ) else if [!key!]==[-mgr-up] ( @@ -347,6 +358,7 @@ call :dbgprint "-metalib = " wMetaLib call :dbgprint "-metacor = " wMetaCor call :dbgprint "-dxp-target = " wDxpTarget call :dbgprint "-wz-target = " tWizard +call :dbgprint "#opt " wDxpOpt if defined dxpVersion ( if "!dxpVersion!"=="actual" ( diff --git a/Manager/batch/tests.bat b/Manager/batch/tests.bat index 7c5fd8d..ca34dcf 100644 --- a/Manager/batch/tests.bat +++ b/Manager/batch/tests.bat @@ -159,11 +159,18 @@ set appl=%app% -pkg-link "..\..\DllExport.$version$.nupkg" setlocal echo Test case 16: checking for -dxp-version, -server, -proxy & set "%flagName%=16" - call %mgrFile% -action Default -dxp-version 1.6.5 - call %app% -action Default -dxp-version 1.6.5 -server "https://127.0.0.1:8082/" -proxy "guest:1234@127.0.0.1:7428" + call %mgrFile% -action Default -dxp-version 1.7.3 + call %app% -action Default -dxp-version 1.7.3 -server "https://127.0.0.1:8082/" -proxy "guest:1234@127.0.0.1:7428" :: -pe-exp-list "bin\Debug\regXwild.dll" endlocal + + setlocal + echo Test case 17: checking for -no-mgr flag & set "%flagName%=17" + + call %appl% -no-mgr + + endlocal endlocal \ No newline at end of file diff --git a/Manager/batch/tests.targets b/Manager/batch/tests.targets index 412b2a5..f739ec5 100644 --- a/Manager/batch/tests.targets +++ b/Manager/batch/tests.targets @@ -19,6 +19,7 @@ + @@ -119,8 +120,8 @@ - - + + @@ -132,4 +133,9 @@ --> + + + + + \ No newline at end of file diff --git a/Wizard/DllExportCfgTask.cs b/Wizard/DllExportCfgTask.cs index d75ffce..9aebbf0 100644 --- a/Wizard/DllExportCfgTask.cs +++ b/Wizard/DllExportCfgTask.cs @@ -126,6 +126,14 @@ public string Storage } } + /// + /// Updates type for . + /// + public long DxpOpt + { + set => Options = (DxpOptType)value; + } + #endregion /// @@ -137,6 +145,9 @@ public string Storage /// public CfgStorageType CfgStorage { get; set; } = CfgStorageType.Default; + /// + public DxpOptType Options { get; protected set; } + /// public ActionType Type { get; protected set; } @@ -253,6 +264,7 @@ private void PrintKeys(Message.Level level) LSender.Send(this, $"Proxy: '{Proxy}'", level); LSender.Send(this, $"DxpTarget: '{DxpTarget}'", level); LSender.Send(this, $"RootPath: '{RootPath}'", level); + LSender.Send(this, $"Options: '{Options}'", level); LSender.Send(this, $"Storage: '{CfgStorage}'", level); LSender.Send(this, $"StoragePath: '{StoragePath}'", level); LSender.Send(this, $"Action: '{Type}'", level); diff --git a/Wizard/DxpOptType.cs b/Wizard/DxpOptType.cs new file mode 100644 index 0000000..0d69008 --- /dev/null +++ b/Wizard/DxpOptType.cs @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2021 Denis Kuzmin github/3F + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +*/ + +using System; + +namespace net.r_eg.DllExport.Wizard +{ + [Flags] + public enum DxpOptType + { + None, + + /// + /// Do not use manager for automatic restore the remote package. + /// + NoMgr = 0x01, + } +} \ No newline at end of file diff --git a/Wizard/Extensions/XProjectExtension.cs b/Wizard/Extensions/XProjectExtension.cs index d5d615e..0e2200d 100644 --- a/Wizard/Extensions/XProjectExtension.cs +++ b/Wizard/Extensions/XProjectExtension.cs @@ -125,5 +125,32 @@ internal static void RemovePropertyGroups(this IXProject xp, Func xp.RemovePropertyGroups(p => p.Properties.Count < 1); + + internal static bool RemoveXmlTarget(this IXProject xp, string name) + { + if(string.IsNullOrWhiteSpace(name)) + { + return false; + } + + var target = xp?.Project.Xml.Targets?.FirstOrDefault(t => t.Name == name); + if(target != null) + { + xp.Project.Xml.RemoveChild(target); + return true; + } + return false; + } + + internal static void RemoveProperties(this IXProject xp, params string[] names) + { + if(xp == null) return; + + foreach(string name in names) + { + if(!string.IsNullOrWhiteSpace(name)) while(xp.RemoveProperty(name, true)) { } + } + xp.RemoveEmptyPropertyGroups(); + } } } \ No newline at end of file diff --git a/Wizard/IWizardConfig.cs b/Wizard/IWizardConfig.cs index ef9bee4..c50bdab 100644 --- a/Wizard/IWizardConfig.cs +++ b/Wizard/IWizardConfig.cs @@ -87,6 +87,11 @@ public interface IWizardConfig /// string Proxy { get; } + /// + /// Options through . + /// + DxpOptType Options { get; } + /// /// Path to external storage if used. /// diff --git a/Wizard/Project.cs b/Wizard/Project.cs index c3d79fa..cc97973 100644 --- a/Wizard/Project.cs +++ b/Wizard/Project.cs @@ -57,32 +57,18 @@ public class Project: IProject, IProjectSvc private readonly IEnumerable gears; private readonly LegacyPackagesFile lpf; - /// - /// Access to found project. - /// - public IXProject XProject - { - get; - protected set; - } + /// + public IXProject XProject { get; protected set; } - /// - /// Installation checking. - /// + /// public bool Installed => InternalError == null && !string.IsNullOrWhiteSpace(GetProperty(MSBuildProperties.DXP_ID)); - /// - /// Message if an internal error occurred, otherwise null value. - /// TODO: because of DxpIsolatedEnv. See details there. - /// + /// public string InternalError => XProject?.GetProperty(DxpIsolatedEnv.ERR_MSG, true).evaluatedValue; - /// - /// Special identifier. Like `ProjectGuid` that is not available in SDK-based projects. - /// https://github.com/3F/DllExport/issues/36#issuecomment-320794498 - /// + /// public string DxpIdent { get @@ -103,9 +89,7 @@ public string DxpIdent } private string _dxpIdent; - /// - /// Relative path from location of sln file. - /// + /// public string ProjectPath { get @@ -119,57 +103,28 @@ public string ProjectPath } } - /// - /// Full path to root solution directory. - /// + /// public virtual string SlnDir => XProject?.Sln?.SolutionDir ?? Config?.Wizard?.SlnDir; - /// - /// Get defined namespace for project. - /// + /// public string ProjectNamespace => GetProperty(MSBuildProperties.PRJ_NAMESPACE); - /// - /// Checks usage of external storage for this project. - /// + /// public bool HasExternalStorage => XProject?.GetImports(null, Guids.X_EXT_STORAGE).Count() > 0; - /// - /// Active configuration of user data. - /// - public IUserConfig Config - { - get; - set; - } + /// + public IUserConfig Config { get; set; } - /// - /// List of used MSBuild properties. - /// - public IDictionary ConfigProperties - { - get; - private set; - } = new Dictionary(); + /// + public IDictionary ConfigProperties { get; private set; } + = new Dictionary(); - /// - /// Limitation of actions if not used PublicKeyToken. - /// https://github.com/3F/DllExport/issues/65 - /// - public bool PublicKeyTokenLimit - { - get; - set; - } = true; + /// + public bool PublicKeyTokenLimit { get; set; } = true; protected ISender Log => Config?.Log ?? LSender._; - /// - /// Returns fullpath to meta library for current project. - /// - /// Will return unevaluated value if false. - /// netfx-based or netcore-based meta lib. - /// + /// public virtual string MetaLib(bool evaluate, bool corlib = false) { string mdll = GetMetaDll(corlib); @@ -192,11 +147,7 @@ public virtual string MetaLib(bool evaluate, bool corlib = false) ); } - /// - /// To recover references with project file. - /// IWizardConfig.CfgStorage value can affect on type of this references. - /// - /// Known identifier of the references. + /// public void Recover(string id) { if(string.IsNullOrWhiteSpace(id)) { @@ -208,9 +159,7 @@ public void Recover(string id) ActionConfigure(true); } - /// - /// To unset configured data from project if presented. - /// + /// public void Unset() { Log.send(this, $"Trying to unset data from '{DxpIdent}'", Message.Level.Info); @@ -218,11 +167,7 @@ public void Unset() Save(); } - /// - /// To configure project via specific action. - /// - /// - /// + /// public virtual bool Configure(ActionType type) { switch(type) { @@ -246,7 +191,7 @@ public virtual bool Configure(ActionType type) #region IProjectSvc ProjectTargetElement IProjectSvc.AddTarget(string name) => AddTarget(name); - bool IProjectSvc.RemoveXmlTarget(string name) => RemoveXmlTarget(name); + bool IProjectSvc.RemoveXmlTarget(string name) => XProject.RemoveXmlTarget(name); void IProjectSvc.SetProperty(string name, string value) => SetProperty(name, value); void IProjectSvc.SetProperty(string name, bool val) => SetProperty(name, val); void IProjectSvc.SetProperty(string name, int val) => SetProperty(name, val); @@ -254,17 +199,13 @@ public virtual bool Configure(ActionType type) #endregion - /// - /// public Project(IXProject xproject, IConfigInitializer init) : this(xproject) { Config = GetUserConfig(xproject, init); - Config.AddTopNamespace(ProjectNamespace); } - /// public Project(IXProject xproject) { XProject = xproject ?? throw new ArgumentNullException(nameof(xproject)); @@ -448,7 +389,7 @@ protected void CfgPlatform() } } - RemoveProperties(MSBuildProperties.PRJ_PLATFORM); + XProject.RemoveProperties(MSBuildProperties.PRJ_PLATFORM); SetProperty(MSBuildProperties.PRJ_PLATFORM, platform); Log.send(this, $"Export has been configured for platform: {platformS ?? platform}"); } @@ -503,7 +444,7 @@ protected void Reset(bool hardReset) UninstallGears(hardReset); if(hardReset) { - RemoveProperties(ConfigProperties.Keys.ToArray()); + XProject.RemoveProperties(ConfigProperties.Keys.ToArray()); //TODO: id for our group ConfigProperties.Clear(); } @@ -570,6 +511,8 @@ protected ProjectTargetElement AddRestoreDxp(string name, string condition, stri var target = AddTarget(name); target.BeforeTargets = "PrepareForBuild"; + if((Config.Wizard.Options & DxpOptType.NoMgr) == DxpOptType.NoMgr) return target; + var ifManager = $"Exists('$({MSBuildProperties.SLN_DIR}){manager}')"; var taskMsg = target.AddTask("Error"); @@ -687,10 +630,10 @@ protected void RemoveDllExportLib() while(XProject.RemoveImport(XProject.GetImport(null, METALIB_PK_TOKEN))) { } Log.send(this, $"Trying to remove old restore-target: '{MSBuildTargets.DXP_PKG_R}'", Message.Level.Info); - while(RemoveXmlTarget(MSBuildTargets.DXP_PKG_R)) { } + while(XProject.RemoveXmlTarget(MSBuildTargets.DXP_PKG_R)) { } Log.send(this, $"Trying to remove dynamic `import` section: '{MSBuildTargets.DXP_R_DYN}'", Message.Level.Info); - while(RemoveXmlTarget(MSBuildTargets.DXP_R_DYN)) { } + while(XProject.RemoveXmlTarget(MSBuildTargets.DXP_R_DYN)) { } Log.send(this, $"Trying to remove X_EXT_STORAGE Import elements: '{Guids.X_EXT_STORAGE}'", Message.Level.Info); while(XProject.RemoveImport(XProject.GetImport(null, Guids.X_EXT_STORAGE))) { } @@ -708,29 +651,6 @@ protected void RemoveDllExportLib() } } - protected bool RemoveXmlTarget(string name) - { - if(string.IsNullOrWhiteSpace(name)) { - return false; - } - - var target = XProject.Project.Xml.Targets.FirstOrDefault(t => t.Name == name); - if(target != null) { - XProject.Project.Xml.RemoveChild(target); - return true; - } - return false; - } - - protected void RemoveProperties(params string[] names) - { - foreach(string name in names) - { - if(!string.IsNullOrWhiteSpace(name)) while(XProject.RemoveProperty(name, true)) { } - } - XProject.RemoveEmptyPropertyGroups(); //TODO: id for our group - } - /// /// To add `import` section. /// diff --git a/Wizard/UI/SimpleConfFormater.cs b/Wizard/UI/SimpleConfFormater.cs index fd77bc5..c8a74f9 100644 --- a/Wizard/UI/SimpleConfFormater.cs +++ b/Wizard/UI/SimpleConfFormater.cs @@ -77,6 +77,7 @@ public string Parse(IProject prj) sb.AppendLine($"UseCecil: {prj.Config.UseCecil}"); sb.AppendLine($"intermediateFiles: {prj.Config.Compiler.intermediateFiles}"); sb.AppendLine($"timeout: {prj.Config.Compiler.timeout}"); + sb.AppendLine($"Options: {prj.Config.Wizard.Options}"); sb.AppendLine($"RootPath: {prj.Config.Wizard.RootPath}"); sb.AppendLine($"PkgPath: {prj.Config.Wizard.PkgPath}"); sb.AppendLine($"SlnFile: {prj.Config.Wizard.SlnFile}"); diff --git a/Wizard/Wizard.csproj b/Wizard/Wizard.csproj index e12ad56..282fadb 100644 --- a/Wizard/Wizard.csproj +++ b/Wizard/Wizard.csproj @@ -59,6 +59,7 @@ + diff --git a/Wizard/net.r_eg.DllExport.Wizard.targets b/Wizard/net.r_eg.DllExport.Wizard.targets index 1cf5980..b5499f8 100644 --- a/Wizard/net.r_eg.DllExport.Wizard.targets +++ b/Wizard/net.r_eg.DllExport.Wizard.targets @@ -27,6 +27,7 @@ + 0 @@ -54,6 +55,7 @@ Action="$(wAction)" PkgVer="$(wPkgVer)" Proxy="$(wProxy)" + DxpOpt="$(wDxpOpt)" MsgGuiLevel="$(MsgGuiLevel)" />