Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (chocolateyGH-268) Remove Unused Code
  (chocolateyGH-268) Add BeforeModify to install template
  (maint) solution folders for nuspecs / top level
  (maint) catch pack catastrophic errors
  (chocolateyGH-586) Ignore invalid options/switches by default
  (specs) update scenarios
  (chocolateyGH-596) Allow failure on invalid license
  (chocolateyGH-571) Arg parsing error should be warning
  (chocolateyGH-680) Switch to .NET Client Profile
  • Loading branch information
ferventcoder committed Apr 11, 2016
2 parents 18075dd + 15944b6 commit 35ec3ef
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 27 deletions.
16 changes: 13 additions & 3 deletions Scenarios.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Chocolatey Usage Scenarios

### ChocolateyInstallCommand [ 35 Scenario(s), 289 Observation(s) ]
### ChocolateyInstallCommand [ 35 Scenario(s), 291 Observation(s) ]

#### when force installing a package that depends on an unavailable newer version of an installed dependency forcing dependencies

Expand Down Expand Up @@ -140,6 +140,7 @@
* should have a graphical shim that is set for gui access
* should have a successful package result
* should have a version of one dot zero dot zero
* should have executed chocolateyInstall script
* should install the expected version of the package
* should install the package in the lib directory
* should install where install location reports
Expand Down Expand Up @@ -366,6 +367,7 @@

* should contain a message that it would have run a powershell script
* should contain a message that it would have used Nuget to install a package
* should not contain a message that it would have run powershell modification script
* should not install a package in the lib directory

#### when noop installing a package that does not exist
Expand Down Expand Up @@ -499,7 +501,7 @@

* should contain success message

### ChocolateyUninstallCommand [ 13 Scenario(s), 90 Observation(s) ]
### ChocolateyUninstallCommand [ 13 Scenario(s), 93 Observation(s) ]

#### when force uninstalling a package

Expand Down Expand Up @@ -530,6 +532,7 @@
#### when noop uninstalling a package

* should contain a message that it would have run a powershell script
* should contain a message that it would have run powershell modification script
* should contain a message that it would have uninstalled a package
* should not uninstall a package from the lib directory

Expand All @@ -546,6 +549,8 @@
* should delete any files created during the install
* should delete the rollback
* should have a successful package result
* should have executed chocolateyBeforeModify script
* should have executed chocolateyUninstall script
* should not have inconclusive package result
* should not have warning package result
* should remove the package from the lib directory
Expand Down Expand Up @@ -630,7 +635,7 @@

* should throw an error that it is not allowed

### ChocolateyUpgradeCommand [ 29 Scenario(s), 221 Observation(s) ]
### ChocolateyUpgradeCommand [ 29 Scenario(s), 226 Observation(s) ]

#### when force upgrading a package

