package org.openslx.taskmanager.tasks; import java.util.ArrayList; import java.util.List; import org.openslx.taskmanager.api.SystemCommandTask; import com.google.gson.annotations.Expose; public class LsTask extends SystemCommandTask { /* * Serialize */ @Expose private String directory = null; /* * Private, no serialization */ private Output status = new Output(); private List files = new ArrayList<>(); @Override protected boolean initTask() { if ( directory == null ) { status.error ="Missing directory argument"; return false; } return true; } @Override protected String[] initCommandLine() { return new String[] { "/bin/ls", directory }; } @Override protected void processStarted() { setStatusObject( status ); } @Override protected boolean processEnded( int exitCode ) { if ( exitCode != 0 ) { status.files = null; return false; } status.files = this.files; return true; } @Override protected void processStdOut( String line ) { this.files.add( line ); } @Override protected void processStdErr( String line ) { status.error = line; } /** * Output - contains additional status data of this task */ @SuppressWarnings( "unused" ) private static class Output { protected String error = null; protected List files = null; } }