Skip to content

Commit

Permalink
NH-3905 - Add AsyncGenerator CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Aug 31, 2017
1 parent 072cc8c commit 62addd9
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ In most cases, you will be adding your test to the NHibernate.Test project. If t
1. Sometimes tests fail when run under x64. If required (ex. SQLite and Firebird), go to the project properties Build tab and set the target to x86.
2. Next, just run the tests as usual.

## Regenerate async code

NHibernate uses a code generator for its async implementation and tests. If your changes, including tests, involve any synchronous method having an async
counter-part, you should regenerate the async code. Use build-menu option H for this. Then test any async counter-part it may have generated from your tests.

## Commit your Test Case

Ensure that your e-mail address and name are configured appropriately in Git.
Expand Down
14 changes: 11 additions & 3 deletions ShowBuildMenu.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ echo E. Build NHibernate (Debug)
echo F. Build NHibernate (Release)
echo G. Build Release Package (Also runs tests and creates documentation)
echo.
echo --- Code generation ---
echo H. Generate async code (Generates files in Async sub-folders)
echo.
echo --- TeamCity (CI) build options
echo I. TeamCity build menu
echo.
echo --- Exit ---
echo X. Make the beautiful build menu go away.
echo.

%BUILDTOOL% prompt BCDEFGIX
if errorlevel 7 goto end
if errorlevel 6 goto teamcity-menu
%BUILDTOOL% prompt BCDEFGHIX
if errorlevel 8 goto end
if errorlevel 7 goto teamcity-menu
if errorlevel 6 goto build-async
if errorlevel 5 goto build-release-package
if errorlevel 4 goto build-release
if errorlevel 3 goto build-debug
Expand Down Expand Up @@ -168,6 +172,10 @@ rem :build-test
rem %NANT% test
rem goto main-menu

:build-async
%NANT% generate-async
goto main-menu

:build-debug
%NANT% clean build
echo.
Expand Down
1 change: 1 addition & 0 deletions Tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nuget.exe
NUnit.*
vswhere.*
CSharpAsyncGenerator.CommandLine.*
1 change: 1 addition & 0 deletions Tools/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net461" />
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.2" targetFramework="net461" />
<package id="NUnit.Extension.VSProjectLoader" version="3.6.0" targetFramework="net461" />
<package id="CSharpAsyncGenerator.CommandLine" version="0.3.6" targetFramework="net461" />
</packages>
7 changes: 7 additions & 0 deletions build-common/common-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
</exec>
</target>

<target name="common.solution-restore" depends="common.nuget-restore">
<exec program="${path::combine(tools.dir, 'msbuild.cmd')}" verbose="true">
<arg value="/t:Restore" />
<arg value="${root.dir}/src/NHibernate.sln" />
</exec>
</target>

<target name="common.compile-all" depends="common.nuget-restore">
<!--property name="msbuild.cmd" value="${cmd.sln} ${cmd.out} ${cmd.platform} ${cmd.debug} ${cmd.optimize} ${cmd.doc} /t:Rebuild /v:q /m" /-->
<exec program="${path::combine(tools.dir, 'msbuild.cmd')}" verbose="true">
Expand Down
21 changes: 19 additions & 2 deletions build-common/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,27 @@
</fileset>
<resourcefileset id="project.resources" />
</target>


<target name="common.get-nuget-package-path">
<xmlpeek
file="${tools.dir}/packages.config"
xpath="/packages/package[@id = '${nuget-package-id}']/@version"
property="nuget-package-version" />
<property name="nuget-package-path" value="${tools.dir}/${nuget-package-id}.${nuget-package-version}/" />
</target>

<target name="common.find-async-generator-console">
<property name="nuget-package-id" value="CSharpAsyncGenerator.CommandLine" />
<call target="common.get-nuget-package-path" />
<property name="async-generator-console" value="${nuget-package-path}/tools/AsyncGenerator.CommandLine.exe" />
</target>

<target name="common.find-nunit">
<property name="nunit-console" value="${tools.dir}/NUnit.ConsoleRunner.3.6.0/tools/nunit3-console.exe" />
<property name="nuget-package-id" value="NUnit.ConsoleRunner" />
<call target="common.get-nuget-package-path" />
<property name="nunit-console" value="${nuget-package-path}/tools/nunit3-console.exe" />
</target>

