001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2003 Jonathan Halliday
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:
022: package com.izforge.izpack.panels;
023:
024: import net.n3.nanoxml.XMLElement;
025:
026: import com.izforge.izpack.installer.AutomatedInstallData;
027: import com.izforge.izpack.installer.IUnpacker;
028: import com.izforge.izpack.installer.PanelAutomation;
029: import com.izforge.izpack.installer.PanelAutomationHelper;
030: import com.izforge.izpack.installer.UnpackerFactory;
031: import com.izforge.izpack.util.AbstractUIProgressHandler;
032:
033: /**
034: * Functions to support automated usage of the InstallPanel
035: *
036: * @author Jonathan Halliday
037: */
038: public class InstallPanelAutomationHelper extends PanelAutomationHelper
039: implements PanelAutomation, AbstractUIProgressHandler {
040:
041: private int noOfPacks = 0;
042:
043: /**
044: * Null op - this panel type has no state to serialize.
045: *
046: * @param installData unused.
047: * @param panelRoot unused.
048: */
049: public void makeXMLData(AutomatedInstallData installData,
050: XMLElement panelRoot) {
051: // do nothing.
052: }
053:
054: /**
055: * Perform the installation actions.
056: *
057: * @param panelRoot The panel XML tree root.
058: *
059: * @return true if the installation was successful.
060: */
061: public boolean runAutomated(AutomatedInstallData idata,
062: XMLElement panelRoot) {
063: /*
064: Unpacker unpacker = new Unpacker(idata, this);
065: unpacker.start();
066: */
067: IUnpacker unpacker = UnpackerFactory.getUnpacker(idata.info
068: .getUnpackerClassName(), idata, this );
069: Thread unpackerthread = new Thread(unpacker,
070: "IzPack - Unpacker thread");
071: unpackerthread.start();
072: boolean done = false;
073: while (!done && unpackerthread.isAlive()) {
074: try {
075: Thread.sleep(100);
076: } catch (InterruptedException e) {
077: // ignore it, we're waiting for the unpacker to finish...
078: }
079: }
080: return unpacker.getResult();
081: }
082:
083: /**
084: * Reports progress on System.out
085: *
086: * @see AbstractUIProgressHandler#startAction(String, int)
087: */
088: public void startAction(String name, int no_of_steps) {
089: System.out.println("[ Starting to unpack ]");
090: this .noOfPacks = no_of_steps;
091: }
092:
093: /**
094: * Sets state variable for thread sync.
095: *
096: * @see com.izforge.izpack.util.AbstractUIProgressHandler#stopAction()
097: */
098: public void stopAction() {
099: System.out.println("[ Unpacking finished ]");
100: boolean done = true;
101: }
102:
103: /**
104: * Null op.
105: *
106: * @param val
107: * @param msg
108: * @see com.izforge.izpack.util.AbstractUIProgressHandler#progress(int, String)
109: */
110: public void progress(int val, String msg) {
111: // silent for now. should log individual files here, if we had a verbose
112: // mode?
113: }
114:
115: /**
116: * Reports progress to System.out
117: *
118: * @param packName The currently installing pack.
119: * @param stepno The number of the pack
120: * @param stepsize unused
121: * @see com.izforge.izpack.util.AbstractUIProgressHandler#nextStep(String, int, int)
122: */
123: public void nextStep(String packName, int stepno, int stepsize) {
124: System.out.print("[ Processing package: " + packName + " (");
125: System.out.print(stepno);
126: System.out.print('/');
127: System.out.print(this .noOfPacks);
128: System.out.println(") ]");
129: }
130:
131: /**
132: * {@inheritDoc}
133: */
134: public void setSubStepNo(int no_of_substeps) {
135: // not used here
136: }
137: }
|