Index: src/build.xml
===================================================================
--- src/build.xml (revision 2615)
+++ src/build.xml (working copy)
@@ -591,9 +591,11 @@
+
+
@@ -618,6 +620,7 @@
+
@@ -655,6 +658,7 @@
+
@@ -696,6 +700,7 @@
+
Index: src/lib/com/izforge/izpack/installer/ConsoleInstaller.java
===================================================================
--- src/lib/com/izforge/izpack/installer/ConsoleInstaller.java (revision 0)
+++ src/lib/com/izforge/izpack/installer/ConsoleInstaller.java (revision 0)
@@ -0,0 +1,266 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2007 Dennis Reil
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.installer;
+
+import java.io.FileReader;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Properties;
+
+import com.izforge.izpack.LocaleDatabase;
+import com.izforge.izpack.Panel;
+import com.izforge.izpack.util.Debug;
+import com.izforge.izpack.util.Housekeeper;
+import com.izforge.izpack.util.OsConstraint;
+import com.izforge.izpack.util.VariableSubstitutor;
+
+/**
+ * Runs the console installer
+ *
+ * @author Mounir el hajj
+ */
+public class ConsoleInstaller extends InstallerBase
+{
+
+ private AutomatedInstallData installdata = new AutomatedInstallData();
+
+ private boolean result = false;
+
+ private Properties properties;
+
+ private PrintWriter printWriter;
+
+ public ConsoleInstaller() throws Exception
+ {
+ super();
+ loadInstallData(this.installdata);
+ this.installdata.localeISO3 = "eng";
+ InputStream in = getClass().getResourceAsStream(
+ "/langpacks/" + this.installdata.localeISO3 + ".xml");
+ this.installdata.langpack = new LocaleDatabase(in);
+ this.installdata.setVariable(ScriptParser.ISO3_LANG, this.installdata.localeISO3);
+ ResourceManager.create(this.installdata);
+ loadConditions(installdata);
+ loadInstallerRequirements();
+ loadDynamicVariables();
+ if (!checkInstallerRequirements(installdata))
+ {
+ Debug.log("not all installerconditions are fulfilled.");
+ return;
+ }
+ addCustomLangpack(installdata);
+ }
+
+ protected void iterateAndPerformAction(String strAction) throws Exception
+ {
+ if (!checkInstallerRequirements(this.installdata))
+ {
+ Debug.log("not all installerconditions are fulfilled.");
+ return;
+ }
+ Debug.log("[ Starting console installation ] " + strAction);
+
+ try
+ {
+ this.result = true;
+ Iterator panelsIterator = this.installdata.panelsOrder.iterator();
+ this.installdata.curPanelNumber = -1;
+ while (panelsIterator.hasNext())
+ {
+ Panel p = (Panel) panelsIterator.next();
+ this.installdata.curPanelNumber++;
+ String praefix = "com.izforge.izpack.panels.";
+ if (p.className.compareTo(".") > -1)
+ {
+ praefix = "";
+ }
+ if (!OsConstraint.oneMatchesCurrentSystem(p.osConstraints))
+ {
+ continue;
+ }
+ String panelClassName = p.className;
+ String consoleHelperClassName = praefix + panelClassName + "ConsoleHelper";
+ Class consoleHelperClass = null;
+
+ Debug.log("ConsoleHelper:" + consoleHelperClassName);
+ try
+ {
+
+ consoleHelperClass = (Class) Class
+ .forName(consoleHelperClassName);
+
+ }
+ catch (ClassNotFoundException e)
+ {
+ Debug.log("ClassNotFoundException-skip :" + consoleHelperClassName);
+ continue;
+ }
+ PanelConsole consoleHelperInstance = null;
+ if (consoleHelperClass != null)
+ {
+ try
+ {
+ Debug.log("Instantiate :" + consoleHelperClassName);
+ refreshDynamicVariables(
+ new VariableSubstitutor(installdata.getVariables()), installdata);
+ consoleHelperInstance = consoleHelperClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ Debug.log("ERROR: no default constructor for " + consoleHelperClassName
+ + ", skipping...");
+ continue;
+ }
+ }
+
+ if (consoleHelperInstance != null)
+ {
+ try
+ {
+ Debug.log("consoleHelperInstance." + strAction + ":"
+ + consoleHelperClassName + " entered.");
+ boolean bActionResult = true;
+ boolean bIsConditionFulfilled = true;
+ String strCondition = p.getCondition();
+ if (strCondition != null)
+ {
+ bIsConditionFulfilled = installdata.getRules().isConditionTrue(
+ strCondition);
+ }
+
+ if (strAction.equals("doInstall") &&bIsConditionFulfilled)
+ {
+ bActionResult = consoleHelperInstance.runConsole(this.installdata);
+ }
+ else if (strAction.equals("doGeneratePropertiesFile"))
+ {
+ bActionResult = consoleHelperInstance.runGeneratePropertiesFile(
+ this.installdata, this.printWriter);
+ }
+ else if (strAction.equals("doInstallFromPropertiesFile") &&bIsConditionFulfilled)
+ {
+ bActionResult = consoleHelperInstance.runConsoleFromPropertiesFile(
+ this.installdata, this.properties);
+ }
+ if (!bActionResult)
+ {
+ this.result = false;
+ return;
+ }
+ else
+ {
+ Debug.log("consoleHelperInstance." + strAction + ":"
+ + consoleHelperClassName + " successfully done.");
+ }
+ }
+ catch (Exception e)
+ {
+ Debug.log("ERROR: console installation failed for panel " + panelClassName);
+ e.printStackTrace();
+ this.result = false;
+ }
+
+ }
+
+ }
+
+ if (this.result)
+ {
+ System.out.println("[ Console installation done ]");
+ }
+ else
+ {
+ System.out.println("[ Console installation FAILED! ]");
+ }
+ }
+ catch (Exception e)
+ {
+ this.result = false;
+ System.err.println(e.toString());
+ e.printStackTrace();
+ System.out.println("[ Console installation FAILED! ]");
+ }
+
+ }
+
+ protected void doInstall() throws Exception
+ {
+ try
+ {
+ iterateAndPerformAction("doInstall");
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+
+ finally
+ {
+ Housekeeper.getInstance().shutDown(this.result ? 0 : 1);
+ }
+ }
+
+ protected void doGeneratePropertiesFile(String strFile) throws Exception
+ {
+ try
+ {
+ this.printWriter = new PrintWriter(strFile);
+ iterateAndPerformAction("doGeneratePropertiesFile");
+ this.printWriter.flush();
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+
+ finally
+ {
+ this.printWriter.close();
+ Housekeeper.getInstance().shutDown(this.result ? 0 : 1);
+ }
+
+ }
+
+ protected void doInstallFromPropertiesFile(String strFile) throws Exception
+ {
+ FileReader fileReader = null;
+ try
+ {
+ fileReader = new FileReader(strFile);
+ this.properties = new Properties();
+ properties.load(fileReader);
+ iterateAndPerformAction("doInstallFromPropertiesFile");
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ finally
+ {
+ if (fileReader != null)
+ {
+ fileReader.close();
+ }
+ Housekeeper.getInstance().shutDown(this.result ? 0 : 1);
+ }
+ }
+}
Index: src/lib/com/izforge/izpack/installer/Installer.java
===================================================================
--- src/lib/com/izforge/izpack/installer/Installer.java (revision 2643)
+++ src/lib/com/izforge/izpack/installer/Installer.java (working copy)
@@ -21,60 +21,68 @@
package com.izforge.izpack.installer;
+import java.util.Date;
+
import com.izforge.izpack.util.Debug;
import com.izforge.izpack.util.StringTool;
-import java.util.Date;
-
/**
* The program entry point. Selects between GUI and text install modes.
*
* @author Jonathan Halliday
*/
-public class Installer
-{
+public class Installer {
- /**
- * The main method (program entry point).
- *
- * @param args The arguments passed on the command-line.
- */
- public static void main(String[] args)
- {
- Debug.log(" - Logger initialized at '" + new Date(System.currentTimeMillis()) + "'.");
+ /*
+ * The main method (program entry point).
+ *
+ * @param args The arguments passed on the command-line.
+ */
+ public static void main(String[] args) {
+ Debug.log(" - Logger initialized at '" + new Date(System.currentTimeMillis()) + "'.");
- Debug.log(" - commandline args: " + StringTool.stringArrayToSpaceSeparatedString(args));
+ Debug.log(" - commandline args: " + StringTool.stringArrayToSpaceSeparatedString(args));
- // OS X tweakings
- if (System.getProperty("mrj.version") != null)
- {
- System.setProperty("com.apple.mrj.application.apple.menu.about.name", "IzPack");
- System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
- System.setProperty("com.apple.mrj.application.live-resize", "true");
- }
+ // OS X tweakings
+ if (System.getProperty("mrj.version") != null) {
+ System.setProperty("com.apple.mrj.application.apple.menu.about.name", "IzPack");
+ System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
+ System.setProperty("com.apple.mrj.application.live-resize", "true");
+ }
- try
- {
- if (args.length == 0)
- {
- // can't load the GUIInstaller class on headless machines,
- // so we use Class.forName to force lazy loading.
- Class.forName("com.izforge.izpack.installer.GUIInstaller").newInstance();
- }
- else
- {
- AutomatedInstaller ai = new AutomatedInstaller(args[0]);
- // this method will also exit!
- ai.doInstall();
- }
- }
- catch (Exception e)
- {
- System.err.println("- ERROR -");
- System.err.println(e.toString());
- e.printStackTrace();
- System.exit(1);
- }
- }
-
+ try {
+ if (args.length == 0) {
+ // can't load the GUIInstaller class on headless machines,
+ // so we use Class.forName to force lazy loading.
+ Class.forName("com.izforge.izpack.installer.GUIInstaller").newInstance();
+ } else if (args.length == 1) {
+ if ("-console".equals(args[0].trim())) {
+ Debug.log("starting in console mode");
+ ConsoleInstaller consoleInstaller = new ConsoleInstaller();
+ consoleInstaller.doInstall();
+ } else {
+ AutomatedInstaller ai = new AutomatedInstaller(args[0]);
+ ai.doInstall();
+ }
+ } else if (args.length == 2) {
+ if ("-options-template".equals(args[0].trim())) {
+ Debug.log("Generating properties file");
+ ConsoleInstaller consoleInstaller = new ConsoleInstaller();
+ consoleInstaller.doGeneratePropertiesFile(args[1]);
+ }
+ if ("-options".equals(args[0].trim())) {
+ Debug.log("Installing from properties file");
+ ConsoleInstaller consoleInstaller = new ConsoleInstaller();
+ consoleInstaller.doInstallFromPropertiesFile(args[1]);
+ } else {
+ System.out.println("not a valid option!!!!");
+ }
+ }
+ } catch (Exception e) {
+ System.err.println("- ERROR -");
+ System.err.println(e.toString());
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
}
Index: src/lib/com/izforge/izpack/installer/PanelConsole.java
===================================================================
--- src/lib/com/izforge/izpack/installer/PanelConsole.java (revision 0)
+++ src/lib/com/izforge/izpack/installer/PanelConsole.java (revision 0)
@@ -0,0 +1,63 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2003 Jonathan Halliday
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.izforge.izpack.installer;
+
+import java.io.PrintWriter;
+import java.util.Properties;
+
+/**
+ * Defines the Interface that must be implemented for running Panels in console mode.
+ *
+ * Implementing classes MUST NOT link against awt/swing classes. Thus the Panels cannot implement
+ * this interface directly, they should use e.g. helper classes instead.
+ *
+ * @author Mounir El Hajj
+ *
+ */
+
+public interface PanelConsole
+{
+
+ /**
+ * Asks the panel to return all inputed fields/variables in a string with a properties file
+ * style
+ *
+ * @param installData The installation data
+ */
+ public boolean runGeneratePropertiesFile(AutomatedInstallData installData, PrintWriter printWriter);
+
+ /**
+ * Asks the panel to run and do its work, given a set of properties to use as variables
+ *
+ * @param installData The installation data
+ * @param p The the properties
+ */
+ public boolean runConsoleFromPropertiesFile(AutomatedInstallData installData, Properties p);
+
+ /**
+ * Asks the panel to run in interactive console mode
+ *
+ * @param installData The installation data *
+ */
+ public boolean runConsole(AutomatedInstallData installData);
+
+}
Index: src/lib/com/izforge/izpack/installer/PanelConsoleHelper.java
===================================================================
--- src/lib/com/izforge/izpack/installer/PanelConsoleHelper.java (revision 0)
+++ src/lib/com/izforge/izpack/installer/PanelConsoleHelper.java (revision 0)
@@ -0,0 +1,65 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2003 Jonathan Halliday
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.installer;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * Abstract class implementing basic functions needed by all panel console helpers.
+ *
+ * @author Mounir El Hajj
+ */
+abstract public class PanelConsoleHelper
+{
+
+
+
+ public int askEndOfConsolePanel()
+ {
+ try
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ while (true)
+ {
+ System.out.println("press 1 to continue, 2 to quit, 3 to redisplay");
+ String strIn = br.readLine();
+ if (strIn.equals("1"))
+ {
+ return 1;
+ }
+ else if (strIn.equals("2"))
+ {
+ return 2;
+ }
+ else if (strIn.equals("3")) { return 3; }
+ }
+
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ return 2;
+ }
+
+}
Index: src/lib/com/izforge/izpack/panels/FinishPanelConsoleHelper.java
===================================================================
--- src/lib/com/izforge/izpack/panels/FinishPanelConsoleHelper.java (revision 0)
+++ src/lib/com/izforge/izpack/panels/FinishPanelConsoleHelper.java (revision 0)
@@ -0,0 +1,53 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2002 Jan Blok
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.panels;
+
+import java.io.PrintWriter;
+import java.util.Properties;
+
+import com.izforge.izpack.installer.AutomatedInstallData;
+import com.izforge.izpack.installer.PanelConsole;
+import com.izforge.izpack.installer.PanelConsoleHelper;
+/**
+ * Finish Panel console helper
+ *
+ * @author Mounir el hajj
+ */
+public class FinishPanelConsoleHelper extends PanelConsoleHelper implements PanelConsole {
+ public boolean runGeneratePropertiesFile(AutomatedInstallData installData,PrintWriter printWriter) {
+ return true;
+ }
+
+ public boolean runConsoleFromPropertiesFile(AutomatedInstallData installData, Properties p){
+ return true;
+ }
+
+ public boolean runConsole(AutomatedInstallData idata) {
+ if (idata.installSuccess) {
+ System.out.println("Install was successeful");
+ System.out.println("application installed on " + idata.getInstallPath());
+
+ } else {
+ System.out.println("Install Failed!!!");
+ }
+ return true;
+ }
+}
Index: src/lib/com/izforge/izpack/panels/HelloPanelConsoleHelper.java
===================================================================
--- src/lib/com/izforge/izpack/panels/HelloPanelConsoleHelper.java (revision 0)
+++ src/lib/com/izforge/izpack/panels/HelloPanelConsoleHelper.java (revision 0)
@@ -0,0 +1,92 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2002 Jan Blok
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.panels;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import com.izforge.izpack.Info;
+import com.izforge.izpack.installer.AutomatedInstallData;
+import com.izforge.izpack.installer.PanelConsole;
+import com.izforge.izpack.installer.PanelConsoleHelper;
+
+/**
+ * Hello Panel console helper
+ *
+ * @author Mounir el hajj
+ */
+public class HelloPanelConsoleHelper extends PanelConsoleHelper implements PanelConsole
+{
+
+ public boolean runConsoleFromPropertiesFile(AutomatedInstallData installData, Properties p)
+ {
+ return true;
+ }
+
+ public boolean runGeneratePropertiesFile(AutomatedInstallData installData,
+ PrintWriter printWriter)
+ {
+ return true;
+ }
+
+ public boolean runConsole(AutomatedInstallData idata)
+ {
+ String str;
+ str = idata.langpack.getString("HelloPanel.welcome1") + idata.info.getAppName() + " "
+ + idata.info.getAppVersion() + idata.langpack.getString("HelloPanel.welcome2");
+ System.out.println(str);
+ ArrayList authors = idata.info.getAuthors();
+ int size = authors.size();
+ if (size > 0)
+ {
+ str = idata.langpack.getString("HelloPanel.authors");
+
+ for (int i = 0; i < size; i++)
+ {
+ Info.Author a = authors.get(i);
+ String email = (a.getEmail() != null && a.getEmail().length() > 0) ? (" <"
+ + a.getEmail() + ">") : "";
+ System.out.println(" - " + a.getName() + email);
+ }
+
+ }
+
+ if (idata.info.getAppURL() != null)
+ {
+ str = idata.langpack.getString("HelloPanel.url") + idata.info.getAppURL();
+ System.out.println(str);
+ }
+ int i = askEndOfConsolePanel();
+ if (i == 1)
+ {
+ return true;
+ }
+ else if (i == 2)
+ {
+ return false;
+ }
+ else
+ {
+ return runConsole(idata);
+ }
+ }
+}
Index: src/lib/com/izforge/izpack/panels/InstallPanelConsoleHelper.java
===================================================================
--- src/lib/com/izforge/izpack/panels/InstallPanelConsoleHelper.java (revision 0)
+++ src/lib/com/izforge/izpack/panels/InstallPanelConsoleHelper.java (revision 0)
@@ -0,0 +1,139 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2002 Jan Blok
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.panels;
+
+import java.io.PrintWriter;
+import java.util.Properties;
+
+import com.izforge.izpack.installer.AutomatedInstallData;
+import com.izforge.izpack.installer.IUnpacker;
+import com.izforge.izpack.installer.PanelConsole;
+import com.izforge.izpack.installer.PanelConsoleHelper;
+import com.izforge.izpack.installer.UnpackerFactory;
+import com.izforge.izpack.util.AbstractUIHandler;
+import com.izforge.izpack.util.AbstractUIProgressHandler;
+/**
+ * Install Panel console helper
+ *
+ * @author Mounir el hajj
+ */
+public class InstallPanelConsoleHelper extends PanelConsoleHelper implements PanelConsole,
+ AbstractUIProgressHandler
+{
+
+ private int noOfPacks = 0;
+
+
+
+ public boolean runGeneratePropertiesFile(AutomatedInstallData installData,PrintWriter printWriter)
+ {
+ return true;
+ }
+
+ public boolean runConsoleFromPropertiesFile(AutomatedInstallData installData, Properties p)
+ {
+ return runConsole(installData);
+ }
+
+ public boolean runConsole(AutomatedInstallData idata)
+ {
+
+ IUnpacker unpacker = UnpackerFactory.getUnpacker(idata.info.getUnpackerClassName(), idata,
+ this);
+ Thread unpackerthread = new Thread(unpacker, "IzPack - Unpacker thread");
+ unpacker.setRules(idata.getRules());
+ unpackerthread.start();
+ boolean done = false;
+ while (!done && unpackerthread.isAlive())
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e)
+ {
+
+ }
+ }
+ return unpacker.getResult();
+
+ }
+
+
+ public void emitNotification(String message)
+ {
+ System.out.println(message);
+ }
+
+ public boolean emitWarning(String title, String message)
+ {
+ System.err.println("[ WARNING: " + message + " ]");
+
+ return true;
+ }
+
+ public void emitError(String title, String message)
+ {
+ System.err.println("[ ERROR: " + message + " ]");
+ }
+
+ public int askQuestion(String title, String question, int choices)
+ {
+ // don't know what to answer
+ return AbstractUIHandler.ANSWER_CANCEL;
+ }
+
+ public int askQuestion(String title, String question, int choices, int default_choice)
+ {
+ return default_choice;
+ }
+
+ public void startAction(String name, int no_of_steps)
+ {
+ System.out.println("[ Starting to unpack ]");
+ this.noOfPacks = no_of_steps;
+ }
+
+ public void stopAction()
+ {
+ System.out.println("[ Unpacking finished ]");
+ boolean done = true;
+ }
+
+ public void progress(int val, String msg)
+ {
+
+ }
+
+ public void nextStep(String packName, int stepno, int stepsize)
+ {
+ System.out.print("[ Processing package: " + packName + " (");
+ System.out.print(stepno);
+ System.out.print('/');
+ System.out.print(this.noOfPacks);
+ System.out.println(") ]");
+ }
+
+ public void setSubStepNo(int no_of_substeps)
+ {
+
+ }
+}
Index: src/lib/com/izforge/izpack/panels/TargetPanelConsoleHelper.java
===================================================================
--- src/lib/com/izforge/izpack/panels/TargetPanelConsoleHelper.java (revision 0)
+++ src/lib/com/izforge/izpack/panels/TargetPanelConsoleHelper.java (revision 0)
@@ -0,0 +1,113 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2002 Jan Blok
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.panels;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.Properties;
+
+import com.izforge.izpack.installer.AutomatedInstallData;
+import com.izforge.izpack.installer.PanelConsole;
+import com.izforge.izpack.installer.PanelConsoleHelper;
+import com.izforge.izpack.installer.ScriptParser;
+import com.izforge.izpack.util.VariableSubstitutor;
+/**
+ * The Target panel console helper class.
+ *
+ * @author Mounir El Hajj
+ */
+public class TargetPanelConsoleHelper extends PanelConsoleHelper implements PanelConsole
+{
+
+ public boolean runGeneratePropertiesFile(AutomatedInstallData installData,PrintWriter printWriter)
+ {
+ printWriter.println(ScriptParser.INSTALL_PATH + "=");
+ return true;
+ }
+
+ public boolean runConsoleFromPropertiesFile(AutomatedInstallData installData, Properties p)
+ {
+ String strTargetPath = p.getProperty(ScriptParser.INSTALL_PATH);
+ if (strTargetPath == null || "".equals(strTargetPath.trim()))
+ {
+ System.err.println("Inputting the target path is mandatory!!!!");
+ return false;
+ }
+ else
+ {
+ VariableSubstitutor vs = new VariableSubstitutor(installData.getVariables());
+ strTargetPath = vs.substitute(strTargetPath, null);
+ installData.setInstallPath(strTargetPath);
+ return true;
+ }
+ }
+
+ public boolean runConsole(AutomatedInstallData idata)
+ {
+
+ String strTargetPath = "";
+ String strDefaultPath = idata.getVariable("SYSTEM_user_dir"); // this is a special
+ // requirement to make the
+ // default path point to the
+ // current location
+ System.out.println("Select target path [" + strDefaultPath + "] ");
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ try
+ {
+ String strIn = br.readLine();
+ if (!strIn.trim().equals(""))
+ {
+ strTargetPath = strIn;
+ }
+ else
+ {
+ strTargetPath = strDefaultPath;
+ }
+ }
+ catch (IOException e)
+ {
+
+ e.printStackTrace();
+ }
+
+ VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
+
+ strTargetPath = vs.substitute(strTargetPath, null);
+
+ idata.setInstallPath(strTargetPath);
+ int i = askEndOfConsolePanel();
+ if (i == 1)
+ {
+ return true;
+ }
+ else if (i == 2)
+ {
+ return false;
+ }
+ else
+ {
+ return runConsole(idata);
+ }
+
+ }
+}
Index: src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java
===================================================================
--- src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (revision 0)
+++ src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (revision 0)
@@ -0,0 +1,465 @@
+/*
+ * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
+ *
+ * http://izpack.org/
+ * http://izpack.codehaus.org/
+ *
+ * Copyright 2002 Jan Blok
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.panels;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Vector;
+
+import com.izforge.izpack.Panel;
+import com.izforge.izpack.adaptator.IXMLElement;
+import com.izforge.izpack.installer.AutomatedInstallData;
+import com.izforge.izpack.installer.PanelConsole;
+import com.izforge.izpack.installer.PanelConsoleHelper;
+import com.izforge.izpack.util.Debug;
+import com.izforge.izpack.util.SpecHelper;
+import com.izforge.izpack.util.VariableSubstitutor;
+
+/**
+ * The user input panel console helper class.
+ *
+ * @author Mounir El Hajj
+ */
+public class UserInputPanelConsoleHelper extends PanelConsoleHelper implements PanelConsole
+{
+
+ protected int instanceNumber = 0;
+
+ private static int instanceCount = 0;
+
+ private static final String SPEC_FILE_NAME = "userInputSpec.xml";
+
+ private static final String NODE_ID = "panel";
+
+ private static final String INSTANCE_IDENTIFIER = "order";
+
+ protected static final String PANEL_IDENTIFIER = "id";
+
+ private static final String FIELD_NODE_ID = "field";
+
+ protected static final String ATTRIBUTE_CONDITIONID_NAME = "conditionid";
+
+ private static final String VARIABLE = "variable";
+
+ private static final String SET = "set";
+
+ private static final String TEXT = "txt";
+
+ private static final String SPEC = "spec";
+
+ private static final String TYPE_ATTRIBUTE = "type";
+
+ private static final String TEXT_FIELD = "text";
+
+ private static final String COMBO_FIELD = "combo";
+
+ private static final String STATIC_TEXT = "staticText";
+
+ private static final String CHOICE = "choice";
+
+ private static final String VALUE = "value";
+
+ private static final String RADIO_FIELD = "radio";
+
+ private static final String DESCRIPTION = "description";
+
+ private static final String TRUE = "true";
+
+ public List listInputs;
+
+ public UserInputPanelConsoleHelper()
+ {
+ instanceNumber = instanceCount++;
+ listInputs = new ArrayList();
+ }
+
+ public boolean runConsoleFromPropertiesFile(AutomatedInstallData installData, Properties p)
+ {
+ collectInputs(installData);
+ Iterator inputIterator = listInputs.iterator();
+ while (inputIterator.hasNext())
+ {
+ String strVariableName = ((Input) inputIterator.next()).strVariableName;
+ String strVariableValue = p.getProperty(strVariableName);
+ if (strVariableValue != null)
+ {
+ installData.setVariable(strVariableName, strVariableValue);
+ }
+ }
+ return true;
+ }
+
+ public boolean runGeneratePropertiesFile(AutomatedInstallData installData,
+ PrintWriter printWriter)
+ {
+ collectInputs(installData);
+ Iterator inputIterator = listInputs.iterator();
+ while (inputIterator.hasNext())
+ {
+ printWriter.println(((Input) inputIterator.next()).strVariableName + "=");
+ }
+ return true;
+ }
+
+ public boolean runConsole(AutomatedInstallData idata)
+ {
+ collectInputs(idata);
+ boolean status = true;
+ Iterator inputsIterator = listInputs.iterator();
+ while (inputsIterator.hasNext())
+ {
+ Input input = inputsIterator.next();
+ String text = input.strText;
+ if (text != null)
+ {
+ System.out.println(text);
+ }
+ if (TEXT_FIELD.equals(input.strFieldType))
+ {
+ status = status && processTextField(input, idata);
+ }
+ else if (COMBO_FIELD.equals(input.strFieldType)
+ || RADIO_FIELD.equals(input.strFieldType))
+ {
+ status = status && processComboRadioField(input, idata);
+ }
+
+ }
+
+ int i = askEndOfConsolePanel();
+ if (i == 1)
+ {
+ return true;
+ }
+ else if (i == 2)
+ {
+ return false;
+ }
+ else
+ {
+ return runConsole(idata);
+ }
+
+ }
+
+ public boolean collectInputs(AutomatedInstallData idata)
+ {
+ listInputs.clear();
+ IXMLElement data;
+ IXMLElement spec = null;
+ Vector specElements;
+ String attribute;
+ String dataID;
+ String panelid = ((Panel) idata.panelsOrder.get(idata.curPanelNumber)).getPanelid();
+ String instance = Integer.toString(instanceNumber);
+
+ SpecHelper specHelper = new SpecHelper();
+ try
+ {
+ specHelper.readSpec(specHelper.getResource(SPEC_FILE_NAME));
+ }
+ catch (Exception e1)
+ {
+
+ e1.printStackTrace();
+ }
+
+ specElements = specHelper.getSpec().getChildrenNamed(NODE_ID);
+ for (int i = 0; i < specElements.size(); i++)
+ {
+ data = specElements.elementAt(i);
+ attribute = data.getAttribute(INSTANCE_IDENTIFIER);
+ dataID = data.getAttribute(PANEL_IDENTIFIER);
+ if (((attribute != null) && instance.equals(attribute))
+ || ((dataID != null) && (panelid != null) && (panelid.equals(dataID))))
+ {
+ spec = data;
+ }
+ }
+ Vector fields = spec.getChildrenNamed(FIELD_NODE_ID);
+ for (int i = 0; i < fields.size(); i++)
+ {
+ IXMLElement field = fields.elementAt(i);
+ String conditionid = field.getAttribute(ATTRIBUTE_CONDITIONID_NAME);
+ if (conditionid != null)
+ {
+ // check if condition is fulfilled
+ if (!idata.getRules().isConditionTrue(conditionid, idata.getVariables()))
+ {
+ continue;
+ }
+ }
+ listInputs.add(getInputFromField(field));
+ }
+ return true;
+ }
+
+ boolean processTextField(Input input, AutomatedInstallData idata)
+ {
+ String variable = input.strVariableName;
+ String set;
+ String fieldText;
+ if ((variable == null) || (variable.length() == 0)) { return false; }
+
+ if (input.listChoices.size() == 0)
+ {
+ Debug.trace("Error: no spec element defined in file field");
+ return false;
+ }
+ set = input.strDefaultValue;
+ if (set == null)
+ {
+ set = idata.getVariable(variable);
+ if (set == null)
+ {
+ set = "";
+ }
+ }
+ else
+ {
+ if (set != null && !"".equals(set))
+ {
+
+ VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
+ set = vs.substitute(set, null);
+ }
+ }
+
+ fieldText = input.listChoices.get(0).strText;
+ System.out.println(fieldText + " [" + set + "] ");
+ try
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ String strIn = br.readLine();
+ if (!strIn.trim().equals(""))
+ {
+ idata.setVariable(variable, strIn);
+ }
+ else
+ {
+ idata.setVariable(variable, set);
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ return true;
+
+ }
+
+ boolean processComboRadioField(Input input, AutomatedInstallData idata)
+ {// TODO protection if selection not valid and no set value
+ String variable = input.strVariableName;
+ if ((variable == null) || (variable.length() == 0)) { return false; }
+ String currentvariablevalue = idata.getVariable(variable);
+ boolean userinput = false;
+ List lisChoices = input.listChoices;
+ if (lisChoices.size() == 0)
+ {
+ Debug.trace("Error: no spec element defined in file field");
+ return false;
+ }
+ if (currentvariablevalue != null)
+ {
+ userinput = true;
+ }
+ for (int i = 0; i < lisChoices.size(); i++)
+ {
+ Choice choice = lisChoices.get(i);
+ String value = choice.strValue;
+ if (userinput)
+ {
+ if ((value != null) && (value.length() > 0) && (currentvariablevalue.equals(value)))
+ {
+ input.iSelectedChoice = i;
+ }
+ }
+ else
+ {
+ String set = choice.strSet;
+ if (set != null)
+ {
+ if (set != null && !"".equals(set))
+ {
+ VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
+ set = vs.substitute(set, null);
+ }
+ if (set.equals(TRUE))
+ {
+ input.iSelectedChoice = i;
+ }
+ }
+ }
+ System.out.println(i + " [" + (input.iSelectedChoice == i ? "x" : " ") + "] "
+ + (choice.strText != null ? choice.strText : ""));
+ }
+
+ try
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ boolean bKeepAsking = true;
+
+ while (bKeepAsking)
+ {
+ System.out.println("input selection:");
+ String strIn = br.readLine();
+ // take default value if default value exists and no user input
+ if (strIn.trim().equals("") && input.iSelectedChoice != -1)
+ {
+ bKeepAsking = false;
+ }
+ int j = -1;
+ try
+ {
+ j = Integer.valueOf(strIn).intValue();
+ }
+ catch (Exception ex)
+ {}
+ // take user input if user input is valid
+ if (j >= 0 && j < lisChoices.size())
+ {
+ input.iSelectedChoice = j;
+ bKeepAsking = false;
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ idata.setVariable(variable, input.listChoices.get(input.iSelectedChoice).strValue);
+ return true;
+
+ }
+
+ public Input getInputFromField(IXMLElement field)
+ {
+ String strVariableName = field.getAttribute(VARIABLE);
+ String strFieldType = field.getAttribute(TYPE_ATTRIBUTE);
+ if (STATIC_TEXT.equals(strFieldType))
+ {
+ String strText = null;
+ strText = field.getAttribute(TEXT);
+ return new Input(strVariableName, null, null, STATIC_TEXT, strText, 0);
+ }
+ if (TEXT_FIELD.equals(strFieldType))
+ {
+ List choicesList = new ArrayList();
+ String strFieldText = null;
+ String strSet = null;
+ String strText = null;
+ IXMLElement spec = field.getFirstChildNamed(SPEC);
+ IXMLElement description = field.getFirstChildNamed(DESCRIPTION);
+ if (spec != null)
+ {
+ strText = field.getFirstChildNamed(SPEC).getAttribute(TEXT);
+ strSet = field.getFirstChildNamed(SPEC).getAttribute(SET);
+ }
+ if (description != null)
+ {
+ strFieldText = description.getAttribute(TEXT);
+ }
+ choicesList.add(new Choice(strText, null, strSet));
+ return new Input(strVariableName, strSet, choicesList, TEXT_FIELD, strFieldText, 0);
+
+ }
+ else if (COMBO_FIELD.equals(strFieldType) || RADIO_FIELD.equals(strFieldType))
+ {
+ List choicesList = new ArrayList();
+ String strFieldText = null;
+ IXMLElement spec = field.getFirstChildNamed(SPEC);
+ IXMLElement description = field.getFirstChildNamed(DESCRIPTION);
+ Vector choices = null;
+ if (spec != null)
+ {
+ choices = spec.getChildrenNamed(CHOICE);
+ }
+ if (description != null)
+ {
+ strFieldText = description.getAttribute(TEXT);
+ }
+ for (int i = 0; i < choices.size(); i++)
+ {
+ IXMLElement choice = choices.elementAt(i);
+ choicesList.add(new Choice(choice.getAttribute(TEXT), choice.getAttribute(VALUE),
+ choice.getAttribute(SET)));
+ }
+ return new Input(strVariableName, null, choicesList, COMBO_FIELD, strFieldText, -1);
+ }
+ else
+ {
+ System.out.println(strFieldType + " field collection not implemented");
+
+ }
+ return null;
+ }
+
+ public class Input
+ {
+
+ public Input(String strVariableName, String strDefaultValue, List listChoices,
+ String strFieldType, String strText, int iSelectedChoice)
+ {
+ this.strVariableName = strVariableName;
+ this.strDefaultValue = strDefaultValue;
+ this.listChoices = listChoices;
+ this.strFieldType = strFieldType;
+ this.strText = strText;
+ this.iSelectedChoice = iSelectedChoice;
+ }
+
+ String strVariableName;
+
+ String strDefaultValue;
+
+ List listChoices;
+
+ String strFieldType;
+
+ String strText;
+
+ int iSelectedChoice = -1;
+ }
+
+ public class Choice
+ {
+
+ public Choice(String strText, String strValue, String strSet)
+ {
+ this.strText = strText;
+ this.strValue = strValue;
+ this.strSet = strSet;
+ }
+
+ String strText;
+
+ String strValue;
+
+ String strSet;
+ }
+}
Index: src/lib/com/izforge/izpack/rules/RulesEngine.java
===================================================================
--- src/lib/com/izforge/izpack/rules/RulesEngine.java (revision 2643)
+++ src/lib/com/izforge/izpack/rules/RulesEngine.java (working copy)
@@ -204,10 +204,10 @@
conditionclassname += "Condition";
}
- ClassLoader loader = Thread.currentThread().getContextClassLoader(); //RulesEngine.class.getClassLoader();
+ // ClassLoader loader = Thread.currentThread().getContextClassLoader(); //RulesEngine.class.getClassLoader();
try
{
- Class conditionclass = (Class) loader.loadClass(conditionclassname);
+ Class conditionclass = (Class) Class.forName(conditionclassname);
result = conditionclass.newInstance();
result.readFromXML(condition);
if (condid != null){