public void process(@Observes After test) {
doCleanup(test.getTestMethod(), false);
}
private void doCleanup(Method testMethod, boolean isBefore) {
ClearPersistedData clearData = testMethod.getAnnotation(ClearPersistedData.class);
if (clearData != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Clean up for: " + testMethod);
}
//b a x y
//0 0 0 nogo
//0 0 1 nogo
//0 1 0 go
//0 1 1 nogo
//1 0 0 nogo
//1 0 1 go
//1 1 0 go
//1 1 1 go
EnumSet<When> when = toEnumSet(When.class, clearData.when());
boolean hasBefore = when.contains(When.BEFORE_TEST);
boolean hasAfter = when.contains(When.AFTER_TEST);
if ((!hasBefore && !hasAfter) ||
(!hasBefore && isBefore) ||
(hasBefore && !hasAfter && !isBefore)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping clean up. Currently " + (isBefore ? "before" : "after") + " test but scheduled to run:" + when);
}
return;
}
LOG.info("Stopping Plugin Container to clean up data");
pcContainer.get().stopPc();
File dataDir = pcContainer.get().getConfiguration().getDataDirectory();
File tmpDir = pcContainer.get().getConfiguration().getTemporaryDirectory();
FileUtil.purge(tmpDir, false);
if (LOG.isDebugEnabled()) {
LOG.debug("Purged temp dir");
}
if (clearData.ofInventory()) {
File inventoryDat = new File(dataDir, INVENTORY_DAT);
if (inventoryDat.exists()) {
inventoryDat.delete();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Purged inventory dat");
}
}
if (clearData.ofDrift()) {
FileUtil.purge(new File(dataDir, "changesets"), false);
if (LOG.isDebugEnabled()) {
LOG.debug("Purged drift changesets");
}
}
List<String> plugins = Arrays.asList(clearData.ofPlugins());
if (plugins.contains(ClearPersistedData.ALL_PLUGINS)) {
removeAllDataBut(dataDir, new String[] {"inventory.dat", "changesets"});
} else {
for(String n : plugins) {
FileUtil.purge(new File(dataDir, n), true);