001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: package com.izforge.izpack;
021:
022: import java.io.Serializable;
023: import java.text.DecimalFormat;
024: import java.util.ArrayList;
025: import java.util.HashSet;
026: import java.util.List;
027: import java.util.Set;
028:
029: import com.izforge.izpack.compiler.PackInfo;
030: import com.izforge.izpack.util.OsConstraint;
031:
032: /**
033: * Represents a Pack.
034: *
035: * @author Julien Ponge
036: */
037: public class Pack implements Serializable {
038:
039: static final long serialVersionUID = -5458360562175088671L;
040:
041: /** Flag for store files of this pack outside the installation jar file */
042: public boolean loose;
043:
044: /** If true, all files of the pack will be deleted during uninstallation, if
045: * false they are only removed if uninstaller force delete option is
046: * activated.
047: */
048: public boolean uninstall;
049:
050: /** The pack name. */
051: public String name;
052:
053: /** The langpack id */
054: public String id;
055:
056: /** An association of this pack to zero or more installation groups. An
057: * installation group is just a named collection of packs to allow for
058: * different pack collections to be selected, for example: minimal,
059: * default, all.
060: */
061: public Set<String> installGroups = new HashSet<String>();
062:
063: /** All packs in the same excludeGroup are mutually exclusive. The excludeGroup
064: * is a string and serves are key identifying each group of mutually
065: * exclusive packs.
066: */
067: public String excludeGroup = "";
068:
069: /** The group the pack is associated with. The pack group identifies
070: * packs with common functionality to allow for grouping of packs in a
071: * tree in the TargetPanel for example.
072: */
073: public String group;
074:
075: /** The pack description. */
076: public String description;
077:
078: /** The target operation system of this pack */
079: public List<OsConstraint> osConstraints = null;
080:
081: /** Condition for this pack **/
082: private String condition;
083:
084: /** The list of packs this pack depends on */
085: public List<String> dependencies = null;
086:
087: /** Reverse dependencies(childs) */
088: public List<String> revDependencies = null;
089:
090: /** True if the pack is required. */
091: public boolean required;
092:
093: /** The bumber of bytes contained in the pack. */
094: public long nbytes;
095:
096: /** Whether this pack is suggested (preselected for installation). */
097: public boolean preselected;
098:
099: /** Parent pack name to display it in the TreePacksPanel (optional)*/
100: public String parent;
101:
102: /** The color of the node. This is used for the dependency graph algorithms */
103: public int color;
104:
105: /** The id to use if we want to obtain this pack's image resource */
106: public String packImgId;
107:
108: /** white colour */
109: public final static int WHITE = 0;
110:
111: /** grey colour */
112: public final static int GREY = 1;
113:
114: /** black colour */
115: public final static int BLACK = 2;
116:
117: /**
118: * The constructor.
119: *
120: * @param name The pack name.
121: * @param id The id of the pack which is used e.g. for I18N
122: * @param description The pack description.
123: * @param osConstraints the OS constraint (or null for any OS)
124: * @param dependencies dependencies of this pack
125: * @param required Indicates wether the pack is required or not.
126: * @param preselected This pack will be selected automatically.
127: * @param loose Flag for store files of this pack outside the installation jar file
128: * @param excludegroup associated exclude group
129: * @param uninstall If true, pack must be uninstalled.
130: */
131: public Pack(String name, String id, String description,
132: List<OsConstraint> osConstraints,
133: List<String> dependencies, boolean required,
134: boolean preselected, boolean loose, String excludegroup,
135: boolean uninstall) {
136: this .name = name;
137: this .id = id;
138: this .description = description;
139: this .osConstraints = osConstraints;
140: this .dependencies = dependencies;
141: this .required = required;
142: this .preselected = preselected;
143: this .loose = loose;
144: this .excludeGroup = excludegroup;
145: this .uninstall = uninstall;
146: this .packImgId = null;
147: this .condition = null;
148: nbytes = 0;
149: color = PackInfo.WHITE;
150: }
151:
152: /**
153: * To a String (usefull for JLists).
154: *
155: * @return The String representation of the pack.
156: */
157: public String toString() {
158: return name + " (" + description + ")";
159: }
160:
161: /** getter method for dependencies
162: * @return the dependencies list*/
163: public List<String> getDependencies() {
164: return dependencies;
165: }
166:
167: /**
168: * This adds a reverse dependency. With a reverse dependency we imply a child dependency or the
169: * dependents on this pack
170: *
171: * @param name0 The name of the pack that depents to this pack
172: */
173: public void addRevDep(String name0) {
174: if (revDependencies == null)
175: revDependencies = new ArrayList<String>();
176: revDependencies.add(name0);
177: }
178:
179: /**
180: * Creates a text list of all the packs it depend on
181: *
182: * @return the created text
183: */
184: public String depString() {
185: String text = "";
186: if (dependencies == null)
187: return text;
188: String name0;
189: for (int i = 0; i < dependencies.size() - 1; i++) {
190: name0 = dependencies.get(i);
191: text += name0 + ",";
192: }
193: name0 = dependencies.get(dependencies.size() - 1);
194: text += name0;
195: return text;
196:
197: }
198:
199: /** Used of conversions. */
200: private final static double KILOBYTES = 1024.0;
201:
202: /** Used of conversions. */
203: private final static double MEGABYTES = 1024.0 * 1024.0;
204:
205: /** Used of conversions. */
206: private final static double GIGABYTES = 1024.0 * 1024.0 * 1024.0;
207:
208: /** Used of conversions. */
209: private final static DecimalFormat formatter = new DecimalFormat(
210: "#,###.##");
211:
212: /**
213: * Convert bytes into appropiate mesaurements.
214: *
215: * @param bytes A number of bytes to convert to a String.
216: * @return The String-converted value.
217: */
218: public static String toByteUnitsString(long bytes) {
219: if (bytes < KILOBYTES)
220: return String.valueOf(bytes) + " bytes";
221: else if (bytes < (MEGABYTES)) {
222: double value = bytes / KILOBYTES;
223: return formatter.format(value) + " KB";
224: } else if (bytes < (GIGABYTES)) {
225: double value = bytes / MEGABYTES;
226: return formatter.format(value) + " MB";
227: } else {
228: double value = bytes / GIGABYTES;
229: return formatter.format(value) + " GB";
230: }
231: }
232:
233: /**
234: * @return the condition
235: */
236: public String getCondition() {
237: return this .condition;
238: }
239:
240: /**
241: * @param condition the condition to set
242: */
243: public void setCondition(String condition) {
244: this .condition = condition;
245: }
246:
247: public boolean hasCondition() {
248: return this.condition != null;
249: }
250: }
|