├── .gitignore
├── License.md
├── README.md
└── Solutions
├── BreakingChange
├── BreakingChange.csproj
├── Class1.cs
└── Properties
│ └── AssemblyInfo.cs
├── BreakingChange2
├── BreakingChange2.csproj
├── Class1.cs
└── Properties
│ └── AssemblyInfo.cs
├── Endjin.Assembly.ChangeDetection.Specs
├── App.config
├── Endjin.Assembly.ChangeDetection.Specs.csproj
├── Features
│ ├── ChangeRules.feature
│ ├── ChangeRules.feature.cs
│ ├── DifferenceDetection.feature
│ ├── DifferenceDetection.feature.cs
│ ├── SemanticVersioning.feature
│ └── SemanticVersioning.feature.cs
├── Properties
│ └── AssemblyInfo.cs
├── Steps
│ ├── ChangeRulesSteps.cs
│ ├── DifferenceDetectionSteps.cs
│ └── SemanticVersioningSteps.cs
└── packages.config
├── Endjin.Assembly.ChangeDetection.sln
├── Endjin.Assembly.ChangeDetection
├── Diff
│ ├── AssemblyDiffCollection.cs
│ ├── AssemblyDiffer.cs
│ ├── BreakingChangeSearcher.cs
│ ├── DiffCollection.cs
│ ├── DiffOperation.cs
│ ├── DiffPrinter.cs
│ ├── DiffResult.cs
│ └── TypeDiff.cs
├── DiffAssemblies.cs
├── Endjin.Assembly.ChangeDetection.csproj
├── Infrastructure
│ ├── BlockingQueue.cs
│ ├── BlockingQueueAggregator.cs
│ ├── ClrContext.cs
│ ├── DirectorySearcherAsync.cs
│ ├── ExceptionHelper.cs
│ ├── FileEnumerator.cs
│ ├── FileNameComparer.cs
│ ├── FileQuery.cs
│ ├── InternalError.cs
│ ├── LastException.cs
│ ├── LazyFormat.cs
│ ├── Level.cs
│ ├── ListExtensions.cs
│ ├── MessageTypes.cs
│ ├── NullTraceListener.cs
│ ├── PtrConverter.cs
│ ├── SafeFindHandle.cs
│ ├── StaticModule.cs
│ ├── TraceCfgParser.cs
│ ├── TraceFilter.cs
│ ├── TraceFilterMatchAll.cs
│ ├── TraceFilterMatchNone.cs
│ ├── Tracer.cs
│ ├── TracerConfig.cs
│ ├── TypeHashes.cs
│ ├── WIN32_FIND_DATA.cs
│ ├── WorkItemDispatcher.cs
│ ├── WorkItemDispatcherData.cs
│ └── WorkItemOptions.cs
├── Introspection
│ ├── AssemblyLoader.cs
│ ├── FieldPrintOptions.cs
│ ├── FilterFunctions.cs
│ ├── FilterMode.cs
│ ├── ISymChkExecutor.cs
│ ├── MethodPrintOption.cs
│ ├── PdbDownLoader.cs
│ ├── PdbInformationReader.cs
│ ├── SymChkExecutor.cs
│ ├── TypeExtensions.cs
│ └── TypeMapper.cs
├── ListDiffer.cs
├── Properties
│ └── AssemblyInfo.cs
├── Query
│ ├── BaseQuery.cs
│ ├── EventComparer.cs
│ ├── EventQuery.cs
│ ├── FieldComparer.cs
│ ├── FieldQuery.cs
│ ├── GenericTypeMapper.cs
│ ├── Matcher.cs
│ ├── MethodComparer.cs
│ ├── MethodQuery.cs
│ ├── QueryAggregator.cs
│ ├── TypeNameComparer.cs
│ ├── TypeQuery.cs
│ ├── TypeQueryExtensions.cs
│ ├── TypeQueryFactory.cs
│ ├── TypeQueryMode.cs
│ └── UsageQueries
│ │ ├── MatchContext.cs
│ │ ├── QueryResult.cs
│ │ ├── UsageQueryAggregator.cs
│ │ ├── UsageVisitor.cs
│ │ ├── WhoAccessesField.cs
│ │ ├── WhoDerivesFromType.cs
│ │ ├── WhoHasFieldOfType.cs
│ │ ├── WhoImplementsInterface.cs
│ │ ├── WhoInstantiatesType.cs
│ │ ├── WhoReferencesAssembly.cs
│ │ ├── WhoUsesEvents.cs
│ │ ├── WhoUsesMethod.cs
│ │ ├── WhoUsesStringConstant.cs
│ │ └── WhoUsesType.cs
├── Rules
│ ├── BreakingChangeRule.cs
│ └── IRule.cs
├── SemVer
│ ├── AnalysisResult.cs
│ └── SemanticVersionAnalyzer.cs
└── packages.config
├── Endjin.SemanticVersioning.TeamCity
├── App.config
├── AssemblyAttributeExtensions.cs
├── AttributeConverters
│ ├── AssemblyCompanyAttributeConverter.cs
│ ├── AssemblyConfigurationAttributeConverter.cs
│ ├── AssemblyCopyrightAttributeConverter.cs
│ ├── AssemblyDescriptionAttributeConverter.cs
│ ├── AssemblyProductAttributeConverter.cs
│ ├── AssemblyTitleAttributeConverter.cs
│ ├── AssemblyTrademarkAttributeConverter.cs
│ ├── ComVisibleAttributeConverter.cs
│ ├── CompilationRelaxationsAttributeConverter.cs
│ ├── DebuggableAttributeConverter.cs
│ ├── GuidAttributeConverter.cs
│ ├── RuntimeCompatibilityAttributeConverter.cs
│ └── TargetFrameworkAttributeConverter.cs
├── CodeGenerator.cs
├── CommandLineProcessor.cs
├── CommandOptions.cs
├── Endjin.SemanticVersioning.TeamCity.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── NonBreakingAdditiveChange
├── Class1.cs
├── NonBreakingAdditiveChange.csproj
└── Properties
│ └── AssemblyInfo.cs
├── NonBreakingAdditiveChange2
├── Class1.cs
├── NonBreakingAdditiveChange2.csproj
└── Properties
│ └── AssemblyInfo.cs
├── NuGet.config
├── Original
├── Class1.cs
├── Original.csproj
└── Properties
│ └── AssemblyInfo.cs
└── Original2
├── Class1.cs
├── Original2.csproj
└── Properties
└── AssemblyInfo.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studo 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | *_i.c
42 | *_p.c
43 | *_i.h
44 | *.ilk
45 | *.meta
46 | *.obj
47 | *.pch
48 | *.pdb
49 | *.pgc
50 | *.pgd
51 | *.rsp
52 | *.sbr
53 | *.tlb
54 | *.tli
55 | *.tlh
56 | *.tmp
57 | *.tmp_proj
58 | *.log
59 | *.vspscc
60 | *.vssscc
61 | .builds
62 | *.pidb
63 | *.svclog
64 | *.scc
65 |
66 | # Chutzpah Test files
67 | _Chutzpah*
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 | *.cachefile
76 |
77 | # Visual Studio profiler
78 | *.psess
79 | *.vsp
80 | *.vspx
81 |
82 | # TFS 2012 Local Workspace
83 | $tf/
84 |
85 | # Guidance Automation Toolkit
86 | *.gpState
87 |
88 | # ReSharper is a .NET coding add-in
89 | _ReSharper*/
90 | *.[Rr]e[Ss]harper
91 | *.DotSettings.user
92 |
93 | # JustCode is a .NET coding addin-in
94 | .JustCode
95 |
96 | # TeamCity is a build add-in
97 | _TeamCity*
98 |
99 | # DotCover is a Code Coverage Tool
100 | *.dotCover
101 |
102 | # NCrunch
103 | _NCrunch_*
104 | .*crunch*.local.xml
105 |
106 | # MightyMoose
107 | *.mm.*
108 | AutoTest.Net/
109 |
110 | # Web workbench (sass)
111 | .sass-cache/
112 |
113 | # Installshield output folder
114 | [Ee]xpress/
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish/
128 |
129 | # Publish Web Output
130 | *.[Pp]ublish.xml
131 | *.azurePubxml
132 | # TODO: Comment the next line if you want to checkin your web deploy settings
133 | # but database connection strings (with potential passwords) will be unencrypted
134 | *.pubxml
135 | *.publishproj
136 |
137 | # NuGet Packages
138 | *.nupkg
139 | # The packages folder can be ignored because of Package Restore
140 | **/packages/*
141 | # except build/, which is used as an MSBuild target.
142 | !**/packages/build/
143 | # Uncomment if necessary however generally it will be regenerated when needed
144 | #!**/packages/repositories.config
145 |
146 | # Windows Azure Build Output
147 | csx/
148 | *.build.csdef
149 |
150 | # Windows Store app package directory
151 | AppPackages/
152 |
153 | # Others
154 | *.[Cc]ache
155 | ClientBin/
156 | [Ss]tyle[Cc]op.*
157 | ~$*
158 | *~
159 | *.dbmdl
160 | *.dbproj.schemaview
161 | *.pfx
162 | *.publishsettings
163 | node_modules/
164 | bower_components/
165 |
166 | # RIA/Silverlight projects
167 | Generated_Code/
168 |
169 | # Backup & report files from converting an old project file
170 | # to a newer Visual Studio version. Backup files are not needed,
171 | # because we have git ;-)
172 | _UpgradeReport_Files/
173 | Backup*/
174 | UpgradeLog*.XML
175 | UpgradeLog*.htm
176 |
177 | # SQL Server files
178 | *.mdf
179 | *.ldf
180 |
181 | # Business Intelligence projects
182 | *.rdl.data
183 | *.bim.layout
184 | *.bim_*.settings
185 |
186 | # Microsoft Fakes
187 | FakesAssemblies/
188 |
189 | # Node.js Tools for Visual Studio
190 | .ntvs_analysis.dat
191 |
192 | # Visual Studio 6 build log
193 | *.plg
194 |
195 | # Visual Studio 6 workspace options file
196 | *.opt
197 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 endjin limited
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
21 | All licensing enquiries should be directed in the first instance to licensing@endjin.com
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Endjin.Assembly.ChangeDetection
2 |
3 | This is an experiment to see if it is possibly to build a tool to:
4 |
5 | - automatically detect breaking changes in a .NET assembly
6 | - determine the what the next valid SemanticVersion should be
7 | - use ILMerge to re-write the assembly with the new suggested Semantic Version number.
8 |
9 | For the purpose of automating the generation & versioning of NuGet packages.
10 |
11 | ## Breaking Changes rules: ##
12 |
13 | A breaking change is defined as the modification of any public type (either changing of a signature or the removal of a public type from the assembly). The addition of new types to an assembly is not deemed a breaking change.
14 |
15 | ## Thoughts ##
16 |
17 | Next steps, I would like to turn this tool into a TeamCity Meta-Runner, where the new Semantic Version number is echoed up, via a Service Message, to set the new version number for the branch.
18 |
19 | Ideally I would like the concepts laid out here to become a 1st class feature in TeamCity; to provide much better support for Semantic Versioning, Assembly breaking changes and the ability for the CI server to control the version number of the assemblies.
20 |
21 |
22 | ##Notes##
23 |
24 | To get this running locally, you may need install SpecFlow as Visual Studio Extension.
25 |
26 | ##Comments##
27 |
28 | Please ping me via @[HowardvRooijen](http://twitter.com/HowardvRooijen)
29 |
30 | ## Acknowledgements: ##
31 |
32 | Code from the CodePlex project [APIChange](https://apichange.codeplex.com/) by [Alois Kraus](http://geekswithblogs.net/akraus1/archive/2010/06/03/140207.aspx) have been used.
33 | As have modification made by [@GrahamTheCoder](http://twitter.com/grahamthecoder) who upgraded Mono.Cecil to a newer version
34 |
35 |
--------------------------------------------------------------------------------
/Solutions/BreakingChange/BreakingChange.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {282B8835-B9D0-4F6E-B33D-73E9D8BD0D0D}
8 | Library
9 | Properties
10 | Original
11 | Original
12 | v4.5.1
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
53 |
--------------------------------------------------------------------------------
/Solutions/BreakingChange/Class1.cs:
--------------------------------------------------------------------------------
1 | namespace Original
2 | {
3 | public class Class1
4 | {
5 | public void MyTestMethod(string input)
6 | {
7 | }
8 | }
9 | }
--------------------------------------------------------------------------------
/Solutions/BreakingChange/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("BreakingChange")]
9 | [assembly: AssemblyDescription("Assembly with Breaking Change")]
10 | [assembly: AssemblyConfiguration("Release")]
11 | [assembly: AssemblyCompany("endjin")]
12 | [assembly: AssemblyProduct("BreakingChange")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("endjin")]
15 | [assembly: AssemblyCulture("en-gb")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("09b11047-db62-4282-836f-a1ce052bcc20")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Solutions/BreakingChange2/BreakingChange2.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {20FE08AE-4A16-439F-AF5F-490AB49FEBFD}
8 | Library
9 | Properties
10 | Original2
11 | Original2
12 | v4.5.1
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
54 |
--------------------------------------------------------------------------------
/Solutions/BreakingChange2/Class1.cs:
--------------------------------------------------------------------------------
1 | namespace Original2
2 | {
3 | public class Class1
4 | {
5 | public void MyTestMethod(string input)
6 | {
7 | }
8 | }
9 | }
--------------------------------------------------------------------------------
/Solutions/BreakingChange2/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("BreakingChange2")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("BreakingChange2")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("20fe08ae-4a16-439f-af5f-490ab49febfd")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/Features/ChangeRules.feature:
--------------------------------------------------------------------------------
1 | Feature: Change Rules
2 | In order to establish what the semantic version of the build should be
3 | As the build process
4 | I want to decide if the current assembly has breaking changes from the previous version
5 |
6 | Scenario: New Assembly has a non breaking additive change does not violate any rules
7 | Given the previous assembly is called "TestData\Original\Original.dll"
8 | Given the new assembly is called "TestData\NonBreakingAdditiveChange\Original.dll"
9 | When I compare the two assemblies and validate the rules
10 | Then I should be told that the rule has not been violated
11 |
12 | Scenario: New Assembly has a breaking change due to a public api being modified does violate rules
13 | Given the previous assembly is called "TestData\Original\Original.dll"
14 | Given the new assembly is called "TestData\BreakingChange\Original.dll"
15 | When I compare the two assemblies and validate the rules
16 | Then I should be told that the rule has been violated
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/Features/DifferenceDetection.feature:
--------------------------------------------------------------------------------
1 | Feature: Difference Detection
2 | In order to establish what the semantic version of the build should be
3 | As the build process
4 | I want to decide if the current assembly has breaking changes from the previous version
5 |
6 | Scenario: New Assembly has a non breaking additive change
7 | Given the previous assembly is called "TestData\Original\Original.dll"
8 | Given the new assembly is called "TestData\NonBreakingAdditiveChange\Original.dll"
9 | When I compare the two assemblies
10 | Then I should be told there is 1 change
11 | And I should be told that the change is 1 method has been added
12 | And I should be told that the change is 0 method has been removed
13 |
14 | Scenario: New Assembly has a breaking change due to a public api being modified
15 | Given the previous assembly is called "TestData\Original\Original.dll"
16 | Given the new assembly is called "TestData\BreakingChange\Original.dll"
17 | When I compare the two assemblies
18 | Then I should be told there is 1 change
19 | And I should be told that the change is 1 method has been added
20 | And I should be told that the change is 1 method has been removed
21 |
22 | Scenario: Two new assemblies have non breaking additive changes
23 | Given the previous assemblies are "TestData\Original\*.dll;TestData\Original2\*.dll"
24 | Given the new assemblies are "TestData\NonBreakingAdditiveChange\*.dll;TestData\NonBreakingAdditiveChange2\*.dll"
25 | When I compare the two sets of assemblies
26 | Then I should be told there are 2 changes
27 | And I should be told that the changes include 2 methods have been added
28 | And I should be told that the changes include 0 methods have been removed
29 |
30 | Scenario: Two new assemblies both have a breaking change due to a public api being modified
31 | Given the previous assemblies are "TestData\Original\Original.dll;TestData\Original2\Original2.dll"
32 | Given the new assemblies are "TestData\BreakingChange\Original.dll;TestData\BreakingChange2\Original2.dll"
33 | When I compare the two sets of assemblies
34 | Then I should be told there are 2 changes
35 | And I should be told that the changes include 2 methods have been added
36 | And I should be told that the changes include 2 methods have been removed
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/Features/SemanticVersioning.feature:
--------------------------------------------------------------------------------
1 | Feature: SemanticVersioning
2 | In order to establish what the semantic version of the build should be
3 | As the build process
4 | I want to decide what the next public build number should be by comparing the current build with the previous build
5 |
6 | Scenario: New Assembly has a non breaking additive change
7 | Given the previous assembly is called "TestData\Original\Original.dll"
8 | Given the new assembly is called "TestData\NonBreakingAdditiveChange\Original.dll"
9 | Given the proposed version number is 1.0.1
10 | When I compare the two assemblies and validate the rules and the version number
11 | Then I should be told that the rule has not been violated
12 | And I should be told that the version number is 1.0.1
13 |
14 | Scenario: New Assembly has a breaking change due to a public api being modified does violate rules
15 | Given the previous assembly is called "TestData\Original\Original.dll"
16 | Given the new assembly is called "TestData\BreakingChange\Original.dll"
17 | Given the proposed version number is 1.0.1
18 | When I compare the two assemblies and validate the rules and the version number
19 | Then I should be told that the rule has been violated
20 | And I should be told that the version number is 2.0.0
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Endjin.Assembly.ChangeDetection.Specs")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Endjin.Assembly.ChangeDetection.Specs")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("a93aa5c3-e033-4463-b9b1-0a0776a81a61")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/Steps/ChangeRulesSteps.cs:
--------------------------------------------------------------------------------
1 | using Endjin.Assembly.ChangeDetection.Infrastructure;
2 | using Endjin.Assembly.ChangeDetection.Rules;
3 |
4 | namespace Endjin.Assembly.ChangeDetection.Specs.Steps
5 | {
6 | #region Using Directives
7 |
8 | using System.Collections.Generic;
9 | using Should;
10 |
11 | using TechTalk.SpecFlow;
12 |
13 | #endregion
14 |
15 | [Binding]
16 | public class ChangeRulesSteps
17 | {
18 | [When(@"I compare the two assemblies and validate the rules")]
19 | public void WhenICompareTheTwoAssembliesAndValidateTheRules()
20 | {
21 | var differ = new DiffAssemblies();
22 |
23 | var previous = new FileQuery(ScenarioContext.Current.Get("PreviousAssembly"));
24 | var newAssembly = new FileQuery(ScenarioContext.Current.Get("NewAssembly"));
25 |
26 | var differences = differ.Execute(new List { previous }, new List { newAssembly });
27 | var rule = new BreakingChangeRule();
28 |
29 | var result = rule.Detect(differences);
30 |
31 | ScenarioContext.Current.Set(result, "Results");
32 | }
33 |
34 | [Then(@"I should be told that the rule has been violated")]
35 | public void ThenIShouldBeToldThatTheRuleHasBeenViolated()
36 | {
37 | var results = ScenarioContext.Current.Get("Results");
38 |
39 | results.ShouldBeTrue();
40 | }
41 |
42 | [Then(@"I should be told that the rule has not been violated")]
43 | public void ThenIShouldBeToldThatTheRuleHasNotBeenViolated()
44 | {
45 | var results = ScenarioContext.Current.Get("Results");
46 |
47 | results.ShouldBeFalse();
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/Steps/DifferenceDetectionSteps.cs:
--------------------------------------------------------------------------------
1 | using Endjin.Assembly.ChangeDetection.Diff;
2 | using Endjin.Assembly.ChangeDetection.Infrastructure;
3 |
4 | namespace Endjin.Assembly.ChangeDetection.Specs.Steps
5 | {
6 | #region Using Directives
7 |
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Linq;
11 | using Should;
12 |
13 | using TechTalk.SpecFlow;
14 |
15 | #endregion
16 |
17 | [Binding]
18 | public class DifferenceDetectionSteps
19 | {
20 | [Given(@"the previous assembly is called ""(.*)""")]
21 | public void GivenThePreviousAssemblyIsCalled(string previousAssembly)
22 | {
23 | ScenarioContext.Current.Set(previousAssembly, "PreviousAssembly");
24 | }
25 |
26 | [Given(@"the new assembly is called ""(.*)""")]
27 | public void GivenTheNewAssemblyIsCalled(string newAssembly)
28 | {
29 | ScenarioContext.Current.Set(newAssembly.ResolveBaseDirectory(), "NewAssembly");
30 | }
31 |
32 | [Given(@"the previous assemblies are ""(.*)""")]
33 | public void GivenThePreviousAssembliesAre(string query)
34 | {
35 | ScenarioContext.Current.Set(query, "PreviousAssembliesQuery");
36 | }
37 |
38 | [Given(@"the new assemblies are ""(.*)""")]
39 | public void GivenTheNewAssembliesAre(string query)
40 | {
41 | ScenarioContext.Current.Set(query, "NewAssembliesQuery");
42 | }
43 |
44 | [When(@"I compare the two sets of assemblies")]
45 | public void WhenICompareTheTwoSetsOfAssemblies()
46 | {
47 | var differ = new DiffAssemblies();
48 |
49 | var previousAssemblies = FileQuery.ParseQueryList(ScenarioContext.Current.Get("PreviousAssembliesQuery"));
50 | var newAssemblies = FileQuery.ParseQueryList(ScenarioContext.Current.Get("NewAssembliesQuery"));
51 |
52 | var differences = differ.Execute(previousAssemblies, newAssemblies);
53 |
54 | ScenarioContext.Current.Set(differences, "Results");
55 | }
56 |
57 | [When(@"I compare the two assemblies")]
58 | public void WhenICompareTheTwoAssemblies()
59 | {
60 | var differ = new DiffAssemblies();
61 |
62 | var previous = new FileQuery(ScenarioContext.Current.Get("PreviousAssembly"));
63 | var newAssembly = new FileQuery(ScenarioContext.Current.Get("NewAssembly"));
64 |
65 | var differences = differ.Execute(new List { previous }, new List { newAssembly });
66 |
67 | ScenarioContext.Current.Set(differences, "Results");
68 | }
69 |
70 | [Then(@"I should be told there is (.*) change")]
71 | [Then(@"I should be told there are (.*) changes")]
72 | public void ThenIShouldBeToldThereAreChanges(int numberOfChanges)
73 | {
74 | var results = ScenarioContext.Current.Get("Results");
75 |
76 | results.ChangedTypes.Count.ShouldEqual(numberOfChanges);
77 | }
78 |
79 | [Then(@"I should be told that the change is (.*) method has been added")]
80 | [Then(@"I should be told that the change is (.*) methods have been added")]
81 | public void ThenIShouldBeToldThatTheChangeIsMethodHasBeenAdded(int numberAdded)
82 | {
83 | var results = ScenarioContext.Current.Get("Results");
84 | results.ChangedTypes.First().Methods.AddedCount.ShouldEqual(numberAdded);
85 | }
86 |
87 | [Then(@"I should be told that the change is (.*) method has been removed")]
88 | [Then(@"I should be told that the change is (.*) methods have been removed")]
89 | public void ThenIShouldBeToldThatTheChangeIsMethodHasBeenRemoved(int numberRemoved)
90 | {
91 | var results = ScenarioContext.Current.Get("Results");
92 | results.ChangedTypes.First().Methods.RemovedCount.ShouldEqual(numberRemoved);
93 | }
94 |
95 | [Then(@"I should be told that the changes include (.*) method has been added")]
96 | [Then(@"I should be told that the changes include (.*) methods have been added")]
97 | public void ThenIShouldBeToldThatTheChangesIncludeMethodsHaveBeenAdded(int numberAdded)
98 | {
99 | var results = ScenarioContext.Current.Get("Results");
100 | results.ChangedTypes.Sum(diff => diff.Methods.AddedCount).ShouldEqual(numberAdded);
101 | }
102 |
103 | [Then(@"I should be told that the changes include (.*) method has been removed")]
104 | [Then(@"I should be told that the changes include (.*) methods have been removed")]
105 | public void ThenIShouldBeToldThatTheChangeIncludeMethodHasBeenRemoved(int numberRemoved)
106 | {
107 | var results = ScenarioContext.Current.Get("Results");
108 | results.ChangedTypes.Sum(diff => diff.Methods.RemovedCount).ShouldEqual(numberRemoved);
109 | }
110 |
111 | }
112 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/Steps/SemanticVersioningSteps.cs:
--------------------------------------------------------------------------------
1 | using Endjin.Assembly.ChangeDetection.SemVer;
2 |
3 | namespace Endjin.Assembly.ChangeDetection.Specs.Steps
4 | {
5 | #region Using Directives
6 |
7 | using System.Collections.Generic;
8 | using Should;
9 |
10 | using TechTalk.SpecFlow;
11 |
12 | #endregion
13 |
14 | [Binding]
15 | public class SemanticVersioningSteps
16 | {
17 | [Given(@"the proposed version number is (.*)")]
18 | public void GivenTheProposedVersionNumberIs(string proposedVersionNumberVersion)
19 | {
20 | ScenarioContext.Current.Set(proposedVersionNumberVersion, "ProposedVersionNumber");
21 | }
22 |
23 | [When(@"I compare the two assemblies and validate the rules and the version number")]
24 | public void WhenICompareTheTwoAssembliesAndValidateTheRulesAndTheVersionNumber()
25 | {
26 | var previous = ScenarioContext.Current.Get("PreviousAssembly");
27 | var current = ScenarioContext.Current.Get("NewAssembly");
28 | var proposedVersionNumber = ScenarioContext.Current.Get("ProposedVersionNumber");
29 |
30 | var semanticVersionAnalyzer = new SemanticVersionAnalyzer();
31 |
32 | var result = semanticVersionAnalyzer.Analyze(previous, current, proposedVersionNumber);
33 |
34 | ScenarioContext.Current.Set(result, "AnalysisResult");
35 | ScenarioContext.Current.Set(result.BreakingChangesDetected, "Results");
36 | }
37 |
38 | [Then(@"I should be told that the version number is (.*)")]
39 | public void ThenIShouldBeToldThatTheVersionNumberIs(string versionNumber)
40 | {
41 | var decidedVersionNumber = ScenarioContext.Current.Get("AnalysisResult");
42 |
43 | decidedVersionNumber.VersionNumber.ShouldEqual(versionNumber);
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection.Specs/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Diff/AssemblyDiffCollection.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Diagnostics;
3 | using Mono.Cecil;
4 |
5 | namespace Endjin.Assembly.ChangeDetection.Diff
6 | {
7 | [DebuggerDisplay("Add {AddedRemovedTypes.AddedCount} Remove {AddedRemovedTypes.RemovedCount} Changed {ChangedTypes.Count}")]
8 | public class AssemblyDiffCollection
9 | {
10 | public DiffCollection AddedRemovedTypes;
11 |
12 | public List ChangedTypes;
13 |
14 | public AssemblyDiffCollection()
15 | {
16 | this.AddedRemovedTypes = new DiffCollection();
17 | this.ChangedTypes = new List();
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Diff/AssemblyDiffer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Endjin.Assembly.ChangeDetection.Introspection;
4 | using Endjin.Assembly.ChangeDetection.Query;
5 | using Mono.Cecil;
6 |
7 | namespace Endjin.Assembly.ChangeDetection.Diff
8 | {
9 | #region Using Directives
10 |
11 |
12 |
13 | #endregion
14 |
15 | public class AssemblyDiffer
16 | {
17 | private readonly AssemblyDiffCollection myDiff = new AssemblyDiffCollection();
18 |
19 | private readonly AssemblyDefinition myV1;
20 |
21 | private readonly AssemblyDefinition myV2;
22 |
23 | public AssemblyDiffer(AssemblyDefinition v1, AssemblyDefinition v2)
24 | {
25 | if (v1 == null)
26 | {
27 | throw new ArgumentNullException("v1");
28 | }
29 | if (v2 == null)
30 | {
31 | throw new ArgumentNullException("v2");
32 | }
33 |
34 | this.myV1 = v1;
35 | this.myV2 = v2;
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the class.
40 | ///
41 | /// The assembly file v1.
42 | /// The assembly file v2.
43 | public AssemblyDiffer(string assemblyFileV1, string assemblyFileV2)
44 | {
45 | if (string.IsNullOrEmpty(assemblyFileV1))
46 | {
47 | throw new ArgumentNullException("assemblyFileV1");
48 | }
49 | if (string.IsNullOrEmpty(assemblyFileV2))
50 | {
51 | throw new ArgumentNullException("assemblyFileV2");
52 | }
53 |
54 | this.myV1 = AssemblyLoader.LoadCecilAssembly(assemblyFileV1);
55 | if (this.myV1 == null)
56 | {
57 | throw new ArgumentException(string.Format("Could not load assemblyV1 {0}", assemblyFileV1));
58 | }
59 |
60 | this.myV2 = AssemblyLoader.LoadCecilAssembly(assemblyFileV2);
61 | if (this.myV2 == null)
62 | {
63 | throw new ArgumentException(string.Format("Could not load assemblyV2 {0}", assemblyFileV2));
64 | }
65 | }
66 |
67 | private void OnAddedType(TypeDefinition type)
68 | {
69 | var diff = new DiffResult(type, new DiffOperation(true));
70 | this.myDiff.AddedRemovedTypes.Add(diff);
71 | }
72 |
73 | private void OnRemovedType(TypeDefinition type)
74 | {
75 | var diff = new DiffResult(type, new DiffOperation(false));
76 | this.myDiff.AddedRemovedTypes.Add(diff);
77 | }
78 |
79 | public AssemblyDiffCollection GenerateTypeDiff(QueryAggregator queries)
80 | {
81 | if (queries == null || queries.TypeQueries.Count == 0)
82 | {
83 | throw new ArgumentNullException("queries is null or contains no queries");
84 | }
85 |
86 | var typesV1 = queries.ExeuteAndAggregateTypeQueries(this.myV1);
87 | var typesV2 = queries.ExeuteAndAggregateTypeQueries(this.myV2);
88 |
89 | var differ = new ListDiffer(this.ShallowTypeComapare);
90 |
91 | differ.Diff(typesV1, typesV2, this.OnAddedType, this.OnRemovedType);
92 |
93 | this.DiffTypes(typesV1, typesV2, queries);
94 |
95 | return this.myDiff;
96 | }
97 |
98 | private bool ShallowTypeComapare(TypeDefinition v1, TypeDefinition v2)
99 | {
100 | return v1.FullName == v2.FullName;
101 | }
102 |
103 | private void DiffTypes(List typesV1, List typesV2, QueryAggregator queries)
104 | {
105 | TypeDefinition typeV2;
106 | foreach (var typeV1 in typesV1)
107 | {
108 | typeV2 = this.GetTypeByDefinition(typeV1, typesV2);
109 | if (typeV2 != null)
110 | {
111 | var diffed = TypeDiff.GenerateDiff(typeV1, typeV2, queries);
112 | if (TypeDiff.None != diffed)
113 | {
114 | this.myDiff.ChangedTypes.Add(diffed);
115 | }
116 | }
117 | }
118 | }
119 |
120 | private TypeDefinition GetTypeByDefinition(TypeDefinition search, List types)
121 | {
122 | foreach (var type in types)
123 | {
124 | if (type.IsEqual(search))
125 | {
126 | return type;
127 | }
128 | }
129 |
130 | return null;
131 | }
132 | }
133 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Diff/DiffCollection.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace Endjin.Assembly.ChangeDetection.Diff
5 | {
6 | public class DiffCollection : List>
7 | {
8 | public int AddedCount
9 | {
10 | get
11 | {
12 | var added = 0;
13 | foreach (var obj in this)
14 | {
15 | if (obj.Operation.IsAdded)
16 | {
17 | added++;
18 | }
19 | }
20 |
21 | return added;
22 | }
23 | }
24 |
25 | public int RemovedCount
26 | {
27 | get
28 | {
29 | var removed = 0;
30 | foreach (var obj in this)
31 | {
32 | if (obj.Operation.IsRemoved)
33 | {
34 | removed++;
35 | }
36 | }
37 |
38 | return removed;
39 | }
40 | }
41 |
42 | public IEnumerable> Added
43 | {
44 | get
45 | {
46 | foreach (var obj in this)
47 | {
48 | if (obj.Operation.IsAdded)
49 | {
50 | yield return obj;
51 | }
52 | }
53 | }
54 | }
55 |
56 | public IEnumerable> Removed
57 | {
58 | get
59 | {
60 | foreach (var obj in this)
61 | {
62 | if (obj.Operation.IsRemoved)
63 | {
64 | yield return obj;
65 | }
66 | }
67 | }
68 | }
69 |
70 | public List RemovedList
71 | {
72 | get
73 | {
74 | return (from type in this.Removed select type.ObjectV1).ToList();
75 | }
76 | }
77 |
78 | public List AddedList
79 | {
80 | get
81 | {
82 | return (from type in this.Added select type.ObjectV1).ToList();
83 | }
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Diff/DiffOperation.cs:
--------------------------------------------------------------------------------
1 | namespace Endjin.Assembly.ChangeDetection.Diff
2 | {
3 | public class DiffOperation
4 | {
5 | public DiffOperation(bool isAdded)
6 | {
7 | this.IsAdded = isAdded;
8 | }
9 |
10 | public bool IsAdded { get; private set; }
11 |
12 | public bool IsRemoved
13 | {
14 | get
15 | {
16 | return !this.IsAdded;
17 | }
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Diff/DiffPrinter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using Endjin.Assembly.ChangeDetection.Introspection;
4 | using Mono.Cecil;
5 |
6 | namespace Endjin.Assembly.ChangeDetection.Diff
7 | {
8 | public class DiffPrinter
9 | {
10 | private readonly TextWriter Out;
11 |
12 | ///
13 | /// Print diffs to console
14 | ///
15 | public DiffPrinter()
16 | {
17 | this.Out = Console.Out;
18 | }
19 |
20 | ///
21 | /// Initializes a new instance of the class.
22 | ///
23 | /// The output stream to print the change diff.
24 | public DiffPrinter(TextWriter outputStream)
25 | {
26 | if (outputStream == null)
27 | {
28 | throw new ArgumentNullException("outputStream");
29 | }
30 |
31 | this.Out = outputStream;
32 | }
33 |
34 | internal void Print(AssemblyDiffCollection diff)
35 | {
36 | this.PrintAddedRemovedTypes(diff.AddedRemovedTypes);
37 |
38 | if (diff.ChangedTypes.Count > 0)
39 | {
40 | foreach (var typeChange in diff.ChangedTypes)
41 | {
42 | this.PrintTypeChanges(typeChange);
43 | }
44 | }
45 | }
46 |
47 | private void PrintTypeChanges(TypeDiff typeChange)
48 | {
49 | this.Out.WriteLine("\t" + typeChange.TypeV1.Print());
50 | if (typeChange.HasChangedBaseType)
51 | {
52 | this.Out.WriteLine("\t\tBase type changed: {0} -> {1}", typeChange.TypeV1.IsNotNull(() => typeChange.TypeV1.BaseType.IsNotNull(() => typeChange.TypeV1.BaseType.FullName)), typeChange.TypeV2.IsNotNull(() => typeChange.TypeV2.BaseType.IsNotNull(() => typeChange.TypeV2.BaseType.FullName)));
53 | }
54 |
55 | if (typeChange.Interfaces.Count > 0)
56 | {
57 | foreach (var addedItf in typeChange.Interfaces.Added)
58 | {
59 | this.Out.WriteLine("\t\t+ interface: {0}", addedItf.ObjectV1.FullName);
60 | }
61 | foreach (var removedItd in typeChange.Interfaces.Removed)
62 | {
63 | this.Out.WriteLine("\t\t- interface: {0}", removedItd.ObjectV1.FullName);
64 | }
65 | }
66 |
67 | foreach (var addedEvent in typeChange.Events.Added)
68 | {
69 | this.Out.WriteLine("\t\t+ {0}", addedEvent.ObjectV1.Print());
70 | }
71 |
72 | foreach (var remEvent in typeChange.Events.Removed)
73 | {
74 | this.Out.WriteLine("\t\t- {0}", remEvent.ObjectV1.Print());
75 | }
76 |
77 | foreach (var addedField in typeChange.Fields.Added)
78 | {
79 | this.Out.WriteLine("\t\t+ {0}", addedField.ObjectV1.Print(FieldPrintOptions.All));
80 | }
81 |
82 | foreach (var remField in typeChange.Fields.Removed)
83 | {
84 | this.Out.WriteLine("\t\t- {0}", remField.ObjectV1.Print(FieldPrintOptions.All));
85 | }
86 |
87 | foreach (var addedMethod in typeChange.Methods.Added)
88 | {
89 | this.Out.WriteLine("\t\t+ {0}", addedMethod.ObjectV1.Print(MethodPrintOption.Full));
90 | }
91 |
92 | foreach (var remMethod in typeChange.Methods.Removed)
93 | {
94 | this.Out.WriteLine("\t\t- {0}", remMethod.ObjectV1.Print(MethodPrintOption.Full));
95 | }
96 | }
97 |
98 | private void PrintAddedRemovedTypes(DiffCollection diffCollection)
99 | {
100 | if (diffCollection.RemovedCount > 0)
101 | {
102 | this.Out.WriteLine("\tRemoved {0} public type/s", diffCollection.RemovedCount);
103 | foreach (var remType in diffCollection.Removed)
104 | {
105 | this.Out.WriteLine("\t\t- {0}", remType.ObjectV1.Print());
106 | }
107 | }
108 |
109 | if (diffCollection.AddedCount > 0)
110 | {
111 | this.Out.WriteLine("\tAdded {0} public type/s", diffCollection.AddedCount);
112 | foreach (var addedType in diffCollection.Added)
113 | {
114 | this.Out.WriteLine("\t\t+ {0}", addedType.ObjectV1.Print());
115 | }
116 | }
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Diff/DiffResult.cs:
--------------------------------------------------------------------------------
1 | namespace Endjin.Assembly.ChangeDetection.Diff
2 | {
3 | public class DiffResult
4 | {
5 | public DiffResult(T v1, DiffOperation diffType)
6 | {
7 | this.ObjectV1 = v1;
8 | this.Operation = diffType;
9 | }
10 |
11 | public DiffOperation Operation { get; private set; }
12 |
13 | public T ObjectV1 { get; private set; }
14 |
15 | public override string ToString()
16 | {
17 | return string.Format("{0}, {1}", this.ObjectV1, this.Operation.IsAdded ? "added" : "removed");
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/DiffAssemblies.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using Endjin.Assembly.ChangeDetection.Diff;
5 | using Endjin.Assembly.ChangeDetection.Infrastructure;
6 | using Endjin.Assembly.ChangeDetection.Introspection;
7 | using Endjin.Assembly.ChangeDetection.Query;
8 |
9 | namespace Endjin.Assembly.ChangeDetection
10 | {
11 | public class DiffAssemblies
12 | {
13 | private static readonly TypeHashes MyType = new TypeHashes(typeof(DiffAssemblies));
14 |
15 | //protected CommandData myParsedArgs;
16 |
17 | protected void Validate()
18 | {
19 | /*base.Detect();
20 |
21 | ValidateFileQuery(myParsedArgs.NewFiles,
22 | "-new is missing.",
23 | "Invalid directory in -new {0} query.",
24 | "The -new query {0} did not match any files.");
25 |
26 | ValidateFileQuery(myParsedArgs.OldFiles,
27 | "-old is missing.",
28 | "Not existing directory in -old {0} query.",
29 | "The -old query {0} did not match any files.");
30 |
31 | if (myParsedArgs.OutputToExcel)
32 | {
33 | AddErrorMessage("Excel output is not supported by this comand");
34 | SetInvalid();
35 | }*/
36 | }
37 |
38 | public AssemblyDiffCollection Execute(List oldFiles, List newFiles)
39 | {
40 | using (var t = new Tracer(MyType, "Execute"))
41 | {
42 | //var removedTypes = 0;
43 | //var changedTypes = 0;
44 |
45 | var removedFiles = oldFiles.GetNotExistingFilesInOtherQuery(newFiles);
46 |
47 | if (removedFiles.Count > 0)
48 | {
49 | foreach (var str in removedFiles)
50 | {
51 | Console.WriteLine("\t{0}", Path.GetFileName(str));
52 | }
53 | }
54 |
55 | var oldFilesQuery = new HashSet(oldFiles.GetFiles(), new FileNameComparer());
56 | var newFilesQuery = new HashSet(newFiles.GetFiles(), new FileNameComparer());
57 |
58 | // Get files which are present in one set and the other
59 | oldFilesQuery.IntersectWith(newFilesQuery);
60 | //DiffPrinter printer = new DiffPrinter(Out);
61 |
62 | var result = new AssemblyDiffCollection();
63 |
64 | foreach (var fileName1 in oldFilesQuery)
65 | {
66 | if (fileName1.EndsWith(".XmlSerializers.dll", StringComparison.OrdinalIgnoreCase))
67 | {
68 | t.Info("Ignore xml serializer dll {0}", fileName1);
69 | continue;
70 | }
71 |
72 | var fileName2 = newFiles.GetMatchingFileByName(fileName1);
73 |
74 | var assemblyV1 = AssemblyLoader.LoadCecilAssembly(fileName1);
75 | var assemblyV2 = AssemblyLoader.LoadCecilAssembly(fileName2);
76 |
77 | if (assemblyV1 != null && assemblyV2 != null)
78 | {
79 | var differ = new AssemblyDiffer(assemblyV1, assemblyV2);
80 | var differences = differ.GenerateTypeDiff(QueryAggregator.PublicApiQueries);
81 | result.AddedRemovedTypes.AddRange(differences.AddedRemovedTypes);
82 | result.ChangedTypes.AddRange(differences.ChangedTypes);
83 |
84 | //removedTypes += differences.AddedRemovedTypes.RemovedCount;
85 | //changedTypes += differences.ChangedTypes.Count;
86 |
87 | /*if (diff.AddedRemovedTypes.Count > 0 || diff.ChangedTypes.Count > 0)
88 | {
89 | // Out.WriteLine("{0} has {1} changes", Path.GetFileName(fileName1), diff.AddedRemovedTypes.Count + diff.ChangedTypes.Sum(type => type.Events.Count + type.Fields.Count + type.Interfaces.Count + type.Methods.Count));
90 |
91 | // printer.Print(diff);
92 | // Out.WriteLine("From {0} assemblies were {1} types removed and {2} changed.", myParsedArgs.Queries1.GetFiles().Count(), removedTypes, changedTypes);
93 | *
94 | }*/
95 | }
96 | }
97 |
98 | return result;
99 | }
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Infrastructure/BlockingQueue.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Threading;
5 |
6 | namespace Endjin.Assembly.ChangeDetection.Infrastructure
7 | {
8 | ///
9 | /// A blocking queue which supports end markers to signal that no more work is left by inserting
10 | /// a null reference. This constrains the queue to reference types only.
11 | ///
12 | ///
13 | public class BlockingQueue : IEnumerable, IEnumerable, IDisposable
14 | where T : class
15 | {
16 | private readonly ManualResetEvent myEmptyEvent = new ManualResetEvent(false);
17 |
18 | ///
19 | /// The queue used to store the elements
20 | ///
21 | private readonly Queue myQueue = new Queue();
22 |
23 | private bool myAllItemsProcessed;
24 |
25 | #region IDisposable Members
26 |
27 | ///
28 | /// Closes the EmptyEvent WaitHandle.
29 | ///
30 | public void Dispose()
31 | {
32 | this.myEmptyEvent.Close();
33 | }
34 |
35 | #endregion
36 |
37 | ///
38 | /// Returns an IEnumerator of Type T for this queue
39 | ///
40 | ///
41 | IEnumerator IEnumerable.GetEnumerator()
42 | {
43 | while (true)
44 | {
45 | var item = this.Dequeue();
46 | if (item == null)
47 | {
48 | break;
49 | }
50 | yield return item;
51 | }
52 | }
53 |
54 | ///
55 | /// Returns a untyped IEnumerator for this queue
56 | ///
57 | ///
58 | IEnumerator IEnumerable.GetEnumerator()
59 | {
60 | return ((IEnumerable)this).GetEnumerator();
61 | }
62 |
63 | ///
64 | /// Deques an element from the queue and returns it.
65 | /// If the queue is empty the thread will block. If the queue is stopped it will immedieately
66 | /// return with null.
67 | ///
68 | /// An object of type T
69 | public T Dequeue()
70 | {
71 | if (this.myAllItemsProcessed)
72 | {
73 | return null;
74 | }
75 |
76 | lock (this.myQueue)
77 | {
78 | while (this.myQueue.Count == 0)
79 | {
80 | if (!Monitor.Wait(this.myQueue, 45))
81 | {
82 | // dispatch any work which is not done yet
83 | if (this.myQueue.Count > 0)
84 | {
85 | continue;
86 | }
87 | }
88 |
89 | // finito
90 | if (this.myAllItemsProcessed)
91 | {
92 | return null;
93 | }
94 | }
95 |
96 | var result = this.myQueue.Dequeue();
97 | if (result == null)
98 | {
99 | this.myAllItemsProcessed = true;
100 | this.myEmptyEvent.Set();
101 | }
102 | return result;
103 | }
104 | }
105 |
106 | ///
107 | /// Releases the waiters by enqueuing a null reference which causes all waiters to be released.
108 | /// The will then get a null reference as queued element to signal that they should terminate.
109 | ///
110 | public void ReleaseWaiters()
111 | {
112 | this.Enqueue(null);
113 | }
114 |
115 | ///
116 | /// Waits the until empty. This does not mean that all items are already process. Only that
117 | /// the queue contains no more pending work.
118 | ///
119 | public void WaitUntilEmpty()
120 | {
121 | this.myEmptyEvent.WaitOne();
122 | }
123 |
124 | ///
125 | /// Adds an element of type T to the queue.
126 | /// The consumer thread is notified (if waiting)
127 | ///
128 | /// An object of type T
129 | public void Enqueue(T data_in)
130 | {
131 | lock (this.myQueue)
132 | {
133 | this.myQueue.Enqueue(data_in);
134 | Monitor.PulseAll(this.myQueue);
135 | }
136 | }
137 | }
138 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Infrastructure/BlockingQueueAggregator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Endjin.Assembly.ChangeDetection.Infrastructure
5 | {
6 | ///
7 | /// Aggregate one or a list of queues for processing with WorkItemDispatcher. The queues
8 | /// are processed in the order of addition. Only when the first queue is empty the next
9 | /// queue is used until no more queues are left.
10 | ///
11 | ///
12 | public class BlockingQueueAggregator
13 | where T : class
14 | {
15 | private readonly Queue> myQueues = new Queue>();
16 |
17 | private BlockingQueue myCurrent;
18 |
19 | public BlockingQueueAggregator(BlockingQueue queue)
20 | {
21 | if (queue == null)
22 | {
23 | throw new ArgumentNullException("queue");
24 | }
25 |
26 | this.myQueues.Enqueue(queue);
27 | }
28 |
29 | public BlockingQueueAggregator(IEnumerable> queues)
30 | {
31 | if (queues == null)
32 | {
33 | throw new ArgumentNullException("queues");
34 | }
35 |
36 | foreach (var queue in queues)
37 | {
38 | this.myQueues.Enqueue(queue);
39 | }
40 | }
41 |
42 | internal T Dequeue()
43 | {
44 | T lret = null;
45 |
46 | lock (this.myQueues)
47 | {
48 | TryNextQueue:
49 | if (this.myCurrent == null && this.myQueues.Count > 0)
50 | {
51 | this.myCurrent = this.myQueues.Dequeue();
52 | }
53 |
54 | // No more queues available
55 | if (this.myCurrent == null)
56 | {
57 | return lret;
58 | }
59 |
60 | // get next element or null if no more elements are in the queue
61 | lret = this.myCurrent.Dequeue();
62 | if (lret == null)
63 | {
64 | this.myCurrent = null;
65 | goto TryNextQueue;
66 | }
67 | }
68 |
69 | return lret;
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Infrastructure/ClrContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Endjin.Assembly.ChangeDetection.Infrastructure
4 | {
5 | ///
6 | /// There are currently 4 combinations possible but I want to
7 | /// stay extensible since some .NET Framework patch might need
8 | /// additional treatement.
9 | ///
10 | [Flags]
11 | internal enum ClrContext
12 | {
13 | None,
14 |
15 | Is32Bit = 1,
16 |
17 | Is64Bit = 2,
18 |
19 | IsNet2 = 4,
20 |
21 | IsNet4 = 8
22 | }
23 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Infrastructure/FileNameComparer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace Endjin.Assembly.ChangeDetection.Infrastructure
6 | {
7 | internal class FileNameComparer : IEqualityComparer
8 | {
9 | #region IEqualityComparer Members
10 |
11 | public bool Equals(string x, string y)
12 | {
13 | return string.Compare(Path.GetFileName(x), Path.GetFileName(y), StringComparison.OrdinalIgnoreCase) == 0;
14 | }
15 |
16 | public int GetHashCode(string obj)
17 | {
18 | return Path.GetFileName(obj).ToLower().GetHashCode();
19 | }
20 |
21 | #endregion
22 | }
23 | }
--------------------------------------------------------------------------------
/Solutions/Endjin.Assembly.ChangeDetection/Infrastructure/InternalError.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace Endjin.Assembly.ChangeDetection.Infrastructure
5 | {
6 | internal static class InternalError
7 | {
8 | private static readonly string Help = "Tracing can be enabled via the environment variable " + TracerConfig.TraceEnvVarName + Environment.NewLine + "Format: