public override bool Execute()
        {
            if (!File.Exists(ManifestPath))
            {
                Log.LogError($"Manifest file at '{ManifestPath}' not found.");
                return(false);
            }

            try
            {
                var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(ManifestPath));

                Assets = manifest.Assets?.Select(a => a.ToTaskItem()).ToArray() ?? Array.Empty <ITaskItem>();

                DiscoveryPatterns = manifest.DiscoveryPatterns?.Select(dp => dp.ToTaskItem()).ToArray() ?? Array.Empty <ITaskItem>();

                ReferencedProjectsConfiguration = manifest.ReferencedProjectsConfiguration?.Select(m => m.ToTaskItem()).ToArray() ?? Array.Empty <ITaskItem>();
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex, showStackTrace: true, showDetail: true, file: ManifestPath);
            }

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 2
0
        private void ReadCandidateManifests(List <StaticWebAssetsManifest> manifests)
        {
            for (var i = 0; i < Manifests.Length; i++)
            {
                var manifest     = Manifests[i];
                var manifestType = manifest.GetMetadata("ManifestType");
                if (!StaticWebAssetsManifest.ManifestTypes.IsType(manifestType, AssetKind))
                {
                    Log.LogMessage(
                        "Skipping manifest '{0}' because manifest type '{1}' is different from asset kind '{2}'",
                        manifest.ItemSpec,
                        manifestType,
                        AssetKind);

                    continue;
                }

                if (!File.Exists(manifest.ItemSpec))
                {
                    Log.LogError($"Manifest file '{manifest.ItemSpec}' does not exist.");
                    return;
                }

                manifests.Add(StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(manifest.ItemSpec)));
            }
        }
Exemplo n.º 3
0
        public override bool Execute()
        {
            if (!File.Exists(ManifestPath))
            {
                Log.LogError($"Manifest file at '{ManifestPath}' not found.");
            }

            try
            {
                var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(ManifestPath));

                // When we are reading a publish manifest we are about to compute the list of files to publish
                // so we filter out files marked as Reference here since they don't have to be copied to the output.
                // The process for merging assets from dependent projects reads their manifests directly, so its not
                // an issue there.
                var isPublishManifest = string.Equals(manifest.ManifestType, StaticWebAssetsManifest.ManifestTypes.Publish, StringComparison.Ordinal);
                if (isPublishManifest)
                {
                    var assets = new List <StaticWebAsset>();
                    foreach (var asset in manifest.Assets)
                    {
                        if (string.Equals(asset.SourceId, manifest.Source, StringComparison.Ordinal) &&
                            string.Equals(asset.AssetMode, StaticWebAsset.AssetModes.Reference))
                        {
                            continue;
                        }

                        assets.Add(asset);
                    }

                    Assets = assets.Select(a => a.ToTaskItem()).ToArray();
                }
                else
                {
                    Assets = manifest.Assets.Select(a => a.ToTaskItem()).ToArray();
                }

                RelatedManifests = manifest.RelatedManifests.Select(m => m.ToTaskItem()).ToArray();
            }
            catch (Exception ex)
            {
                Log.LogError(ex.ToString());
            }

            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 4
0
        public override bool Execute()
        {
            try
            {
                var assets = Assets.OrderBy(a => a.GetMetadata("FullPath")).Select(StaticWebAsset.FromTaskItem);

                var assetsByTargetPath = assets.GroupBy(a => a.ComputeTargetPath("", '/'), StringComparer.OrdinalIgnoreCase);
                foreach (var group in assetsByTargetPath)
                {
                    if (!StaticWebAsset.ValidateAssetGroup(group.Key, group.ToArray(), ManifestType, out var reason))
                    {
                        Log.LogError(reason);
                        return(false);
                    }
                }

                var discoveryPatterns = DiscoveryPatterns
                                        .OrderBy(a => a.ItemSpec)
                                        .Select(StaticWebAssetsManifest.DiscoveryPattern.FromTaskItem)
                                        .ToArray();

                var referencedProjectsConfiguration = ReferencedProjectsConfigurations.OrderBy(a => a.ItemSpec)
                                                      .Select(StaticWebAssetsManifest.ReferencedProjectConfiguration.FromTaskItem)
                                                      .ToArray();

                PersistManifest(
                    StaticWebAssetsManifest.Create(
                        Source,
                        BasePath,
                        Mode,
                        ManifestType,
                        referencedProjectsConfiguration,
                        discoveryPatterns,
                        assets.ToArray()));
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex, showStackTrace: true, showDetail: true, file: null);
            }
            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 5
