示例#1
0
 public AssetSerializableLogMessage(AssetLogMessage logMessage)
     : base(logMessage)
 {
     if (logMessage.AssetReference != null)
     {
         AssetId  = logMessage.AssetReference.Id;
         AssetUrl = logMessage.AssetReference.Location;
     }
 }
示例#2
0
        private void BuildStepProcessed(object sender, BuildStepEventArgs e)
        {
            var assetItem  = (AssetItem)e.Step.Tag;
            var assetRef   = assetItem.ToReference();
            var project    = assetItem.Package;
            var stepLogger = e.Logger is BuildStepLogger ? ((BuildStepLogger)e.Logger).StepLogger : null;

            if (stepLogger != null)
            {
                foreach (var message in stepLogger.Messages.Where(x => x.LogMessage.IsAtLeast(LogMessageType.Warning)))
                {
                    var assetMessage = new AssetLogMessage(project, assetRef, message.LogMessage.Type, AssetMessageCode.CompilationMessage, assetRef.Location, message.LogMessage.Text)
                    {
                        Exception = message.LogMessage is LogMessage ? ((LogMessage)message.LogMessage).Exception : null
                    };
                    builderOptions.Logger.Log(assetMessage);
                }
            }
            switch (e.Step.Status)
            {
            // This case should never happen
            case ResultStatus.NotProcessed:
                builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Fatal, AssetMessageCode.InternalCompilerError, assetRef.Location));
                break;

            case ResultStatus.Successful:
                builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Verbose, AssetMessageCode.CompilationSucceeded, assetRef.Location));
                break;

            case ResultStatus.Failed:
                builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Error, AssetMessageCode.CompilationFailed, assetRef.Location));
                break;

            case ResultStatus.Cancelled:
                builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Verbose, AssetMessageCode.CompilationCancelled, assetRef.Location));
                break;

            case ResultStatus.NotTriggeredWasSuccessful:
                builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Verbose, AssetMessageCode.AssetUpToDate, assetRef.Location));
                break;

            case ResultStatus.NotTriggeredPrerequisiteFailed:
                builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Error, AssetMessageCode.PrerequisiteFailed, assetRef.Location));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            e.Step.StepProcessed -= BuildStepProcessed;
        }
示例#3
0
 protected override void LogRaw(ILogMessage logMessage)
 {
     loggerToForward?.Log(AssetLogMessage.From(package, assetReference, logMessage, assetFullPath));
 }
示例#4
0
        /// <summary>
        /// Validates the inheritance of an asset by checking base accessibility up to the root base.
        /// </summary>
        /// <param name="assetItem">The asset item.</param>
        /// <param name="log">The log to output the result of the analysis.</param>
        /// <returns>A list of all the base in bottom-up order.</returns>
        /// <exception cref="System.ArgumentNullException">asset
        /// or
        /// log</exception>
        public List <Asset> ValidateAssetBase(AssetItem assetItem, ILogger log)
        {
            if (assetItem == null)
            {
                throw new ArgumentNullException(nameof(assetItem));
            }
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            var baseItems = new List <Asset>();

            // 1) Check that item is actually in the package and is the same instance
            var assetItemFound = Session.FindAsset(assetItem.Id);

            if (!ReferenceEquals(assetItem.Asset, assetItemFound.Asset))
            {
                var assetReference = assetItem.ToReference();
                log.Error(assetItem.Package, assetReference, AssetMessageCode.AssetForPackageNotFound, assetReference, assetItem.Package.FullPath.GetFileNameWithoutExtension());
                return(baseItems);
            }

            // 2) Iterate on each base and perform validation
            var currentAsset = assetItem;

            while (currentAsset.Asset.Archetype != null)
            {
                // 2.1) Check that asset has not been already processed
                if (baseItems.Contains(currentAsset.Asset))
                {
                    // Else this is a circular reference
                    log.Error(assetItem.Package, currentAsset.ToReference(), AssetMessageCode.InvalidCircularReferences, baseItems.Select(item => item.Id));
                    break;
                }

                // TODO: here we need to add a deep-scan of each base (including the root) for any embedded assets that are
                //

                // 2.2) Check that base asset is existing
                var baseAssetItem = Session.FindAsset(currentAsset.Asset.Archetype.Id);
                if (baseAssetItem == null)
                {
                    AssetLogMessage error;

                    // If an asset with the same location is registered
                    // Add this asset as a reference in the error message
                    var newBaseAsset = Session.FindAsset(currentAsset.Asset.Archetype.Location);
                    if (newBaseAsset != null)
                    {
                        // If asset location exist, log a message with the new location, but don't perform any automatic fix
                        error = new AssetLogMessage(currentAsset.Package, currentAsset.ToReference(), LogMessageType.Error, AssetMessageCode.BaseChanged, currentAsset.Asset.Archetype.Location);
                        error.Related.Add(newBaseAsset.ToReference());
                    }
                    else
                    {
                        // Base was not found. The base asset has been removed.
                        error = new AssetLogMessage(currentAsset.Package, currentAsset.ToReference(), LogMessageType.Error, AssetMessageCode.BaseNotFound);
                    }

                    // Set the member to Base.
                    error.Member = TypeDescriptorFactory.Default.Find(typeof(Asset)).TryGetMember("Base");

                    // Log the error
                    log.Log(error);
                    break;
                }
                else
                {
                    if (baseAssetItem.GetType() != assetItem.Asset.GetType())
                    {
                        log.Error(currentAsset.Package, currentAsset.ToReference(), AssetMessageCode.BaseInvalidType, baseAssetItem.GetType(), assetItem.Asset.GetType());
                    }
                }

                currentAsset = baseAssetItem;
                baseItems.Add(currentAsset.Asset);
            }
            return(baseItems);
        }
