use of org.wildfly.plugin.core.UndeployDescription in project wildfly-maven-plugin by wildfly.
the class UndeployMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().debug(String.format("Skipping undeploy of %s:%s", project.getGroupId(), project.getArtifactId()));
return;
}
final PackageType packageType = PackageType.resolve(project);
// Configure the name if it wasn't yet set
if (name == null) {
name = String.format("%s.%s", project.getBuild().getFinalName(), packageType.getFileExtension());
}
if (checkPackaging && packageType.isIgnored()) {
getLog().debug(String.format("Ignoring packaging type %s.", packageType.getPackaging()));
} else {
final DeploymentResult result;
try (ModelControllerClient client = createClient();
MavenModelControllerClientConfiguration configuration = getClientConfiguration()) {
final boolean failOnMissing = !ignoreMissingDeployment;
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
if (matchPattern == null) {
result = deploymentManager.undeploy(UndeployDescription.of(name).addServerGroups(getServerGroups()).setFailOnMissing(failOnMissing));
} else {
final Set<UndeployDescription> matchedDeployments = findDeployments(deploymentManager, failOnMissing);
if (matchedDeployments.isEmpty()) {
if (failOnMissing) {
throw new MojoDeploymentException("No deployments matched the match-pattern %s.", matchPattern);
}
// nothing to undeploy
return;
}
result = deploymentManager.undeploy(matchedDeployments);
}
} catch (IOException e) {
throw new MojoFailureException("Failed to execute undeploy goal.", e);
}
if (!result.successful()) {
throw new MojoDeploymentException("Failed to undeploy %s. Reason: %s", name, result.getFailureMessage());
}
}
}
use of org.wildfly.plugin.core.UndeployDescription in project wildfly-maven-plugin by wildfly.
the class UndeployMojo method findDeployments.
private Set<UndeployDescription> findDeployments(final DeploymentManager deploymentManager, final boolean failOnMissing) throws IOException, MojoDeploymentException {
if (name == null && matchPattern == null) {
throw new IllegalArgumentException("deploymentName and matchPattern are null. One of them must " + "be set in order to find an existing deployment.");
}
final MatchPatternStrategy matchPatternStrategy = getMatchPatternStrategy();
final Set<UndeployDescription> matchedDeployments = new TreeSet<>();
final Collection<DeploymentDescription> deployments = deploymentManager.getDeployments();
final Pattern pattern = Pattern.compile(matchPattern);
for (DeploymentDescription deployment : deployments) {
boolean matchFound = false;
final String deploymentName = deployment.getName();
final Collection<String> serverGroups = getServerGroups();
if (pattern.matcher(deploymentName).matches()) {
if (serverGroups.isEmpty()) {
matchFound = true;
matchedDeployments.add(UndeployDescription.of(deploymentName).setFailOnMissing(failOnMissing));
} else {
final UndeployDescription undeployDescription = UndeployDescription.of(deploymentName);
for (String serverGroup : serverGroups) {
if (deployment.getServerGroups().contains(serverGroup)) {
matchFound = true;
undeployDescription.addServerGroup(serverGroup);
}
}
if (matchFound) {
matchedDeployments.add(undeployDescription.setFailOnMissing(failOnMissing));
}
}
if (matchFound && matchPatternStrategy == MatchPatternStrategy.FIRST) {
break;
}
}
}
if (matchPatternStrategy == MatchPatternStrategy.FAIL && matchedDeployments.size() > 1) {
throw new MojoDeploymentException("Deployment failed, found %d deployed artifacts for pattern '%s' (%s)", matchedDeployments.size(), matchPattern, matchedDeployments);
}
return matchedDeployments;
}
Aggregations