Skip to content

Commit

Permalink
Improve the license UI and messaging. (#2507)
Browse files Browse the repository at this point in the history
uGet.Core/NuGet.Build.Tasks.Pack/Strings.resx
  • Loading branch information
nkolev92 committed Nov 5, 2018
1 parent 199dd1d commit 4996f11
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static IReadOnlyList<IText> GenerateLicenseLinks(LicenseMetadata licens
}
else if (licenseUrl != null)
{
return new List<IText>() { new LicenseText(licenseUrl.OriginalString, licenseUrl) };
return new List<IText>() { new LicenseText(Resources.Text_ViewLicense, licenseUrl) };
}
return new List<IText>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Hyperlink
AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseTermLink_{0}'}"
Style="{StaticResource HyperlinkStyle}"
ToolTip="{Binding Link}"
RequestNavigate="OnViewLicenseTermsRequestNavigate"
NavigateUri="{Binding Link}">
<Run Text="{Binding Text}"></Run>
Expand All @@ -50,8 +51,7 @@
</DataTemplate>

<DataTemplate DataType="{x:Type nuget:LicenseFileText}">
<TextBlock
Margin="8,8,0,0">
<TextBlock>
<Hyperlink
AutomationProperties.AutomationId="{Binding Text}"
Click="ViewLicense_Click">
Expand Down Expand Up @@ -207,7 +207,6 @@
Visibility="Collapsed"
AutomationProperties.Name="{Binding Text}"
Text="{Binding LicenseHeader, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
FontSize="{Binding ElementName=_self,Path=FontSize,Converter={StaticResource Font122PercentSizeConverter}}"
TextWrapping="Wrap"
/>

Expand All @@ -227,14 +226,14 @@
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Disabled"
>
<TextBlock
<TextBox
Style="{DynamicResource SelectableTextBlockStyle}"
Margin="12,0,12,12"
x:Name="_licenseFileText"
AutomationProperties.Name="{Binding Text}"
Text="{Binding LicenseText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
</ScrollViewer>
</Border>

</Grid>
</nuget:VsDialogWindow>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MinHeight="450"
Width="450"
Height="450"
WindowStartupLocation="CenterOwner"
Background="{DynamicResource {x:Static nuget:Brushes.BackgroundBrushKey}}"
Foreground="{DynamicResource {x:Static nuget:Brushes.UIText}}"
mc:Ignorable="d"
Expand All @@ -31,16 +32,16 @@
BorderThickness="1"
BorderBrush="{DynamicResource {x:Static nuget:Brushes.BorderBrush}}">
<ScrollViewer
Name="scrollViewerLicenseFile"
Name="scrollViewerLicenseFile"
CanContentScroll="True"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Disabled">
<TextBlock
<TextBox
Style="{DynamicResource SelectableTextBlockStyle}"
Name="textBlockLicenseFile"
Margin="12,8,12,8"
TextWrapping="Wrap">
<Run Text="{Binding LicenseContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</TextBlock>
TextWrapping="Wrap"
Text="{Binding LicenseContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</ScrollViewer>
</Border>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"
<nuget:DateTimeConverter x:Key="DateFormatConverter" />
<DataTemplate DataType="{x:Type nuget:LicenseText}">
<TextBlock
Margin="8,8,0,0"
AutomationProperties.LabeledBy="{Binding ElementName=_packageLicenseText}"
AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseTerm_{0}'}">
<Hyperlink
AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseTermLink_{0}'}"
Style="{StaticResource HyperlinkStyle}"
Command="{x:Static nuget:PackageManagerControlCommands.OpenExternalLink}"
ToolTip="{Binding Link}"
NavigateUri="{Binding Link}">
<Run Text="{Binding Text}"></Run>
</Hyperlink>
Expand All @@ -35,7 +35,6 @@ Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"

<DataTemplate DataType="{x:Type nuget:LicenseFileText}">
<TextBlock
Margin="8,8,0,0"
AutomationProperties.LabeledBy="{Binding ElementName=_packageLicenseText}"
AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseFile'}">
<Hyperlink
Expand All @@ -49,7 +48,7 @@ Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"
<DataTemplate DataType="{x:Type nuget:WarningText}">
<imaging:CrispImage
x:Name="_licenseWarning"
Margin="8,8,0,0"
Margin="0,0,4,0"
Width="13"
Height="13"
Visibility="{Binding Text, Converter={StaticResource NullToVisibilityConverter}}"
Expand All @@ -59,7 +58,6 @@ Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"

<DataTemplate DataType="{x:Type nuget:FreeText}">
<TextBlock
Margin="8,8,0,0"
AutomationProperties.LabeledBy="{Binding ElementName=_packageLicenseOperator}"
AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseOperator_{0}'}"
Text="{Binding Text}" />
Expand Down Expand Up @@ -194,7 +192,7 @@ Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"
<ItemsControl Grid.Row="3" Grid.Column="1" ItemsSource="{Binding LicenseLinks}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
<WrapPanel Margin="8,8,0,0" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Expand Down
6 changes: 3 additions & 3 deletions src/NuGet.Core/NuGet.Build.Tasks.Pack/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/NuGet.Core/NuGet.Build.Tasks.Pack/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
<comment>{0} is the file being packed.</comment>
</data>
<data name="InvalidLicenseCombination" xml:space="preserve">
<value>Invalid metadata. Cannot specify both a License Expression and a License File.</value>
<value>Invalid metadata. Cannot specify both a PackageLicenseExpression and a PackageLicenseFile.</value>
<comment>Please don't localize PackageLicenseFile and PackageLicenseExpression.</comment>
</data>
<data name="InvalidLicenseExppressionVersion_VersionTooHigh" xml:space="preserve">
<value>The version string '{0}' is not supported by this toolset. The highest supported version is '{1}'. Either use a lower version or upgrade your toolset.</value>
Expand All @@ -140,7 +141,7 @@
<comment>0 - the license expression, 1 further details</comment>
</data>
<data name="InvalidLicenseExpressionVersion" xml:space="preserve">
<value>The version string '{0}' for the License Expression is invalid.</value>
<value>The PackageLicenseExpressionVersion string '{0}' is not a valid version.</value>
<comment>{0} version string</comment>
</data>
<data name="InvalidMinClientVersion" xml:space="preserve">
Expand Down Expand Up @@ -168,7 +169,7 @@
<value>No project was provided to the PackTask.</value>
</data>
<data name="NuGetLicenses_LicenseUrlCannotBeUsedInConjuctionWithLicense" xml:space="preserve">
<value>The PackageLicenseUrl cannot be used cannot be used in conjunction with the PackageLicenseFile and PackageLicenseExpression.</value>
<value>The PackageLicenseUrl is being deprecated and cannot be used in conjunction with the PackageLicenseFile or PackageLicenseExpression.</value>
<comment>Please don't localize PackageLicenseUrl, PackageLicenseFile and PackageLicenseExpression.</comment>
</data>
</root>
2 changes: 1 addition & 1 deletion src/NuGet.Core/NuGet.Packaging/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/NuGet.Core/NuGet.Packaging/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ Valid from:</comment>
<value>The license element value is empty. This is likely due to an authoring error. </value>
</data>
<data name="NuGetLicenseExpression_NonStandardIdentifier" xml:space="preserve">
<value>The license identifier(s) {0} is(are) not recognized by the current toolset.</value>
<value>The license identifier(s) '{0}' is(are) not recognized by the current toolset.</value>
<comment>0 - semicolon delimited list of identifiers</comment>
</data>
<data name="Error_RepositorySettings_UnsignedPackage" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void PackageLicenseUtility_GeneratesLegacyLicenseUrlCorrectly()
var licenseText = links[0] as LicenseText;

Assert.NotNull(licenseText);
Assert.Equal(originalUri, licenseText.Text);
Assert.Equal(Resources.Text_ViewLicense, licenseText.Text);
Assert.Equal(uri, licenseText.Link);
}