0
        private void PersistManifest(StaticWebAssetsManifest manifest)
        {
            var data                 = JsonSerializer.SerializeToUtf8Bytes(manifest, ManifestSerializationOptions);
            var fileExists           = File.Exists(ManifestPath);
            var existingManifestHash = fileExists ? StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(ManifestPath)).Hash : "";

            if (!fileExists)
            {
                Log.LogMessage($"Creating manifest because manifest file '{ManifestPath}' does not exist.");
                File.WriteAllBytes(ManifestPath, data);
            }
            else if (!string.Equals(manifest.Hash, existingManifestHash, StringComparison.Ordinal))
            {
                Log.LogMessage($"Updating manifest because manifest version '{manifest.Hash}' is different from existing manifest hash '{existingManifestHash}'.");
                File.WriteAllBytes(ManifestPath, data);
            }
            else
            {
                Log.LogMessage($"Skipping manifest updated because manifest version '{manifest.Hash}' has not changed.");
            }
        }
Exemplo n.º 6
0
        public override bool Execute()
        {
            try
            {
                var assets = Assets.OrderBy(a => a.GetMetadata("FullPath")).Select(StaticWebAsset.FromTaskItem);

                var relatedManifests = RelatedManifests.OrderBy(a => a.GetMetadata("FullPath"))
                                       .Select(ComputeManifestReference)
                                       .Where(r => r != null)
                                       .ToArray();

                if (Log.HasLoggedErrors)
                {
                    return(false);
                }

                var discoveryPatterns = DiscoveryPatterns
                                        .OrderBy(a => a.ItemSpec)
                                        .Select(ComputeDiscoveryPattern)
                                        .ToArray();

                PersistManifest(
                    StaticWebAssetsManifest.Create(
                        Source,
                        BasePath,
                        Mode,
                        ManifestType,
                        relatedManifests,
                        discoveryPatterns,
                        assets.ToArray()));
            }
            catch (Exception ex)
            {
                Log.LogError(ex.ToString());
                Log.LogErrorFromException(ex);
            }
            return(!Log.HasLoggedErrors);
        }
Exemplo n.º 7
0
        private StaticWebAssetsManifest.ManifestReference ComputeManifestReference(ITaskItem reference)
        {
            var identity      = reference.GetMetadata("FullPath");
            var source        = reference.GetMetadata(nameof(StaticWebAssetsManifest.ManifestReference.Source));
            var manifestType  = reference.GetMetadata(nameof(StaticWebAssetsManifest.ManifestReference.ManifestType));
            var projectFile   = reference.GetMetadata(nameof(StaticWebAssetsManifest.ManifestReference.ProjectFile));
            var publishTarget = reference.GetMetadata(nameof(StaticWebAssetsManifest.ManifestReference.PublishTarget));
            var additionalPublishProperties         = reference.GetMetadata(nameof(StaticWebAssetsManifest.ManifestReference.AdditionalPublishProperties));
            var additionalPublishPropertiesToRemove = reference.GetMetadata(nameof(StaticWebAssetsManifest.ManifestReference.AdditionalPublishPropertiesToRemove));

            if (!File.Exists(identity))
            {
                if (!StaticWebAssetsManifest.ManifestTypes.IsPublish(manifestType))
                {
                    Log.LogError("Manifest '{0}' for project '{1}' with type '{2}' does not exist.", identity, source, manifestType);
                    return(null);
                }

                var publishManifest = StaticWebAssetsManifest.ManifestReference.Create(identity, source, manifestType, projectFile, "");
                publishManifest.PublishTarget = publishTarget;
                publishManifest.AdditionalPublishProperties         = additionalPublishProperties;
                publishManifest.AdditionalPublishPropertiesToRemove = additionalPublishPropertiesToRemove;

                return(publishManifest);
            }

            var relatedManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(identity));

            var result = StaticWebAssetsManifest.ManifestReference.Create(identity, source, manifestType, projectFile, relatedManifest.Hash);

            result.PublishTarget = publishTarget;
            result.AdditionalPublishProperties         = additionalPublishProperties;
            result.AdditionalPublishPropertiesToRemove = additionalPublishPropertiesToRemove;

            return(result);
        }