private async Task <Envoy> ResolveComponentToBuildAsync(Project project) { ITargetScopeService targetScopeService; if (string.IsNullOrEmpty(Target)) { targetScopeService = GetSingleTargetInProject(project); if (targetScopeService == null) { string errorMessage = await CreateTargetNotProvidedErrorMessageAsync(project); CommandLineInterfaceApplication.WriteError(errorMessage); return(null); } } else { targetScopeService = GetTargetScopeServiceByName(project, Target); if (targetScopeService == null) { string errorMessage = await CreateResolveTargetErrorMessageAsync(project, Target); CommandLineInterfaceApplication.WriteError(errorMessage); return(null); } } return(await ResolveComponentOnTargetAsync(ComponentName, targetScopeService)); }
private static void WriteBeginRootBuildMessage(string componentName) { CommandLineInterfaceApplication.WriteLine( string.Format( CultureInfo.CurrentCulture, LocalizedStrings.BuildComponentTool_RootBuildStartMessage, componentName)); }
private static void WriteBeginChildBuildMessage(string componentName) { CommandLineInterfaceApplication.WriteLine( string.Format( CultureInfo.CurrentCulture, " " + LocalizedStrings.BuildComponentTool_ChildBuildStartMessage, componentName, CommandLineHelpers.GetFullDateTimeString())); }
private static void WriteChildBuildFinishedMessage(string componentName) { string message = string.Format( CultureInfo.CurrentCulture, " " + LocalizedStrings.BuildComponentTool_ChildBuildSuccess, componentName, CommandLineHelpers.GetFullDateTimeString()); CommandLineInterfaceApplication.WriteLine(message); }
private static void WriteSuccessMessage(string componentName, string outputDirectory) { string message = string.Format( CultureInfo.CurrentCulture, LocalizedStrings.BuildComponentTool_RootBuildSuccess, componentName, outputDirectory, CommandLineHelpers.GetFullDateTimeString()); CommandLineInterfaceApplication.WriteLine(message); }
private static async Task <bool> TrySaveProjectAsync(Project project) { try { await project.SaveAsync(); return(true); } catch (Exception e) when(ExceptionHelper.ShouldExceptionBeCaught(e)) { CommandLineInterfaceApplication.WriteError(DocumentExtensions.GetUserVisibleSaveFailureMessage(project.ProjectFileName, e)); return(false); } }
private void CancelBuild() { if (_rootJob == null) { return; } _rootJob.Cancel(); string cancelMessage = string.Format( CultureInfo.CurrentCulture, LocalizedStrings.BuildComponentTool_BuildCanceledMessage, _rootJob.AssociatedEnvoy.Name.Last, CommandLineHelpers.GetFullDateTimeString()); CommandLineInterfaceApplication.WriteLine(cancelMessage); }
private bool ShowErrorIfSubTypeNotSupported(ComponentConfigurationReference configurationReference) { var componentSubtype = configurationReference.Configuration.ComponentSubtype; if (!CanBuildSubtype(componentSubtype)) { string message = string.Format( CultureInfo.CurrentCulture, LocalizedStrings.BuildComponentTool_ComponentSubTypeNotSupported, configurationReference.ComponentName.Last, configurationReference.Configuration.ComponentSubtype.DisplayName); CommandLineInterfaceApplication.WriteError(message); return(true); } return(false); }
private static void BuildJobPropertyChanged(object sender, PropertyChangedEventArgs eventArgs, bool isChildBuild) { string spacingString = isChildBuild ? " " : string.Empty; var job = (IBuildQueueJob)sender; if (!IsStatusChangedEvent(eventArgs)) { return; } bool buildFinished = false; if (job.State == JobState.Error || job.State == JobState.Failed) { WriteErrorsFromJob(job); buildFinished = true; } else if (job.State == JobState.Success) { if (isChildBuild) { WriteChildBuildFinishedMessage(job.AssociatedEnvoy.Name.Last); } buildFinished = true; } if (buildFinished) { if (isChildBuild) { job.PropertyChanged -= OnChildBuildJobPropertyChanged; } else { job.PropertyChanged -= OnRootBuildJobPropertyChanged; } return; } // We've already printed an update for the first build step (starting the build), so we don't want to print it again here. if (job.CurrentStepIndex != 0) { CommandLineInterfaceApplication.WriteLine($"{spacingString}{job.AssociatedEnvoy.Name.Last} -- {job.CurrentActionDisplayName}. -- {CommandLineHelpers.GetFullDateTimeString()}"); } }
private static void WriteErrorsFromJob(IBuildQueueJob job) { var componentEnvoy = job.AssociatedEnvoy; IEnumerable <MessageInfo> errors; if (ComponentExtensions.ComponentHasBuildOrCompileErrors(componentEnvoy, out errors)) { CommandLineInterfaceApplication.WriteError(CreateComponentBuildErrorMessage(componentEnvoy.Name.Last, errors.ToList())); } else { CommandLineInterfaceApplication.WriteError( string.Format( CultureInfo.CurrentCulture, LocalizedStrings.BuildComponentTool_BuildFailedWithoutErrorMessages, componentEnvoy.Name.Last)); } }
private async Task <Envoy> ResolveComponentOnTargetAsync(string componentName, ITargetScopeService targetScope) { ITargetScopeService targetbuildBuildSpecScope = targetScope.GetDefaultBuildSpecScope(); IEnumerable <Envoy> matchingComponents = await targetbuildBuildSpecScope.TargetScope.ResolveAsync(new QualifiedName(componentName)); if (matchingComponents.HasMoreThan(1)) { throw new CommandLineOperationException("Multiple components matching the provided name were found. This likely indicates a corrupt project file."); } Envoy componentEnvoy = matchingComponents.SingleOrDefault(); if (componentEnvoy == null) { CommandLineInterfaceApplication.WriteError(await CreateResolveComponentErrorMessageAsync(componentName, targetScope.GetScopeDisplayName(), targetScope)); } return(componentEnvoy); }
private async Task <bool> LoadAndBuildComponentEnvoyAsync(Envoy componentEnvoy) { CommandLineInterfaceApplication.WriteLineVerbose($"Resolved to {componentEnvoy.Name.Last}"); ILockedSourceFile componentFileLock; try { componentFileLock = await componentEnvoy.LoadAsync(); } catch (Exception e) when(ExceptionHelper.ShouldExceptionBeCaught(e)) { string loadErrorMessage = DocumentExtensions.GetLoadErrorMessageForException(e, componentEnvoy.FileName()); throw new CommandLineOperationException(loadErrorMessage, e); } using (componentFileLock) { CommandLineInterfaceApplication.WriteLineVerbose($"Loaded {componentEnvoy.Name.Last}"); var configurationReference = componentEnvoy.GetOwningComponentConfigurationReference(); if (ShowErrorIfSubTypeNotSupported(configurationReference)) { return(false); } bool buildSucceeded = await BuildComponentAsync(configurationReference); bool saveFailed = Save && !await TrySaveProjectFilesAsync(componentEnvoy.Project); if (!buildSucceeded || saveFailed) { CommandLineInterfaceApplication.WriteError( string.Format( CultureInfo.CurrentCulture, LocalizedStrings.BuildComponentTool_BuildFailed, componentEnvoy.Name.Last)); return(false); } WriteSuccessMessage(componentEnvoy.Name.Last, configurationReference.Configuration.GetOutputDirectory()); return(true); } }
/// <inheritdoc /> protected override async Task <int> RunAsync(IEnumerable <string> extraArguments, ProjectAndHostCreator projectAndHostCreator) { if (!LongPath.IsPathRooted(ProjectPath)) { ProjectPath = LongPath.GetFullPath(LongPath.Combine(Environment.CurrentDirectory, ProjectPath)); } Project project = await projectAndHostCreator.OpenProjectAsync(ProjectPath); CommandLineInterfaceApplication.WriteLineVerbose($"Opened project at {ProjectPath}"); Envoy componentEnvoy = await ResolveComponentToBuildAsync(project); if (componentEnvoy == null) { return(1); } bool buildSucceeded = await LoadAndBuildComponentEnvoyAsync(componentEnvoy); return(buildSucceeded ? 0 : 1); }