@@ -19,27 +19,21 @@ public static class JavaAppHostingExtension
19
19
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
20
20
public static IResourceBuilder < JavaAppContainerResource > AddJavaApp ( this IDistributedApplicationBuilder builder , string name , JavaAppContainerResourceOptions options )
21
21
{
22
- if ( string . IsNullOrWhiteSpace ( options . ContainerImageName ) == true )
23
- {
24
- throw new ArgumentException ( "Container image name must be specified." , nameof ( options ) ) ;
25
- }
22
+ ArgumentNullException . ThrowIfNull ( builder , nameof ( builder ) ) ;
23
+ ArgumentNullException . ThrowIfNull ( options , nameof ( options ) ) ;
24
+ ArgumentException . ThrowIfNullOrWhiteSpace ( name , nameof ( name ) ) ;
25
+ ArgumentException . ThrowIfNullOrWhiteSpace ( options . ContainerImageName , nameof ( options . ContainerImageName ) ) ;
26
26
27
27
var resource = new JavaAppContainerResource ( name ) ;
28
28
29
- var rb = builder . AddResource ( resource ) ;
30
- if ( string . IsNullOrWhiteSpace ( options . ContainerRegistry ) == false )
31
- {
32
- rb . WithImageRegistry ( options . ContainerRegistry ) ;
33
- }
34
- rb . WithImage ( options . ContainerImageName )
35
- . WithImageTag ( options . ContainerImageTag )
29
+ var rb = builder . AddResource ( resource )
30
+ . WithAnnotation ( new ContainerImageAnnotation { Image = options . ContainerImageName , Tag = options . ContainerImageTag , Registry = options . ContainerRegistry } )
36
31
. WithHttpEndpoint ( port : options . Port , targetPort : options . TargetPort , name : JavaAppContainerResource . HttpEndpointName )
37
32
. WithJavaDefaults ( options ) ;
33
+
38
34
if ( options . Args is { Length : > 0 } )
39
35
{
40
- #pragma warning disable CS8604 // Possible null reference argument.
41
36
rb . WithArgs ( options . Args ) ;
42
- #pragma warning restore CS8604 // Possible null reference argument.
43
37
}
44
38
45
39
return rb ;
@@ -52,10 +46,8 @@ public static IResourceBuilder<JavaAppContainerResource> AddJavaApp(this IDistri
52
46
/// <param name="name">The name of the resource.</param>
53
47
/// <param name="options">The <see cref="JavaAppContainerResourceOptions"/> to configure the Java application.</param>"
54
48
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
55
- public static IResourceBuilder < JavaAppContainerResource > AddSpringApp ( this IDistributedApplicationBuilder builder , string name , JavaAppContainerResourceOptions options )
56
- {
57
- return builder . AddJavaApp ( name , options ) ;
58
- }
49
+ public static IResourceBuilder < JavaAppContainerResource > AddSpringApp ( this IDistributedApplicationBuilder builder , string name , JavaAppContainerResourceOptions options ) =>
50
+ builder . AddJavaApp ( name , options ) ;
59
51
60
52
/// <summary>
61
53
/// Adds a Java application to the application model. Executes the executable Java app.
@@ -67,6 +59,11 @@ public static IResourceBuilder<JavaAppContainerResource> AddSpringApp(this IDist
67
59
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
68
60
public static IResourceBuilder < JavaAppExecutableResource > AddJavaApp ( this IDistributedApplicationBuilder builder , string name , string workingDirectory , JavaAppExecutableResourceOptions options )
69
61
{
62
+ ArgumentNullException . ThrowIfNull ( builder , nameof ( builder ) ) ;
63
+ ArgumentNullException . ThrowIfNull ( options , nameof ( options ) ) ;
64
+ ArgumentException . ThrowIfNullOrWhiteSpace ( name , nameof ( name ) ) ;
65
+ ArgumentException . ThrowIfNullOrWhiteSpace ( workingDirectory , nameof ( workingDirectory ) ) ;
66
+
70
67
#pragma warning disable CS8601 // Possible null reference assignment.
71
68
string [ ] allArgs = options . Args is { Length : > 0 }
72
69
? [ "-jar" , options . ApplicationName , .. options . Args ]
@@ -90,10 +87,8 @@ public static IResourceBuilder<JavaAppExecutableResource> AddJavaApp(this IDistr
90
87
/// <param name="workingDirectory">The working directory to use for the command. If null, the working directory of the current process is used.</param>
91
88
/// <param name="options">The <see cref="JavaAppExecutableResourceOptions"/> to configure the Java application.</param>"
92
89
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
93
- public static IResourceBuilder < JavaAppExecutableResource > AddSpringApp ( this IDistributedApplicationBuilder builder , string name , string workingDirectory , JavaAppExecutableResourceOptions options )
94
- {
95
- return builder . AddJavaApp ( name , workingDirectory , options ) ;
96
- }
90
+ public static IResourceBuilder < JavaAppExecutableResource > AddSpringApp ( this IDistributedApplicationBuilder builder , string name , string workingDirectory , JavaAppExecutableResourceOptions options ) =>
91
+ builder . AddJavaApp ( name , workingDirectory , options ) ;
97
92
98
93
private static IResourceBuilder < JavaAppContainerResource > WithJavaDefaults (
99
94
this IResourceBuilder < JavaAppContainerResource > builder ,
0 commit comments