1- // Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2-
3- using JetBrains . Annotations ;
4- using PostSharp . Engineering . BuildTools . Build ;
5- using PostSharp . Engineering . BuildTools . Build . Files ;
6- using PostSharp . Engineering . BuildTools . Dependencies . Model ;
7- using System ;
8-
9- namespace PostSharp . Engineering . BuildTools . Dependencies
10- {
11- /// <summary>
12- /// Sets the source of a dependency to <see cref="DependencySourceKind.Local"/>, <see cref="DependencySourceKind.BuildServer"/>
13- /// or <see cref="DependencySourceKind.Feed"/>.
14- /// </summary>
15- [ UsedImplicitly ]
16- internal class SetDependenciesCommand : ConfigureDependenciesCommand < SetDependenciesCommandSettings >
17- {
18- protected override bool ConfigureDependency (
19- BuildContext context ,
20- DependenciesConfigurationFile dependenciesConfigurationFile ,
21- DependencyDefinition dependencyDefinition ,
22- SetDependenciesCommandSettings settings ,
23- DependenciesConfigurationFile defaultDependenciesConfigurationFile )
24- {
25- DependencySource dependencySource ;
26-
27- switch ( settings . Source )
28- {
29- case DependencySourceKind . Local :
30- dependencySource = DependencySource . CreateLocalDependency ( DependencyConfigurationOrigin . Override , settings . LocalPath ) ;
31-
32- break ;
33-
34- case DependencySourceKind . RestoredDependency :
35- if ( settings . SimulateContinuousIntegration )
36- {
37- #pragma warning disable CS0618
38-
39- // TODO: What to use instead of settings.BuildConfiguration?
40- if ( settings . BuildConfiguration == null )
41-
42- {
43- context . Console . WriteError ( $ "-c|--configuration is mandatory with --ci." ) ;
44-
45- return false ;
46- }
47-
48- #pragma warning restore CS0618
49- }
50-
51- #pragma warning disable CS0618
52-
53- // TODO: What to use instead of settings.BuildConfiguration?
54- dependencySource = DependencySource . CreateRestoredDependency (
55- context ,
56- dependencyDefinition ,
57- DependencyConfigurationOrigin . Override ) ;
58- #pragma warning restore CS0618
59-
60- break ;
61-
62- case DependencySourceKind . Feed :
63- dependencySource = DependencySource . CreateFeed ( null , DependencyConfigurationOrigin . Override ) ;
64-
65- break ;
66-
67- case DependencySourceKind . BuildServer :
68- ICiBuildSpec buildSpec ;
69-
70- if ( settings . Branch != null )
71- {
72- buildSpec = new CiLatestBuildOfBranch ( settings . Branch ) ;
73- }
74- else if ( settings . BuildNumber != null )
75- {
76- buildSpec = new CiBuildId ( settings . BuildNumber . Value , settings . CiBuildTypeId ) ;
77- }
78- else
79- {
80- context . Console . WriteError ( "Either the --branch or --buildNumber parameter should be specified." ) ;
81-
82- return false ;
83- }
84-
85- dependencySource = DependencySource . CreateBuildServerSource (
86- buildSpec ,
87- DependencyConfigurationOrigin . Override ) ;
88-
89- break ;
90-
91- default :
92- throw new InvalidOperationException ( ) ;
93- }
94-
95- dependenciesConfigurationFile . Dependencies [ dependencyDefinition . Name ] = dependencySource ;
96-
97- return true ;
98- }
99- }
1+ // Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+ using JetBrains . Annotations ;
4+ using PostSharp . Engineering . BuildTools . Build ;
5+ using PostSharp . Engineering . BuildTools . Build . Files ;
6+ using PostSharp . Engineering . BuildTools . Dependencies . Model ;
7+ using System ;
8+
9+ namespace PostSharp . Engineering . BuildTools . Dependencies
10+ {
11+ /// <summary>
12+ /// Sets the source of a dependency to <see cref="DependencySourceKind.Local"/>, <see cref="DependencySourceKind.BuildServer"/>
13+ /// or <see cref="DependencySourceKind.Feed"/>.
14+ /// </summary>
15+ [ UsedImplicitly ]
16+ internal class SetDependenciesCommand : ConfigureDependenciesCommand < SetDependenciesCommandSettings >
17+ {
18+ protected override bool ConfigureDependency (
19+ BuildContext context ,
20+ DependenciesConfigurationFile dependenciesConfigurationFile ,
21+ DependencyDefinition dependencyDefinition ,
22+ SetDependenciesCommandSettings settings ,
23+ DependenciesConfigurationFile defaultDependenciesConfigurationFile )
24+ {
25+ DependencySource dependencySource ;
26+
27+ switch ( settings . Source )
28+ {
29+ case DependencySourceKind . Local :
30+ dependencySource = DependencySource . CreateLocalDependency ( DependencyConfigurationOrigin . Override , settings . LocalPath ) ;
31+
32+ break ;
33+
34+ case DependencySourceKind . RestoredDependency :
35+ if ( settings . SimulateContinuousIntegration )
36+ {
37+ #pragma warning disable CS0618
38+
39+ // TODO: What to use instead of settings.BuildConfiguration?
40+ if ( settings . BuildConfiguration == null )
41+
42+ {
43+ context . Console . WriteError ( $ "-c|--configuration is mandatory with --ci." ) ;
44+
45+ return false ;
46+ }
47+
48+ #pragma warning restore CS0618
49+ }
50+
51+ #pragma warning disable CS0618
52+
53+ // TODO: What to use instead of settings.BuildConfiguration?
54+ dependencySource = DependencySource . CreateRestoredDependency (
55+ context ,
56+ dependencyDefinition ,
57+ DependencyConfigurationOrigin . Override ) ;
58+ #pragma warning restore CS0618
59+
60+ break ;
61+
62+ case DependencySourceKind . Feed :
63+ dependencySource = DependencySource . CreateFeed ( null , DependencyConfigurationOrigin . Override ) ;
64+
65+ break ;
66+
67+ case DependencySourceKind . BuildServer :
68+ ICiBuildSpec buildSpec ;
69+
70+ if ( settings . Branch != null )
71+ {
72+ buildSpec = new CiLatestBuildOfBranch ( settings . Branch ) ;
73+ }
74+ else if ( settings . BuildNumber != null )
75+ {
76+ buildSpec = new CiBuildId ( settings . BuildNumber . Value , settings . CiBuildTypeId ) ;
77+ }
78+ else
79+ {
80+ context . Console . WriteError ( "Either the --branch or --buildNumber parameter should be specified." ) ;
81+
82+ return false ;
83+ }
84+
85+ dependencySource = DependencySource . CreateBuildServerSource (
86+ buildSpec ,
87+ DependencyConfigurationOrigin . Override ) ;
88+
89+ break ;
90+
91+ default :
92+ throw new InvalidOperationException ( ) ;
93+ }
94+
95+ dependenciesConfigurationFile . Dependencies [ dependencyDefinition . Name ] = dependencySource ;
96+
97+ return true ;
98+ }
99+ }
100100}
0 commit comments