Skip to content

Commit

Permalink
Merge pull request #1230 from jamill/upgrader_tasks/installer_command
Browse files Browse the repository at this point in the history
 Upgrader: add command install action
  • Loading branch information
jamill committed Jun 13, 2019
2 parents 6924119 + 6aba70f commit dcdd18d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
15 changes: 12 additions & 3 deletions GVFS/GVFS.Common/NuGetUpgrade/InstallActionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ public class InstallActionInfo
/// </summary>
public const string ManifestEntryInstallationIdToken = "installation_id";
public const string ManifestEntryLogDirectoryToken = "log_directory";
public const string ManifestEntryInstallerBaseDirectoryToken = "installer_base_path";

public InstallActionInfo(string name, string version, string args, string installerRelativePath)
public InstallActionInfo(string name, string version, string args, string installerRelativePath, string command)
{
this.Name = name;
this.Version = version;
this.Args = args;
this.InstallerRelativePath = installerRelativePath;
this.Command = command;
}

/// <summary>
Expand All @@ -27,14 +29,21 @@ public InstallActionInfo(string name, string version, string args, string instal
public string Name { get; }

/// <summary>
/// The path to the installer, relative to the
/// content directory of the NuGet package.
/// The path to the application or document to start. The path
/// is relative to the content directory of the NuGet package.
/// </summary>
public string InstallerRelativePath { get; }

/// <summary>
/// The version of the component that this entry installs
/// </summary>
public string Version { get; }

/// <summary>
/// The command to run. If this is present, the command is run
/// directly (with the processed args), and the
/// InstallerRelativePath property is ignored.
/// </summary>
public string Command { get; }
}
}
32 changes: 21 additions & 11 deletions GVFS/GVFS.Common/NuGetUpgrade/NuGetUpgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ public class NuGetUpgrader : ProductUpgrader
/// <param name="src">The unprocessed string to use as arguments to an install command</param>
/// <param name="installationId">A unique installer ID to replace the installer_id token with.</param>
/// <returns>The argument string with tokens replaced.</returns>
public static string ReplaceArgTokens(string src, string installationId, string logsDirectory)
public static string ReplaceArgTokens(string src, string installationId, string logsDirectory, string installerBaseDirectory)
{
string dst = src.Replace(NuGetUpgrader.replacementToken(InstallActionInfo.ManifestEntryLogDirectoryToken), logsDirectory)
.Replace(NuGetUpgrader.replacementToken(InstallActionInfo.ManifestEntryInstallationIdToken), installationId);
string dst = src
.Replace(NuGetUpgrader.ReplacementToken(InstallActionInfo.ManifestEntryLogDirectoryToken), logsDirectory)
.Replace(NuGetUpgrader.ReplacementToken(InstallActionInfo.ManifestEntryInstallationIdToken), installationId)
.Replace(NuGetUpgrader.ReplacementToken(InstallActionInfo.ManifestEntryInstallerBaseDirectoryToken), installerBaseDirectory);
return dst;
}