Expand Down Expand Up @@ -929,7 +934,12 @@
* should contain newer version in directory
* should delete the rollback
* should have a successful package result
* should have executed chocolateyBeforeModify before chocolateyInstall
* should have executed chocolateyBeforeModify script for original package
* should have executed chocolateyInstall script for new package
* should match the upgrade version of one dot one dot zero
* should not have executed chocolateyBeforeModify script for new package
* should not have executed chocolateyUninstall script for original package
* should not have inconclusive package result
* should not have warning package result
* should upgrade a package in the lib directory
Expand Down
3 changes: 1 addition & 2 deletions src/chocolatey.console/chocolatey.console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.XmlTransform">
<HintPath>..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
Expand Down
30 changes: 30 additions & 0 deletions src/chocolatey.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{7A36F8
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{FB6236DD-17EF-4C36-943C-47792FBC3306}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "chocolatey", "chocolatey", "{DAB29F30-149D-4005-A8D2-4FA56CF2784D}"
ProjectSection(SolutionItems) = preProject
..\nuget\chocolatey\chocolatey.nuspec = ..\nuget\chocolatey\chocolatey.nuspec
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{E5C987F8-6B95-4835-BBDD-A25C9D370BB9}"
ProjectSection(SolutionItems) = preProject
..\nuget\chocolatey\tools\chocolateyInstall.ps1 = ..\nuget\chocolatey\tools\chocolateyInstall.ps1
..\nuget\chocolatey\tools\chocolateysetup.psm1 = ..\nuget\chocolatey\tools\chocolateysetup.psm1
..\nuget\chocolatey\tools\init.ps1 = ..\nuget\chocolatey\tools\init.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "chocolatey.lib", "chocolatey.lib", "{DD9689F3-1D2D-41AE-A672-063EE70C0C9A}"
ProjectSection(SolutionItems) = preProject
..\nuget\chocolatey.lib\chocolatey.lib.nuspec = ..\nuget\chocolatey.lib\chocolatey.lib.nuspec
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "toplevel", "toplevel", "{18FEFF9F-7352-4230-8B4E-E8D8BE976095}"
ProjectSection(SolutionItems) = preProject
..\CHANGELOG.md = ..\CHANGELOG.md
..\COMMITTERS.md = ..\COMMITTERS.md
..\CONTRIBUTING.md = ..\CONTRIBUTING.md
..\README.md = ..\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -87,5 +114,8 @@ Global
GlobalSection(NestedProjects) = preSolution
{5C4C60F0-47B1-498E-ABF7-D315E1A94BC9} = {7656D054-387D-409C-A9FB-62A44599AA77}
{12ECAD4F-D463-4D72-A792-A4FCCFE9C456} = {7656D054-387D-409C-A9FB-62A44599AA77}
{DAB29F30-149D-4005-A8D2-4FA56CF2784D} = {FB6236DD-17EF-4C36-943C-47792FBC3306}
{DD9689F3-1D2D-41AE-A672-063EE70C0C9A} = {FB6236DD-17EF-4C36-943C-47792FBC3306}
{E5C987F8-6B95-4835-BBDD-A25C9D370BB9} = {DAB29F30-149D-4005-A8D2-4FA56CF2784D}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<HintPath>..\..\lib\bdddoc\bdddoc.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.XmlTransform, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
Expand Down
3 changes: 1 addition & 2 deletions src/chocolatey.tests/chocolatey.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.XmlTransform, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
Expand Down
9 changes: 6 additions & 3 deletions src/chocolatey/chocolatey.csproj
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>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -38,8 +39,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.XmlTransform, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -93,6 +93,7 @@
<Compile Include="infrastructure.app\events\HandlePackageResultCompletedMessage.cs" />
<Compile Include="infrastructure.app\services\FileTypeDetectorService.cs" />
<Compile Include="infrastructure.app\services\IFileTypeDetectorService.cs" />
<Compile Include="infrastructure.app\templates\ChocolateyBeforeModifyTemplate.cs" />
<Compile Include="infrastructure.app\templates\ChocolateyLicenseFileTemplate.cs" />
<Compile Include="infrastructure.app\templates\ChocolateyVerificationFileTemplate.cs" />
<Compile Include="infrastructure\commandline\ReadKeyTimeout.cs" />
Expand Down Expand Up @@ -286,7 +287,9 @@
<EmbeddedResource Include="infrastructure.app\configuration\chocolatey.config">
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="targets\Microsoft.Application.targets" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public static class Features
public static readonly string UsePowerShellHost = "powershellHost";
public static readonly string LogEnvironmentValues = "logEnvironmentValues";
public static readonly string VirusCheck = "virusCheck";
public static readonly string FailOnInvalidOrMissingLicense = "failOnInvalidOrMissingLicense";
public static readonly string IgnoreInvalidOptionsSwitches = "ignoreInvalidOptionsSwitches";
}

public static class Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.UsePowerShellHost = set_feature_flag(ApplicationParameters.Features.UsePowerShellHost, configFileSettings, defaultEnabled: true, description: "Use Chocolatey's built-in PowerShell host.");
config.Features.LogEnvironmentValues = set_feature_flag(ApplicationParameters.Features.LogEnvironmentValues, configFileSettings, defaultEnabled: false, description: "Log Environment Values - will log values of environment before and after install (could disclose sensitive data).");
config.Features.VirusCheck = set_feature_flag(ApplicationParameters.Features.VirusCheck, configFileSettings, defaultEnabled: false, description: "Virus Check [licensed versions only] - perform virus checking on downloaded files.");
config.Features.FailOnInvalidOrMissingLicense = set_feature_flag(ApplicationParameters.Features.FailOnInvalidOrMissingLicense, configFileSettings, defaultEnabled: false, description: "Fail On Invalid Or Missing License - allows knowing when a license is expired or not applied to a machine.");
config.Features.IgnoreInvalidOptionsSwitches = set_feature_flag(ApplicationParameters.Features.IgnoreInvalidOptionsSwitches, configFileSettings, defaultEnabled: true, description: "Ignore Invalid Options/Switches - If a switch or option is passed that is not recognized, should choco fail?");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ public sealed class FeaturesConfiguration
public bool UsePowerShellHost { get; set; }
public bool LogEnvironmentValues { get; set; }
public bool VirusCheck { get; set; }
public bool FailOnInvalidOrMissingLicense { get; set; }
public bool IgnoreInvalidOptionsSwitches { get; set; }
}