<target name="common.find-ndoc">
<property name="ndoc-console" value="${tools.dir}/ndoc/NDocConsole.exe" />
</target>
Expand Down
6 changes: 6 additions & 0 deletions default.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<target name="build"
depends="check-framework-version init prepare-build-directory common.compile-all"
description="Builds NHibernate in the current configuration" />

<target name="generate-async" depends="common.nuget-restore common.solution-restore common.find-async-generator-console">
<exec
workingdir="${root.dir}/src"
program="${async-generator-console}" />
</target>

<target name="check-framework-version">
<echo>Running with ${framework::get-target-framework()}</echo>
Expand Down
248 changes: 248 additions & 0 deletions src/AsyncGenerator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
projects:
- filePath: NHibernate\NHibernate.csproj
concurrentRun: true
applyChanges: true
analyzation:
methodConversion:
- conversion: Ignore
hasAttributeName: ObsoleteAttribute
- conversion: Ignore
name: PostProcessInsert
containingTypeName: HqlSqlWalker
- conversion: Ignore
name: Intercept
containingTypeName: IInterceptor
- conversion: Ignore
name: Intercept
containingTypeName: IFieldInterceptor
- conversion: Ignore
name: InitializeOrGetAssociation
containingTypeName: AbstractFieldInterceptor
- conversion: Ignore
name: InitializeLazyProperty
containingTypeName: ILazyPropertyInitializer
- conversion: Ignore
name: InitializeLazyPropertiesFromDatastore
containingTypeName: AbstractEntityPersister
- conversion: Ignore
name: InitializeLazyPropertiesFromCache
containingTypeName: AbstractEntityPersister
- conversion: Ignore
name: Invoke
containingTypeName: BasicLazyInitializer
- conversion: Ignore
name: SetReadOnly
containingTypeName: StatefulPersistenceContext
- conversion: Ignore
name: Unproxy
containingTypeName: StatefulPersistenceContext
- conversion: Ignore
name: Contains
containingTypeName: CollectionType
- conversion: Ignore
name: GuessClass
containingTypeName: NHibernateProxyHelper
- conversion: Ignore
name: IsPropertyInitialized
containingTypeName: NHibernateUtil
- conversion: Ignore
name: BestGuessEntityName
containingTypeName: ISession
- conversion: Ignore
name: Contains
containingTypeName: ISession
- conversion: Ignore
name: BestGuessEntityName
containingTypeName: ISessionImplementor
- conversion: Ignore
name: Contains
containingTypeName: ISessionImplementor
- conversion: Ignore
name: GetUnsavedVersionValue
containingTypeName: UnsavedValueFactory
- conversion: Ignore
name: ReadSize
containingTypeName: AbstractPersistentCollection
- conversion: Ignore
name: ReadIndexExistence
containingTypeName: AbstractPersistentCollection
- conversion: Ignore
name: ReadElementExistence
containingTypeName: AbstractPersistentCollection
- conversion: Ignore
name: ReadElementByIndex
containingTypeName: AbstractPersistentCollection
- conversion: Ignore
name: Read
containingTypeName: AbstractPersistentCollection
- conversion: Ignore
name: Write
containingTypeName: AbstractPersistentCollection
- conversion: Ignore
name: GetSize
containingTypeName: ICollectionPersister
- conversion: Ignore
name: IndexExists
containingTypeName: ICollectionPersister
- conversion: Ignore
name: ElementExists
containingTypeName: ICollectionPersister
- conversion: Ignore
name: GetElementByIndex
containingTypeName: ICollectionPersister
- conversion: Ignore
name: Exists
containingTypeName: ICollectionPersister
- conversion: Ignore
name: Exists
containingTypeName: AbstractCollectionPersister
- conversion: ToAsync
name: ExecuteReader
containingTypeName: IBatcher
- conversion: ToAsync
name: ExecuteNonQuery
containingTypeName: IBatcher
- conversion: ToAsync
rule: EventListener
- conversion: ToAsync
rule: ICache
typeConversion:
- conversion: Ignore
name: EnumerableImpl
ignoreSearchForAsyncCounterparts:
- name: GetFieldValue
- name: IsDBNull
- name: WriteLine
callForwarding: true
cancellationTokens:
guards: true
methodParameter:
- anyInterfaceRule: PubliclyExposedType
parameter: Optional
- parameter: Optional
rule: PubliclyExposedType
- parameter: Required
requiresCancellationToken:
- rule: EventListener
- rule: ICache
scanMethodBody: true
transformation:
configureAwaitArgument: false
localFunctions: true
asyncLock:
type: NHibernate.Util.AsyncLock
methodName: LockAsync
documentationComments:
addOrReplaceMethodSummary:
- name: Commit
containingTypeName: AdoTransaction
content: |
/// Commits the <see cref="ITransaction"/> by flushing asynchronously the <see cref="ISession"/>
/// then committing synchronously the <see cref="DbTransaction"/>.
registerPlugin:
- type: AsyncGenerator.Core.Plugins.TransactionScopeAsyncFlowAdder
assemblyName: AsyncGenerator.Core
- type: AsyncGenerator.Core.Plugins.EmptyRegionRemover
assemblyName: AsyncGenerator.Core
- filePath: NHibernate.DomainModel\NHibernate.DomainModel.csproj
concurrentRun: true
applyChanges: true
analyzation:
scanMethodBody: true
scanForMissingAsyncMembers:
- all: true
- filePath: NHibernate.Test\NHibernate.Test.csproj
concurrentRun: true
applyChanges: true
analyzation:
methodConversion:
- conversion: Ignore
hasAttributeName: IgnoreAttribute
- conversion: Smart
hasAttributeName: TestAttribute
- conversion: Smart
hasAttributeName: TheoryAttribute
asyncExtensionMethods:
projectFiles:
- fileName: LinqExtensionMethods.cs
projectName: NHibernate
preserveReturnType:
- hasAttributeName: TestAttribute
- hasAttributeName: TheoryAttribute
typeConversion:
- conversion: Ignore
name: NorthwindDbCreator
- conversion: Ignore
name: ObjectAssert
- conversion: Ignore
name: LinqReadonlyTestsContext
- conversion: Ignore
hasAttributeName: IgnoreAttribute
- conversion: NewType
hasAttributeName: TestFixtureAttribute
- conversion: Ignore
rule: IsTestCase
- conversion: Ignore
anyBaseTypeRule: IsTestCase
ignoreDocuments:
- filePathEndsWith: Linq\MathTests.cs
- filePathEndsWith: Linq\ExpressionSessionLeakTest.cs
cancellationTokens:
withoutCancellationToken:
- hasAttributeName: TestAttribute
- hasAttributeName: TheoryAttribute
scanMethodBody: true
scanForMissingAsyncMembers:
- anyInterfaceRule: NHibernateAssembly
registerPlugin:
- type: AsyncGenerator.Core.Plugins.NUnitAsyncCounterpartsFinder
assemblyName: AsyncGenerator.Core
- type: AsyncGenerator.Core.Plugins.TransactionScopeAsyncFlowAdder
assemblyName: AsyncGenerator.Core
methodRules:
- filters:
- containingTypeName: IAutoFlushEventListener
- containingTypeName: IFlushEventListener
- containingTypeName: IDeleteEventListener
- containingTypeName: ISaveOrUpdateEventListener
- containingTypeName: IPostCollectionRecreateEventListener
- containingTypeName: IPostCollectionRemoveEventListener
- containingTypeName: IPostCollectionUpdateEventListener
- containingTypeName: IPostDeleteEventListener
- containingTypeName: IPostInsertEventListener
- containingTypeName: IPostUpdateEventListener
- containingTypeName: IPreCollectionRecreateEventListener
- containingTypeName: IPreCollectionRemoveEventListener
- containingTypeName: IPreCollectionUpdateEventListener
- containingTypeName: IPreDeleteEventListener
- containingTypeName: IPreInsertEventListener
- containingTypeName: IPreLoadEventListener
- containingTypeName: IPreUpdateEventListener
name: EventListener
- filters:
- containingType: NHibernate.Cache.ICache
name: Get
- containingType: NHibernate.Cache.ICache
name: Put
- containingType: NHibernate.Cache.ICache
name: Remove
- containingType: NHibernate.Cache.ICache
name: Clear
- containingType: NHibernate.Cache.ICache
name: Lock
- containingType: NHibernate.Cache.ICache
name: Unlock
name: ICache
- filters:
- containingNamespace: NHibernate
- containingType: NHibernate.Tool.hbm2ddl.SchemaUpdate
- containingType: NHibernate.Tool.hbm2ddl.SchemaValidator
- containingType: NHibernate.Tool.hbm2ddl.SchemaExport
name: PubliclyExposedType
typeRules:
- filters:
- containingAssemblyName: NHibernate
name: NHibernateAssembly
- filters:
- name: TestCase
name: IsTestCase

0 comments on commit 62addd9

Please sign in to comment.