Expand Down Expand Up @@ -326,7 +328,7 @@ public override bool TryRunInstaller(InstallActionWrapper installActionWrapper,
InstallActionInfo currentInstallAction = null;
try
{
string platformKey = InstallManifest.WindowsPlatformKey;
string platformKey = GVFSPlatform.Instance.Name;

if (!this.TryRecursivelyDeleteInstallerDirectory(out error))
{
Expand Down Expand Up @@ -359,18 +361,19 @@ public override bool TryRunInstaller(InstallActionWrapper installActionWrapper,
foreach (InstallActionInfo entry in platformInstallManifest.InstallActions)
{
currentInstallAction = entry;
string installerPath = Path.Combine(this.ExtractedInstallerPath, ContentDirectoryName, entry.InstallerRelativePath);
string installerBasePath = Path.Combine(this.ExtractedInstallerPath, ContentDirectoryName);

string args = entry.Args ?? string.Empty;

// Replace tokens on args
string processedArgs = NuGetUpgrader.ReplaceArgTokens(args, this.UpgradeInstanceId, ProductUpgraderInfo.GetLogDirectoryPath());
string processedArgs = NuGetUpgrader.ReplaceArgTokens(args, this.UpgradeInstanceId, ProductUpgraderInfo.GetLogDirectoryPath(), $"\"{installerBasePath}\"");

activity.RelatedInfo(
"Running install action: Name: {0}, Version: {1}, InstallerPath: {2} RawArgs: {3}, ProcessedArgs: {4}",
"Running install action: Name: {0}, Version: {1}, InstallerPath: {2}, Command: {3}, RawArgs: {4}, ProcessedArgs: {5}",
entry.Name,
entry.Version,
installerPath,
entry.InstallerRelativePath ?? string.Empty,
entry.Command ?? string.Empty,
args,
processedArgs);

Expand All @@ -383,7 +386,15 @@ public override bool TryRunInstaller(InstallActionWrapper installActionWrapper,
{
if (!this.dryRun)
{
this.RunInstaller(installerPath, processedArgs, out installerExitCode, out localError);
if (!string.IsNullOrEmpty(entry.Command))
{
this.RunInstaller(entry.Command, processedArgs, out installerExitCode, out localError);
}
else
{
string installerPath = Path.Combine(installerBasePath, entry.InstallerRelativePath);
this.RunInstaller(installerPath, processedArgs, out installerExitCode, out localError);
}
}
else
{
Expand Down Expand Up @@ -453,7 +464,7 @@ protected static EventMetadata CreateEventMetadata(Exception e = null)
return metadata;
}

private static string replacementToken(string tokenString)
private static string ReplacementToken(string tokenString)
{
return "{" + tokenString + "}";
}
Expand All @@ -477,7 +488,6 @@ private PackageIdentity GetPackageForVersion(Version version)

private bool TryGetPersonalAccessToken(string credentialUrl, ITracer tracer, out string token, out string error)
{
error = null;
return this.credentialStore.TryGetCredential(this.tracer, credentialUrl, out string username, out token, out error);
}

Expand Down
3 changes: 2 additions & 1 deletion GVFS/GVFS.UnitTests/Common/InstallManifestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ private InstallActionInfo CreateInstallActionInfo()
name: $"Installer{entrySuffix}",
version: $"1.{entrySuffix}.1.2",
args: $"/nodowngrade{entrySuffix}",
installerRelativePath: $"installers/installer1{entrySuffix}");
installerRelativePath: $"installers/installer1{entrySuffix}",
command: string.Empty);
}

private void VerifyInstallManifestsAreEqual(InstallManifest expected, InstallManifest actual)
Expand Down
8 changes: 4 additions & 4 deletions GVFS/GVFS.UnitTests/Common/NuGetUpgrade/NuGetUpgraderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ public void WellKnownArgumentTokensReplaced()
{
string logDirectory = "mock:\\test_log_directory";
string noTokenSourceString = "/arg no_token log_directory installation_id";
NuGetUpgrader.ReplaceArgTokens(noTokenSourceString, "unique_id", logDirectory).ShouldEqual(noTokenSourceString, "String with no tokens should not be modifed");
NuGetUpgrader.ReplaceArgTokens(noTokenSourceString, "unique_id", logDirectory, "installerBase").ShouldEqual(noTokenSourceString, "String with no tokens should not be modifed");

string sourceStringWithTokens = "/arg /log {log_directory}_{installation_id}";
string expectedProcessedString = "/arg /log " + logDirectory + "_" + "unique_id";
NuGetUpgrader.ReplaceArgTokens(sourceStringWithTokens, "unique_id", logDirectory).ShouldEqual(expectedProcessedString, "expected tokens have not been replaced");
string sourceStringWithTokens = "/arg /log {log_directory}_{installation_id}_{installer_base_path}";
string expectedProcessedString = "/arg /log " + logDirectory + "_unique_id_installerBase";
NuGetUpgrader.ReplaceArgTokens(sourceStringWithTokens, "unique_id", logDirectory, "installerBase").ShouldEqual(expectedProcessedString, "expected tokens have not been replaced");
}

[TestCase]
Expand Down

0 comments on commit dcdd18d

Please sign in to comment.