aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/util/ProcessResult.java
blob: d2b4a0d84a4773f3a95320e405613353dca64bee (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2014 Obeo. and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.util;

/**
 * Describes the result of running an external process.
 *
 * @since 3.7
 */
public class ProcessResult {
	/**
	 * Status of a process' execution.
	 */
	public enum Status {
		/**
		 * The script was found and launched properly. It may still have exited
		 * with a non-zero {@link #exitCode}.
		 */
		OK,

		/** The script was not found on disk and thus could not be launched. */
		NOT_PRESENT,

		/**
		 * The script was found but could not be launched since it was not
		 * supported by the current {@link FS}.
		 */
		NOT_SUPPORTED;
	}

	/** The exit code of the process. */
	private final int exitCode;

	/** Status of the process' execution. */
	private final Status status;

	/**
	 * Instantiates a process result with the given status and an exit code of
	 * <code>-1</code>.
	 *
	 * @param status
	 *            Status describing the execution of the external process.
	 */
	public ProcessResult(Status status) {
		this(-1, status);
	}

	/**
	 * <p>Constructor for ProcessResult.</p>
	 *
	 * @param exitCode
	 *            Exit code of the process.
	 * @param status
	 *            Status describing the execution of the external process.
	 */
	public ProcessResult(int exitCode, Status status) {
		this.exitCode = exitCode;
		this.status = status;
	}

	/**
	 * Get exit code of the process.
	 *
	 * @return The exit code of the process.
	 */
	public int getExitCode() {
		return exitCode;
	}

	/**
	 * Get the status of the process' execution.
	 *
	 * @return The status of the process' execution.
	 */
	public Status getStatus() {
		return status;
	}

	/**
	 * Whether the execution occurred and resulted in an error
	 *
	 * @return <code>true</code> if the execution occurred and resulted in a
	 *         return code different from 0, <code>false</code> otherwise.
	 * @since 4.0
	 */
	public boolean isExecutedWithError() {
		return getStatus() == ProcessResult.Status.OK && getExitCode() != 0;
	}
}