Skip to content

Commit ab9abfb

Browse files
committed
Added Lucene.Net.CodeAnalysis.Dev.Package project to provide centralized packaging for analyzers, code fixes, and the sample project
1 parent ed3c30d commit ab9abfb

11 files changed

Lines changed: 304 additions & 21 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<Product>Lucene.Net</Product>
3939
<Company>The Apache Software Foundation</Company>
4040
<CurrentYear Condition=" '$(CurrentYear)' == '' ">$([System.DateTime]::UtcNow.Year.ToString())</CurrentYear>
41-
<BeginCopyrightYear>2025</BeginCopyrightYear>
41+
<BeginCopyrightYear>2023</BeginCopyrightYear>
4242
<CopyrightYearRange>$(BeginCopyrightYear) - $(CurrentYear)</CopyrightYearRange>
4343
<CopyrightYearRange Condition=" '$(BeginCopyrightYear)' == '$(CurrentYear)' ">$(CurrentYear)</CopyrightYearRange>
4444
<Copyright>Copyright © $(CopyrightYearRange) $(Company)</Copyright>

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2023 Shad Storhaug
190+
Copyright 2023-2025 The Apache Software Foundation
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

Lucene.Net.CodeAnalysis.Dev.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lucene.Net.CodeAnalysis.Dev
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.CodeAnalysis.Dev.Sample", "src\Lucene.Net.CodeAnalysis.Dev.Sample\Lucene.Net.CodeAnalysis.Dev.Sample.csproj", "{62BE25C9-72F2-4348-96C4-7329252E9DE8}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.CodeAnalysis.Dev.Package", "src\Lucene.Net.CodeAnalysis.Dev.Package\Lucene.Net.CodeAnalysis.Dev.Package.csproj", "{A476A043-926E-488B-A825-02EB0B410CFD}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -31,6 +33,10 @@ Global
3133
{62BE25C9-72F2-4348-96C4-7329252E9DE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
3234
{62BE25C9-72F2-4348-96C4-7329252E9DE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
3335
{62BE25C9-72F2-4348-96C4-7329252E9DE8}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{A476A043-926E-488B-A825-02EB0B410CFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{A476A043-926E-488B-A825-02EB0B410CFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{A476A043-926E-488B-A825-02EB0B410CFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{A476A043-926E-488B-A825-02EB0B410CFD}.Release|Any CPU.Build.0 = Release|Any CPU
3440
EndGlobalSection
3541
GlobalSection(SolutionProperties) = preSolution
3642
HideSolutionNode = FALSE
@@ -39,6 +45,7 @@ Global
3945
{0611A6A8-372D-4E03-BAAF-731FF4844D6C} = {1A48DD8E-1D71-43AE-B15D-977A87972623}
4046
{007DD065-3DF1-4AC1-9403-FE11E4654AF4} = {8170F744-3AE0-41EE-8986-611BA2C20425}
4147
{62BE25C9-72F2-4348-96C4-7329252E9DE8} = {1A48DD8E-1D71-43AE-B15D-977A87972623}
48+
{A476A043-926E-488B-A825-02EB0B410CFD} = {1A48DD8E-1D71-43AE-B15D-977A87972623}
4249
EndGlobalSection
4350
GlobalSection(ExtensibilityGlobals) = postSolution
4451
SolutionGuid = {B261893F-67D2-4098-B66F-9191951DB5BB}

NOTICE.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Apache Lucene.Net
2+
Copyright 2023-2025 The Apache Software Foundation
3+
4+
This product includes software developed at
5+
The Apache Software Foundation (http://www.apache.org/).
5.31 KB
Loading

eng/WildcardVersionSupport.targets

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<!-- This is very limited support for version wildcards (1.0.* and 1.0.0.*) and does
4+
not take into consideration $(Version) or $(VersionPrefix) -->
5+
6+
<PropertyGroup Condition="$(FileVersion.Contains('*'))">
7+
<WildcardFileVersion>$(FileVersion)</WildcardFileVersion>
8+
<!-- Empty the FileVersion so that MSBuild doesn't complain later about it not being valid -->
9+
<FileVersion></FileVersion>
10+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
11+
</PropertyGroup>
12+
<PropertyGroup Condition="$(AssemblyVersion.Contains('*'))">
13+
<WildcardAssemblyVersion>$(AssemblyVersion)</WildcardAssemblyVersion>
14+
<!-- Empty the AssemblyVersion so that MSBuild doesn't complain later about it not being valid -->
15+
<AssemblyVersion></AssemblyVersion>
16+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
17+
</PropertyGroup>
18+
19+
<Target Name="EmitFileVersionAttribute" BeforeTargets="BeforeCompile" Condition="'$(WildcardFileVersion)' != ''">
20+
<GenerateTimestampVersion VersionTemplate="$(WildcardFileVersion)">
21+
<Output TaskParameter="OutputVersion" PropertyName="GeneratedFileVersion" />
22+
</GenerateTimestampVersion>
23+
<ItemGroup>
24+
<AssemblyAttribute Include="System.Reflection.AssemblyFileVersion">
25+
<_Parameter1>$(GeneratedFileVersion)</_Parameter1>
26+
</AssemblyAttribute>
27+
</ItemGroup>
28+
</Target>
29+
30+
<Target Name="EmitAssemblyVersionAttribute" BeforeTargets="BeforeCompile" Condition="'$(WildcardAssemblyVersion)' != ''">
31+
<GenerateTimestampVersion VersionTemplate="$(WildcardAssemblyVersion)">
32+
<Output TaskParameter="OutputVersion" PropertyName="GeneratedAssemblyVersion" />
33+
</GenerateTimestampVersion>
34+
<ItemGroup>
35+
<AssemblyAttribute Include="System.Reflection.AssemblyVersion">
36+
<_Parameter1>$(GeneratedAssemblyVersion)</_Parameter1>
37+
</AssemblyAttribute>
38+
</ItemGroup>
39+
</Target>
40+
41+
<UsingTask TaskName="GenerateTimestampVersion"
42+
TaskFactory="RoslynCodeTaskFactory"
43+
AssemblyFile="$(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll">
44+
<ParameterGroup>
45+
<VersionTemplate ParameterType="System.String" Required="false" />
46+
<OutputVersion ParameterType="System.String" Output="true" />
47+
</ParameterGroup>
48+
<Task>
49+
<Using Namespace="System" />
50+
<Code Type="Fragment" Language="cs">
51+
<![CDATA[
52+
string baseVersion = VersionTemplate ?? "1.0.*";
53+
var now = DateTime.UtcNow;
54+
var build = (now - new DateTime(2000, 1, 1)).Days;
55+
var revision = (int)(now.TimeOfDay.TotalSeconds / 2);
56+
57+
string[] parts = baseVersion.Split('.');
58+
int major = parts.Length > 0 && int.TryParse(parts[0], out var m) ? m : 1;
59+
int minor = parts.Length > 1 && int.TryParse(parts[1], out var n) ? n : 0;
60+
int buildPart = parts.Length > 2 && parts[2] != "*" ? int.Parse(parts[2]) : build;
61+
int revPart = parts.Length > 3 && parts[3] != "*" ? int.Parse(parts[3]) : revision;
62+
63+
OutputVersion = $"{major}.{minor}.{buildPart}.{revPart}";
64+
]]>
65+
</Code>
66+
</Task>
67+
</UsingTask>
68+
</Project>

eng/nuget.props

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project>
2+
<PropertyGroup Label="NuGet Package Properties">
3+
<IsPackable>true</IsPackable>
4+
<Authors>The Apache Software Foundation</Authors>
5+
<PackageProjectUrl>https://lucenenet.apache.org</PackageProjectUrl>
6+
<PackageIcon>lucene-net-icon-128x128.png</PackageIcon>
7+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
8+
<ReleaseNotesUrl Condition=" '$(PackageVersion)' != '' ">https://github.com/$(GitHubOrganization)/$(GitHubProject)/releases/tag/v$(PackageVersion)</ReleaseNotesUrl>
9+
<PackageReleaseNotes>$(ReleaseNotesUrl)</PackageReleaseNotes>
10+
<PackageReadmeFile>readme.md</PackageReadmeFile>
11+
</PropertyGroup>
12+
<ItemGroup>
13+
<None Include="$(RepositoryRoot)README.md" Pack="true" PackagePath="$(PackageReadmeFile)"/>
14+
<None Include="$(RepositoryRoot)branding\$(PackageIcon)" Pack="true" PackagePath="$(PackageIcon)" Visible="false"/>
15+
</ItemGroup>
16+
</Project>

src/Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<PropertyGroup Label="Assembly Documentation">
55
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
6+
<NoWarn>$(NoWarn);CS1591</NoWarn>
67
</PropertyGroup>
78

89
</Project>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="$(RepositoryRoot)eng/nuget.props" />
4+
5+
<PropertyGroup>
6+
<!-- Note TargetFramework or TargetFrameworks must match the output projects for the directories to be build correctly -->
7+
<TargetFramework>netstandard2.0</TargetFramework>
8+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9+
<IncludeBuildOutput>false</IncludeBuildOutput>
10+
<IncludeSymbols>false</IncludeSymbols>
11+
12+
<NoPackageAnalysis>true</NoPackageAnalysis>
13+
<DevelopmentDependency>true</DevelopmentDependency>
14+
</PropertyGroup>
15+
16+
<PropertyGroup Label="NuGet Package Settings">
17+
<PackageId>Lucene.Net.CodeAnalysis.Dev</PackageId>
18+
<Description>Analyzers and code fixes for Lucene.NET development.</Description>
19+
<PackageTags>$(PackageTags);code analysis;code maintenance;roslyn</PackageTags>
20+
<PackageOutputPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\_artifacts\NuGetPackages\$(Configuration)'))</PackageOutputPath>
21+
<_PackageVersionPropsFile>$(PackageOutputPath)\Lucene.Net.CodeAnalysis.Dev.Version.props</_PackageVersionPropsFile>
22+
</PropertyGroup>
23+
24+
<PropertyGroup Label="NuGet Package File Paths">
25+
<_CodeAnalysisCSAssemblyFile>$(RepositoryRoot)src\Lucene.Net.CodeAnalysis.Dev\bin\$(Configuration)\$(TargetFramework)\Lucene.Net.CodeAnalysis.Dev.dll</_CodeAnalysisCSAssemblyFile>
26+
<_CodeAnalysisCodeFixesCSAssemblyFile>$(RepositoryRoot)src\Lucene.Net.CodeAnalysis.Dev\bin\$(Configuration)\$(TargetFramework)\Lucene.Net.CodeAnalysis.Dev.CodeFixes.dll</_CodeAnalysisCodeFixesCSAssemblyFile>
27+
</PropertyGroup>
28+
29+
<ItemGroup Label="Localized Resources">
30+
<_CodeAnalyisisResources Include="$(RepositoryRoot)src\Lucene.Net.CodeAnalysis.Dev\bin\$(Configuration)\$(TargetFramework)\**\*.resources.dll" />
31+
</ItemGroup>
32+
33+
<ItemGroup Label="NuGet Package Files">
34+
<None Include="$(_CodeAnalysisCSAssemblyFile)" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
35+
36+
<None Include="$(_CodeAnalysisCodeFixesCSAssemblyFile)" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" Condition="Exists('$(_CodeAnalysisCodeFixesCSAssemblyFile)')" />
37+
38+
<None Include="@(_CodeAnalyisisResources)" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
39+
</ItemGroup>
40+
41+
<ItemGroup>
42+
<!-- We only need this to ensure it is built before this project is. We include all dependent projects because
43+
it is required by the MSBuild target below. Granted, including only Lucene.Net.CodeAnalysis.Dev.csproj would work
44+
in normal scenarios, but when executing an MSBuild target from a consuming project (SPDX.CodeAnalysis.Sample.csproj),
45+
these are required to be built first and in the order that they are listed here. -->
46+
<ProjectReference Include="..\Lucene.Net.CodeAnalysis.Dev\Lucene.Net.CodeAnalysis.Dev.csproj" ReferenceOutputAssembly="false" />
47+
<ProjectReference Include="..\Lucene.Net.CodeAnalysis.Dev\Lucene.Net.CodeAnalysis.Dev.CodeFixes.csproj" ReferenceOutputAssembly="false" Condition="Exists('..\Lucene.Net.CodeAnalysis.Dev\Lucene.Net.CodeAnalysis.Dev.CodeFixes.csproj')" />
48+
</ItemGroup>
49+
50+
<Target Name="EnsureDependenciesBuilt" BeforeTargets="PrepareForBuild">
51+
<MSBuild Projects="@(ProjectReference)" Targets="Restore;PrepareForBuild;Build" Properties="Configuration=$(Configuration)" BuildInParallel="false" />
52+
</Target>
53+
54+
<UsingTask TaskName="GenerateVersionProps" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
55+
56+
<ParameterGroup>
57+
<OutputFile ParameterType="System.String" Required="true" />
58+
<Version ParameterType="System.String" Required="true" />
59+
</ParameterGroup>
60+
61+
<Task>
62+
<Using Namespace="System.Xml" />
63+
<Code Type="Fragment" Language="cs">
64+
<![CDATA[
65+
var trimmedVersion = Version.Trim();
66+
var settings = new XmlWriterSettings { Indent = true };
67+
using (var writer = XmlWriter.Create(OutputFile, settings))
68+
{
69+
writer.WriteStartDocument();
70+
writer.WriteStartElement("Project");
71+
writer.WriteStartElement("PropertyGroup");
72+
writer.WriteElementString("_CodeAnalysisPackageVersion", trimmedVersion);
73+
writer.WriteEndElement(); // PropertyGroup
74+
writer.WriteEndElement(); // Project
75+
writer.WriteEndDocument();
76+
}
77+
]]>
78+
</Code>
79+
</Task>
80+
</UsingTask>
81+
82+
<Target Name="AppendDebugTimestampToPackageVersion"
83+
AfterTargets="GetBuildVersion">
84+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
85+
<!-- Append timestamp every ~2 seconds -->
86+
<PackageVersion>
87+
$(PackageVersion)-debug-$([System.DateTime]::UtcNow.DayOfYear)-$([System.Math]::Floor($([System.DateTime]::UtcNow.TimeOfDay.TotalSeconds)))
88+
</PackageVersion>
89+
</PropertyGroup>
90+
</Target>
91+
92+
<Target Name="GeneratePackageVersionProps" DependsOnTargets="GetBuildVersion" AfterTargets="BeforeBuild">
93+
<MakeDir Directories="$(PackageOutputPath)" Condition="!Exists('$(PackageOutputPath)')" />
94+
95+
<GenerateVersionProps OutputFile="$(_PackageVersionPropsFile)" Version="$(PackageVersion)" />
96+
</Target>
97+
98+
<Target Name="CleanNuGetPackagesDirectory" AfterTargets="Clean">
99+
<ItemGroup>
100+
<__NuGetFilePaths Include="$(PackageOutputPath)\*.nupkg" />
101+
</ItemGroup>
102+
103+
<Delete Files="@(__NuGetFilePaths);$(_PackageVersionPropsFile)" />
104+
</Target>
105+
106+
</Project>
Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,94 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
8-
9-
<ItemGroup>
10-
<ProjectReference Include="../Lucene.Net.CodeAnalysis.Dev/Lucene.Net.CodeAnalysis.Dev.csproj"
11-
OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
12-
</ItemGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<_ArtifactsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\_artifacts'))</_ArtifactsDirectory>
11+
<_NuGetPackageOutputPath>$(_ArtifactsDirectory)\NuGetPackages\$(Configuration)</_NuGetPackageOutputPath>
12+
<_PackageVersionPropsFilePath>$(_NuGetPackageOutputPath)\Lucene.Net.CodeAnalysis.Dev.Version.props</_PackageVersionPropsFilePath>
13+
<!-- We install the analyzer package in a local directory so we don't pollute the
14+
.nuget cache on the dev machine with temporary builds -->
15+
<RestorePackagesPath>obj\LocalNuGetPackages</RestorePackagesPath>
16+
<_RestorePackagesPath>$(RestorePackagesPath)\lucene.net.codeanalsis.dev</_RestorePackagesPath>
17+
</PropertyGroup>
18+
19+
<PropertyGroup Condition="Exists('$(_NuGetPackageOutputPath)')">
20+
<RestoreSources>$(RestoreSources);$(_NuGetPackageOutputPath)</RestoreSources>
21+
</PropertyGroup>
22+
23+
<PropertyGroup>
24+
<RestoreSources>$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
25+
</PropertyGroup>
26+
27+
<PropertyGroup>
28+
<!-- Visual Studio blocks MSBuild from being able to check whether files are up-to-date.
29+
So, we disable that here to gain access to that info. -->
30+
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
31+
</PropertyGroup>
32+
33+
<Import Project="$(_PackageVersionPropsFilePath)" Condition="Exists('$(_PackageVersionPropsFilePath)')"/>
34+
35+
<ItemGroup Condition="Exists('$(_PackageVersionPropsFilePath)')">
36+
<PackageReference Include="Lucene.Net.CodeAnalysis.Dev" VersionOverride="$(_CodeAnalysisPackageVersion)" />
37+
</ItemGroup>
38+
39+
<Target Name="EnsureNuGetPackageBuilt" BeforeTargets="PrepareForBuild" Condition="'$(DesignTimeBuild)' != 'true'">
40+
41+
<Message Importance="high" Text="Running NuGet Package Build..." />
42+
43+
<!-- Build the project that produces the NuGet package -->
44+
<MSBuild
45+
Projects="..\Lucene.Net.CodeAnalysis.Dev.Package\Lucene.Net.CodeAnalysis.Dev.Package.csproj"
46+
Targets="Restore;PrepareForBuild;Build"
47+
Properties="Configuration=$(Configuration)"
48+
/>
49+
50+
<!-- Since we may be continually using the last build number (unless a commit occured),
51+
we need to clear the project local NuGet cache. -->
52+
<ForceDeleteDirectory DirectoryPath="$(_RestorePackagesPath)" />
53+
54+
<!-- Restore again, now that the .nupkg should exist -->
55+
<MSBuild
56+
Projects="$(MSBuildProjectFullPath)"
57+
Targets="Restore"
58+
Properties="Configuration=$(Configuration)" />
59+
</Target>
60+
61+
<Target Name="CleanRestorePackagesPath" AfterTargets="Clean" Condition="'$(DesignTimeBuild)' != 'true'">
62+
<ForceDeleteDirectory DirectoryPath="$(_RestorePackagesPath)" />
63+
</Target>
64+
65+
<UsingTask
66+
TaskName="ForceDeleteDirectory"
67+
TaskFactory="RoslynCodeTaskFactory"
68+
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
69+
<ParameterGroup>
70+
<DirectoryPath ParameterType="System.String" Required="true" />
71+
</ParameterGroup>
72+
<Task>
73+
<Using Namespace="System" />
74+
<Using Namespace="System.IO" />
75+
<Code Type="Fragment" Language="cs">
76+
<![CDATA[
77+
try
78+
{
79+
if (Directory.Exists(DirectoryPath))
80+
{
81+
Directory.Delete(DirectoryPath, recursive: true);
82+
}
83+
}
84+
catch (Exception ex)
85+
{
86+
// Swallow all exceptions unless MSBuild wants you to fail
87+
Log.LogMessage(MessageImportance.Low, $"Failed to delete directory '{DirectoryPath}': {ex.Message}");
88+
}
89+
]]>
90+
</Code>
91+
</Task>
92+
</UsingTask>
1393

1494
</Project>

0 commit comments

Comments
 (0)