001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2001,2002 Olexij Tkatchenko
008 *
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package com.izforge.izpack;
023
024import java.io.Serializable;
025import java.util.ArrayList;
026import java.util.List;
027
028/**
029 * Encloses information about a executable file. This class abstracts the way to do a system
030 * dependent postprocessing of installation.
031 * 
032 * @author Olexij Tkatchenko <ot@parcs.de>
033 */
034
035public class ExecutableFile implements Serializable
036{
037
038    static final long serialVersionUID = 4175489415984990405L;
039
040    /** when to execute this file */
041    public final static int POSTINSTALL = 0;
042
043    public final static int NEVER = 1;
044
045    public final static int UNINSTALL = 2;
046
047    /** type of a file */
048    public final static int BIN = 0;
049
050    public final static int JAR = 1;
051
052    /** what to do if execution fails */
053    public final static int ABORT = 0;
054
055    public final static int WARN = 1;
056
057    public final static int ASK = 2;
058
059    /** The file path */
060    public String path;
061
062    /** Execution stage (NEVER, POSTINSTALL, UNINSTALL) */
063    public int executionStage;
064
065    /** Main class of jar file */
066    public String mainClass;
067
068    /** type (BIN|JAR) */
069    public int type;
070
071    /** Failure handling (ABORT, WARN, ASK) */
072    public int onFailure;
073
074    /** List of arguments */
075    public List argList = null;
076
077    /** List of operating systems to run on */
078    public List osList = null;
079
080    /**
081     * Indicates the file should be kept after executing. Default is false for backward
082     * compatibility.
083     */
084    public boolean keepFile;
085
086    /** Constructs a new uninitialized instance. */
087    public ExecutableFile()
088    {
089        this.path = null;
090        executionStage = NEVER;
091        mainClass = null;
092        type = BIN;
093        onFailure = ASK;
094        osList = new ArrayList();
095        argList = new ArrayList();
096        keepFile = false;
097    }
098
099    /**
100     * Constructs and initializes a new instance.
101     * 
102     * @param path the file path
103     * @param executionStage when to execute
104     * @param onFailure what to do if execution fails
105     * @param osList list of operating systems to run on
106     */
107    public ExecutableFile(String path, int executionStage, int onFailure, java.util.List osList,
108            boolean keepFile)
109    {
110        this.path = path;
111        this.executionStage = executionStage;
112        this.onFailure = onFailure;
113        this.osList = osList;
114        this.keepFile = keepFile;
115    }
116
117    public ExecutableFile(String path, int type, String mainClass, int executionStage,
118            int onFailure, java.util.List argList, java.util.List osList, boolean keepFile)
119    {
120        this.path = path;
121        this.mainClass = mainClass;
122        this.type = type;
123        this.executionStage = executionStage;
124        this.onFailure = onFailure;
125        this.argList = argList;
126        this.osList = osList;
127        this.keepFile = keepFile;
128    }
129
130    public String toString()
131    {
132        StringBuffer retval = new StringBuffer();
133        retval.append("path = " + path);
134        retval.append("\n");
135        retval.append("mainClass = " + mainClass);
136        retval.append("\n");
137        retval.append("type = " + type);
138        retval.append("\n");
139        retval.append("executionStage = " + executionStage);
140        retval.append("\n");
141        retval.append("onFailure = " + onFailure);
142        retval.append("\n");
143        retval.append("argList: " + argList);
144        retval.append("\n");
145        if (argList != null)
146        {
147            for (int i = 0; i < argList.size(); i++)
148            {
149                retval.append("\targ: " + argList.get(i));
150                retval.append("\n");
151            }
152        }
153        retval.append("\n");
154        retval.append("osList = " + osList);
155        retval.append("\n");
156        if (osList != null)
157        {
158            for (int i = 0; i < osList.size(); i++)
159            {
160                retval.append("\tos: " + osList.get(i));
161                retval.append("\n");
162            }
163        }
164        retval.append("keepFile = " + keepFile);
165        retval.append("\n");
166        return retval.toString();
167    }
168}