From bdc85b7525cfa0f0b918891b5e07f5a1306c5bf8 Mon Sep 17 00:00:00 2001 From: Glen Nicol <58054391+Glen-Nicol-Garmin@users.noreply.github.com> Date: Sun, 16 Feb 2020 12:41:06 -0800 Subject: [PATCH] Feature: GitWeb Source Link provider (#505) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Feature: GitWeb Source Link provider GitWeb only currently supports SSH repository URLs. https://github.com/dotnet/sourcelink/pull/505 * Remove Resources.Designer.cs * Remove comment Co-authored-by: Tomáš Matoušek --- SourceLink.sln | 12 ++ src/Common/TranslateRepositoryUrlGitTask.cs | 41 ++++-- .../GitWebTests.cs | 130 ++++++++++++++++++ ...oft.SourceLink.Git.IntegrationTests.csproj | 1 + .../GetSourceLinkUrlTests.cs | 56 ++++++++ ...crosoft.SourceLink.GitWeb.UnitTests.csproj | 9 ++ .../TranslateRepositoryUrlsTests.cs | 51 +++++++ src/SourceLink.GitWeb/GetSourceLinkUrl.cs | 37 +++++ .../Microsoft.SourceLink.GitWeb.csproj | 35 +++++ .../Microsoft.SourceLink.GitWeb.nuspec | 17 +++ src/SourceLink.GitWeb/Resources.resx | 123 +++++++++++++++++ .../TranslateRepositoryUrls.cs | 31 +++++ .../build/Microsoft.SourceLink.GitWeb.targets | 65 +++++++++ .../Microsoft.SourceLink.GitWeb.targets | 4 + src/SourceLink.GitWeb/xlf/Resources.cs.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.de.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.es.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.fr.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.it.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.ja.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.ko.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.pl.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.pt-BR.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.ru.xlf | 12 ++ src/SourceLink.GitWeb/xlf/Resources.tr.xlf | 12 ++ .../xlf/Resources.zh-Hans.xlf | 12 ++ .../xlf/Resources.zh-Hant.xlf | 12 ++ 27 files changed, 758 insertions(+), 10 deletions(-) create mode 100644 src/SourceLink.Git.IntegrationTests/GitWebTests.cs create mode 100644 src/SourceLink.GitWeb.UnitTests/GetSourceLinkUrlTests.cs create mode 100644 src/SourceLink.GitWeb.UnitTests/Microsoft.SourceLink.GitWeb.UnitTests.csproj create mode 100644 src/SourceLink.GitWeb.UnitTests/TranslateRepositoryUrlsTests.cs create mode 100644 src/SourceLink.GitWeb/GetSourceLinkUrl.cs create mode 100644 src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.csproj create mode 100644 src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.nuspec create mode 100644 src/SourceLink.GitWeb/Resources.resx create mode 100644 src/SourceLink.GitWeb/TranslateRepositoryUrls.cs create mode 100644 src/SourceLink.GitWeb/build/Microsoft.SourceLink.GitWeb.targets create mode 100644 src/SourceLink.GitWeb/buildMultiTargeting/Microsoft.SourceLink.GitWeb.targets create mode 100644 src/SourceLink.GitWeb/xlf/Resources.cs.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.de.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.es.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.fr.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.it.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.ja.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.ko.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.pl.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.pt-BR.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.ru.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.tr.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.zh-Hans.xlf create mode 100644 src/SourceLink.GitWeb/xlf/Resources.zh-Hant.xlf diff --git a/SourceLink.sln b/SourceLink.sln index 49098d14..b185660e 100644 --- a/SourceLink.sln +++ b/SourceLink.sln @@ -54,6 +54,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SourceLink.AzureD EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SourceLink.AzureDevOpsServer.Git.UnitTests", "src\SourceLink.AzureDevOpsServer.Git.UnitTests\Microsoft.SourceLink.AzureDevOpsServer.Git.UnitTests.csproj", "{79371F26-FB84-408D-A4A1-B142B247C288}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SourceLink.GitWeb", "src\SourceLink.GitWeb\Microsoft.SourceLink.GitWeb.csproj", "{C78DD3EF-9D20-4E00-8237-E871BB53F840}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SourceLink.GitWeb.UnitTests", "src\SourceLink.GitWeb.UnitTests\Microsoft.SourceLink.GitWeb.UnitTests.csproj", "{50503A43-08C0-493B-B8CC-F368983644C1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -136,6 +140,14 @@ Global {79371F26-FB84-408D-A4A1-B142B247C288}.Debug|Any CPU.Build.0 = Debug|Any CPU {79371F26-FB84-408D-A4A1-B142B247C288}.Release|Any CPU.ActiveCfg = Release|Any CPU {79371F26-FB84-408D-A4A1-B142B247C288}.Release|Any CPU.Build.0 = Release|Any CPU + {C78DD3EF-9D20-4E00-8237-E871BB53F840}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C78DD3EF-9D20-4E00-8237-E871BB53F840}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C78DD3EF-9D20-4E00-8237-E871BB53F840}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C78DD3EF-9D20-4E00-8237-E871BB53F840}.Release|Any CPU.Build.0 = Release|Any CPU + {50503A43-08C0-493B-B8CC-F368983644C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50503A43-08C0-493B-B8CC-F368983644C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50503A43-08C0-493B-B8CC-F368983644C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50503A43-08C0-493B-B8CC-F368983644C1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Common/TranslateRepositoryUrlGitTask.cs b/src/Common/TranslateRepositoryUrlGitTask.cs index b87b2d70..02c0e032 100644 --- a/src/Common/TranslateRepositoryUrlGitTask.cs +++ b/src/Common/TranslateRepositoryUrlGitTask.cs @@ -1,4 +1,5 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See +// License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -48,13 +49,13 @@ private void ExecuteImpl() } static bool isMatchingHostUri(Uri hostUri, Uri uri) - => uri.GetHost().Equals(hostUri.GetHost(), StringComparison.OrdinalIgnoreCase) || + => uri.GetHost().Equals(hostUri.GetHost(), StringComparison.OrdinalIgnoreCase) || uri.GetHost().EndsWith("." + hostUri.GetHost(), StringComparison.OrdinalIgnoreCase); // only need to translate valid ssh URLs that match one of our hosts: string? translate(string? url) { - if (Uri.TryCreate(url, UriKind.Absolute, out var uri) && + if (Uri.TryCreate(url, UriKind.Absolute, out var uri) && hostUris.Any(h => isMatchingHostUri(h, uri))) { return (uri.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase) ? TranslateHttpUrl(uri) : @@ -66,7 +67,16 @@ static bool isMatchingHostUri(Uri hostUri, Uri uri) return url; } - TranslatedRepositoryUrl = translate(RepositoryUrl); + try + { + TranslatedRepositoryUrl = translate(RepositoryUrl); + } + catch (NotSupportedException e) + { + Log.LogError(e.Message); + return; + } + TranslatedSourceRoots = SourceRoots; if (TranslatedSourceRoots != null) @@ -78,12 +88,23 @@ static bool isMatchingHostUri(Uri hostUri, Uri uri) continue; } - // Item metadata are stored msbuild-escaped. GetMetadata unescapes, SetMetadata stores the value as specified. - // When initializing the URL metadata from git information we msbuild-escaped the URL to preserve any URL escapes in it. - // Here, GetMetadata unescapes the msbuild escapes, then we translate the URL and finally msbuild-escape - // the resulting URL to preserve any URL escapes. - sourceRoot.SetMetadata(Names.SourceRoot.ScmRepositoryUrl, - Evaluation.ProjectCollection.Escape(translate(sourceRoot.GetMetadata(Names.SourceRoot.ScmRepositoryUrl)))); + string? translatedUrl; + try + { + translatedUrl = translate(sourceRoot.GetMetadata(Names.SourceRoot.ScmRepositoryUrl)); + } + catch (NotSupportedException e) + { + Log.LogError(e.Message); + continue; + } + + // Item metadata are stored msbuild-escaped. GetMetadata unescapes, SetMetadata + // stores the value as specified. When initializing the URL metadata from git + // information we msbuild-escaped the URL to preserve any URL escapes in it. + // Here, GetMetadata unescapes the msbuild escapes, then we translate the URL + // and finally msbuild-escape the resulting URL to preserve any URL escapes. + sourceRoot.SetMetadata(Names.SourceRoot.ScmRepositoryUrl, Evaluation.ProjectCollection.Escape(translatedUrl)); } } } diff --git a/src/SourceLink.Git.IntegrationTests/GitWebTests.cs b/src/SourceLink.Git.IntegrationTests/GitWebTests.cs new file mode 100644 index 00000000..b0958d59 --- /dev/null +++ b/src/SourceLink.Git.IntegrationTests/GitWebTests.cs @@ -0,0 +1,130 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See +// License.txt in the project root for license information. + +using Microsoft.Build.Tasks.SourceControl; +using System; +using System.IO; +using TestUtilities; + +namespace Microsoft.SourceLink.IntegrationTests +{ + public class GitWebTests : DotNetSdkTestBase + { + public GitWebTests() + : base("Microsoft.SourceLink.GitWeb") + { + } + + [ConditionalFact(typeof(DotNetSdkAvailable))] + public void FullValidation_Ssh() + { + // Test non-ascii characters and escapes in the URL. Escaped URI reserved characters + // should remain escaped, non-reserved characters unescaped in the results. + var repoUrl = $"ssh://git@噸.com/test-%72epo\u1234%24%2572%2F.git"; + var repoName = "test-repo\u1234%24%2572%2F.git"; + + var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var commitSha = repo.Head.Tip.Sha; + + VerifyValues( + customProps: @" + + true + + + + +", + customTargets: "", + targets: new[] + { + "Build", "Pack" + }, + expressions: new[] + { + "@(SourceRoot)", + "@(SourceRoot->'%(SourceLinkUrl)')", + "$(SourceLink)", + "$(PrivateRepositoryUrl)", + "$(RepositoryUrl)" + }, + expectedResults: new[] + { + ProjectSourceRoot, + $"https://噸.com/gitweb/?p={repoName};a=blob_plain;hb={commitSha};f=*", + s_relativeSourceLinkJsonPath, + $"ssh://git@噸.com/{repoName}", + $"ssh://git@噸.com/{repoName}" + }); + + AssertEx.AreEqual( + $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://噸.com/gitweb/?p={repoName};a=blob_plain;hb={commitSha};f=*""}}}}", + File.ReadAllText(Path.Combine(ProjectDir.Path, s_relativeSourceLinkJsonPath))); + + TestUtilities.ValidateAssemblyInformationalVersion( + Path.Combine(ProjectDir.Path, s_relativeOutputFilePath), + "1.0.0+" + commitSha); + + TestUtilities.ValidateNuSpecRepository( + Path.Combine(ProjectDir.Path, s_relativePackagePath), + type: "git", + commit: commitSha, + url: $"ssh://git@噸.com/{repoName}"); + } + + [ConditionalFact(typeof(DotNetSdkAvailable))] + public void Issues_error_on_git_url() + { + var repoUrl = "git://噸.com/invalid_url_protocol.git"; + var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var commitSha = repo.Head.Tip.Sha; + + VerifyValues( + customProps: @" + + true + + + + +", + customTargets: "", + targets: new[] + { + "Build", "Pack" + }, + expressions: Array.Empty(), + expectedErrors: new[]{ + string.Format(GitWeb.Resources.RepositoryUrlIsNotSupportedByProvider, "GIT") + }); + } + + [ConditionalFact(typeof(DotNetSdkAvailable))] + public void Issues_error_on_https_url() + { + var repoUrl = "https://噸.com/invalid_url_protocol.git"; + var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var commitSha = repo.Head.Tip.Sha; + + VerifyValues( + customProps: @" + + true + + + + +", + customTargets: "", + targets: new[] + { + "Build", "Pack" + }, + expressions: Array.Empty(), + expectedErrors: new[] + { + string.Format(GitWeb.Resources.RepositoryUrlIsNotSupportedByProvider, "HTTP") + }); + } + } +} diff --git a/src/SourceLink.Git.IntegrationTests/Microsoft.SourceLink.Git.IntegrationTests.csproj b/src/SourceLink.Git.IntegrationTests/Microsoft.SourceLink.Git.IntegrationTests.csproj index efc7ea5d..a3f1755e 100644 --- a/src/SourceLink.Git.IntegrationTests/Microsoft.SourceLink.Git.IntegrationTests.csproj +++ b/src/SourceLink.Git.IntegrationTests/Microsoft.SourceLink.Git.IntegrationTests.csproj @@ -7,6 +7,7 @@ + diff --git a/src/SourceLink.GitWeb.UnitTests/GetSourceLinkUrlTests.cs b/src/SourceLink.GitWeb.UnitTests/GetSourceLinkUrlTests.cs new file mode 100644 index 00000000..b215d1a0 --- /dev/null +++ b/src/SourceLink.GitWeb.UnitTests/GetSourceLinkUrlTests.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See +// License.txt in the project root for license information. +using Microsoft.Build.Tasks.SourceControl; +using TestUtilities; +using Xunit; +using static TestUtilities.KeyValuePairUtils; + +namespace Microsoft.SourceLink.GitWeb.UnitTests +{ + public class GetSourceLinkUrlTests + { + [Fact] + public void EmptyHosts() + { + var engine = new MockEngine(); + + var task = new GetSourceLinkUrl() + { + BuildEngine = engine, + SourceRoot = new MockItem("x", KVP("RepositoryUrl", "http://abc.com"), KVP("SourceControl", "git")), + }; + + bool result = task.Execute(); + + AssertEx.AssertEqualToleratingWhitespaceDifferences( + "ERROR : " + string.Format(CommonResources.AtLeastOneRepositoryHostIsRequired, "SourceLinkGitWebHost", "GitWeb"), engine.Log); + + Assert.False(result); + } + + [Theory] + [InlineData("", "")] + [InlineData("", "/")] + [InlineData("/", "")] + [InlineData("/", "/")] + public void BuildSourceLinkUrl(string s1, string s2) + { + var engine = new MockEngine(); + + var task = new GetSourceLinkUrl() + { + BuildEngine = engine, + SourceRoot = new MockItem("/src/", KVP("RepositoryUrl", "ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git" + s1), KVP("SourceControl", "git"), KVP("RevisionId", "0123456789abcdefABCDEF000000000000000000")), + Hosts = new[] + { + new MockItem("src.intranet.company.com", KVP("ContentUrl", "https://src.intranet.company.com/gitweb" + s2)), + } + }; + + bool result = task.Execute(); + AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log); + AssertEx.AreEqual("https://src.intranet.company.com/gitweb/?p=root_dir_name/sub_dirs/reponame.git;a=blob_plain;hb=0123456789abcdefABCDEF000000000000000000;f=*", task.SourceLinkUrl); + Assert.True(result); + } + } +} diff --git a/src/SourceLink.GitWeb.UnitTests/Microsoft.SourceLink.GitWeb.UnitTests.csproj b/src/SourceLink.GitWeb.UnitTests/Microsoft.SourceLink.GitWeb.UnitTests.csproj new file mode 100644 index 00000000..16608152 --- /dev/null +++ b/src/SourceLink.GitWeb.UnitTests/Microsoft.SourceLink.GitWeb.UnitTests.csproj @@ -0,0 +1,9 @@ + + + net461;netcoreapp2.0 + + + + + + diff --git a/src/SourceLink.GitWeb.UnitTests/TranslateRepositoryUrlsTests.cs b/src/SourceLink.GitWeb.UnitTests/TranslateRepositoryUrlsTests.cs new file mode 100644 index 00000000..255fdb2f --- /dev/null +++ b/src/SourceLink.GitWeb.UnitTests/TranslateRepositoryUrlsTests.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See +// License.txt in the project root for license information. +using System.Linq; +using TestUtilities; +using Xunit; +using static TestUtilities.KeyValuePairUtils; + +namespace Microsoft.SourceLink.GitWeb.UnitTests +{ + public class TranslateRepositoryUrlsTests + { + [Fact] + public void Translate() + { + var engine = new MockEngine(); + + var task = new TranslateRepositoryUrls() + { + BuildEngine = engine, + RepositoryUrl = "ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git", + IsSingleProvider = true, + SourceRoots = new[] + { + new MockItem("/1/", KVP("SourceControl", "git"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git")), + new MockItem("/2/", KVP("SourceControl", "tfvc"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git")), + new MockItem("/2/", KVP("SourceControl", "git"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git")), + new MockItem("/2/", KVP("SourceControl", "tfvc"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company2.com/root_dir_name/sub_dirs/reponame.git")), + }, + Hosts = new[] + { + new MockItem("src.intranet.company1.com") + } + }; + + bool result = task.Execute(); + AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log); + + AssertEx.AreEqual("ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git", task.TranslatedRepositoryUrl); + + AssertEx.Equal(new[] + { + "ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git", + "ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git", + "ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git", + "ssh://git@src.intranet.company2.com/root_dir_name/sub_dirs/reponame.git", + }, task.TranslatedSourceRoots.Select(r => r.GetMetadata("ScmRepositoryUrl"))); + + Assert.True(result); + } + } +} diff --git a/src/SourceLink.GitWeb/GetSourceLinkUrl.cs b/src/SourceLink.GitWeb/GetSourceLinkUrl.cs new file mode 100644 index 00000000..da5df319 --- /dev/null +++ b/src/SourceLink.GitWeb/GetSourceLinkUrl.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See +// License.txt in the project root for license information. + +using System; +using Microsoft.Build.Framework; +using Microsoft.Build.Tasks.SourceControl; + +namespace Microsoft.SourceLink.GitWeb +{ + /// + /// The task calculates SourceLink URL for a given SourceRoot. If the SourceRoot is associated + /// with a git repository with a recognized domain the output + /// property is set to the content URL corresponding to the domain, otherwise it is set to + /// string "N/A". + /// + public sealed class GetSourceLinkUrl : GetSourceLinkUrlGitTask + { + protected override string HostsItemGroupName => "SourceLinkGitWebHost"; + protected override string ProviderDisplayName => "GitWeb"; + + protected override Uri GetDefaultContentUriFromHostUri(string authority, Uri gitUri) + => new Uri($"https://{authority}/gitweb", UriKind.Absolute); + + protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem? hostItem) + { + var trimLeadingSlash = relativeUrl.TrimStart('/'); + var trimmedContentUrl = contentUri.ToString().TrimEnd('/', '\\'); + + // p = project/path + // a = action + // hb = SHA/revision + // f = repo file path + var gitwebRawUrl = UriUtilities.Combine(trimmedContentUrl, $"?p={trimLeadingSlash}.git;a=blob_plain;hb={revisionId};f=*"); + return gitwebRawUrl; + } + } +} diff --git a/src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.csproj b/src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.csproj new file mode 100644 index 00000000..d9fb3080 --- /dev/null +++ b/src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.csproj @@ -0,0 +1,35 @@ + + + net461;netcoreapp2.0 + true + + + true + $(MSBuildProjectName).nuspec + $(OutputPath) + + Generates source link for Git repositories using a GitWeb server. + MSBuild Tasks GitWeb source link + true + + + + + + + + + Microsoft.Build.Tasks.SourceControl + true + + + + + + + + + + + + diff --git a/src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.nuspec b/src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.nuspec new file mode 100644 index 00000000..5acaea90 --- /dev/null +++ b/src/SourceLink.GitWeb/Microsoft.SourceLink.GitWeb.nuspec @@ -0,0 +1,17 @@ + + + + $CommonMetadataElements$ + + + + + + + $CommonFileElements$ + + + + + + diff --git a/src/SourceLink.GitWeb/Resources.resx b/src/SourceLink.GitWeb/Resources.resx new file mode 100644 index 00000000..143a5dc8 --- /dev/null +++ b/src/SourceLink.GitWeb/Resources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/TranslateRepositoryUrls.cs b/src/SourceLink.GitWeb/TranslateRepositoryUrls.cs new file mode 100644 index 00000000..591cd7d4 --- /dev/null +++ b/src/SourceLink.GitWeb/TranslateRepositoryUrls.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See +// License.txt in the project root for license information. + +using Microsoft.Build.Tasks.SourceControl; +using System; + +namespace Microsoft.SourceLink.GitWeb +{ + /// + /// This task normally translates all protocols to HTTPS git repo URLs for consistency. Not all + /// GitWebs support HTTPS URLs for clones. So instead we keep the SSH URL. The + /// Task converts the URLs to HTTP content URLs which GitWeb does + /// support. The output of this Task is independent of . + /// + public sealed class TranslateRepositoryUrls : TranslateRepositoryUrlsGitTask + { + /// + /// Keep the SSH URL. It is the only protocol currently known to work with GitWeb. + /// + /// + /// as a string + protected override string TranslateSshUrl(Uri uri) + => uri.ToString(); + + protected override string TranslateGitUrl(Uri uri) + => throw new NotSupportedException(string.Format(Resources.RepositoryUrlIsNotSupportedByProvider, "GIT")); + + protected override string TranslateHttpUrl(Uri uri) + => throw new NotSupportedException(string.Format(Resources.RepositoryUrlIsNotSupportedByProvider, "HTTP")); + } +} diff --git a/src/SourceLink.GitWeb/build/Microsoft.SourceLink.GitWeb.targets b/src/SourceLink.GitWeb/build/Microsoft.SourceLink.GitWeb.targets new file mode 100644 index 00000000..d5019e7a --- /dev/null +++ b/src/SourceLink.GitWeb/build/Microsoft.SourceLink.GitWeb.targets @@ -0,0 +1,65 @@ + + + + <_SourceLinkGitWebAssemblyFile Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net461\Microsoft.SourceLink.GitWeb.dll + <_SourceLinkGitWebAssemblyFile Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.0\Microsoft.SourceLink.GitWeb.dll + + + + + + + $(SourceLinkUrlInitializerTargets);_InitializeGitWebSourceLinkUrl + $(SourceControlManagerUrlTranslationTargets);TranslateGitWebUrlsInSourceControlInformation + + + + + + + + + + + + + + + + + + + <_TranslatedSourceRoot Remove="@(_TranslatedSourceRoot)" /> + + + + + + + + + + + + + diff --git a/src/SourceLink.GitWeb/buildMultiTargeting/Microsoft.SourceLink.GitWeb.targets b/src/SourceLink.GitWeb/buildMultiTargeting/Microsoft.SourceLink.GitWeb.targets new file mode 100644 index 00000000..84afbc37 --- /dev/null +++ b/src/SourceLink.GitWeb/buildMultiTargeting/Microsoft.SourceLink.GitWeb.targets @@ -0,0 +1,4 @@ + + + + diff --git a/src/SourceLink.GitWeb/xlf/Resources.cs.xlf b/src/SourceLink.GitWeb/xlf/Resources.cs.xlf new file mode 100644 index 00000000..a83a11e5 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.cs.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.de.xlf b/src/SourceLink.GitWeb/xlf/Resources.de.xlf new file mode 100644 index 00000000..f041b7e6 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.de.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.es.xlf b/src/SourceLink.GitWeb/xlf/Resources.es.xlf new file mode 100644 index 00000000..8e1afbd3 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.es.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.fr.xlf b/src/SourceLink.GitWeb/xlf/Resources.fr.xlf new file mode 100644 index 00000000..afec8a14 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.fr.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.it.xlf b/src/SourceLink.GitWeb/xlf/Resources.it.xlf new file mode 100644 index 00000000..08d11f5e --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.it.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.ja.xlf b/src/SourceLink.GitWeb/xlf/Resources.ja.xlf new file mode 100644 index 00000000..b70c68a7 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.ja.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.ko.xlf b/src/SourceLink.GitWeb/xlf/Resources.ko.xlf new file mode 100644 index 00000000..d17cb1ad --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.ko.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.pl.xlf b/src/SourceLink.GitWeb/xlf/Resources.pl.xlf new file mode 100644 index 00000000..4531f455 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.pl.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.pt-BR.xlf b/src/SourceLink.GitWeb/xlf/Resources.pt-BR.xlf new file mode 100644 index 00000000..864e07dd --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.pt-BR.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.ru.xlf b/src/SourceLink.GitWeb/xlf/Resources.ru.xlf new file mode 100644 index 00000000..240cb3c9 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.ru.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.tr.xlf b/src/SourceLink.GitWeb/xlf/Resources.tr.xlf new file mode 100644 index 00000000..8581c836 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.tr.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.zh-Hans.xlf b/src/SourceLink.GitWeb/xlf/Resources.zh-Hans.xlf new file mode 100644 index 00000000..44b283db --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.zh-Hans.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file diff --git a/src/SourceLink.GitWeb/xlf/Resources.zh-Hant.xlf b/src/SourceLink.GitWeb/xlf/Resources.zh-Hant.xlf new file mode 100644 index 00000000..878bd818 --- /dev/null +++ b/src/SourceLink.GitWeb/xlf/Resources.zh-Hant.xlf @@ -0,0 +1,12 @@ + + + + + + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + The Microsoft.SourceLink.GitWeb provider does not support translating the '{0}' protocol to content URLs. + + + + + \ No newline at end of file