Expand Down
32 changes: 32 additions & 0 deletions test/NuGet.Core.Tests/NuGet.Packaging.Test/NuspecReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,19 @@ public class NuspecReaderTests
</metadata>
</package>";

private const string LicenseExpressionComplexNonStandardLicenses = @"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2016/06/nuspec.xsd"">
<metadata>
<id>packageA</id>
<version>1.0.1-alpha</version>
<title>Package A</title>
<authors>ownera, ownerb</authors>
<owners>ownera, ownerb</owners>
<description>package A description.</description>
<license type=""expression"">BestLicense OR CoolLicense</license>
</metadata>
</package>";

public static IEnumerable<object[]> GetValidVersions()
{
return GetVersionRange(validVersions: true);
Expand Down Expand Up @@ -1018,6 +1031,25 @@ public void NuspecReaderTests_LicenseExpressionNonStandardLicenseAddsMessage()
licenseMetadata.WarningsAndErrors[0].Should().Be(string.Format(CultureInfo.CurrentCulture, Strings.NuGetLicenseExpression_NonStandardIdentifier, "CoolLicense"));
}

[Fact]
public void NuspecReaderTests_LicenseExpressionNonStandardLicensesAddsMessage()
{
// Arrange
var reader = GetReader(LicenseExpressionComplexNonStandardLicenses);

// Act
var licenseMetadata = reader.GetLicenseMetadata();

// Assert
licenseMetadata.Type.Should().Be(LicenseType.Expression);
licenseMetadata.LicenseExpression.Should().NotBeNull();
licenseMetadata.License.Should().Be("BestLicense OR CoolLicense");
licenseMetadata.Version.Should().Be(LicenseMetadata.EmptyVersion);
licenseMetadata.WarningsAndErrors.Count().Should().Be(1);

licenseMetadata.WarningsAndErrors[0].Should().Be(string.Format(CultureInfo.CurrentCulture, Strings.NuGetLicenseExpression_NonStandardIdentifier, "BestLicense, CoolLicense"));
}

[Fact]
public void NuspecReaderTests_UnlicensedAddsAMessage()
{
Expand Down

0 comments on commit 4996f11

Please sign in to comment.