Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / installer / CompileResult.java @ 15280

History | View | Annotate | Download (5.11 KB)

1
/*
2
 *  $Id: CompileResult.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *  IzPack
4
 *  Copyright (C) 2003 Tino Schwarze
5
 *
6
 *  Description :        Class to encapsulate the result of compilation
7
 *  Author's email :     tino.schwarze@community4you.de
8
 *
9
 *  This program is free software; you can redistribute it and/or
10
 *  modify it under the terms of the GNU General Public License
11
 *  as published by the Free Software Foundation; either version 2
12
 *  of the License, or any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
package com.izforge.izpack.installer;
24

    
25
/**
26
 * This class describes the result of the compilation.
27
 *
28
 * This class is here because error handling is not straight-forward with
29
 * regard to compilation.
30
 *
31
 * The error condition consists of an error message, the full command line
32
 * which failed to execute plus it's stdout and stderr. The reason for this
33
 * class to exist is that there are three possible reactions to the error
34
 * (chosen by the user).
35
 * <ol>
36
 * <li>abort</li>
37
 * <li>ignore (continue anyway)</li>
38
 * <li>reconfigure</li>
39
 * </ol>
40
 *
41
 * @author     Tino Schwarze
42
 */
43
public class CompileResult
44
{
45
  // -------- public constants ---------------
46
  // arbitrary values
47
  public final static int SUCCESS = 42;
48
  public final static int FAILED = 23;
49

    
50
  public final static int ACTION_ABORT = 27;
51
  public final static int ACTION_CONTINUE = 39;
52
  public final static int ACTION_RECONFIGURE = 31;
53

    
54
  // -------- private variables ---------------
55
  // we're optimistic...
56
  private int status = SUCCESS;
57
  // here we're pessimistic
58
  private int action = ACTION_ABORT;
59
  /** the error message */
60
  private String message = null;
61
  /** the command line */
62
  private String[] cmdline = null;
63
  /** the stdout of the command */
64
  private String stdout = null;
65
  /** the stderr of the command */
66
  private String stderr = null;
67

    
68
  /**  constructor, create a new successful result */
69
  public CompileResult()
70
  {
71
    this.status = SUCCESS;
72
    this.action = ACTION_CONTINUE;
73
  }
74

    
75
  /**
76
   * creates a new CompileResult with status FAILED
77
   *
78
   * @param  message  description of the exception
79
   * @param  cmdline  full command line of failed command
80
   * @param  stdout   standard output of failed command
81
   * @param  stderr   standard error of failed command
82
   */
83
  public CompileResult (
84
    String message, String[] cmdline, String stdout, String stderr)
85
  {
86
    this.message = message;
87
    this.status = FAILED;
88
    this.cmdline = cmdline;
89
    this.stdout = stdout;
90
    this.stderr = stderr;
91
  }
92

    
93
  public void setStatus (int status)
94
  {
95
    if (   (status == SUCCESS)
96
        || (status == FAILED) )
97
    {
98
      this.status = status;
99
    }
100
  }
101

    
102
  public int getStatus ()
103
  {
104
    return this.status;
105
  }
106

    
107
  public void setAction (int action)
108
  {
109
    if (   (action == ACTION_ABORT)
110
        || (action == ACTION_CONTINUE)
111
        || (action == ACTION_RECONFIGURE) )
112
    {
113
      this.action = action;
114
    }
115

    
116
  }
117

    
118
  public int getAction ()
119
  {
120
    return this.action;
121
  }
122

    
123
  /** check for success  (convenience function) */
124
  public boolean isSuccess ()
125
  {
126
    return (this.status == SUCCESS);
127
  }
128

    
129
  /** check whether to abort (convenience function) */
130
  public boolean isAbort ()
131
  {
132
    return ((this.status == FAILED) && (this.action == ACTION_ABORT));
133
  }
134

    
135
  /** check whether to continue (convenience function) 
136
   *
137
   * @return true if status is SUCCESS or action is CONTINUE
138
   */
139
  public boolean isContinue ()
140
  {
141
    return ((this.status == SUCCESS) || (this.action == ACTION_CONTINUE));
142
  }
143

    
144
  /** check whether to reconfigure (convenience function) */
145
  public boolean isReconfigure ()
146
  {
147
    return ((this.status == FAILED) && (this.action == ACTION_RECONFIGURE));
148
  }
149

    
150
  /** return error message
151
   *
152
   * @return the error message describing the action that failed
153
   *         (might be null)
154
   */
155
  public String getMessage ()
156
  {
157
    return this.message;
158
  }
159

    
160
  /** get command line of failed command as a string
161
   *
162
   * @return command line of failed command
163
   */
164
  public String getCmdline ()
165
  {
166
    StringBuffer sb = new StringBuffer();
167
    for (int i = 0; i < this.cmdline.length; ++i)
168
    {
169
      if (sb.length() > 0)
170
        sb.append (' ');
171
      sb.append (this.cmdline[i]);
172
    }
173
    return sb.toString ();
174
  }
175

    
176
  /** get command line of failed command as an array of strings
177
   *
178
   * @return command line of failed command
179
   */
180
  public String[] getCmdlineArray ()
181
  {
182
    return this.cmdline;
183
  }
184

    
185
  public String getStdout ()
186
  {
187
    return this.stdout;
188
  }
189

    
190
  public String getStderr ()
191
  {
192
    return this.stderr;
193
  }
194

    
195
}