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

com.github.alexcojocaru.mojo.elasticsearch.v2.step.RemoveExistingDataStep Maven / Gradle / Ivy

Go to download

A Maven plugin to run a single node Elasticsearch cluster during the integration test phase of a build

There is a newer version: 6.28
Show newest version
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);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy