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 final List<String> filePathList2Delete;

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

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(filePathList2Delete, "A list of file path for deletion must be set");
    }

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

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

        return null;
    }
}

@@ -282,107 +282,8 @@
 tus;
-%0Aimport org.springframework.beans.factory.InitializingBean;%0Aimport org.springframework.util.Assert;
 %0A%0Aim
@@ -423,26 +423,8 @@
 klet
-, InitializingBean
  %7B%0A%0A
@@ -561,13 +561,12 @@
     
-this.
+if (
 file
@@ -586,130 +586,133 @@
 te =
- filePathList2Delete;
+= null) %7B
 %0A    
-%7D%0A%0A
     
-@Override%0A    public void afterPropertiesSet() throws Exception %7B%0A        Assert.notNull(
+    throw new NullPointerException(%22A list of file path for deletion must be set%22);%0A        %7D%0A        this.
 file
@@ -730,57 +730,30 @@
 lete
-, %22A list of
+ =
  file
- path for deletion must be set%22)
+PathList2Delete
 ;%0A  

Remove InitializingBean