|
From: <ls...@us...> - 2007-07-01 08:46:56
|
Revision: 3343
http://jnode.svn.sourceforge.net/jnode/?rev=3343&view=rev
Author: lsantha
Date: 2007-07-01 01:46:54 -0700 (Sun, 01 Jul 2007)
Log Message:
-----------
Initial version of a JNode installer prototype.
Modified Paths:
--------------
trunk/distr/src/install/org/jnode/install/Main.java
Added Paths:
-----------
trunk/distr/src/install/org/jnode/install/AbstractInstaller.java
trunk/distr/src/install/org/jnode/install/ActionInput.java
trunk/distr/src/install/org/jnode/install/ActionOutput.java
trunk/distr/src/install/org/jnode/install/CopyFile.java
trunk/distr/src/install/org/jnode/install/InputContext.java
trunk/distr/src/install/org/jnode/install/InstallerAction.java
trunk/distr/src/install/org/jnode/install/OutputContext.java
trunk/distr/src/install/org/jnode/install/ProgressAware.java
trunk/distr/src/install/org/jnode/install/ProgressEvent.java
trunk/distr/src/install/org/jnode/install/ProgressListener.java
trunk/distr/src/install/org/jnode/install/ProgressSupport.java
trunk/distr/src/install/org/jnode/install/ProgressiveAction.java
trunk/distr/src/install/org/jnode/install/action/
trunk/distr/src/install/org/jnode/install/action/ActionConstants.java
trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java
trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java
trunk/distr/src/install/org/jnode/install/cmdline/
trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java
Added: trunk/distr/src/install/org/jnode/install/AbstractInstaller.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/AbstractInstaller.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/AbstractInstaller.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,72 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+import java.util.ArrayList;
+import java.util.ListIterator;
+import java.util.List;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public abstract class AbstractInstaller {
+ public static enum Step {back, forth, quit}
+ protected List<InstallerAction> actionList = new ArrayList<InstallerAction>();
+
+ public void start(){
+ InputContext in = getInputContext();
+ OutputContext out = getOutputContext();
+ if(actionList.isEmpty())
+ return;
+
+ ListIterator<InstallerAction> lit = actionList.listIterator();
+ InstallerAction action = lit.next();
+
+ out: while(true){
+ ActionInput input = action.getInput(in);
+ if(input != null){
+ Step step = input.collect();
+ if(step != null && step.equals(Step.quit))
+ break;
+ }
+
+ try {
+ action.execute();
+ } catch(Exception e){
+ e.printStackTrace();
+ break;
+ }
+
+ ActionOutput output = action.getOutput(out);
+ if(output != null){
+ Step step = output.show();
+ if(step == null) step = Step.forth;
+ switch(step){
+ case back:
+ if(lit.hasPrevious())
+ action = lit.previous();
+ else
+ break out;
+ break;
+ case forth:
+ if(lit.hasNext())
+ action = lit.next();
+ else
+ break out;
+ break;
+ case quit:
+ break out;
+ }
+ } else {
+ if(lit.hasNext())
+ action = lit.next();
+ else
+ break;
+ }
+ }
+ }
+
+ protected abstract InputContext getInputContext();
+ protected abstract OutputContext getOutputContext();
+}
Added: trunk/distr/src/install/org/jnode/install/ActionInput.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/ActionInput.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/ActionInput.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,11 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface ActionInput {
+ AbstractInstaller.Step collect();
+}
Added: trunk/distr/src/install/org/jnode/install/ActionOutput.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/ActionOutput.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/ActionOutput.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,11 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface ActionOutput {
+ AbstractInstaller.Step show();
+}
Added: trunk/distr/src/install/org/jnode/install/CopyFile.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/CopyFile.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/CopyFile.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,62 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+import java.io.*;
+
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public class CopyFile implements ProgressAware {
+ private ProgressSupport progress = new ProgressSupport();
+ private boolean progessAware;
+ private File source;
+ private File destination;
+
+ public CopyFile(boolean progessAware) {
+ this.progessAware = progessAware;
+ }
+
+ public void setSource(File source) {
+ this.source = source;
+ }
+
+ public void setDestination(File destination) {
+ this.destination = destination;
+ }
+
+ public void execute() throws Exception {
+ try {
+ if(source == null ||destination == null)
+ throw new RuntimeException("Source or destination is null.");
+
+ long length = source.length();
+ byte[] buf = new byte[128 * 1024];
+ FileInputStream fis = new FileInputStream(source);
+ FileOutputStream fos = new FileOutputStream(destination);
+ int count;
+ long status = 0;
+ while((count = fis.read(buf)) > -1 ){
+ fos.write(buf, 0, count);
+ if(progessAware){
+ status += count;
+ int val = (int)(100L * status / length);
+ progress.fireProgressEvent(new ProgressEvent(val));
+ }
+ }
+ fis.close();
+ fos.flush();
+ fos.close();
+ } catch(FileNotFoundException x){
+ x.printStackTrace();
+ } catch(IOException x){
+ x.printStackTrace();
+ }
+ }
+
+ public void addProgressListener(ProgressListener p) {
+ progress.addProgressListener(p);
+ }
+}
Added: trunk/distr/src/install/org/jnode/install/InputContext.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/InputContext.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/InputContext.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,21 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+import java.util.HashMap;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public abstract class InputContext {
+ private HashMap<String, Object> values = new HashMap<String, Object>();
+ public abstract String getStringInput(String message);
+ public void setStringValue(String key, String value){
+ values.put(key, value);
+ }
+
+ public String getStringValue(String key){
+ return (String) values.get(key);
+ }
+}
Added: trunk/distr/src/install/org/jnode/install/InstallerAction.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/InstallerAction.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/InstallerAction.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,13 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface InstallerAction {
+ ActionInput getInput(InputContext inContext);
+ void execute() throws Exception;
+ ActionOutput getOutput(OutputContext outContext);
+}
Modified: trunk/distr/src/install/org/jnode/install/Main.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/Main.java 2007-07-01 08:45:32 UTC (rev 3342)
+++ trunk/distr/src/install/org/jnode/install/Main.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -21,6 +21,7 @@
package org.jnode.install;
+import org.jnode.install.cmdline.CommandLineInstaller;
/**
* Main class for the JNode installer.
@@ -30,9 +31,10 @@
public class Main implements Runnable {
public void run() {
- System.out.println("Installing JNode");
-
- System.out.println("Done");
+ System.out.println("JNode Installation");
+ CommandLineInstaller.main();
+ System.out.println("JNode installation completed.");
+ /*
while (true) {
try {
Thread.sleep(100000);
@@ -40,5 +42,10 @@
// Ignore
}
}
+ */
}
+
+ public static void main(String[] argv){
+ new Main().run();
+ }
}
Added: trunk/distr/src/install/org/jnode/install/OutputContext.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/OutputContext.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/OutputContext.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,11 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface OutputContext {
+ public void showMessage(String msg);
+}
Added: trunk/distr/src/install/org/jnode/install/ProgressAware.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/ProgressAware.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/ProgressAware.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,11 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface ProgressAware {
+ void addProgressListener(ProgressListener p);
+}
Added: trunk/distr/src/install/org/jnode/install/ProgressEvent.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/ProgressEvent.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/ProgressEvent.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,20 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public class ProgressEvent {
+ private int progress;
+
+ public ProgressEvent(int progress) {
+ this.progress = progress;
+ }
+
+
+ public int getProgress() {
+ return progress;
+ }
+}
Added: trunk/distr/src/install/org/jnode/install/ProgressListener.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/ProgressListener.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/ProgressListener.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,11 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface ProgressListener {
+ void progress(ProgressEvent e);
+}
Added: trunk/distr/src/install/org/jnode/install/ProgressSupport.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/ProgressSupport.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/ProgressSupport.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,28 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public class ProgressSupport implements ProgressAware{
+ List<ProgressListener> listenerList = new ArrayList<ProgressListener>();
+
+ public void addProgressListener(ProgressListener listener) {
+ listenerList.add(listener);
+ }
+
+ void fireProgressEvent(ProgressEvent e){
+ for(ProgressListener listener : listenerList){
+ try {
+ listener.progress(e);
+ } catch(Exception x){
+ x.printStackTrace();
+ }
+ }
+ }
+}
Added: trunk/distr/src/install/org/jnode/install/ProgressiveAction.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/ProgressiveAction.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/ProgressiveAction.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,12 @@
+/*
+ * $Id$
+ */
+package org.jnode.install;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface ProgressiveAction extends InstallerAction, ProgressAware {
+
+}
+
Added: trunk/distr/src/install/org/jnode/install/action/ActionConstants.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/action/ActionConstants.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/action/ActionConstants.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,11 @@
+/*
+ * $Id$
+ */
+package org.jnode.install.action;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public interface ActionConstants {
+ String INSTALL_ROOT_DIR = "INSTALL_ROOT_DIR";
+}
Added: trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/action/CopyFilesAction.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,60 @@
+/*
+ * $Id$
+ */
+package org.jnode.install.action;
+
+import org.jnode.install.InstallerAction;
+import org.jnode.install.ActionInput;
+import org.jnode.install.CopyFile;
+import org.jnode.install.ProgressListener;
+import org.jnode.install.ProgressEvent;
+import org.jnode.install.ActionOutput;
+import org.jnode.install.InputContext;
+import org.jnode.install.OutputContext;
+import org.jnode.install.AbstractInstaller;
+import java.io.File;
+
+/**
+ * @author Levente S\xE1ntha
+*/
+public class CopyFilesAction implements InstallerAction {
+ private String targetDirectory;
+ public ActionInput getInput(final InputContext inContext) {
+ return new ActionInput() {
+ public AbstractInstaller.Step collect() {
+ targetDirectory = inContext.getStringValue(ActionConstants.INSTALL_ROOT_DIR);
+ return AbstractInstaller.Step.forth;
+ }
+ };
+ }
+
+ public void execute() throws Exception {
+ System.out.println("Installing jnode32.gz ...");
+ CopyFile cf = new CopyFile(true);
+ cf.setSource(new File("/devices/sg0/jnode32.gz"));
+ cf.setDestination(new File(targetDirectory + "jnode32.gz"));
+ cf.addProgressListener(new ProgressListener() {
+ public void progress(ProgressEvent e) {
+ System.out.print('.');
+ }
+ });
+ cf.execute();
+ System.out.println("Done.");
+
+ System.out.println("Installing full.jgz ...");
+ cf = new CopyFile(true);
+ cf.setSource(new File("/devices/sg0/full.jgz"));
+ cf.setDestination(new File(targetDirectory + "full.jgz"));
+ cf.addProgressListener(new ProgressListener() {
+ public void progress(ProgressEvent e) {
+ System.out.print('.');
+ }
+ });
+ cf.execute();
+ System.out.println("Done.");
+ }
+
+ public ActionOutput getOutput(OutputContext outContext) {
+ return null;
+ }
+}
Added: trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/action/GrubInstallerAction.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,44 @@
+/*
+ * $Id$
+ */
+package org.jnode.install.action;
+
+import org.jnode.install.InstallerAction;
+import org.jnode.install.ActionInput;
+import org.jnode.install.ActionOutput;
+import org.jnode.install.OutputContext;
+import org.jnode.install.InputContext;
+import org.jnode.install.AbstractInstaller;
+import org.jnode.fs.jfat.command.JGrubInstallCommand;
+
+/**
+ * @author Levente S\xE1ntha
+*/
+public class GrubInstallerAction implements InstallerAction {
+ private String disk;
+ private String partition;
+ private String targetDirectory;
+ public ActionInput getInput(final InputContext inContext) {
+ return new ActionInput() {
+ public AbstractInstaller.Step collect() {
+ try {
+ disk = inContext.getStringInput("Enter the installation disk device name: ");
+ partition = inContext.getStringInput("Enter the partition number: ");
+ targetDirectory = "/devices/" + disk + partition + "/";
+ inContext.setStringValue(ActionConstants.INSTALL_ROOT_DIR, targetDirectory);
+ return AbstractInstaller.Step.forth;
+ } catch(Exception e){
+ return AbstractInstaller.Step.back;
+ }
+ }
+ };
+ }
+
+ public void execute() throws Exception {
+ JGrubInstallCommand.main(disk,"-p", partition, targetDirectory);
+ }
+
+ public ActionOutput getOutput(OutputContext outContext) {
+ return null;
+ }
+}
Added: trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java
===================================================================
--- trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java (rev 0)
+++ trunk/distr/src/install/org/jnode/install/cmdline/CommandLineInstaller.java 2007-07-01 08:46:54 UTC (rev 3343)
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ */
+package org.jnode.install.cmdline;
+
+import org.jnode.install.*;
+import org.jnode.install.action.*;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+/**
+ * @author Levente S\xE1ntha
+ */
+public class CommandLineInstaller extends AbstractInstaller {
+
+ public CommandLineInstaller() {
+ //grub
+ actionList.add(new GrubInstallerAction());
+ //files
+ actionList.add(new CopyFilesAction());
+ }
+
+ public static void main(String...argv){
+ new CommandLineInstaller().start();
+ }
+
+
+ protected InputContext getInputContext() {
+ return new InputContext() {
+ private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ public String getStringInput(String message) {
+ try {
+ System.out.println(message);
+ return in.readLine();
+ }catch(IOException e){
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
+
+ protected OutputContext getOutputContext() {
+ return new OutputContext() {
+ public void showMessage(String msg) {
+ System.out.println(msg);
+ }
+ };
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|