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

org.wildfly.plugin.tools.UndeployDescription Maven / Gradle / Ivy

/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.plugin.tools;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

import org.wildfly.common.Assert;
import org.wildfly.plugin.tools.util.Assertions;

/**
 * Represents the description for undeploying content from a running container.
 * 

* Instances of this are not thread-safe. *

* * @author James R. Perkins */ @SuppressWarnings({ "unused", "WeakerAccess" }) public class UndeployDescription implements DeploymentDescription, Comparable { private final String name; private final Set serverGroups; private boolean failOnMissing; private boolean removeContent; /** * Creates a new undeploy description. * * @param name the name of the deployment */ private UndeployDescription(final String name) { this.name = name; serverGroups = new LinkedHashSet<>(); failOnMissing = false; removeContent = true; } /** * Creates a new undeploy description. * * @param name the name of the deployment * * @return the description */ public static UndeployDescription of(final String name) { return new UndeployDescription(Assertions.requiresNotNullOrNotEmptyParameter("name", name)); } /** * Creates a new undeploy description. * * @param deploymentDescription the deployment description to copy * * @return the description */ public static UndeployDescription of(final DeploymentDescription deploymentDescription) { Assert.checkNotNullParam("deploymentDescription", deploymentDescription); return of(deploymentDescription.getName()).addServerGroups(deploymentDescription.getServerGroups()); } /** * Adds a server group for the deployment description. * * @param serverGroup the server group to add * * @return this deployment description */ public UndeployDescription addServerGroup(final String serverGroup) { serverGroups.add(serverGroup); return this; } /** * Adds the server groups for the deployment description. * * @param serverGroups the server groups to add * * @return this deployment description */ public UndeployDescription addServerGroups(final String... serverGroups) { return addServerGroups(Arrays.asList(serverGroups)); } /** * Adds the server groups for the deployment description. * * @param serverGroups the server groups to add * * @return this deployment description */ public UndeployDescription addServerGroups(final Collection serverGroups) { this.serverGroups.addAll(serverGroups); return this; } @Override public Set getServerGroups() { return Collections.unmodifiableSet(serverGroups); } @Override public String getName() { return name; } /** * Indicates whether or not a failure should occur if the deployment does not exist on the container. A value of * {@code true} indicates the deployment should fail. * * @return {@code true} if the undeploy should fail if not found on the container, otherwise {@code false} */ public boolean isFailOnMissing() { return failOnMissing; } /** * Sets whether or not a failure should occur if the deployment does exist on the container. * * @param failOnMissing {@code true} if the undeploy should fail if the deployment was not found on the server, * {@code false} if the deployment does not exist and the undeploy should be ignored * * @return the deployment description */ public UndeployDescription setFailOnMissing(final boolean failOnMissing) { this.failOnMissing = failOnMissing; return this; } /** * Indicates whether or not the content should be removed from the content repository. * * @return {@code true} if the content should also be removed from the repository, {@code false} it only an * {@code undeploy} operation should be executed and the content should remain in the repository */ public boolean isRemoveContent() { return removeContent; } /** * Sets whether or not the content should be removed after the {@code undeploy} operation. *

* The default value is {@code true}. *

* * @param removeContent {@code true} if the content should be removed, {@code false} if the content should remain * in the repository * * @return the deployment description */ public UndeployDescription setRemoveContent(final boolean removeContent) { this.removeContent = removeContent; return this; } @Override public int compareTo(@SuppressWarnings("NullableProblems") final UndeployDescription o) { return name.compareTo(o.name); } @Override public int hashCode() { return Objects.hash(name); } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof UndeployDescription)) { return false; } final UndeployDescription other = (UndeployDescription) obj; return Objects.equals(name, other.name); } @Override public String toString() { final StringBuilder result = new StringBuilder(UndeployDescription.class.getSimpleName()); result.append('('); result.append("name=").append(name); result.append(", failOnMissing=").append(failOnMissing); result.append(", removeContent=").append(removeContent); if (!serverGroups.isEmpty()) { result.append(", serverGroups=").append(serverGroups); } return result.append(')').toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy