KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > compiler > PackInfo


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2004 Chadwick McHenry
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.compiler;
23
24 import java.io.File JavaDoc;
25 import java.io.FileNotFoundException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.Set JavaDoc;
31
32 import com.izforge.izpack.ExecutableFile;
33 import com.izforge.izpack.Pack;
34 import com.izforge.izpack.PackFile;
35 import com.izforge.izpack.ParsableFile;
36 import com.izforge.izpack.UpdateCheck;
37
38 /**
39  * Temporary holding place for Pack information as the Packager is built. The packager is used by
40  * the compiler to collect info about an installer, and finally create the actual installer files.
41  *
42  * @author Chadwick McHenry
43  */

44 public class PackInfo
45 {
46
47     /** The pack object serialized in the installer. */
48     private Pack pack;
49
50     /** The color of the node. This is used for the dependency graph algorithms */
51     public int colour;
52
53     /** white colour */
54     public final static int WHITE = 0;
55
56     /** grey colour */
57     public final static int GREY = 1;
58
59     /** black colour */
60     public final static int BLACK = 2;
61
62     /** Files of the Pack. */
63     private Map JavaDoc files = new HashMap JavaDoc();
64
65     /** Parsables files in this Pack. */
66     private List JavaDoc parsables = new ArrayList JavaDoc();
67
68     /** Executable files in this Pack. */
69     private List JavaDoc executables = new ArrayList JavaDoc();
70
71     /** Update check specifications in this Pack. */
72     private List JavaDoc updateChecks = new ArrayList JavaDoc();
73
74     /** Constructor with required info.
75      * @param name name of the pack
76      * @param id id of the pack e.g. to resolve I18N
77      * @param description descripton in English
78      * @param required pack is required or not
79      * @param loose files of pack should be stored separatly or not
80      * @param excludegroup name of the exclude group
81      */

82     protected PackInfo(String JavaDoc name, String JavaDoc id, String JavaDoc description, boolean required, boolean loose, String JavaDoc excludegroup)
83     {
84         boolean ispreselected = (excludegroup == null) ? true : false;
85         pack = new Pack(name, id, description, null, null, required, ispreselected, loose, excludegroup);
86         colour = PackInfo.WHITE;
87     }
88
89     /***********************************************************************************************
90      * Attributes of the Pack
91      **********************************************************************************************/

92
93     public void setDependencies(List JavaDoc dependencies)
94     {
95         pack.dependencies = dependencies;
96     }
97     
98     /**
99      * Set the name of the group which contains the packs which exludes mutual.
100      * @param group name of the mutal exclude group
101      */

102     public void setExcludeGroup(String JavaDoc group)
103     {
104         pack.excludeGroup = group;
105     }
106     
107     public void setOsConstraints(List JavaDoc osConstraints)
108     {
109         pack.osConstraints = osConstraints;
110     }
111
112     public List JavaDoc getOsConstraints(List JavaDoc osConstraints)
113     {
114         return pack.osConstraints;
115     }
116
117     public void setPreselected(boolean preselected)
118     {
119         pack.preselected = preselected;
120     }
121
122     public boolean isPreselected()
123     {
124         return pack.preselected;
125     }
126
127     /**
128      * Get the pack group.
129      * @return Get the pack group, null if there is no group.
130      */

131     public String JavaDoc getGroup()
132     {
133         return pack.group;
134     }
135     /**
136      * Set the pack group.
137      * @param group the group to associate the pack with.
138      */

139     public void setGroup(String JavaDoc group)
140     {
141         pack.group = group;
142     }
143
144     /**
145      * Add an install group to the pack.
146      * @param group the install group to associate the pack with.
147      */

148     public void addInstallGroup(String JavaDoc group)
149     {
150         pack.installGroups.add(group);
151     }
152     /**
153      * See if the pack is associated with the given install group.
154      * @param group the install group name to check
155      * @return true if the given group is associated with the pack.
156      */

157     public boolean hasInstallGroup(String JavaDoc group)
158     {
159         return pack.installGroups.contains(group);
160     }
161     /**
162      * Get the install group names.
163      * @return Set<String> for the install groups
164      */

165     public Set JavaDoc getInstallGroups()
166     {
167         return pack.installGroups;
168     }
169
170     public Pack getPack()
171     {
172         return pack;
173     }
174
175     /***********************************************************************************************
176      * Public methods to add data to the Installer being packed
177      **********************************************************************************************/

178
179     /**
180      * Add a file or directory to be installed.
181      *
182      * @param file the file or basedir to be installed.
183      * @param targetfile path file will be installed to.
184      * @param osList the target operation system(s) of this pack.
185      * @param override what to do if the file already exists when installing
186      *
187      * @throws FileNotFoundException if the file specified does not exist. The file is not read
188      * until the {@link Packager#createInstaller} is invoked, thus a FileNotFoundEception will occur
189      * then, if the file is deleted in between.
190      */

191     /*
192      * public void addFile(File file, String targetfile, List osList, int override) throws
193      * FileNotFoundException { addFile( file,targetfile, osList, override, null); }
194      *
195      *
196      * /** Add a file or directory to be installed.
197      *
198      * @param file the file or basedir to be installed. @param targetfile path file will be
199      * installed to. @param osList the target operation system(s) of this pack. @param override what
200      * to do if the file already exists when installing @param additionals Map which contains
201      * additional data
202      *
203      * @throws FileNotFoundException if the file specified does not exist. The file is not read
204      * until the {@link Packager#createInstaller} is invoked, thus a FileNotFoundEception will occur
205      * then, if the file is deleted in between.
206      */

207     public void addFile(File JavaDoc baseDir, File JavaDoc file, String JavaDoc targetfile, List JavaDoc osList, int override, Map JavaDoc additionals)
208             throws FileNotFoundException JavaDoc
209     {
210         if (!file.exists()) throw new FileNotFoundException JavaDoc(file.toString());
211
212         PackFile packFile = new PackFile(baseDir, file, targetfile, osList, override, additionals);
213         files.put(packFile, file);
214     }
215
216     /** Set of PackFile objects for this Pack. */
217     public Set JavaDoc getPackFiles()
218     {
219         return files.keySet();
220     }
221
222     /**
223      * The file described by the specified PackFile. Returns <tt>null</tt> if the PackFile did not
224      * come from the set returned by {@link #getPackFiles()}.
225      */

226     public File JavaDoc getFile(PackFile packFile)
227     {
228         return (File JavaDoc) files.get(packFile);
229     }
230
231     /**
232      * Parsable files have variables substituted after installation.
233      */

234     public void addParsable(ParsableFile parsable)
235     {
236         parsables.add(parsable);
237     }
238
239     /** List of parsables for this Pack. */
240     public List JavaDoc getParsables()
241     {
242         return parsables;
243     }
244
245     /**
246      * Executables files have their executable flag set, may be executed, and optionally, deleted
247      * when finished executing.
248      */

249     public void addExecutable(ExecutableFile executable)
250     {
251         executables.add(executable);
252     }
253
254     /** List of parsables for this Pack. */
255     public List JavaDoc getExecutables()
256     {
257         return executables;
258     }
259
260     /**
261      * Executables files have their executable flag set, may be executed, and optionally, deleted
262      * when finished executing.
263      */

264     public void addUpdateCheck(UpdateCheck updateCheck)
265     {
266         updateChecks.add(updateCheck);
267     }
268
269     /** List of update checks for this Pack. */
270     public List JavaDoc getUpdateChecks()
271     {
272         return updateChecks;
273     }
274
275     /**
276      * The packs that this file depends on
277      */

278     public void addDependency(String JavaDoc dependency)
279     {
280         if (pack.dependencies == null)
281         {
282             pack.dependencies = new ArrayList JavaDoc();
283         }
284         pack.dependencies.add(dependency);
285     }
286     
287     public List JavaDoc getDependencies()
288     {
289         return pack.dependencies;
290     }
291     
292     public String JavaDoc toString()
293     {
294         return pack.name;
295     }
296 }
297
Popular Tags