package com.boissinot.jenkins.csvexporter.batch;

import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

import java.io.File;
import java.util.List;

/**
 * @author Gregory Boissinot
 */
public class CleanupOutputFilesTasklet implements Tasklet, InitializingBean {

    private List<String> filePath2Delete;

    public CleanupOutputFilesTasklet(List<String> filePath2Delete) {
        this.filePath2Delete = filePath2Delete;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(filePath2Delete, "A file list to delete must be set");
    }

    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {

        for (String filePath : filePath2Delete) {
            File file = new File(filePath);
            if (file.exists()) {
                file.delete();
            }
        }

        return null;
    }
}

@@ -565,32 +565,36 @@
 String%3E filePath
+List
 2Delete;%0A%0A    pu
@@ -638,32 +638,36 @@
 tring%3E filePath2
+List
 Delete) %7B%0A      
@@ -677,24 +677,28 @@
 his.filePath
+List
 2Delete = fi
@@ -699,24 +699,28 @@
 e = filePath
+List
 2Delete;%0A   
@@ -820,24 +820,28 @@
 ull(filePath
+List
 2Delete, %22A 
@@ -844,27 +844,38 @@
  %22A 
-file list to
+list of file path for
  delet
-e
+ion
  mus
@@ -1056,16 +1056,20 @@
 filePath
+List
 2Delete)

Rename filed name