All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cloudshiftdev.awscdk.pipelines.WaveOptions.kt Maven / Gradle / Ivy

The newest version!
@file:Suppress("RedundantVisibilityModifier","RedundantUnitReturnType","RemoveRedundantQualifierName","unused","UnusedImport","ClassName","REDUNDANT_PROJECTION","DEPRECATION")

package io.cloudshiftdev.awscdk.pipelines

import io.cloudshiftdev.awscdk.common.CdkDslMarker
import io.cloudshiftdev.awscdk.common.CdkObject
import io.cloudshiftdev.awscdk.common.CdkObjectWrappers
import kotlin.Unit
import kotlin.collections.List

/**
 * Options to pass to `addWave`.
 *
 * Example:
 *
 * ```
 * CodePipeline pipeline = CodePipeline.Builder.create(this, "Pipeline")
 * .synth(ShellStep.Builder.create("Synth")
 * .input(CodePipelineSource.connection("my-org/my-app", "main", ConnectionSourceOptions.builder()
 * .connectionArn("arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41")
 * .build()))
 * .commands(List.of("npm ci", "npm run build", "npx cdk synth"))
 * .build())
 * // Turn this on because the pipeline uses Docker image assets
 * .dockerEnabledForSelfMutation(true)
 * .build();
 * pipeline.addWave("MyWave", WaveOptions.builder()
 * .post(List.of(
 * CodeBuildStep.Builder.create("RunApproval")
 * .commands(List.of("command-from-image"))
 * .buildEnvironment(BuildEnvironment.builder()
 * // The user of a Docker image asset in the pipeline requires turning on
 * // 'dockerEnabledForSelfMutation'.
 * .buildImage(LinuxBuildImage.fromAsset(this, "Image", DockerImageAssetProps.builder()
 * .directory("./docker-image")
 * .build()))
 * .build())
 * .build()))
 * .build());
 * ```
 */
public interface WaveOptions {
  /**
   * Additional steps to run after all of the stages in the wave.
   *
   * Default: - No additional steps
   */
  public fun post(): List = unwrap(this).getPost()?.map(Step::wrap) ?: emptyList()

  /**
   * Additional steps to run before any of the stages in the wave.
   *
   * Default: - No additional steps
   */
  public fun pre(): List = unwrap(this).getPre()?.map(Step::wrap) ?: emptyList()

  /**
   * A builder for [WaveOptions]
   */
  @CdkDslMarker
  public interface Builder {
    /**
     * @param post Additional steps to run after all of the stages in the wave.
     */
    public fun post(post: List)

    /**
     * @param post Additional steps to run after all of the stages in the wave.
     */
    public fun post(vararg post: Step)

    /**
     * @param pre Additional steps to run before any of the stages in the wave.
     */
    public fun pre(pre: List)

    /**
     * @param pre Additional steps to run before any of the stages in the wave.
     */
    public fun pre(vararg pre: Step)
  }

  private class BuilderImpl : Builder {
    private val cdkBuilder: software.amazon.awscdk.pipelines.WaveOptions.Builder =
        software.amazon.awscdk.pipelines.WaveOptions.builder()

    /**
     * @param post Additional steps to run after all of the stages in the wave.
     */
    override fun post(post: List) {
      cdkBuilder.post(post.map(Step.Companion::unwrap))
    }

    /**
     * @param post Additional steps to run after all of the stages in the wave.
     */
    override fun post(vararg post: Step): Unit = post(post.toList())

    /**
     * @param pre Additional steps to run before any of the stages in the wave.
     */
    override fun pre(pre: List) {
      cdkBuilder.pre(pre.map(Step.Companion::unwrap))
    }

    /**
     * @param pre Additional steps to run before any of the stages in the wave.
     */
    override fun pre(vararg pre: Step): Unit = pre(pre.toList())

    public fun build(): software.amazon.awscdk.pipelines.WaveOptions = cdkBuilder.build()
  }

  private class Wrapper(
    cdkObject: software.amazon.awscdk.pipelines.WaveOptions,
  ) : CdkObject(cdkObject),
      WaveOptions {
    /**
     * Additional steps to run after all of the stages in the wave.
     *
     * Default: - No additional steps
     */
    override fun post(): List = unwrap(this).getPost()?.map(Step::wrap) ?: emptyList()

    /**
     * Additional steps to run before any of the stages in the wave.
     *
     * Default: - No additional steps
     */
    override fun pre(): List = unwrap(this).getPre()?.map(Step::wrap) ?: emptyList()
  }

  public companion object {
    public operator fun invoke(block: Builder.() -> Unit = {}): WaveOptions {
      val builderImpl = BuilderImpl()
      return Wrapper(builderImpl.apply(block).build())
    }

    internal fun wrap(cdkObject: software.amazon.awscdk.pipelines.WaveOptions): WaveOptions =
        CdkObjectWrappers.wrap(cdkObject) as? WaveOptions ?: Wrapper(cdkObject)

    internal fun unwrap(wrapped: WaveOptions): software.amazon.awscdk.pipelines.WaveOptions =
        (wrapped as CdkObject).cdkObject as software.amazon.awscdk.pipelines.WaveOptions
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy