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 2004 Chadwick McHenry 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.compiler; 023 024import java.io.File; 025import java.io.FileNotFoundException; 026import java.util.ArrayList; 027import java.util.HashMap; 028import java.util.List; 029import java.util.Map; 030import java.util.Set; 031 032import com.izforge.izpack.ExecutableFile; 033import com.izforge.izpack.Pack; 034import com.izforge.izpack.PackFile; 035import com.izforge.izpack.ParsableFile; 036import com.izforge.izpack.UpdateCheck; 037 038/** 039 * Temporary holding place for Pack information as the Packager is built. The packager is used by 040 * the compiler to collect info about an installer, and finally create the actual installer files. 041 * 042 * @author Chadwick McHenry 043 */ 044public class PackInfo 045{ 046 047 /** The pack object serialized in the installer. */ 048 private Pack pack; 049 050 /** The color of the node. This is used for the dependency graph algorithms */ 051 public int colour; 052 053 /** white colour */ 054 public final static int WHITE = 0; 055 056 /** grey colour */ 057 public final static int GREY = 1; 058 059 /** black colour */ 060 public final static int BLACK = 2; 061 062 /** Files of the Pack. */ 063 private Map files = new HashMap(); 064 065 /** Parsables files in this Pack. */ 066 private List parsables = new ArrayList(); 067 068 /** Executable files in this Pack. */ 069 private List executables = new ArrayList(); 070 071 /** Update check specifications in this Pack. */ 072 private List updateChecks = new ArrayList(); 073 074 /** Constructor with required info. */ 075 protected PackInfo(String name, String id, String description, boolean required, boolean loose) 076 { 077 pack = new Pack(name, id, description, null, null, required, true, loose); 078 colour = PackInfo.WHITE; 079 } 080 081 /*********************************************************************************************** 082 * Attributes of the Pack 083 **********************************************************************************************/ 084 085 public void setDependencies(List dependencies) 086 { 087 pack.dependencies = dependencies; 088 } 089 090 public void setOsConstraints(List osConstraints) 091 { 092 pack.osConstraints = osConstraints; 093 } 094 095 public List getOsConstraints(List osConstraints) 096 { 097 return pack.osConstraints; 098 } 099 100 public void setPreselected(boolean preselected) 101 { 102 pack.preselected = preselected; 103 } 104 105 public boolean isPreselected() 106 { 107 return pack.preselected; 108 } 109 110 /** 111 * Get the pack group. 112 * @return Get the pack group, null if there is no group. 113 */ 114 public String getGroup() 115 { 116 return pack.group; 117 } 118 /** 119 * Set the pack group. 120 * @param group the group to associate the pack with. 121 */ 122 public void setGroup(String group) 123 { 124 pack.group = group; 125 } 126 127 /** 128 * Add an install group to the pack. 129 * @param group the install group to associate the pack with. 130 */ 131 public void addInstallGroup(String group) 132 { 133 pack.installGroups.add(group); 134 } 135 /** 136 * See if the pack is associated with the given install group. 137 * @param group the install group name to check 138 * @return true if the given group is associated with the pack. 139 */ 140 public boolean hasInstallGroup(String group) 141 { 142 return pack.installGroups.contains(group); 143 } 144 /** 145 * Get the install group names. 146 * @return Set<String> for the install groups 147 */ 148 public Set getInstallGroups() 149 { 150 return pack.installGroups; 151 } 152 153 public Pack getPack() 154 { 155 return pack; 156 } 157 158 /*********************************************************************************************** 159 * Public methods to add data to the Installer being packed 160 **********************************************************************************************/ 161 162 /** 163 * Add a file or directory to be installed. 164 * 165 * @param file the file or basedir to be installed. 166 * @param targetfile path file will be installed to. 167 * @param osList the target operation system(s) of this pack. 168 * @param override what to do if the file already exists when installing 169 * 170 * @throws FileNotFoundException if the file specified does not exist. The file is not read 171 * until the {@link Packager#createInstaller} is invoked, thus a FileNotFoundEception will occur 172 * then, if the file is deleted in between. 173 */ 174 /* 175 * public void addFile(File file, String targetfile, List osList, int override) throws 176 * FileNotFoundException { addFile( file,targetfile, osList, override, null); } 177 * 178 * 179 * /** Add a file or directory to be installed. 180 * 181 * @param file the file or basedir to be installed. @param targetfile path file will be 182 * installed to. @param osList the target operation system(s) of this pack. @param override what 183 * to do if the file already exists when installing @param additionals Map which contains 184 * additional data 185 * 186 * @throws FileNotFoundException if the file specified does not exist. The file is not read 187 * until the {@link Packager#createInstaller} is invoked, thus a FileNotFoundEception will occur 188 * then, if the file is deleted in between. 189 */ 190 public void addFile(File file, String targetfile, List osList, int override, Map additionals) 191 throws FileNotFoundException 192 { 193 if (!file.exists()) throw new FileNotFoundException(file.toString()); 194 195 PackFile packFile = new PackFile(file, targetfile, osList, override, additionals); 196 files.put(packFile, file); 197 } 198 199 /** Set of PackFile objects for this Pack. */ 200 public Set getPackFiles() 201 { 202 return files.keySet(); 203 } 204 205 /** 206 * The file described by the specified PackFile. Returns <tt>null</tt> if the PackFile did not 207 * come from the set returned by {@link #getPackFiles()}. 208 */ 209 public File getFile(PackFile packFile) 210 { 211 return (File) files.get(packFile); 212 } 213 214 /** 215 * Parsable files have variables substituted after installation. 216 */ 217 public void addParsable(ParsableFile parsable) 218 { 219 parsables.add(parsable); 220 } 221 222 /** List of parsables for this Pack. */ 223 public List getParsables() 224 { 225 return parsables; 226 } 227 228 /** 229 * Executables files have their executable flag set, may be executed, and optionally, deleted 230 * when finished executing. 231 */ 232 public void addExecutable(ExecutableFile executable) 233 { 234 executables.add(executable); 235 } 236 237 /** List of parsables for this Pack. */ 238 public List getExecutables() 239 { 240 return executables; 241 } 242 243 /** 244 * Executables files have their executable flag set, may be executed, and optionally, deleted 245 * when finished executing. 246 */ 247 public void addUpdateCheck(UpdateCheck updateCheck) 248 { 249 updateChecks.add(updateCheck); 250 } 251 252 /** List of update checks for this Pack. */ 253 public List getUpdateChecks() 254 { 255 return updateChecks; 256 } 257 258 /** 259 * The packs that this file depends on 260 */ 261 public void addDependency(String dependency) 262 { 263 if (pack.dependencies == null) 264 { 265 pack.dependencies = new ArrayList(); 266 } 267 pack.dependencies.add(dependency); 268 } 269 270 public List getDependencies() 271 { 272 return pack.dependencies; 273 } 274 275 public String toString() 276 { 277 return pack.name; 278 } 279}