Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-296) Enhance installer template
  (GH-296) Add readme template
  (GH-305) get full path to cache folder
  (posh) add aliases for filetype/url64bit
  (GH-60) Fix: Pin errors on pkg folders w/versions
  (log) add debug logging around list
  (GH-302) Fix: choco pin list fails
  (log) use warn level messages as result summaries
  (log) add debug log search filter for nuget list
  (GH-317) Throw on non-existing features
  (GH-319) always log debug output to log file

Conflicts:
	src/chocolatey/chocolatey.csproj
  • Loading branch information
ferventcoder committed Jun 5, 2015
2 parents 4a25c56 + 7b468c8 commit 012b118
Show file tree
Hide file tree
Showing 19 changed files with 302 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static void Main(string[] args)
Environment.Exit(-1);
}

Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, ChocolateyLoggers.Verbose.to_string());
Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug);
"chocolatey".Log().Debug(() => "{0} is running on {1} v {2}".format_with(ApplicationParameters.Name, config.Information.PlatformType, config.Information.PlatformVersion.to_string()));
//"chocolatey".Log().Debug(() => "Command Line: {0}".format_with(Environment.CommandLine));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Install-ChocolateyPackage
#>
param(
[string] $packageName,
[string] $fileType = 'exe',
[alias("installerType")][string] $fileType = 'exe',
[string] $silentArgs = '',
[string] $file,
$validExitCodes = @(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Install-ChocolateyInstallPackage
#>
param(
[string] $packageName,
[string] $fileType = 'exe',
[alias("installerType")][string] $fileType = 'exe',
[string] $silentArgs = '',
[string] $url,
[string] $url64bit = '',
[alias("url64")][string] $url64bit = '',
$validExitCodes = @(0),
[string] $checksum = '',
[string] $checksumType = '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ param(
[string] $packageName,
[string] $psFileFullPath,
[string] $url ='',
[string] $url64bit = '',
[alias("url64")][string] $url64bit = '',
[string] $checksum = '',
[string] $checksumType = '',
[string] $checksum64 = '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ param(
[string] $packageName,
[string] $url,
[string] $unzipLocation,
[string] $url64bit = '',
[alias("url64")][string] $url64bit = '',
[string] $specificFolder ="",
[string] $checksum = '',
[string] $checksumType = '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Uninstall-ChocolateyPackage
#>
param(
[string] $packageName,
[string] $fileType = 'exe',
[alias("installerType")][string] $fileType = 'exe',
[string] $silentArgs = '',
[string] $file,
$validExitCodes = @(0)
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="infrastructure.app\services\FilesService.cs" />
<Compile Include="infrastructure.app\services\IFilesService.cs" />
<Compile Include="infrastructure.app\services\ISourceRunner.cs" />
<Compile Include="infrastructure.app\templates\ChocolateyReadMeTemplate.cs" />
<Compile Include="infrastructure.app\services\PythonService.cs" />
<Compile Include="infrastructure.app\services\RubyGemsService.cs" />
<Compile Include="infrastructure.app\services\WindowsFeatureService.cs" />
Expand Down
39 changes: 31 additions & 8 deletions src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public sealed class ChocolateyPinCommand : ICommand
private readonly IChocolateyPackageInformationService _packageInfoService;
private readonly ILogger _nugetLogger;
private readonly INugetService _nugetService;
private const string NO_CHANGE_MESSAGE = "Nothing to change. Pin already set or removed.";

public ChocolateyPinCommand(IChocolateyPackageInformationService packageInfoService, ILogger nugetLogger, INugetService nugetService)
{
Expand All @@ -56,7 +57,7 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati

public void handle_additional_argument_parsing(IList<string> unparsedArguments, ChocolateyConfiguration configuration)
{
configuration.Input = string.Join(" ", unparsedArguments);
// don't set configuration.Input or it will be passed to list

if (unparsedArguments.Count > 1)
{
Expand All @@ -67,12 +68,12 @@ public void handle_additional_argument_parsing(IList<string> unparsedArguments,
string unparsedCommand = unparsedArguments.DefaultIfEmpty(string.Empty).FirstOrDefault();
Enum.TryParse(unparsedCommand, true, out command);

if (command == PinCommandType.unknown)
if (command == PinCommandType.unknown)
{
if (!string.IsNullOrWhiteSpace(unparsedCommand)) this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand));
command = PinCommandType.list;
}

configuration.PinCommand.Command = command;
configuration.Sources = ApplicationParameters.PackagesLocation;
configuration.ListCommand.LocalOnly = true;
Expand Down Expand Up @@ -115,7 +116,7 @@ choco pin remove --name git

public void noop(ChocolateyConfiguration configuration)
{
this.Log().Info("Pin would have called {0} with other options:{1} Name={2}{1} Version={3}".format_with(configuration.PinCommand.Command.to_string(),Environment.NewLine,configuration.PinCommand.Name.to_string(),configuration.Version.to_string()));
this.Log().Info("Pin would have called {0} with other options:{1} Name={2}{1} Version={3}".format_with(configuration.PinCommand.Command.to_string(), Environment.NewLine, configuration.PinCommand.Name.to_string(), configuration.Version.to_string()));
}

public void run(ChocolateyConfiguration configuration)
Expand All @@ -124,7 +125,6 @@ public void run(ChocolateyConfiguration configuration)
installSuccessAction: null,
uninstallSuccessAction: null,
addUninstallHandler: false);

switch (configuration.PinCommand.Command)
{
case PinCommandType.list:
Expand All @@ -145,25 +145,48 @@ public void list_pins(IPackageManager packageManager, ChocolateyConfiguration co
var pkgInfo = _packageInfoService.get_package_information(pkg.Value.Package);
if (pkgInfo != null && pkgInfo.IsPinned)
{
this.Log().Info(() => "{0}|{1}".format_with(pkgInfo.Package.Id,pkgInfo.Package.Version));
this.Log().Info(() => "{0}|{1}".format_with(pkgInfo.Package.Id, pkgInfo.Package.Version));
}
}
}

public void set_pin(IPackageManager packageManager, ChocolateyConfiguration config)
{
var addingAPin = config.PinCommand.Command == PinCommandType.add;
this.Log().Info("Trying to {0} a pin for {1}".format_with(config.PinCommand.Command.to_string(), config.PinCommand.Name));
var versionUnspecified = string.IsNullOrWhiteSpace(config.Version);
SemanticVersion semanticVersion = versionUnspecified ? null : new SemanticVersion(config.Version);
IPackage installedPackage = packageManager.LocalRepository.FindPackage(config.PinCommand.Name, semanticVersion);
if (installedPackage == null)
{
throw new ApplicationException("Unable to find package named '{0}'{1} to pin. Please check to ensure it is installed.".format_with(config.PinCommand.Name, versionUnspecified ? "" : " (version '{0}')".format_with(config.Version)));
var pathResolver = packageManager.PathResolver as ChocolateyPackagePathResolver;
if (pathResolver != null)
{
pathResolver.UseSideBySidePaths = true;
installedPackage = packageManager.LocalRepository.FindPackage(config.PinCommand.Name, semanticVersion);
}

if (installedPackage == null)
{
throw new ApplicationException("Unable to find package named '{0}'{1} to pin. Please check to ensure it is installed.".format_with(config.PinCommand.Name, versionUnspecified ? "" : " (version '{0}')".format_with(config.Version)));
}
}

var pkgInfo = _packageInfoService.get_package_information(installedPackage);

pkgInfo.IsPinned = config.PinCommand.Command == PinCommandType.add;
bool changeMessage = pkgInfo.IsPinned != addingAPin;

pkgInfo.IsPinned = addingAPin;
_packageInfoService.save_package_information(pkgInfo);

if (changeMessage)
{
this.Log().Warn("Successfully {0} a pin for {1} v{2}.".format_with(addingAPin ? "added" : "removed", pkgInfo.Package.Id, pkgInfo.Package.Version.to_string()));
}
else
{
this.Log().Warn(NO_CHANGE_MESSAGE);
}
}

public bool may_require_admin_access()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)
{
//todo: ultimately we should merge keys
uninstallArgs += " " + installer.build_uninstall_command_arguments();
var logLocation = _fileSystem.combine_paths(config.CacheLocation, "chocolatey", pkgInfo.Package.Id, pkgInfo.Package.Version.to_string());
_fileSystem.create_directory_if_not_exists(_fileSystem.get_directory_name(logLocation));

uninstallArgs = uninstallArgs.Replace(InstallTokens.PACKAGE_LOCATION, logLocation);
}

var logLocation = _fileSystem.combine_paths(_fileSystem.get_full_path(config.CacheLocation), "chocolatey", pkgInfo.Package.Id, pkgInfo.Package.Version.to_string());
_fileSystem.create_directory_if_not_exists(_fileSystem.get_directory_name(logLocation));
uninstallArgs = uninstallArgs.Replace(InstallTokens.PACKAGE_LOCATION, logLocation);

this.Log().Debug(() => " Args are '{0}'".format_with(uninstallArgs));

if (!key.HasQuietUninstall && installer.GetType() == typeof(CustomInstaller))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void source_add(ChocolateyConfiguration configuration)

_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);

this.Log().Info(() => "Added {0} - {1}".format_with(configuration.SourceCommand.Name, configuration.Sources));
this.Log().Warn(() => "Added {0} - {1}".format_with(configuration.SourceCommand.Name, configuration.Sources));
}
else
{
Expand All @@ -95,7 +95,7 @@ public void source_remove(ChocolateyConfiguration configuration)
configFileSettings.Sources.Remove(source);
_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);

this.Log().Info(() => "Removed {0}".format_with(source.Id));
this.Log().Warn(() => "Removed {0}".format_with(source.Id));
}
else
{
Expand All @@ -110,7 +110,7 @@ public void source_disable(ChocolateyConfiguration configuration)
{
source.Disabled = true;
_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
this.Log().Info(() => "Disabled {0}".format_with(source.Id));
this.Log().Warn(() => "Disabled {0}".format_with(source.Id));
}
else
{
Expand All @@ -125,7 +125,7 @@ public void source_enable(ChocolateyConfiguration configuration)
{
source.Disabled = false;
_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
this.Log().Info(() => "Enabled {0}".format_with(source.Id));
this.Log().Warn(() => "Enabled {0}".format_with(source.Id));
}
else
{
Expand All @@ -144,16 +144,21 @@ public void feature_list(ChocolateyConfiguration configuration)
public void feature_disable(ChocolateyConfiguration configuration)
{
var feature = configFileSettings.Features.FirstOrDefault(p => p.Name.is_equal_to(configuration.FeatureCommand.Name));
if (feature != null && (feature.Enabled || !feature.SetExplicitly))
if (feature == null)
{
throw new ApplicationException("Feature '{0}' not found".format_with(configuration.FeatureCommand.Name));
}

if (feature.Enabled || !feature.SetExplicitly)
{
if (!feature.Enabled && !feature.SetExplicitly)
{
this.Log().Warn(() => "{0} was disabled by default. Explicitly setting value.".format_with(feature.Name));
this.Log().Info(() => "{0} was disabled by default. Explicitly setting value.".format_with(feature.Name));
}
feature.Enabled = false;
feature.SetExplicitly = true;
_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
this.Log().Info(() => "Disabled {0}".format_with(feature.Name));
this.Log().Warn(() => "Disabled {0}".format_with(feature.Name));
}
else
{
Expand All @@ -164,16 +169,22 @@ public void feature_disable(ChocolateyConfiguration configuration)
public void feature_enable(ChocolateyConfiguration configuration)
{
var feature = configFileSettings.Features.FirstOrDefault(p => p.Name.is_equal_to(configuration.FeatureCommand.Name));
if (feature != null && (!feature.Enabled || !feature.SetExplicitly))

if (feature == null)
{
throw new ApplicationException("Feature '{0}' not found".format_with(configuration.FeatureCommand.Name));
}

if (!feature.Enabled || !feature.SetExplicitly)
{
if (feature.Enabled && !feature.SetExplicitly)
{
this.Log().Warn(() => "{0} was enabled by default. Explicitly setting value.".format_with(feature.Name));
this.Log().Info(() => "{0} was enabled by default. Explicitly setting value.".format_with(feature.Name));
}
feature.Enabled = true;
feature.SetExplicitly = true;
_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
this.Log().Info(() => "Enabled {0}".format_with(feature.Name));
this.Log().Warn(() => "Enabled {0}".format_with(feature.Name));
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfigurat
{
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);

if (config.RegularOutput) this.Log().Debug(() => "Running list with the following filter = '{0}'".format_with(config.Input));

var packages = NugetList.GetPackages(config, _nugetLogger).ToList();

if (config.RegularOutput) this.Log().Debug(() => "--- Start of List ---");
foreach (var package in packages.or_empty_list_if_null())
{
if (logResults)
Expand All @@ -112,6 +115,7 @@ public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfigurat

packageResults.GetOrAdd(package.Id, new PackageResult(package, null));
}
if (config.RegularOutput) this.Log().Debug(() => "--- End of List ---");

return packageResults;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void generate(ChocolateyConfiguration configuration)
generate_file_from_template(configuration, tokens, NuspecTemplate.Template, _fileSystem.combine_paths(packageLocation, "{0}.nuspec".format_with(tokens.PackageNameLower)), Encoding.UTF8);
generate_file_from_template(configuration, tokens, ChocolateyInstallTemplate.Template, _fileSystem.combine_paths(packageToolsLocation, "chocolateyinstall.ps1"), Encoding.UTF8);
generate_file_from_template(configuration, tokens, ChocolateyUninstallTemplate.Template, _fileSystem.combine_paths(packageToolsLocation, "chocolateyuninstall.ps1"), Encoding.UTF8);
generate_file_from_template(configuration, tokens, ChocolateyReadMeTemplate.Template, _fileSystem.combine_paths(packageToolsLocation, "ReadMe.md"), Encoding.UTF8);

this.Log().Info(ChocolateyLoggers.Important, "Successfully generated {0}{1} package specification files{2} at '{3}'".format_with(configuration.NewCommand.Name, configuration.NewCommand.AutomaticPackage ? " (automatic)" : string.Empty, Environment.NewLine, packageLocation));
}
Expand Down
Loading

0 comments on commit 012b118

Please sign in to comment.