Exemplo n.º 1
0
    public override bool Execute()
    {
        try
        {
            var refPaths = RefAssemblyPaths?.Split(';') ?? Array.Empty <string>();
            var addPaths = AdditionalDocPaths?.Split(';') ?? Array.Empty <string>();
            var logger   = new TaskLogger(Log, NoWarn?.Split(';') ?? Array.Empty <string>()) as ILogger;
            var trim     = (ApiLevel)Math.Min((int)(Enum.TryParse <ApiLevel>(TrimLevel, true, out var t) ? t : ApiLevel.Internal), (int)ApiLevel.Internal);

            Log.LogCommandLine(MessageImportance.Normal,
                               typeof(InheritDocTask).Assembly.GetName().FullName +
                               Environment.NewLine + nameof(AssemblyPath) + ": " + AssemblyPath +
                               Environment.NewLine + nameof(InDocPath) + ": " + InDocPath +
                               Environment.NewLine + nameof(OutDocPath) + ": " + OutDocPath +
                               Environment.NewLine + nameof(RefAssemblyPaths) + ": " + RefAssemblyPaths +
                               Environment.NewLine + nameof(AdditionalDocPaths) + ": " + AdditionalDocPaths +
                               Environment.NewLine + nameof(TrimLevel) + ": " + trim
                               );

            var(replaced, total, trimmed) = InheritDocProcessor.InheritDocs(AssemblyPath, InDocPath, OutDocPath, refPaths, addPaths, trim, logger);

            logger.Write(ILogger.Severity.Message, $"{nameof(InheritDocTask)} replaced {replaced} of {total} inheritdoc tags {(trim > ApiLevel.None ? $"and removed {trimmed} {(trim == ApiLevel.Private ? "private" : "non-public")} member docs " : null)}in {Path.GetFullPath(OutDocPath)}");
            return(true);
        }
        catch (Exception ex)
        {
            Log.LogErrorFromException(ex, true);
            return(false);
        }
    }
Exemplo n.º 2
0
        public void LogMessage(MessageContainer message)
        {
            if (!LogMessages || message == MessageContainer.Empty)
            {
                return;
            }

            if (message.Category == MessageCategory.Warning &&
                NoWarn.Contains((uint)message.Code))
            {
                // This warning was turned off by --nowarn.
                return;
            }

            // Note: message.Version is nullable. The comparison is false if it is null.
            // Unversioned warnings are not controlled by WarnVersion.
            // Error messages are guaranteed to only have a version if they were created for a warning due to warnaserror.
            if ((message.Category == MessageCategory.Warning || message.Category == MessageCategory.Error) &&
                message.Version > WarnVersion)
            {
                // This warning was turned off by --warn.
                return;
            }

            if (OutputWarningSuppressions && message.Category == MessageCategory.Warning && message.Origin?.MemberDefinition != null)
            {
                WarningSuppressionWriter.AddWarning(message.Code.Value, message.Origin?.MemberDefinition);
            }

            Logger?.LogMessage(message);
        }
Exemplo n.º 3
0
        private static async Task <IEnumerable <Diagnostic> > GetCompilerDiagnosticsAsync(Document document)
        {
            var model = await document.GetSemanticModelAsync();

            return(model
                   .GetDiagnostics()
                   .Where(d => !NoWarn.Contains(d.Id)));
        }
Exemplo n.º 4
0
        public override int GetHashCode()
        {
            var hashCode = new HashCodeCombiner();

            hashCode.AddObject(AllWarningsAsErrors);
            hashCode.AddSequence(WarningsAsErrors.OrderBy(e => e));
            hashCode.AddSequence(NoWarn.OrderBy(e => e));

            return(hashCode.CombinedHash);
        }
Exemplo n.º 5
0
        public bool IsWarningSuppressed(int warningCode, MessageOrigin origin)
        {
            // This warning was turned off by --nowarn.
            if (NoWarn.Contains(warningCode))
            {
                return(true);
            }

            if (Suppressions == null)
            {
                return(false);
            }

            return(Suppressions.IsSuppressed(warningCode, origin, out _));
        }
Exemplo n.º 6
0
        public bool Equals(WarningProperties other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(AllWarningsAsErrors == other.AllWarningsAsErrors &&
                   WarningsAsErrors.SetEquals(other.WarningsAsErrors) &&
                   NoWarn.SetEquals(other.NoWarn));
        }
