Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-420) Set env vars once config is complete
  (GH-420) Environment adapter
  (spec) remove logger
  (maint)(spec) overwrite readonly files
  (GH-113) fix message

# Conflicts:
#	src/chocolatey/infrastructure/adapters/Environment.cs
#	src/chocolatey/infrastructure/adapters/IEnvironment.cs
  • Loading branch information
ferventcoder committed Sep 30, 2015
2 parents f5d5ae5 + ff7e4c4 commit 6b7f3b2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 53 deletions.
Binary file modified src/chocolatey.resources/helpers/functions/Get-CheckSumValid.ps1
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<OverwriteReadOnlyFiles>true</OverwriteReadOnlyFiles>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public override void Context()

public override void Because()
{
MockLogger.LogMessagesToConsole = true;
Results = Service.uninstall_run(Configuration);
_packageResult = Results.FirstOrDefault().Value;
}
Expand Down
47 changes: 47 additions & 0 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace chocolatey.infrastructure.app.builders
using information;
using infrastructure.services;
using logging;
using nuget;
using platforms;
using tolerance;
using Environment = adapters.Environment;
Expand Down Expand Up @@ -64,6 +65,7 @@ public static void set_up_configuration(IList<string> args, ChocolateyConfigurat
ConfigurationOptions.reset_options();
set_global_options(args, config);
set_environment_options(config);
set_environment_variables(config);
}

private static void set_file_configuration(ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService, Action<string> notifyWarnLoggingAction)
Expand Down Expand Up @@ -329,5 +331,50 @@ private static void set_environment_options(ChocolateyConfiguration config)
config.Information.IsUserAdministrator = ProcessInformation.user_is_administrator();
config.Information.IsProcessElevated = ProcessInformation.process_is_elevated();
}

public static void set_environment_variables(ChocolateyConfiguration config)
{
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, ApplicationParameters.InstallLocation);
Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION", config.Information.ChocolateyVersion);
Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION_PRODUCT", config.Information.ChocolateyProductVersion);
Environment.SetEnvironmentVariable("OS_PLATFORM", config.Information.PlatformType.get_description_or_value());
Environment.SetEnvironmentVariable("OS_VERSION", config.Information.PlatformVersion.to_string());
Environment.SetEnvironmentVariable("OS_NAME", config.Information.PlatformName.to_string());
// experimental until we know if this value returns correctly based on the OS and not the current process.
Environment.SetEnvironmentVariable("OS_IS64BIT", config.Information.Is64Bit ? "true" : "false");
Environment.SetEnvironmentVariable("IS_ADMIN", config.Information.IsUserAdministrator ? "true" : "false");
Environment.SetEnvironmentVariable("IS_PROCESSELEVATED", config.Information.IsProcessElevated ? "true" : "false");

Environment.SetEnvironmentVariable("TEMP", config.CacheLocation);
if (config.Debug)
{
Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true");
}
if (config.Verbose)
{
Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true");
}
if (!config.Features.CheckSumFiles)
{
Environment.SetEnvironmentVariable("ChocolateyIgnoreChecksums", "true");
}
if (!string.IsNullOrWhiteSpace(config.Proxy.Location))
{
var proxyCreds = string.Empty;
if (!string.IsNullOrWhiteSpace(config.Proxy.User) &&
!string.IsNullOrWhiteSpace(config.Proxy.EncryptedPassword)
)
{
proxyCreds = "{0}:{1}@".format_with(config.Proxy.User, NugetEncryptionUtility.DecryptString(config.Proxy.EncryptedPassword));

Environment.SetEnvironmentVariable("chocolateyProxyUser", config.Proxy.User);
Environment.SetEnvironmentVariable("chocolateyProxyPassword", NugetEncryptionUtility.DecryptString(config.Proxy.EncryptedPassword));
}

Environment.SetEnvironmentVariable("http_proxy", "{0}{1}".format_with(proxyCreds, config.Proxy.Location));
Environment.SetEnvironmentVariable("https_proxy", "{0}{1}".format_with(proxyCreds, config.Proxy.Location));
Environment.SetEnvironmentVariable("chocolateyProxyLocation", config.Proxy.Location);
}
}
}
}
48 changes: 6 additions & 42 deletions src/chocolatey/infrastructure.app/services/PowershellService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace chocolatey.infrastructure.app.services
using System.IO;
using System.Linq;
using adapters;
using builders;
using commandline;
using configuration;
using domain;
Expand Down Expand Up @@ -165,17 +166,10 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack

var failure = false;

//todo: this is here for any possible compatibility issues. Should be reviewed and removed.
ConfigurationBuilder.set_environment_variables(configuration);

