com.github.alexcojocaru.mojo.elasticsearch.v2.step.RemoveExistingDataStep Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-maven-plugin Show documentation
Show all versions of elasticsearch-maven-plugin Show documentation
A Maven plugin to run a single node Elasticsearch cluster during the integration test phase of a build
package com.github.alexcojocaru.mojo.elasticsearch.v2.step;
import com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException;
import com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration;
import com.github.alexcojocaru.mojo.elasticsearch.v2.util.FilesystemUtil;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class RemoveExistingDataStep
implements InstanceStep
{
@Override
public void execute(InstanceConfiguration config)
{
if (Boolean.FALSE.equals(config.getClusterConfiguration().isKeepExistingData()))
{
File baseDir = new File(config.getBaseDir());
try
{
File dataDir = FilesystemUtil.getDataDirectory(baseDir);
File logsDir = FilesystemUtil.getLogsDirectory(baseDir);
FileUtils.deleteDirectory(dataDir);
FileUtils.deleteDirectory(logsDir);
}
catch (IOException e)
{
throw new ElasticsearchSetupException(
"Failed to delete the existing Elasticsearch data from "
+ baseDir.getAbsolutePath(),
e);
}
}
}
}