//todo: retrofit other command configs this way
Expand Down
13 changes: 8 additions & 5 deletions src/chocolatey/infrastructure.app/runners/ConsoleApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public void run(string[] args, ChocolateyConfiguration config, Container contain

command.handle_additional_argument_parsing(unparsedArgs, config);

// all options / switches should be parsed,
// so show help menu if there are any left
foreach (var unparsedArg in unparsedArgs.or_empty_list_if_null())
if (!config.Features.IgnoreInvalidOptionsSwitches)
{
if (unparsedArg.StartsWith("-") || unparsedArg.StartsWith("/"))
// all options / switches should be parsed,
// so show help menu if there are any left
foreach (var unparsedArg in unparsedArgs.or_empty_list_if_null())
{
config.HelpRequested = true;
if (unparsedArg.StartsWith("-") || unparsedArg.StartsWith("/"))
{
config.HelpRequested = true;
}
}
}
},
Expand Down
13 changes: 13 additions & 0 deletions src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,17 @@ private void set_source_type(ChocolateyConfiguration config)
this.Log().Debug(()=> "The source '{0}' evaluated to a '{1}' source type".format_with(config.Sources,sourceType.to_string()));
}

public void fail_when_license_is_missing_or_invalid_if_requested(ChocolateyConfiguration config)
{
if (!config.Features.FailOnInvalidOrMissingLicense) return;

if (!config.Information.IsLicensedVersion) throw new ApplicationException("License is missing or invalid.");
}

public void run(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs)
{
fail_when_license_is_missing_or_invalid_if_requested(config);

var command = find_command(config, container, isConsole, parseArgs);
if(command != null)
{
Expand All @@ -134,6 +143,8 @@ public void run(ChocolateyConfiguration config, Container container, bool isCons

public IEnumerable<T> list<T>(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs)
{
fail_when_license_is_missing_or_invalid_if_requested(config);

var command = find_command(config, container, isConsole, parseArgs) as IListCommand<T>;
if (command == null)
{
Expand All @@ -152,6 +163,8 @@ public IEnumerable<T> list<T>(ChocolateyConfiguration config, Container containe

public int count(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs)
{
fail_when_license_is_missing_or_invalid_if_requested(config);

var command = find_command(config, container, isConsole, parseArgs) as IListCommand;
if (command == null)
{
Expand Down
8 changes: 6 additions & 2 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ public void pack_run(ChocolateyConfiguration config)

this.Log().Info(() => "Attempting to build package from '{0}'.".format_with(_fileSystem.get_file_name(nuspecFilePath)));

//IPackage package =
NugetPack.BuildPackage(builder, _fileSystem, outputPath);
IPackage package = NugetPack.BuildPackage(builder, _fileSystem, outputPath);
// package.Validate().Any(v => v.Level == PackageIssueLevel.Error)
if (package == null)
{
throw new ApplicationException("Unable to create nupkg. See the log for error details.");
}
//todo: v1 analyze package
//if (package != null)
//{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,6 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
{
var installerRun = false;

var file = "chocolateyInstall.ps1";
switch (command)
{
case CommandNameType.uninstall:
file = "chocolateyUninstall.ps1";
break;
}

var packageDirectory = packageResult.InstallLocation;
if (packageDirectory.is_equal_to(ApplicationParameters.InstallLocation) || packageDirectory.is_equal_to(ApplicationParameters.PackagesLocation))
{
Expand Down Expand Up @@ -213,6 +205,7 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
Environment.SetEnvironmentVariable("chocolateyInstallArguments", configuration.InstallArguments);
Environment.SetEnvironmentVariable("packageParameters", configuration.PackageParameters);
Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters);

if (configuration.ForceX86)
{
Environment.SetEnvironmentVariable("chocolateyForceX86", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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, ChocolateyBeforeModifyTemplate.Template, _fileSystem.combine_paths(packageToolsLocation, "chocolateybeforemodify.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, ChocolateyLicenseFileTemplate.Template, _fileSystem.combine_paths(packageToolsLocation, "LICENSE.txt"), Encoding.UTF8);
generate_file_from_template(configuration, tokens, ChocolateyVerificationFileTemplate.Template, _fileSystem.combine_paths(packageToolsLocation, "VERIFICATION.txt"), Encoding.UTF8);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.templates
{
public class ChocolateyBeforeModifyTemplate
{
public static string Template =
@"# This runs in 0.9.10+ before upgrade and uninstall.
# Use this file to do things like stop services prior to upgrade or uninstall.
# NOTE: It is an anti-pattern to call chocolateyUninstall.ps1 from here. If you
# need to uninstall an MSI prior to upgrade, put the functionality in this
# file without calling the uninstall script. Make it idempotent in the
# uninstall script so that it doesn't fail when it is already uninstalled.
# NOTE: For upgrades - like the uninstall script, this script always runs from
# the currently installed version, not from the new upgraded package version.
";
}
}
Loading

0 comments on commit 35ec3ef

Please sign in to comment.