1
16package org.tp23.antinstaller;
17
18import java.io.File;
19import java.io.FileOutputStream;
20import java.util.Iterator;
21import java.util.List;
22import java.util.Properties;
23
24import org.tp23.antinstaller.input.ConditionalField;
25import org.tp23.antinstaller.input.InputField;
26import org.tp23.antinstaller.input.OutputField;
27import org.tp23.antinstaller.input.SecretPropertyField;
28import org.tp23.antinstaller.page.Page;
29
30
31
32
38public class DefaultPropertiesFileRenderer
39 implements PropertiesFileRenderer {
40
41 public DefaultPropertiesFileRenderer() {
42 }
43
44 public void renderProperties(InstallerContext ctx, File baseDir){
45 Installer installer = ctx.getInstaller();
46 Page[] completedPages = installer.getPages();
47 Properties props = new Properties();
48 props.put(FILE_ROOT_PROPERTY, baseDir.getAbsolutePath());
49 props.setProperty(INSTALLER_VERSION_PROPERTY,
50 ctx.getInstaller().getVersion());
51
52
53 for (int i = 0; i < completedPages.length; i++) {
54 OutputField[] fields = completedPages[i].getOutputField();
55
56 retrieveProperties( fields, props );
57
58 List targets = completedPages[i].getTargets(ctx);
60 if(targets.size() > 0){
61 Iterator iterator = targets.iterator();
62 StringBuffer targetProperty = new StringBuffer();
63 while (iterator.hasNext()) {
64 String target = (String) iterator.next();
65 targetProperty.append(target).append(",");
66 }
67 props.put(completedPages[i].getName() + TARGETS_SUFFIX, targetProperty.toString());
68 }
69
70 }
71 try {
72 File antInstallProperties = new File(baseDir.getAbsolutePath(), PROPERTIES_FILE_NAME);
73 FileOutputStream fos = new FileOutputStream(antInstallProperties);
74 props.store(fos,
75 "Ant Installer - AutoGenerated properties");
76 fos.close();
77 }
78 catch (Throwable ex) {
79 if(ctx.getInstaller().isVerbose()) {
80 ctx.log(ex);
81 }
82 }
84 }
85
86 private void retrieveProperties( OutputField[] fields, Properties props ) {
87 for (int f = 0; f < fields.length; f++) {
88 if (fields[f] instanceof SecretPropertyField) {
89 }
92 else if( fields[f] instanceof ConditionalField ) {
93 ConditionalField confField = (ConditionalField) fields[f];
94 retrieveProperties( confField.getFields(), props );
95 }
96 else if (fields[f] instanceof InputField) {
97 InputField field = (InputField)fields[f];
98
99 String result = field.getInputResult();
00 if( result == null ) {
02 result = "";
03 }
04 props.put(field.getProperty(), result);
05 }
06 }
07 }
08}
09