/// <inheritdoc /> protected override int DoExecute(ITaskContextInternal context) { ExecutablePath = FindNuGetCmdLinePath(); if (ExecutablePath == null) { context.Fail( string.Format( "Could not find NuGet.CommandLine package in the {0} directory. You have to download it yourself.", PackagesDirName), -1); return(5); } _command.MustNotBeNullOrEmpty("Nuget command must not be empty."); InsertArgument(0, _command); if (Verbosity.HasValue) { WithArguments("-Verbosity", Verbosity.ToString()); } if (ApiKey != null) { WithArgumentsValueRequired("-ApiKey", ApiKey, true); } return(base.DoExecute(context)); }
/// <inheritdoc /> protected override void PrepareExecutableParameters(ITaskContextInternal context) { ExecutablePath = FindNuGetCmdLinePath(); if (ExecutablePath == null) { context.Fail( string.Format( "Could not find NuGet.CommandLine package in the {0} directory. You have to download it yourself.", PackagesDirName), -1); return; } InsertArgument(0, _command); if (Verbosity.HasValue) { WithArguments("-Verbosity", Verbosity.ToString()); } if (ApiKey != null) { WithArguments("-ApiKey", ApiKey); } }
private static string FetchNuGetApiKeyFromLocalFile(ITaskContextInternal context, string fileName = DefaultApiKeyFileName) { if (!File.Exists(fileName)) { context.Fail($"NuGet API key file ('{fileName}') does not exist, cannot publish the package.", 1); return(null); } return(File.ReadAllText(fileName).Trim()); }
private static string FetchNuGetApiKeyFromEnvVariable(ITaskContextInternal context, string environmentVariableName = DefaultNuGetApiKeyEnvVariable) { string apiKey = Environment.GetEnvironmentVariable(environmentVariableName); if (string.IsNullOrEmpty(apiKey)) { context.Fail($"NuGet API key environment variable ('{environmentVariableName}') does not exist, cannot publish the package.", 1); return(null); } return(apiKey); }
protected override int DoExecute(ITaskContextInternal context) { if (string.IsNullOrEmpty(ExecutablePath)) { ExecutablePath = context.Properties.GetDotnetExecutable(); if (string.IsNullOrEmpty(ExecutablePath)) { context.Fail("Dotnet executable not set!", -1); return(-1); } } KeepProgramErrorOutput = true; KeepProgramOutput = true; return(base.DoExecute(context)); }
protected override int DoExecute(ITaskContextInternal context) { string program = ExecutablePath; if (string.IsNullOrEmpty(program)) { program = context.Properties.GetDotnetExecutable(); } if (string.IsNullOrEmpty(program)) { context.Fail("Dotnet executable not set!", -1); return(-1); } IRunProgramTask task = context.Tasks().RunProgramTask(program); if (NoOutputLog) { task.DoNotLogOutput(); } if (DoNotLog) { task.NoLog(); } BeforeExecute(context); var argumentsFlat = ValidateAndGetArgumentsFlat(); task .WithArguments(Command); foreach (var arg in argumentsFlat) { task.WithArguments(arg.arg, arg.maskArg); } task .WorkingFolder(ExecuteWorkingFolder) .CaptureErrorOutput() .CaptureOutput() .ExecuteVoid(context); return(0); }
protected override int DoExecute(ITaskContextInternal context) { string program = _dotnetExecutable; if (string.IsNullOrEmpty(program)) { program = context.Properties.GetDotnetExecutable(); } if (string.IsNullOrEmpty(program)) { context.Fail("Dotnet executable not set!", -1); return(-1); } BeforeExecute(context); IRunProgramTask task = context.Tasks().RunProgramTask(program); if (_doNotLogOutput) { task.DoNotLogOutput(); } if (DoNotLog) { task.NoLog(); } task .WithArguments(Command) .WithArguments(Arguments.ToArray()) .WorkingFolder(_workingFolder) .CaptureErrorOutput() .CaptureOutput() .ExecuteVoid(context); return(0); }
/// <inheritdoc /> protected override int DoExecute(ITaskContextInternal context) { if (_commandFactory == null) { _commandFactory = new CommandFactory(); } string currentDirectory = Directory.GetCurrentDirectory(); FileInfo info = new FileInfo(_programToExecute); string cmd = _programToExecute; if (info.Exists) { cmd = info.FullName; } ICommand command = _commandFactory.Create(cmd, _arguments); command .CaptureStdErr() .CaptureStdOut() .WorkingDirectory(_workingFolder ?? currentDirectory) .OnErrorLine(l => { if (!_doNotLogOutput) { DoLogInfo(l); } if (_captureOutput) { _errorOutput.AppendLine(l); } }) .OnOutputLine(l => { if (!_doNotLogOutput) { DoLogInfo(l); } if (_captureErrorOutput) { _output.AppendLine(l); } }); DoLogInfo( $"Running program '{command.CommandName}':(work.dir='{_workingFolder}',args='{command.CommandArgs}')"); int res = command.Execute() .ExitCode; if (!DoNotFail && res != 0) { context.Fail($"External program {cmd} failed with {res}.", res); } return(res); }
protected override int DoExecute(ITaskContextInternal context) { if (!File.Exists(_fileName)) { context.Fail($"JSON file {_fileName} not found!", 1); return(1); } if (_updates.Count <= 0) { context.Fail($"Nothing to update in file {_fileName}!", 2); return(2); } DoLogInfo($"Update JSON file {_fileName} to file {_output ?? _fileName}. With {_updates.Count} updates"); string file = File.ReadAllText(_fileName); JObject json = JObject.Parse(file); int res = 0; foreach (KeyValuePair <string, JValue> pair in _updates) { JToken token = json.SelectToken(pair.Key, false); if (token == null) { if (_failIfNotFound) { context.Fail($"Propety {pair.Key} not found in {_fileName}", 3); } else { DoLogInfo($"Propety {pair.Key} not found in {_fileName}"); } res = 3; continue; } if (token.Type != pair.Value.Type) { if (_failOnTypeMismatch) { context.Fail($"Propety {pair.Key} type mismatch.", 4); continue; } DoLogInfo($"Propety {pair.Key} type mismatch."); res = 4; } DoLogInfo($"Replacing {token.Path} with {pair.Value}."); token.Replace(pair.Value); } if (string.IsNullOrEmpty(_output)) { _output = _fileName; } File.WriteAllText(_output, json.ToString(Formatting.Indented), Encoding.UTF8); return(res); }