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

de.gesellix.gradle.docker.tasks.DockerRmTask Maven / Gradle / Ivy

package de.gesellix.gradle.docker.tasks;

import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;

public class DockerRmTask extends GenericDockerTask {

  private final Property containerId;

  @Input
  public Property getContainerId() {
    return containerId;
  }

  private final Property removeVolumes;

  @Input
  @Optional
  public Property getRemoveVolumes() {
    return removeVolumes;
  }

  @Inject
  public DockerRmTask(ObjectFactory objectFactory) {
    super(objectFactory);
    setDescription("Remove one or more containers");

    containerId = objectFactory.property(String.class);
    removeVolumes = objectFactory.property(Boolean.class);
    removeVolumes.convention(false);
  }

  @TaskAction
  public void rm() {
    getLogger().info("docker rm");
    Map query = new HashMap<>(1);
    query.put("v", getRemoveVolumes().get() ? 1 : 0);
    getDockerClient().rm(getContainerId().get(), query);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy