Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@

var apiapp = builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Java_ApiApp>("apiapp");

var containerapp = builder.AddSpringApp("containerapp",
new JavaAppContainerResourceOptions()
{
ContainerImageName = "aliencube/aspire-spring-maven-sample",
OtelAgentPath = "/agents"
});
var executableapp = builder.AddSpringApp("executableapp",
workingDirectory: "../CommunityToolkit.Aspire.Hosting.Java.Spring.Maven",
new JavaAppExecutableResourceOptions()
{
ApplicationName = "target/spring-maven-0.0.1-SNAPSHOT.jar",
Port = 8085,
OtelAgentPath = "../../../agents",
})
.WithMavenBuild()
.PublishAsDockerFile(c =>
{
c.WithBuildArg("JAR_NAME", "spring-maven-0.0.1-SNAPSHOT.jar")
.WithBuildArg("AGENT_PATH", "/agents")
.WithBuildArg("SERVER_PORT", "8085");
})
var containerapp = builder.AddJavaContainerApp("containerapp", image: "docker.io/aliencube/aspire-spring-maven-sample")
.WithOtelAgent("/agents/opentelemetry-javaagent.jar")
.WithHttpEndpoint(targetPort: 8080, env: "SERVER_PORT");

var executableapp = builder.AddJavaApp("executableapp",
workingDirectory: "../CommunityToolkit.Aspire.Hosting.Java.Spring.Maven")
.WithMavenGoal("spring-boot:run")
.WithOtelAgent("../../../agents/opentelemetry-javaagent.jar")
.WithHttpEndpoint(targetPort: 8080, env: "SERVER_PORT")
.WithHttpHealthCheck("/health");

var webapp = builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Java_WebApp>("webapp")
Expand Down
10 changes: 10 additions & 0 deletions src/CommunityToolkit.Aspire.Hosting.Java/GradleBuildResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// A resource that represents a Gradle build step.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="wrapperScript">The full path to the Gradle wrapper script.</param>
/// <param name="workingDirectory">The working directory to use for the command.</param>
public class GradleBuildResource(string name, string wrapperScript, string workingDirectory)
: ExecutableResource(name, wrapperScript, workingDirectory);
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <summary>
/// This represents the options entity for configuring a Java application running in a container.
/// </summary>
[Obsolete("This class will be removed in a future version.")]
public class JavaAppContainerResourceOptions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,35 @@
/// <summary>
/// A resource that represents a Java application.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="command">The command to execute.</param>
/// <param name="workingDirectory">The working directory to use for the command. If null, the working directory of the current process is used.</param>
public class JavaAppExecutableResource(string name, string command, string workingDirectory)
: ExecutableResource(name, command, workingDirectory), IResourceWithServiceDiscovery
public class JavaAppExecutableResource
: ExecutableResource, IResourceWithServiceDiscovery, IResourceWithWaitSupport
{
internal const string HttpEndpointName = "http";

/// <summary>
/// Initializes a new instance of the <see cref="JavaAppExecutableResource"/> class.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="workingDirectory">The working directory to use for the command.</param>
public JavaAppExecutableResource(string name, string workingDirectory)
: base(name, "java", workingDirectory)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="JavaAppExecutableResource"/> class.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="command">The command to execute.</param>
/// <param name="workingDirectory">The working directory to use for the command.</param>
[Obsolete("Use JavaAppExecutableResource(string, string) instead. This constructor will be removed in a future version.")]
public JavaAppExecutableResource(string name, string command, string workingDirectory)
: base(name, command, workingDirectory)
{
}

/// <summary>
/// Gets or sets the path to the JAR file to execute.
/// </summary>
public string? JarPath { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <summary>
/// This represents the options entity for configuring an executable Java application.
/// </summary>
[Obsolete("This class will be removed in a future version.")]
public class JavaAppExecutableResourceOptions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Globalization;
using Aspire.Hosting.ApplicationModel;
using CommunityToolkit.Aspire.Utils;

Expand All @@ -14,8 +13,31 @@ public static partial class JavaAppHostingExtension
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
/// <param name="name">The name of the resource.</param>
/// <param name="options">The <see cref="JavaAppContainerResourceOptions"/> to configure the Java application.</param>"
/// <param name="image">The container image name.</param>
/// <param name="imageTag">The container image tag.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<JavaAppContainerResource> AddJavaContainerApp(this IDistributedApplicationBuilder builder, [ResourceName] string name,
string image, string? imageTag = null)
{
ArgumentNullException.ThrowIfNull(builder, nameof(builder));
ArgumentException.ThrowIfNullOrWhiteSpace(name, nameof(name));
ArgumentException.ThrowIfNullOrWhiteSpace(image, nameof(image));

var resource = new JavaAppContainerResource(name);

return builder.AddResource(resource)
.WithImage(image, imageTag)
.WithOtlpExporter();
}

/// <summary>
/// Adds a Java application to the application model. Executes the containerized Java app.
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
/// <param name="name">The name of the resource.</param>
/// <param name="options">The <see cref="JavaAppContainerResourceOptions"/> to configure the Java application.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
[Obsolete("Use AddJavaContainerApp instead. This method will be removed in a future version.")]
public static IResourceBuilder<JavaAppContainerResource> AddJavaApp(this IDistributedApplicationBuilder builder, [ResourceName] string name, JavaAppContainerResourceOptions options)
{
ArgumentNullException.ThrowIfNull(builder, nameof(builder));
Expand Down Expand Up @@ -43,14 +65,17 @@ public static IResourceBuilder<JavaAppContainerResource> AddJavaApp(this IDistri
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
/// <param name="name">The name of the resource.</param>
/// <param name="options">The <see cref="JavaAppContainerResourceOptions"/> to configure the Java application.</param>"
/// <param name="options">The <see cref="JavaAppContainerResourceOptions"/> to configure the Java application.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
[Obsolete("Use AddJavaContainerApp instead. This method will be removed in a future version.")]
public static IResourceBuilder<JavaAppContainerResource> AddSpringApp(this IDistributedApplicationBuilder builder, [ResourceName] string name, JavaAppContainerResourceOptions options) =>
builder.AddJavaApp(name, options);

#pragma warning disable CS0618
private static IResourceBuilder<JavaAppContainerResource> WithJavaDefaults(
this IResourceBuilder<JavaAppContainerResource> builder,
JavaAppContainerResourceOptions options) =>
builder.WithOtlpExporter()
.WithEnvironment("JAVA_TOOL_OPTIONS", $"-javaagent:{options.OtelAgentPath?.TrimEnd('/')}/opentelemetry-javaagent.jar");
#pragma warning restore CS0618
}
Loading
Loading