var package = packageResult.Package;
Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, ApplicationParameters.InstallLocation);
Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION", configuration.Information.ChocolateyVersion);
Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION_PRODUCT", configuration.Information.ChocolateyProductVersion);
Environment.SetEnvironmentVariable("OS_PLATFORM", configuration.Information.PlatformType.get_description_or_value());
Environment.SetEnvironmentVariable("OS_VERSION", configuration.Information.PlatformVersion.to_string());
Environment.SetEnvironmentVariable("OS_NAME", configuration.Information.PlatformName.to_string());
// experimental until we know if this value returns correctly based on the OS and not the current process.
Environment.SetEnvironmentVariable("OS_IS64BIT", configuration.Information.Is64Bit ? "true" : "false");
Environment.SetEnvironmentVariable("IS_ADMIN", configuration.Information.IsUserAdministrator ? "true" : "false");
Environment.SetEnvironmentVariable("IS_PROCESSELEVATED", configuration.Information.IsProcessElevated ? "true" : "false");
Environment.SetEnvironmentVariable("chocolateyPackageName", package.Id);
Environment.SetEnvironmentVariable("packageName", package.Id);
Environment.SetEnvironmentVariable("chocolateyPackageVersion", package.Version.to_string());
Expand All @@ -195,42 +189,12 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
{
Environment.SetEnvironmentVariable("chocolateyInstallOverride", "true");
}

Environment.SetEnvironmentVariable("TEMP", configuration.CacheLocation);


if (configuration.NotSilent)
{
Environment.SetEnvironmentVariable("chocolateyInstallOverride", "true");
}
if (configuration.Debug)
{
Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true");
}
if (configuration.Verbose)
{
Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true");
}
if (!configuration.Features.CheckSumFiles)
{
Environment.SetEnvironmentVariable("ChocolateyIgnoreChecksums", "true");
}
if (!string.IsNullOrWhiteSpace(configuration.Proxy.Location))
{
var proxy_creds = string.Empty;
if (!string.IsNullOrWhiteSpace(configuration.Proxy.User) &&
!string.IsNullOrWhiteSpace(configuration.Proxy.EncryptedPassword)
)
{
proxy_creds = "{0}:{1}@".format_with(configuration.Proxy.User, NugetEncryptionUtility.DecryptString(configuration.Proxy.EncryptedPassword));

Environment.SetEnvironmentVariable("chocolateyProxyUser", configuration.Proxy.User);
Environment.SetEnvironmentVariable("chocolateyProxyPassword", NugetEncryptionUtility.DecryptString(configuration.Proxy.EncryptedPassword));
}

Environment.SetEnvironmentVariable("http_proxy", "{0}{1}".format_with(proxy_creds, configuration.Proxy.Location));
Environment.SetEnvironmentVariable("https_proxy", "{0}{1}".format_with(proxy_creds, configuration.Proxy.Location));
Environment.SetEnvironmentVariable("chocolateyProxyLocation", configuration.Proxy.Location);
}

//todo:if (configuration.NoOutput)
//{
// Environment.SetEnvironmentVariable("ChocolateyEnvironmentQuiet","true");
Expand Down
15 changes: 10 additions & 5 deletions src/chocolatey/infrastructure/adapters/Environment.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright © 2011 - Present RealDimensions Software, LLC
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
//
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -43,5 +43,10 @@ public string GetEnvironmentVariable(string variable)
{
return System.Environment.GetEnvironmentVariable(variable);
}

public void SetEnvironmentVariable(string variable, string value)
{
System.Environment.SetEnvironmentVariable(variable, value);
}
}
}
}
40 changes: 35 additions & 5 deletions src/chocolatey/infrastructure/adapters/IEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright © 2011 - Present RealDimensions Software, LLC
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
//
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -69,7 +69,37 @@ public interface IEnvironment
/// <param name="variable">The variable.</param>
/// <returns></returns>
string GetEnvironmentVariable(string variable);

/// <summary>
/// Creates, modifies, or deletes an environment variable stored in the current process.
/// </summary>
/// <param name="variable">
/// The name of an environment variable.
/// </param>
/// <param name="value">
/// A value to assign to <paramref name="variable" />.
/// </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="variable" /> is null.
/// </exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="variable" /> contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("=").
/// -or-
/// The length of <paramref name="variable" /> or <paramref name="value" /> is greater than or equal to 32,767 characters.
/// -or-
/// An error occurred during the execution of this operation.
/// </exception>
/// <exception cref="T:System.Security.SecurityException">
/// The caller does not have the required permission to perform this operation.
/// </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission
/// class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/// version="1" Unrestricted="true" />
/// </PermissionSet>
void SetEnvironmentVariable(string variable, string value);
}

// ReSharper restore InconsistentNaming
}
}

0 comments on commit 6b7f3b2

Please sign in to comment.