protected override ITaskResult<Nothing> SafeExecute(TaskContext context) { if (Destination == null) { throw new Exception("Destination file is not set"); } using (var zipStream = new ZipOutputStream(Destination.WriteStream)) { foreach (var fileToCompress in _sourceFiles) { var entry = new ZipEntry(fileToCompress.EntityPath) { Size = fileToCompress.File.Length }; zipStream.PutNextEntry(entry); using (var fileReadStream = fileToCompress.File.ReadStream) { fileReadStream.CopyTo(zipStream); } zipStream.CloseEntry(); } zipStream.IsStreamOwner = true; } return Success; }
public void BeforeTaskExecute(Identity id, ITask<object> task, TaskContext context) { try { foreach (ITaskInterceptor nestedInterceptor in _nestedInterceptors) { nestedInterceptor.BeforeTaskExecute(id, task, context); } } catch (Exception ex) { context.Log.Error(ex.Message); } }
protected virtual string GetProjectFile(TaskContext context) { if (ProjectFile != null) { return ProjectFile.AbsolutePath; } context.Log.Info( @"No project file defined. Start solution file lookup from directory {0}", context.WorkDirectory.AbsolutePath); var currentDirectory = context.WorkDirectory; while (currentDirectory != null) { var solutionFiles = currentDirectory.Files.IncludeByExtension("sln").ToArray(); if (solutionFiles.Length > 0) { if (solutionFiles.Length > 1) { context.Log.Info( @"Multiple solution files found in directory {0} The first file will be used.", currentDirectory.AbsolutePath); } var solutionFile = solutionFiles.First().AbsolutePath; context.Log.Info("Solution file found: {0}", solutionFile); return solutionFile; } context.Log.Info( @"No solution files found in {0} Go to parent directory.", currentDirectory.AbsolutePath); currentDirectory = currentDirectory.Parent; } context.Log.Warning("No solution file found. Default MSBuild lookup mechanism will be used."); return null; }
protected override ITaskResult<Nothing> SafeExecute(TaskContext context) { if (_destination == null) { throw new Exception("Destination file could not be null"); } _destination.EnsureExists(); var model = new Model { Attributes = new List<AttributeInfo>(), Namespaces = new List<Namespace>() }; foreach (var attributeExpression in Attributes) { var body = (NewExpression)attributeExpression.Body; var attributeInfo = new AttributeInfo(); var namespaceName = body.Type.Namespace; if (model.Namespaces.All(n => n.Name != namespaceName)) { model.Namespaces.Add(new Namespace { Name = namespaceName }); } attributeInfo.Name = body.Type.Name; attributeInfo.Arguments = string.Join(", ", GetArgumetValues(body)); model.Attributes.Add(attributeInfo); } var result = Render.StringToString(Template, model); _destination.EnsureExists(); _destination.WriteStringToFile(result); return Success; }
public void AfterTaskExecute(Identity id, ITask<object> task, TaskContext context, ITaskResult<object> result) { if (result.IsSuccess) { object data = result.Data; if (data == null || data is Nothing) { context.Log.Info("Completed"); } else { context.Log.Info("Completed. Result is {0}", FormatData(data)); } } else { context.Log.Error(result.Error == null ? "Unknown error occured" : result.Error.Message); } }
private static ITaskResult<Nothing> ExecuteWorkflow( IWorkflow workflow, Identities tasks, ILogRenderer logRenderer, IDirectory workDirectory) { var executer = new SubflowTask<Nothing>( workflow, tasks); var context = new TaskContext( new ParallelExecutionStrategy(), logRenderer, workDirectory, new DefaultEnvironment(), new CompositeInterceptor( new LoggingInterceptor())); return executer.Execute(context); }
protected override IEnumerable<Assembly> GetAssemblies(LookupOptions options) { var buildWorkflow = new BuildWorkflowProjectWorkflow(options.RunningOptions); var executerTask = new SubflowTask<Nothing>(buildWorkflow, Identities.Empty); var taskContext = new TaskContext( new SequenceExecutionStrategy(), options.RunningOptions.LogRenderer, options.RunningOptions.WorkDirectory, new DefaultEnvironment(), interceptor: null); ITaskResult<Nothing> buildResult = executerTask.Execute(taskContext); if (buildResult.IsSuccess) { var projectName = options.RunningOptions.InputFile.NameWithoutExtension; IFile assemblyFile = options.RunningOptions.InputFile.Directory["bin"]["Debug"][projectName + ".dll"]; yield return Assembly.LoadFile(assemblyFile.AbsolutePath); } }
protected override IDirectory GetToolWorkDirectory(TaskContext context) { return SpecFile.Directory; }
protected override string GetToolArguments(TaskContext context) { return string.Format("pack {0}", SpecFile.Name); }
protected override ITaskResult<Nothing> SafeExecute(TaskContext context) { Destination.EnsureExists(); using (var writer = new StreamWriter(Destination.WriteStream)) { writer.WriteLine("<?xml version='1.0' encoding='utf-8'?>"); writer.WriteLine("<package xmlns='http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'>"); writer.WriteLine(" <metadata>"); foreach (var metadata in Metadata) { writer.WriteLine(" <{0}>{1}</{0}>", metadata.Key, metadata.Value); } if (Dependencies.Count > 0) { writer.WriteLine(" <dependencies>"); var targetFrameworks = Dependencies.Select(x => x.TargetFramework).Distinct(); foreach (var targetFramework in targetFrameworks) { var framework = targetFramework; writer.Write(" <group"); WriteOptionalAttribute("targetFramework", targetFramework, writer); writer.WriteLine(">"); foreach (var dependency in Dependencies.Where(d => d.TargetFramework == framework)) { writer.Write(" <dependency id='{0}'", dependency.Id); WriteOptionalAttribute("version", dependency.Version, writer); writer.WriteLine(" />"); } writer.WriteLine(" </group>"); } writer.WriteLine(" </dependencies>"); } if (References.Count > 0) { writer.WriteLine(" <references>"); foreach (var reference in References) { writer.WriteLine(" <reference file='{0}' />", reference); } writer.WriteLine(" </references>"); } if (FrameworkAssemblies.Count > 0) { writer.WriteLine(" <frameworkAssemblies>"); foreach (var frameworkAssembly in FrameworkAssemblies) { writer.Write(" <frameworkAssembly assemblyName='{0}'", frameworkAssembly.AssemblyName); WriteOptionalAttribute("targetFramework", frameworkAssembly.TargetFramework, writer); writer.WriteLine(" />"); } writer.WriteLine(" </frameworkAssemblies>"); } writer.WriteLine(" </metadata>"); if (Files.Count > 0) { writer.WriteLine(" <files>"); foreach (var file in Files) { writer.Write(" <file src='{0}'", file.Src); WriteOptionalAttribute("target", file.Target, writer); WriteOptionalAttribute("exclude", file.Exclude, writer); writer.WriteLine(" />"); } writer.WriteLine(" </files>"); } writer.WriteLine("</package>"); } return Success; }
public void BeforeTaskExecute(Identity id, ITask<object> task, TaskContext context) { }
protected override IEnumerable<IFile> GetToolPathLookup(TaskContext context) { try { string[] registryKeys = ToolVersion == null ? /* * If no specific version provided we look up for * the mosk fresh version of MsBuild */ LookUpMsBuildRegistryKeys() : new [] { ToolVersion.Value }; if (registryKeys.Length == 0) { context.Log.Warning("No MsBuild registry entries have been found. MsBuild probably hav not been installed."); } return registryKeys .Select(key => { string registryKey = string.Format(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\{0}", key); string toolDirectory = (string) Registry.GetValue(registryKey, "MSBuildToolsPath", null); return new DefaultFile(Path.Combine(toolDirectory, "MsBuild.exe")); }); } catch (Exception ex) { context.Log.Warning("Error occured while reading registry: {0}", ex.Message); } return new IFile[0]; }
protected override string GetToolPath(TaskContext context) { if (context.Environment.IsMono) { return "xbuild"; } return base.GetToolPath(context); }
protected override string GetToolArguments(TaskContext context) { string projectFile = GetProjectFile(context); string switches = string.Join(" ", Switches.Select(s => s.CommandLinePart)); return string.Format("{0} {1}", switches, projectFile); }
// protected override string GetToolPath(TaskContext context) // { // return "nuget"; // } protected override string GetToolArguments(TaskContext context) { return string.Format( "push \"{1}\" {0} {2} -NonInteractive", ApiKey, PackageFile.AbsolutePath, string.Join(" ", Options.Select(option => option.CommandLinePart))); }