Exemplo n.º 7
0
        public bool Equals(LibraryDependency other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(AutoReferenced == other.AutoReferenced &&
                   EqualityUtility.EqualsWithNullCheck(LibraryRange, other.LibraryRange) &&
                   EqualityUtility.EqualsWithNullCheck(Type, other.Type) &&
                   IncludeType == other.IncludeType &&
                   SuppressParent == other.SuppressParent &&
                   NoWarn.SequenceEqualWithNullCheck(other.NoWarn));
        }
        public bool Equals(LibraryDependency other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(AutoReferenced == other.AutoReferenced &&
                   EqualityUtility.EqualsWithNullCheck(LibraryRange, other.LibraryRange) &&
                   EqualityUtility.EqualsWithNullCheck(Type, other.Type) &&
                   IncludeType == other.IncludeType &&
                   SuppressParent == other.SuppressParent &&
                   NoWarn.SequenceEqualWithNullCheck(other.NoWarn) &&
                   GeneratePathProperty == other.GeneratePathProperty &&
                   VersionCentrallyManaged == other.VersionCentrallyManaged);
        }
Exemplo n.º 9
0
        public override bool Execute()
        {
            if (!Enum.TryParse(OutputType, true, out m_OutputType))
            {
                Log.LogError("Unrecognized OutputType {0}", OutputType);
                return(false);
            }

            if (!Enum.TryParse(Platform, true, out m_Platform))
            {
                Log.LogError("Unrecognized Platform {0}", Platform);
                return(false);
            }

            m_responseFile = Path.GetTempFileName();
            List <string> argv = new List <string>();

            argv.Add("-nologo");
            argv.Add("-version:1.8");
            argv.Add("-w4");

            switch (m_OutputType)
            {
            case ParsedOutputType.Exe:
                argv.Add("-target:exe");
                break;

            case ParsedOutputType.WinExe:
                argv.Add("-target:winexe");
                break;

            case ParsedOutputType.Library:
                argv.Add("-target:library");
                break;
            }

            switch (m_Platform)
            {
            case ParsedPlatform.AnyCpu:
                argv.Add("-platform:anycpu");
                break;

            case ParsedPlatform.AnyCpuPrefer32Bit:
                argv.Add("-platform:anycpu32bitpreferred");
                break;

            case ParsedPlatform.ARM:
                argv.Add("-platform:arm");
                break;

            case ParsedPlatform.x64:
                argv.Add("-platform:x64");
                break;

            case ParsedPlatform.x86:
                argv.Add("-platform:x86");
                break;
            }

            if (!string.IsNullOrEmpty(Version))
            {
                argv.Add("-version:" + Version);
            }
            if (!string.IsNullOrEmpty(FileVersion))
            {
                argv.Add("-fileversion:" + FileVersion);
            }
            if (!string.IsNullOrEmpty(ApplicationIcon))
            {
                argv.Add("-win32icon:" + ApplicationIcon);
            }
            if (!string.IsNullOrEmpty(Win32Manifest))
            {
                argv.Add("-win32manifest:" + Win32Manifest);
            }

            argv.AddRange(NoWarn.Select(x => "-nowarn:" + x));
            if (CompressResources)
            {
                argv.Add("-compressresources");
            }
            if (StrictFieldSemantics)
            {
                argv.Add("-strictfinalfieldsemantics");
            }
            if (RemoveAssertions)
            {
                argv.Add("-removeassertions");
            }
            if (SharedClassLoader)
            {
                argv.Add("-sharedclassloader");
            }
            if (SuppressParameterReflection)
            {
                argv.Add("-noparameterreflection");
            }
            argv.AddRange(ExtraArguments ?? Enumerable.Empty <string>());
            argv.Add("-highentropyva"); // for security

            argv.Add("-out:" + OutputPath.GetMetadata("FullPath"));
            // Don't use FullPath here, as some of these might be bare filenames, and those must be preserved.
            argv.AddRange(References?.Select(x => "-r:" + x.ItemSpec) ?? Enumerable.Empty <string>());
            argv.AddRange(ClassFiles?.Select(x => x.GetMetadata("FullPath")) ?? Enumerable.Empty <string>());

            File.WriteAllLines(m_responseFile, argv);
            bool taskSuccess = base.Execute();

            if (taskSuccess)
            {
                DeleteTempFile(m_responseFile);
            }
            else
            {
                Log.LogMessage(MessageImportance.High, "Migrator arguments can be found here: {0}", m_responseFile);
            }

            return(taskSuccess);
        }