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 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 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 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); } }