summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager/tasks/LsTask.java
blob: 2e0116775117f841279cab0ebcbfa1d8ad73447d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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<String> 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<String> files = null;
	}

}