Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix license link generation #2534

Merged
merged 5 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ public Uri LicenseUrl
return LicenseFileDeprecationUrl;

case LicenseType.Expression:
return new Uri(string.Format(LicenseServiceLinkTemplate, License));
return new Uri(GenerateLicenseServiceLink(License));

default:
return null;
}
}
}

private string GenerateLicenseServiceLink(string license)
{
return new Uri(string.Format(LicenseServiceLinkTemplate, License)).AbsoluteUri;
}
}

public enum LicenseType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public static XElement ToXElement(this ManifestMetadata metadata, XNamespace ns)
{
elem.Add(new XElement(ns + "developmentDependency", metadata.DevelopmentDependency));
}
var licenseUrlToWrite = metadata.LicenseUrl;
var licenseUrlToWrite = metadata.LicenseUrl?.ToString();
if (metadata.LicenseMetadata != null)
{
var licenseElement = GetXElementFromLicenseMetadata(ns, metadata.LicenseMetadata);
if (licenseElement != null)
{
elem.Add(licenseElement);
}
licenseUrlToWrite = metadata.LicenseMetadata.LicenseUrl;
licenseUrlToWrite = metadata.LicenseMetadata.LicenseUrl.OriginalString;
}
AddElementIfNotNull(elem, ns, "licenseUrl", licenseUrlToWrite);
AddElementIfNotNull(elem, ns, "projectUrl", metadata.ProjectUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4481,6 +4481,7 @@ public void PackCommand_PackLicense_SimpleExpression_StandardLicense(string lice
var licenseMetadata = nuspecReader.GetLicenseMetadata();
Assert.Equal(new Uri(string.Format(LicenseMetadata.LicenseServiceLinkTemplate, licenseExpr)), new Uri(nuspecReader.GetLicenseUrl()));
Assert.NotNull(licenseMetadata);
Assert.Equal(licenseMetadata.LicenseUrl.AbsoluteUri, nuspecReader.GetLicenseUrl());
nkolev92 marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(licenseMetadata.LicenseUrl, new Uri(nuspecReader.GetLicenseUrl()));
Assert.Equal(licenseMetadata.Type, LicenseType.Expression);
Assert.Equal(licenseMetadata.Version, LicenseMetadata.EmptyVersion);
Expand Down Expand Up @@ -5097,6 +5098,7 @@ public void PackCommand_PackLicense_BasicLicenseFileReadFileFromNupkg(string lic
Assert.Equal(LicenseMetadata.LicenseFileDeprecationUrl, new Uri(nuspecReader.GetLicenseUrl()));
var licenseMetadata = nuspecReader.GetLicenseMetadata();
Assert.NotNull(licenseMetadata);
Assert.Equal(licenseMetadata.LicenseUrl.AbsoluteUri, nuspecReader.GetLicenseUrl());
Assert.Equal(licenseMetadata.Type, LicenseType.File);
Assert.Equal(licenseMetadata.Version, LicenseMetadata.EmptyVersion);
Assert.Equal(licenseMetadata.License, licenseFileName);
Expand Down