示例#5
0
        /// <summary>
        /// Compile the required build step necessary to produce the desired output item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="compilationResult">The compilation result.</param>
        /// <param name="assetItem">The asset item.</param>
        protected ListBuildStep CompileItem(CompilerContext context, AssetCompilerResult compilationResult, AssetItem assetItem)
        {
            // First try to find an asset compiler for this particular asset.
            IAssetCompiler compiler;

            try
            {
                compiler = compilerRegistry.GetCompiler(assetItem.Asset.GetType());
            }
            catch (Exception ex)
            {
                compilationResult.Error("Cannot find a compiler for asset [{0}] from path [{1}]", ex, assetItem.Id,
                                        assetItem.Location);
                return(null);
            }

            if (compiler == null)
            {
                return(null);
            }

            // Second we are compiling the asset (generating a build step)
            try
            {
                var resultPerAssetType = compiler.Compile(context, assetItem);

                // Raise the AssetCompiled event.
                var handler = AssetCompiled;
                if (handler != null)
                {
                    handler(this, new AssetCompiledArgs(assetItem, resultPerAssetType));
                }

                // TODO: See if this can be unified with PackageBuilder.BuildStepProcessed
                foreach (var message in resultPerAssetType.Messages)
                {
                    var assetMessage = new AssetLogMessage(null, assetItem.ToReference(), message.Type, AssetMessageCode.CompilationMessage, assetItem.Location, message.Text)
                    {
                        Exception = message is LogMessage ? ((LogMessage)message).Exception : null
                    };
                    // Forward log messages to compilationResult
                    compilationResult.Log(assetMessage);

                    // Forward log messages to build step logger
                    resultPerAssetType.BuildSteps.Logger.Log(assetMessage);
                }

                // Make the build step fail if there was an error during compiling (only when we are compiling the build steps of an asset)
                if (resultPerAssetType.BuildSteps is AssetBuildStep && resultPerAssetType.BuildSteps.Logger.HasErrors)
                {
                    resultPerAssetType.BuildSteps.Add(new CommandBuildStep(new FailedCommand(assetItem.Location)));
                }

                // Build the module string
                var assetAbsolutePath = assetItem.FullPath;
                assetAbsolutePath = Path.GetFullPath(assetAbsolutePath);
                var module = string.Format("{0}(1,1)", assetAbsolutePath);

                // Assign module string to all command build steps
                SetModule(resultPerAssetType.BuildSteps, module);

                // Add a wait command to the build steps if required by the item build
                if (resultPerAssetType.ShouldWaitForPreviousBuilds)
                {
                    compilationResult.BuildSteps.Add(new WaitBuildStep());
                }

                foreach (var buildStep in resultPerAssetType.BuildSteps)
                {
                    buildStep.Priority = latestPriority++;
                }

                // Add the item result build steps the item list result build steps
                return(resultPerAssetType.BuildSteps);
            }
            catch (Exception ex)
            {
                compilationResult.Error("Unexpected exception while compiling asset [{0}] from path [{1}]", ex, assetItem.Id,
                                        assetItem.Location);
                return(null);
            }
        }
示例#6
0
        /// <summary>
        /// Compile the required build step necessary to produce the desired output item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="compilationResult">The compilation result.</param>
        /// <param name="assetItem">The asset item.</param>
        public ListBuildStep CompileItem(AssetCompilerContext context, AssetCompilerResult compilationResult, AssetItem assetItem)
        {
            // First try to find an asset compiler for this particular asset.
            IAssetCompiler compiler;

            try
            {
                compiler = compilerRegistry.GetCompiler(assetItem.Asset.GetType(), compilationContext);
            }
            catch (Exception ex)
            {
                compilationResult.Error($"Cannot find a compiler for asset [{assetItem.Id}] from path [{assetItem.Location}]", ex);
                return(null);
            }

            if (compiler == null)
            {
                return(null);
            }

            // Second we are compiling the asset (generating a build step)
            try
            {
                var resultPerAssetType = compiler.Prepare(context, assetItem);

                // Raise the AssetCompiled event.
                AssetCompiled?.Invoke(this, new AssetCompiledArgs(assetItem, resultPerAssetType));

                // TODO: See if this can be unified with PackageBuilder.BuildStepProcessed
                var assetFullPath = assetItem.FullPath.ToWindowsPath();
                foreach (var message in resultPerAssetType.Messages)
                {
                    var assetMessage = AssetLogMessage.From(null, assetItem.ToReference(), message, assetFullPath);
                    // Forward log messages to compilationResult
                    compilationResult.Log(assetMessage);

                    // Forward log messages to build step logger
                    resultPerAssetType.BuildSteps.Logger.Log(assetMessage);
                }

                // Make the build step fail if there was an error during compiling (only when we are compiling the build steps of an asset)
                if (resultPerAssetType.BuildSteps is AssetBuildStep && resultPerAssetType.BuildSteps.Logger.HasErrors)
                {
                    resultPerAssetType.BuildSteps.Add(new CommandBuildStep(new FailedCommand(assetItem.Location)));
                }

                // TODO: Big review of the log infrastructure of CompilerApp & BuildEngine!
                // Assign module string to all command build steps
                SetAssetLogger(resultPerAssetType.BuildSteps, assetItem.Package, assetItem.ToReference(), assetItem.FullPath.ToWindowsPath());

                foreach (var buildStep in resultPerAssetType.BuildSteps)
                {
                    buildStep.Priority = latestPriority++;
                }

                // Add the item result build steps the item list result build steps
                return(resultPerAssetType.BuildSteps);
            }
            catch (Exception ex)
            {
                compilationResult.Error($"Unexpected exception while compiling asset [{assetItem.Id}] from path [{assetItem.Location}]", ex);
                return(null);
            }
        }