Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dummy Gradle Task
public class DummyTask extends DefaultTask {
private Logger log = LogManager.getLogger(EOL.class);
private class MyThread extends Thread {
private Integer count = 5;
private ActionListenerAdapter adapter;
public MyThread(ActionListenerAdapter adapter) {
this.adapter = adapter;
}
@Override
public void run() {
while (count > 0) {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
count = count - 1;
log.info("reducing");
adapter.actionPerformed(new ActionEvent(this, 1, ""));
}
}
public int getCount() {
return count;
}
}
private class ActionListenerAdapter implements ActionListener {
private final DummyTask task;
public ActionListenerAdapter(final DummyTask task){
this.task = task;
new MyThread(this).start();
}
@Override
public void actionPerformed(ActionEvent e) {
task.setInputValue(((MyThread) e.getSource()).getCount());
if (task.getInputValue() == 0) {
log.info("deleting tmp file");
task.getInputFile().delete();
}
}
}
private final Property<Integer> input;
private File inputFile;
@InputFile
public File getInputFile(){
if (inputFile == null) {
setInputFile();
}
return inputFile;
}
public void setInputFile(){
try {
inputFile = File.createTempFile("hasfdasdfi", "ho");
} catch (IOException e) {
e.printStackTrace();
}
}
@Input
public Integer getInputValue(){
return input.get();
}
public void setInputValue(Integer value){
input.set(value);
}
public DummyTask() {
ListenerManager listenerManager = getServices().get(ListenerManager.class);
listenerManager.addListener(new ActionListenerAdapter(this));
input = getProject().getObjects().property(Integer.class);
input.set(5);
}
@TaskAction
public void executing(){
log.info("Hello Dummy : " + getInputValue());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment