|
From: <ls...@us...> - 2007-04-21 13:11:21
|
Revision: 3171
http://jnode.svn.sourceforge.net/jnode/?rev=3171&view=rev
Author: lsantha
Date: 2007-04-21 06:11:19 -0700 (Sat, 21 Apr 2007)
Log Message:
-----------
Factored out the code related to emulation.
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
Added Paths:
-----------
trunk/distr/src/emu/
trunk/distr/src/emu/org/
trunk/distr/src/emu/org/jnode/
trunk/distr/src/emu/org/jnode/emu/
trunk/distr/src/emu/org/jnode/emu/DeviceManager.java
trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java
trunk/distr/src/emu/org/jnode/emu/EditEmu.java
trunk/distr/src/emu/org/jnode/emu/Emu.java
trunk/distr/src/emu/org/jnode/emu/ShellEmu.java
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java
trunk/distr/src/apps/org/jnode/apps/editor/EditEmu.java
Deleted: trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java 2007-04-15 21:49:12 UTC (rev 3170)
+++ trunk/distr/src/apps/org/jnode/apps/console/ShellEmu.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -1,21 +0,0 @@
-package org.jnode.apps.console;
-
-import org.jnode.test.gui.Emu;
-import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
-import org.jnode.driver.console.TextConsole;
-import org.jnode.driver.console.ConsoleManager;
-import org.jnode.shell.CommandShell;
-
-/**
- * @author Levente S\u00e1ntha
- */
-public class ShellEmu extends Emu {
-
- public static void main(String[] argv) throws Exception {
- initEnv();
- SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
- new Thread(new CommandShell((TextConsole) cm.createConsole("Console 1",
- ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE))).
- start();
- }
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/editor/EditEmu.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/EditEmu.java 2007-04-15 21:49:12 UTC (rev 3170)
+++ trunk/distr/src/apps/org/jnode/apps/editor/EditEmu.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -1,31 +0,0 @@
-package org.jnode.apps.editor;
-
-import org.jnode.driver.console.ConsoleManager;
-import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
-import org.jnode.driver.console.textscreen.TextScreenConsole;
-import org.jnode.test.gui.Emu;
-
-import java.io.File;
-
-/**
- * @author Levente S\u00e1ntha
- */
-public class EditEmu extends Emu {
- public static void main(String[] argv) throws Exception{
- initEnv();
-
-
- if(argv.length == 0){
- System.out.println("No file specified");
- return;
- }
-
- SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
- final TextScreenConsole console = cm.createConsole(null,
- ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN);
-
- TextEditor te = new TextEditor(console);
- File f = new File(argv[0]);
- te.loadFile(f);
- }
-}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-04-15 21:49:12 UTC (rev 3170)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -7,11 +7,11 @@
import org.jnode.naming.InitialNaming;
import org.jnode.naming.NameSpace;
import org.jnode.test.fs.driver.stubs.StubDeviceManager;
-import org.jnode.test.gui.Emu;
import org.jnode.util.OsUtils;
+import org.jnode.emu.Emu;
+import org.jnode.driver.DeviceManager;
-public class JPartition extends Emu
-{
+public class JPartition extends Emu {
private static final Logger log = Logger.getLogger(JPartition.class);
public static void main(String[] args) throws Throwable
Added: trunk/distr/src/emu/org/jnode/emu/DeviceManager.java
===================================================================
--- trunk/distr/src/emu/org/jnode/emu/DeviceManager.java (rev 0)
+++ trunk/distr/src/emu/org/jnode/emu/DeviceManager.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -0,0 +1,101 @@
+/*
+ * $Id$
+ */
+package org.jnode.emu;
+
+import org.jnode.driver.*;
+import org.apache.log4j.Logger;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+
+/**
+ * @author Levente S\xE1ntha
+*/
+public class DeviceManager extends AbstractDeviceManager {
+ public static final Logger log = Logger.getLogger(DeviceManager.class);
+
+ public static final DeviceManager INSTANCE = new DeviceManager();
+
+ private List<DeviceFinder> finders = new ArrayList<DeviceFinder>();
+
+ private List<DeviceToDriverMapper> mappers = new ArrayList<DeviceToDriverMapper>();
+
+ private DeviceManager() {
+ }
+
+ public void removeAll() {
+ finders.clear();
+ mappers.clear();
+
+ for (Device device : getDevices()) {
+ try {
+ unregister(device);
+ } catch (DriverException e) {
+ log.error("can't unregister " + device);
+ }
+ }
+ }
+
+ public void add(DeviceFinder finder, DeviceToDriverMapper mapper) {
+ boolean doStart = false;
+
+ if (!finders.contains(finder)) {
+ finders.add(finder);
+ doStart = true;
+ }
+
+ if (!mappers.contains(mapper)) {
+ mappers.add(mapper);
+ doStart = true;
+ }
+
+ if (doStart) {
+ start();
+ }
+ }
+
+ /**
+ * Start this manager
+ */
+ final public void start() {
+ // Thread thread = new Thread()
+ // {
+ // public void run()
+ // {
+ log.debug("Loading extensions ...");
+ loadExtensions();
+ log.debug("Extensions loaded !");
+ // }
+ // };
+ // thread.start();
+
+ try {
+ // must be called before findDeviceDrivers
+ log.debug("findDevices ...");
+ findDevices();
+
+ log.debug("findDeviceDrivers ...");
+ findDeviceDrivers();
+
+ log.debug("StubDeviceManager initialized !");
+ } catch (InterruptedException e) {
+ log.fatal("can't find devices", e);
+ }
+ }
+
+ protected final void refreshFinders(List<DeviceFinder> finders) {
+ log.info("refreshFinders");
+ finders.clear();
+ finders.addAll(this.finders);
+ }
+
+ protected final void refreshMappers(List<DeviceToDriverMapper> mappers) {
+ log.info("refreshMappers");
+ mappers.clear();
+ mappers.addAll(this.mappers);
+
+ // Now sort them
+ Collections.sort(mappers, MapperComparator.INSTANCE);
+ }
+}
Added: trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java
===================================================================
--- trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java (rev 0)
+++ trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ */
+package org.jnode.emu;
+
+import org.jnode.plugin.ExtensionPoint;
+import org.jnode.plugin.Extension;
+import org.jnode.plugin.ExtensionPointListener;
+import org.jnode.plugin.PluginDescriptor;
+
+/**
+ * @author Levente S\xE1ntha
+*/
+class DummyExtensionPoint implements ExtensionPoint {
+ public String getSimpleIdentifier() {
+ return "A";
+ }
+
+ public String getUniqueIdentifier() {
+ return "aaa";
+ }
+
+ public String getName() {
+ return "B";
+ }
+
+ public Extension[] getExtensions() {
+ return new Extension[0];
+ }
+
+ public void addListener(ExtensionPointListener listener) {
+ }
+
+ public void addPriorityListener(ExtensionPointListener listener) {
+ }
+
+ public void removeListener(ExtensionPointListener listener) {
+ }
+
+ public PluginDescriptor getDeclaringPluginDescriptor() {
+ return null;
+ }
+}
Added: trunk/distr/src/emu/org/jnode/emu/EditEmu.java
===================================================================
--- trunk/distr/src/emu/org/jnode/emu/EditEmu.java (rev 0)
+++ trunk/distr/src/emu/org/jnode/emu/EditEmu.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -0,0 +1,31 @@
+package org.jnode.emu;
+
+import org.jnode.driver.console.ConsoleManager;
+import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
+import org.jnode.driver.console.textscreen.TextScreenConsole;
+import org.jnode.apps.editor.TextEditor;
+
+import java.io.File;
+
+/**
+ * @author Levente S\u00e1ntha
+ */
+public class EditEmu extends Emu {
+ public static void main(String[] argv) throws Exception{
+ initEnv();
+
+
+ if(argv.length == 0){
+ System.out.println("No file specified");
+ return;
+ }
+
+ SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
+ final TextScreenConsole console = cm.createConsole(null,
+ ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN);
+
+ TextEditor te = new TextEditor(console);
+ File f = new File(argv[0]);
+ te.loadFile(f);
+ }
+}
Added: trunk/distr/src/emu/org/jnode/emu/Emu.java
===================================================================
--- trunk/distr/src/emu/org/jnode/emu/Emu.java (rev 0)
+++ trunk/distr/src/emu/org/jnode/emu/Emu.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -0,0 +1,61 @@
+package org.jnode.emu;
+
+import org.jnode.naming.InitialNaming;
+import org.jnode.naming.NameSpace;
+import org.jnode.shell.alias.AliasManager;
+import org.jnode.shell.alias.def.DefaultAliasManager;
+import org.jnode.shell.ShellManager;
+import org.jnode.shell.help.Help;
+import org.jnode.shell.help.def.DefaultHelp;
+import org.jnode.shell.def.DefaultShellManager;
+
+import javax.naming.NamingException;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+
+/**
+ * @author Levente S\u00e1ntha
+ */
+public class Emu {
+ protected static void initEnv() throws NamingException {
+ if(true){
+ InitialNaming.setNameSpace(new NameSpace() {
+ private Map<Class<?>, Object> space = new HashMap<Class<?>, Object>();
+
+ public <T> void bind(Class<T> name, T service) throws NamingException, NameAlreadyBoundException {
+ if (space.get(name) != null) throw new NameAlreadyBoundException();
+ space.put(name, service);
+ }
+
+ public void unbind(Class<?> name) {
+ space.remove(name);
+ }
+
+ public <T> T lookup(Class<T> name) throws NameNotFoundException {
+ T obj = (T) space.get(name);
+ if (obj == null) throw new NameNotFoundException(name.getName());
+ return obj;
+ }
+
+ public Set<Class<?>> nameSet() {
+ return space.keySet();
+ }
+ });
+ InitialNaming.bind(DeviceManager.NAME, DeviceManager.INSTANCE);
+ AliasManager alias_mgr = new DefaultAliasManager(new DummyExtensionPoint()).createAliasManager();
+ alias_mgr.add("console", "org.jnode.shell.command.driver.console.ConsoleCommand");
+ alias_mgr.add("help", "org.jnode.shell.command.HelpCommand");
+ alias_mgr.add("alias", "org.jnode.shell.command.AliasCommand");
+ alias_mgr.add("exit", "org.jnode.shell.command.ExitCommand");
+ alias_mgr.add("edit", "org.jnode.apps.edit.EditCommand");
+ alias_mgr.add("leed", "org.jnode.apps.editor.LeedCommand");
+ alias_mgr.add("sconsole", "org.jnode.apps.console.SwingConsole");
+ InitialNaming.bind(AliasManager.NAME, alias_mgr);
+ InitialNaming.bind(ShellManager.NAME, new DefaultShellManager());
+ InitialNaming.bind(Help.NAME, new DefaultHelp());
+ }
+ }
+}
Added: trunk/distr/src/emu/org/jnode/emu/ShellEmu.java
===================================================================
--- trunk/distr/src/emu/org/jnode/emu/ShellEmu.java (rev 0)
+++ trunk/distr/src/emu/org/jnode/emu/ShellEmu.java 2007-04-21 13:11:19 UTC (rev 3171)
@@ -0,0 +1,19 @@
+package org.jnode.emu;
+
+import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
+import org.jnode.driver.console.ConsoleManager;
+import org.jnode.shell.CommandShell;
+
+/**
+ * @author Levente S\u00e1ntha
+ */
+public class ShellEmu extends Emu {
+
+ public static void main(String[] argv) throws Exception {
+ initEnv();
+ SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
+ new Thread(new CommandShell(cm.createConsole("Console 1",
+ ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE))).
+ start();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-08-04 10:24:58
|
Revision: 3380
http://jnode.svn.sourceforge.net/jnode/?rev=3380&view=rev
Author: lsantha
Date: 2007-08-04 03:24:21 -0700 (Sat, 04 Aug 2007)
Log Message:
-----------
Optimized imports.
Modified Paths:
--------------
trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java
trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java
trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java
trunk/distr/src/apps/org/jnode/apps/debug/ListPanel.java
trunk/distr/src/apps/org/jnode/apps/debug/RootObjectPanel.java
trunk/distr/src/apps/org/jnode/apps/debug/TC.java
trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java
trunk/distr/src/apps/org/jnode/apps/edit/Editor.java
trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java
trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java
trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/ExtentDeclaration.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Descriptor.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Extent.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/FileDescriptor.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleDescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleIOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTableRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/EntryArray.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainDirectory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtent.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeader.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentIO.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseFileDescriptor.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/BaseTest.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestCreation.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/BaseReadWriteTest.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestHeader.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestVMWareDisk.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java
trunk/distr/src/emu/org/jnode/emu/DeviceManager.java
trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java
trunk/distr/src/emu/org/jnode/emu/EditEmu.java
trunk/distr/src/emu/org/jnode/emu/Emu.java
trunk/distr/src/emu/org/jnode/emu/ShellEmu.java
trunk/distr/src/install/org/jnode/install/AbstractInstaller.java
trunk/distr/src/install/org/jnode/install/ProgressSupport.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/CommandLineInstaller.java
Modified: trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java
===================================================================
--- trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -22,8 +22,10 @@
package fi.iki.elonen;
import java.io.*;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URLEncoder;
import java.util.*;
-import java.net.*;
/**
* A simple, tiny, nicely embeddable HTTP 1.0 server in Java
Modified: trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -36,15 +36,14 @@
import charvax.swing.*;
import charvax.swing.border.TitledBorder;
import gnu.java.io.NullOutputStream;
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.naming.NameNotFoundException;
import org.jnode.shell.CommandShell;
import org.jnode.shell.Shell;
import org.jnode.shell.ShellUtils;
-import javax.naming.NameNotFoundException;
-import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
-
/**
* User: Sam Reid
* Date: Mar 19, 2004
Modified: trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,17 +1,16 @@
package org.jnode.apps.console;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.swing.*;
import org.jnode.driver.console.ConsoleManager;
import org.jnode.driver.console.TextConsole;
-import org.jnode.driver.console.textscreen.TextScreenConsoleManager;
import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
+import org.jnode.driver.console.textscreen.TextScreenConsoleManager;
+import org.jnode.naming.InitialNaming;
import org.jnode.shell.CommandShell;
import org.jnode.shell.ShellManager;
-import org.jnode.naming.InitialNaming;
-import javax.swing.JFrame;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-
/**
* @author Levente S\u00e1ntha
*/
Modified: trunk/distr/src/apps/org/jnode/apps/debug/ListPanel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/debug/ListPanel.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/debug/ListPanel.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -21,18 +21,13 @@
package org.jnode.apps.debug;
-import java.util.Vector;
-
import charva.awt.Dimension;
import charva.awt.event.KeyAdapter;
import charva.awt.event.KeyEvent;
-import charvax.swing.DefaultListModel;
-import charvax.swing.JList;
-import charvax.swing.JPanel;
-import charvax.swing.JScrollPane;
-import charvax.swing.ListSelectionModel;
+import charvax.swing.*;
import charvax.swing.event.ListSelectionEvent;
import charvax.swing.event.ListSelectionListener;
+import java.util.Vector;
/**
*
Modified: trunk/distr/src/apps/org/jnode/apps/debug/RootObjectPanel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/debug/RootObjectPanel.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/debug/RootObjectPanel.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -25,9 +25,7 @@
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
-
import javax.naming.NameNotFoundException;
-
import org.jnode.naming.InitialNaming;
/**
Modified: trunk/distr/src/apps/org/jnode/apps/debug/TC.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/debug/TC.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/debug/TC.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -20,7 +20,7 @@
*/
package org.jnode.apps.debug;
-import java.util.Vector;
+
import charva.awt.BorderLayout;
import charva.awt.Color;
import charva.awt.FlowLayout;
@@ -29,6 +29,8 @@
import charvax.swing.JPanel;
import charvax.swing.border.LineBorder;
import charvax.swing.border.TitledBorder;
+import java.util.Vector;
+
/**
* @author blind
*
Modified: trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -21,13 +21,12 @@
package org.jnode.apps.edit;
+import java.io.File;
import org.jnode.shell.help.Help;
import org.jnode.shell.help.Parameter;
import org.jnode.shell.help.ParsedArguments;
import org.jnode.shell.help.argument.FileArgument;
-import java.io.File;
-
/**
* @author Levente S\u00e1ntha
*/
Modified: trunk/distr/src/apps/org/jnode/apps/edit/Editor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/edit/Editor.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/edit/Editor.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -21,33 +21,18 @@
package org.jnode.apps.edit;
-import charvax.swing.JFileChooser;
-import charvax.swing.JFrame;
-import charvax.swing.JMenu;
-import charvax.swing.JMenuBar;
-import charvax.swing.JMenuItem;
-import charvax.swing.JOptionPane;
-import charvax.swing.JPanel;
-import charvax.swing.JScrollPane;
-import charvax.swing.JTextArea;
-import charvax.swing.ListSelectionModel;
-import charvax.swing.border.TitledBorder;
import charva.awt.BorderLayout;
-import charva.awt.Toolkit;
import charva.awt.Color;
+import charva.awt.Toolkit;
import charva.awt.event.ActionEvent;
import charva.awt.event.ActionListener;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
+import charvax.swing.*;
+import charvax.swing.border.TitledBorder;
+import gnu.java.security.action.GetPropertyAction;
+import java.io.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
-
import org.apache.log4j.Logger;
-import gnu.java.security.action.GetPropertyAction;
/**
* @author Levente S\u00e1ntha
Modified: trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,12 +1,11 @@
package org.jnode.apps.editor;
+import java.io.File;
import org.jnode.shell.help.Help;
import org.jnode.shell.help.Parameter;
import org.jnode.shell.help.ParsedArguments;
import org.jnode.shell.help.argument.FileArgument;
-import java.io.File;
-
/**
* @author Levente S\u00e1ntha
*/
Modified: trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,24 +1,19 @@
package org.jnode.apps.editor;
-import org.jnode.driver.input.KeyboardListener;
-import org.jnode.driver.input.KeyboardEvent;
+import java.awt.event.KeyEvent;
+import java.io.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
import org.jnode.driver.console.ConsoleManager;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.console.textscreen.TextScreenConsoleManager;
+import org.jnode.driver.input.KeyboardEvent;
+import org.jnode.driver.input.KeyboardListener;
import org.jnode.naming.InitialNaming;
import org.jnode.shell.ShellManager;
-import java.util.List;
-import java.util.ArrayList;
-import java.io.IOException;
-import java.io.File;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.awt.event.KeyEvent;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
/**
* @author Levente S\u00e1ntha
*/
Modified: trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -21,18 +21,12 @@
package org.jnode.apps.httpd;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
+import fi.iki.elonen.NanoHTTPD;
+import java.io.*;
import java.util.Properties;
-
import org.jnode.shell.Command;
import org.jnode.shell.CommandLine;
-import fi.iki.elonen.NanoHTTPD;
-
/**
* @author Martin Husted Hartvig (ha...@jn...)
*/
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -4,12 +4,12 @@
import org.jnode.apps.jpartition.controller.MainController;
import org.jnode.apps.jpartition.swingview.SwingViewFactory;
import org.jnode.apps.jpartition.utils.BasicNameSpace;
+import org.jnode.driver.DeviceManager;
+import org.jnode.emu.Emu;
import org.jnode.naming.InitialNaming;
import org.jnode.naming.NameSpace;
import org.jnode.test.fs.driver.stubs.StubDeviceManager;
import org.jnode.util.OsUtils;
-import org.jnode.emu.Emu;
-import org.jnode.driver.DeviceManager;
public class JPartition extends Emu {
private static final Logger log = Logger.getLogger(JPartition.class);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
-
import org.apache.log4j.Logger;
public class CommandProcessor {
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -3,12 +3,10 @@
import it.battlehorse.stamps.Dispatcher;
import it.battlehorse.stamps.factories.DispatcherRegistry;
import it.battlehorse.stamps.factories.TransformerRegistry;
-
import org.jnode.apps.jpartition.ViewFactory;
import org.jnode.apps.jpartition.model.CommandProcessorModel;
import org.jnode.apps.jpartition.model.DeviceModel;
import org.jnode.apps.jpartition.model.FileDeviceModel;
-import org.jnode.apps.jpartition.swingview.MainView;
public class MainController
{
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,7 +1,6 @@
package org.jnode.apps.jpartition.model;
import it.battlehorse.stamps.Model;
-
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -2,9 +2,7 @@
import java.util.ArrayList;
import java.util.List;
-
import javax.naming.NameNotFoundException;
-
import org.apache.log4j.Logger;
import org.jnode.driver.Device;
import org.jnode.driver.DeviceListener;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -2,7 +2,6 @@
import java.util.ArrayList;
import java.util.List;
-
import org.jnode.apps.jpartition.utils.device.DeviceUtils;
import org.jnode.driver.bus.ide.IDEDevice;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,7 +1,6 @@
package org.jnode.apps.jpartition.model;
import it.battlehorse.stamps.annotations.Refreshable;
-
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTypes;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,18 +1,10 @@
package org.jnode.apps.jpartition.swingview;
import it.battlehorse.stamps.annotations.ModelDependent;
-
-import java.awt.BorderLayout;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-
-import javax.swing.BorderFactory;
-import javax.swing.DefaultListModel;
-import javax.swing.JButton;
-import javax.swing.JList;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-
+import javax.swing.*;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.controller.MainController;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,12 +1,9 @@
package org.jnode.apps.jpartition.swingview;
import it.battlehorse.stamps.annotations.ModelDependent;
-
-import javax.swing.JPanel;
-
+import javax.swing.*;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.controller.MainController;
-import org.jnode.apps.jpartition.model.DeviceModel;
public class DeviceView extends JPanel
{
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,13 +1,9 @@
package org.jnode.apps.jpartition.swingview;
-import java.awt.Color;
+import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-
-import javax.swing.BorderFactory;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
+import javax.swing.*;
import org.jnode.apps.jpartition.controller.MainController;
public class DiskAreaView extends JPanel
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,9 +1,8 @@
package org.jnode.apps.jpartition.swingview;
-import org.apache.log4j.Logger;
-
import charva.awt.Component;
import charvax.swing.JOptionPane;
+import org.apache.log4j.Logger;
public class ErrorReporter {
public static void reportError(Logger log, Object source, Throwable t)
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,19 +1,10 @@
package org.jnode.apps.jpartition.swingview;
import it.battlehorse.stamps.annotations.ModelDependent;
-
-import java.awt.BorderLayout;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-
-import javax.swing.AbstractListModel;
-import javax.swing.DefaultListModel;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JList;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-
+import javax.swing.*;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.controller.MainController;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,16 +1,10 @@
package org.jnode.apps.jpartition.swingview;
import it.battlehorse.stamps.annotations.ModelDependent;
-
-import java.awt.BorderLayout;
+import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
-
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-
+import javax.swing.*;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.controller.MainController;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,7 +1,6 @@
package org.jnode.apps.jpartition.swingview;
import it.battlehorse.stamps.annotations.ModelDependent;
-
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.controller.MainController;
import org.jnode.partitions.ibm.IBMPartitionTypes;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,8 +1,6 @@
package org.jnode.apps.jpartition.swingview;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-
+import javax.swing.*;
import org.jnode.apps.jpartition.ViewFactory;
import org.jnode.apps.jpartition.controller.MainController;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -1,10 +1,7 @@
package org.jnode.apps.jpartition.swingview.actions;
import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Icon;
-
+import javax.swing.*;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.commands.BaseDeviceCommand;
import org.jnode.apps.jpartition.commands.framework.Command;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -6,11 +6,9 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
-
import org.jnode.naming.NameSpace;
public final class BasicNameSpace implements NameSpace {
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -2,9 +2,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
-
import javax.naming.NameNotFoundException;
-
import org.jnode.driver.DriverException;
import org.jnode.driver.block.PartitionableBlockDeviceAPI;
import org.jnode.driver.bus.ide.IDEConstants;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2007-08-04 10:19:57 UTC (rev 3379)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2007-08-04 10:24:21 UTC (rev 3380)
@@ -2,20 +2,13 @@
import java.io.File;
import java.io.IOException;
-
import javax.naming.NameNotFoundException;
-
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.swingview.ErrorReporter;
import org.jnode.apps.jpartition.swingview.FileDeviceView;
import org.jnode.apps.vmware.disk.VMWareDisk;
import org.jnode.apps.vmware.disk.tools.DiskFactory;
-import org.jnode.driver.ApiNotFoundException;
-import org.jnode.driver.Device;
-import org.jnode.driver.DeviceAlreadyRegisteredException;
-import org.jnode.driver.DeviceManager;
-import org.jnode.driver.DeviceNotFoundException;
-import org.jnode.driver.DriverException;
+import org.jnode.driver.*;
import org.jnode.driver.bus.ide.IDEDevice;
import org.jnode.partitions.command.PartitionHelper;
import org.jnode.partitions.ibm.IBMPartitionTypes;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
====================...
[truncated message content] |
|
From: <fd...@us...> - 2008-01-16 17:03:37
|
Revision: 3704
http://jnode.svn.sourceforge.net/jnode/?rev=3704&view=rev
Author: fduminy
Date: 2008-01-16 09:03:28 -0800 (Wed, 16 Jan 2008)
Log Message:
-----------
jpartition : work in progress (added console view)
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,34 @@
+package org.jnode.apps.jpartition;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+
+
+public class Context {
+ private final BufferedReader in;
+ private final PrintStream out;
+ private final ErrorReporter errorReporter;
+
+ public Context(InputStream in, PrintStream out, ErrorReporter errorReporter)
+ {
+ InputStreamReader r = new InputStreamReader(in);
+ this.in = new BufferedReader(r);
+
+ this.out = out;
+ this.errorReporter = errorReporter;
+ }
+
+ final public PrintStream getOut() {
+ return out;
+ }
+
+ final public BufferedReader getIn() {
+ return in;
+ }
+
+ final public ErrorReporter getErrorReporter() {
+ return errorReporter;
+ }
+}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-01-15 05:37:17 UTC (rev 3703)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -13,7 +13,7 @@
reportError(log, source, (Object) message);
}
- protected void displayError(Object source, Object message)
+ protected void displayError(Object source, String message)
{
// by default display nothing
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2008-01-15 05:37:17 UTC (rev 3703)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -1,38 +1,29 @@
package org.jnode.apps.jpartition;
+import java.io.InputStream;
+import java.io.PrintStream;
+
import org.jnode.apps.jpartition.model.UserFacade;
-import org.jnode.apps.jpartition.swingview.SwingViewFactory;
-import org.jnode.driver.console.ConsoleManager;
-import org.jnode.driver.console.TextConsole;
-import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
-import org.jnode.emu.ShellEmu;
-import org.jnode.naming.InitialNaming;
-import org.jnode.plugin.ExtensionPoint;
-import org.jnode.shell.CommandShell;
-import org.jnode.shell.ShellManager;
-import org.jnode.shell.alias.AliasManager;
-import org.jnode.shell.alias.def.DefaultAliasManager;
-import org.jnode.shell.def.DefaultShellManager;
-import charvax.swing.JLabel;
-
public class JPartition {
- public static void main(String[] args) throws Exception
+ final private ViewFactory viewFactory;
+ final private InputStream in;
+ final private PrintStream out;
+ final private PrintStream err;
+ final private boolean install;
+
+ public JPartition(ViewFactory viewFactory, InputStream in,
+ PrintStream out, PrintStream err, boolean install)
{
- testCharva(args);
-/*
- ViewFactory viewFactory = createViewFactory(args);
- launch(viewFactory);
-*/
+ this.viewFactory = viewFactory;
+ this.in = in;
+ this.out = out;
+ this.err = err;
+ this.install = install;
}
-
- public static ViewFactory createViewFactory(String[] args)
+
+ public final void launch() throws Exception
{
- return new SwingViewFactory();
- }
-
- private static final void launch(ViewFactory viewFactory) throws Exception
- {
ErrorReporter errorReporter = viewFactory.createErrorReporter();
UserFacade.getInstance().setErrorReporter(errorReporter);
@@ -40,36 +31,6 @@
Object cmdProcessorView = viewFactory.createCommandProcessorView();
// Device
- viewFactory.createDeviceView(errorReporter, cmdProcessorView);
+ viewFactory.createDeviceView(errorReporter, cmdProcessorView, install);
}
-
- private static void testCharva(String[] args) throws Exception
- {
-/*
- //initEnv();
- SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
- TextConsole tc = (TextConsole) cm.createConsole("Console 1",
- ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);
- cm.focus(tc);
-
- DefaultShellManager sm = new DefaultShellManager();
- InitialNaming.bind(ShellManager.NAME, sm);
-
- ExtensionPoint aliasesEP = new DummyExtensionPoint();
- DefaultAliasManager am = new DefaultAliasManager(aliasesEP);
- InitialNaming.bind(AliasManager.NAME, am);
-
- //final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
- CommandShell cs = new CommandShell(tc);
- sm.registerShell(cs);
- new Thread(cs).start();
-*/
- charvax.swing.JFrame frm = new charvax.swing.JFrame("test");
- JLabel label = new JLabel("test");
- frm.add(label);
- frm.setFocus(label);
- frm.setSize(20, 20);
- frm.setVisible(true);
- frm.setDefaultCloseOperation(charvax.swing.JFrame.EXIT_ON_CLOSE);
- }
}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,116 @@
+package org.jnode.apps.jpartition;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+
+import org.jnode.apps.jpartition.consoleview.ConsoleViewFactory;
+import org.jnode.apps.jpartition.model.UserFacade;
+import org.jnode.apps.jpartition.swingview.SwingViewFactory;
+import org.jnode.driver.console.ConsoleManager;
+import org.jnode.driver.console.TextConsole;
+import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
+import org.jnode.emu.ShellEmu;
+import org.jnode.naming.InitialNaming;
+import org.jnode.plugin.ExtensionPoint;
+import org.jnode.shell.AbstractCommand;
+import org.jnode.shell.CommandLine;
+import org.jnode.shell.CommandShell;
+import org.jnode.shell.ShellManager;
+import org.jnode.shell.alias.AliasManager;
+import org.jnode.shell.alias.def.DefaultAliasManager;
+import org.jnode.shell.def.DefaultShellManager;
+import org.jnode.shell.help.Help;
+import org.jnode.shell.help.Parameter;
+import org.jnode.shell.help.ParsedArguments;
+import org.jnode.shell.help.argument.FileArgument;
+import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.help.argument.StringArgument;
+
+import charvax.swing.JLabel;
+
+public class JPartitionCommand extends AbstractCommand {
+ static public final String SWINGUI = "swing";
+ static public final String CONSOLEUI = "console";
+
+ static private final OptionArgument ARG_UI = new OptionArgument("ui",
+ "The type of GUI you want to use",
+ new OptionArgument.Option(SWINGUI, "use swing for UI"),
+ new OptionArgument.Option(CONSOLEUI, "use console for UI"));
+
+ static private final StringArgument ARG_INSTALL = new StringArgument("install",
+ "select a partition (optionally being created/formatted)");
+
+ public static Help.Info HELP_INFO = new Help.Info("jpartition", "partition disks",
+ new Parameter[] {
+ new Parameter(ARG_UI, Parameter.MANDATORY),
+ new Parameter(ARG_INSTALL, Parameter.OPTIONAL)
+ });
+
+ public static void main(String[] args) throws Exception
+ {
+// testCharva(args);
+
+ new JPartitionCommand().execute(args);
+ }
+
+ public void execute(CommandLine commandLine, InputStream in,
+ PrintStream out, PrintStream err) throws Exception
+ {
+ ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
+ String ui = ARG_UI.getValue(cmdLine);
+ boolean install = (ARG_INSTALL.getValue(cmdLine) != null);
+
+ ViewFactory viewFactory = createViewFactory(ui, in, out, err);
+
+ JPartition jpartition = new JPartition(viewFactory, in, out, err, install);
+ jpartition.launch();
+ }
+
+ public static ViewFactory createViewFactory(String ui, InputStream in,
+ PrintStream out, PrintStream err)
+ {
+ ViewFactory viewFactory = null;
+ if(CONSOLEUI.equals(ui))
+ {
+ viewFactory = new ConsoleViewFactory(in, out, err);
+ }
+ else if(SWINGUI.equals(ui))
+ {
+ viewFactory = new SwingViewFactory();
+ }
+
+ return viewFactory;
+ }
+
+ private static void testCharva(String[] args) throws Exception
+ {
+/*
+ //initEnv();
+ SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
+ TextConsole tc = (TextConsole) cm.createConsole("Console 1",
+ ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);
+ cm.focus(tc);
+
+ DefaultShellManager sm = new DefaultShellManager();
+ InitialNaming.bind(ShellManager.NAME, sm);
+
+ ExtensionPoint aliasesEP = new DummyExtensionPoint();
+ DefaultAliasManager am = new DefaultAliasManager(aliasesEP);
+ InitialNaming.bind(AliasManager.NAME, am);
+
+ //final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
+ CommandShell cs = new CommandShell(tc);
+ sm.registerShell(cs);
+ new Thread(cs).start();
+*/
+/*
+ charvax.swing.JFrame frm = new charvax.swing.JFrame("test");
+ JLabel label = new JLabel("test");
+ frm.add(label);
+ frm.setFocus(label);
+ frm.setSize(20, 20);
+ frm.setVisible(true);
+ frm.setDefaultCloseOperation(charvax.swing.JFrame.EXIT_ON_CLOSE);
+*/
+ }
+}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java 2008-01-15 05:37:17 UTC (rev 3703)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -2,7 +2,7 @@
public interface ViewFactory {
- Object createDeviceView(ErrorReporter errorReporter, Object cmdProcessorView)
+ Object createDeviceView(ErrorReporter errorReporter, Object cmdProcessorView, boolean install)
throws Exception;
Object createCommandProcessorView();
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleErrorReporter.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleErrorReporter.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,30 @@
+package org.jnode.apps.jpartition.consoleview;
+
+import java.io.PrintStream;
+
+import org.jnode.apps.jpartition.ErrorReporter;
+
+/**
+ *
+ * @author Fabien Duminy
+ *
+ */
+class ConsoleErrorReporter extends ErrorReporter {
+ private final PrintStream err;
+
+ ConsoleErrorReporter(PrintStream err)
+ {
+ this.err = err;
+ }
+
+ protected void displayError(Object source, String message)
+ {
+ StringBuilder sb = new StringBuilder();
+ if(source != null)
+ {
+ sb.append('[').append(String.valueOf(source)).append("] ");
+ }
+ sb.append(message);
+ err.println(sb.toString());
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,79 @@
+package org.jnode.apps.jpartition.consoleview;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.Context;
+import org.jnode.apps.jpartition.ErrorReporter;
+import org.jnode.apps.jpartition.consoleview.components.Options;
+import org.jnode.apps.jpartition.consoleview.components.YesNo;
+import org.jnode.apps.jpartition.model.Partition;
+import org.jnode.apps.jpartition.model.UserFacade;
+
+class ConsoleView {
+ private static final Logger log = Logger.getLogger(ConsoleView.class);
+
+ private final Context context;
+ private final boolean install;
+
+ ConsoleView(InputStream in, PrintStream out, ErrorReporter errorReporter, boolean install)
+ {
+ this.context = new Context(in, out, errorReporter);
+ this.install = install;
+
+ try {
+ start();
+ } catch (Throwable e) {
+ errorReporter.reportError(log, this, e);
+ }
+ }
+
+ private void start() throws Exception
+ {
+ selectDevice();
+ selectPartition();
+ }
+
+ private void selectDevice() throws IOException
+ {
+ String[] devices = UserFacade.getInstance().getDevices();
+ Options devicesOpt = new Options(context);
+ int choice = devicesOpt.show("Select a device", devices);
+
+ String device = devices[choice - 1];
+ UserFacade.getInstance().selectDevice(device);
+ System.err.println("device="+device);
+ }
+
+ private void selectPartition() throws Exception
+ {
+ List<Partition> partitions = UserFacade.getInstance().getPartitions();
+
+ Partition partition = null;
+ if(install)
+ {
+ if(partitions.isEmpty())
+ {
+ //TODO
+ YesNo createPart = new YesNo(context);
+ boolean create = createPart.show("There is no partition. Would you liek to create one ?");
+
+ partition = null; //TODO
+ }
+ }
+
+ if(partition == null)
+ {
+ Options partitionsOpt = new Options(context);
+ int choice = partitionsOpt.show("Select a partition", partitions);
+
+ partition = partitions.get(choice - 1);
+ //UserFacade.getInstance().selectDevice(device);
+ }
+
+ //TODO return result of selection
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,39 @@
+package org.jnode.apps.jpartition.consoleview;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+
+import org.jnode.apps.jpartition.ErrorReporter;
+import org.jnode.apps.jpartition.ViewFactory;
+import org.jnode.shell.help.ParsedArguments;
+
+/**
+ *
+ * @author Fabien Duminy
+ *
+ */
+public class ConsoleViewFactory implements ViewFactory {
+ private final InputStream in;
+ private final PrintStream out;
+ private final PrintStream err;
+
+ public ConsoleViewFactory(InputStream in, PrintStream out, PrintStream err)
+ {
+ this.in = in;
+ this.out = out;
+ this.err = err;
+ }
+
+ public Object createCommandProcessorView() {
+ return null; // nothing particular to create : work is done by createDeviceView
+ }
+
+ public Object createDeviceView(ErrorReporter errorReporter,
+ Object cmdProcessorView, boolean install) throws Exception {
+ return new ConsoleView(in, out, errorReporter, install);
+ }
+
+ public ErrorReporter createErrorReporter() {
+ return new ConsoleErrorReporter(err);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,94 @@
+package org.jnode.apps.jpartition.consoleview.components;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.Context;
+
+public class Component {
+ protected final Context context;
+
+ protected Component(Context context) {
+ this.context = context;
+ }
+
+ final protected void print(String s) {
+ context.getOut().print(s);
+ }
+
+ final protected void println(String s) {
+ context.getOut().println(s);
+ }
+
+ final protected int read() throws IOException {
+ return context.getIn().read();
+ }
+
+ final protected boolean readBoolean(boolean defaultValue) throws IOException {
+ String line = context.getIn().readLine();
+
+ boolean value = defaultValue;
+ try
+ {
+ if(defaultValue)
+ {
+ value = ("no".equals(line)) ? false : true;
+ }
+ else
+ {
+ value = ("yes".equals(line)) ? true : false;
+ }
+ }
+ catch(Exception e)
+ {
+ value = defaultValue;
+ }
+
+ return value;
+ }
+
+ final protected int readInt(int defaultValue) throws IOException {
+ String line = context.getIn().readLine();
+ int value = defaultValue;
+ try
+ {
+ value = Integer.valueOf(line);
+ }
+ catch(NumberFormatException e)
+ {
+ value = defaultValue;
+ }
+ return value;
+ }
+
+ final protected void reportError(Logger log, Object source, Throwable t)
+ {
+ context.getErrorReporter().reportError(log, source, t);
+ }
+
+ final protected void reportError(Logger log, Object source, String message)
+ {
+ context.getErrorReporter().reportError(log, source, message);
+ }
+
+ final protected void checkNonNull(String paramName, Object param)
+ {
+ if(param == null)
+ {
+ throw new NullPointerException("parameter "+paramName+" can't be null");
+ }
+ }
+
+ final protected void checkNonEmpty(String paramName, Collection<?> param)
+ {
+ checkNonNull(paramName, param);
+
+ if(param.isEmpty())
+ {
+ throw new IllegalArgumentException("parameter "+paramName+" can't be empty");
+ }
+ }
+
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,43 @@
+package org.jnode.apps.jpartition.consoleview.components;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.Context;
+
+public class Options extends Component {
+ private static final Logger log = Logger.getLogger(Options.class);
+
+ public Options(Context context) {
+ super(context);
+ }
+
+ public int show(String question, String[] options) throws IOException {
+ return show(question, Arrays.asList(options));
+ }
+
+ public int show(String question, Collection<?> options) throws IOException {
+ checkNonNull("question", question);
+ checkNonEmpty("options", options);
+
+ println(question);
+ int i = 1;
+ for(Object option : options)
+ {
+ println(" " + i + " - "+option);
+ i++;
+ }
+ print("Choice : ");
+
+ int choice = readInt(-1);
+ while((choice < 1) || (choice > options.size()))
+ {
+ reportError(log, null, "invalid choice");
+ choice = readInt(-1);
+ }
+
+ return choice;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -0,0 +1,24 @@
+package org.jnode.apps.jpartition.consoleview.components;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.Context;
+
+public class YesNo extends Component {
+ private static final Logger log = Logger.getLogger(YesNo.class);
+
+ public YesNo(Context context) {
+ super(context);
+ }
+
+ public boolean show(String question) throws IOException {
+ checkNonNull("question", question);
+
+ print(question);
+
+ return readBoolean(false);
+ }
+}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingErrorReporter.java 2008-01-15 05:37:17 UTC (rev 3703)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingErrorReporter.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -9,7 +9,7 @@
public class SwingErrorReporter extends ErrorReporter
{
@Override
- protected void displayError(Object source, Object message) {
+ protected void displayError(Object source, String message) {
Component parent = (source instanceof Component) ? (Component) source : null;
JOptionPane.showMessageDialog(parent,
"an error happened : "+message+"\nSee logs for details",
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java 2008-01-15 05:37:17 UTC (rev 3703)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -7,7 +7,7 @@
public class SwingViewFactory implements ViewFactory {
public Object createDeviceView(ErrorReporter errorReporter,
- Object cmdProcessorView) throws Exception
+ Object cmdProcessorView, boolean install) throws Exception
{
return new MainView(errorReporter, (JComponent)cmdProcessorView);
}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java 2008-01-15 05:37:17 UTC (rev 3703)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -8,7 +8,6 @@
import org.jnode.apps.jpartition.model.TestRemovePartitionFromDevice;
import org.jnode.apps.jpartition.swingview.FileDeviceView;
import org.jnode.apps.jpartition.utils.device.DeviceUtils;
-import org.jnode.emu.ShellEmu;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -24,31 +23,31 @@
}
public static void main(String[] args) throws Throwable {
-/*
- UserFacade.getInstance().selectDevice("dev1");
- System.out.print("devices:");
- for(String device : UserFacade.getInstance().getDevices())
- {
- System.out.print(device);
- System.out.print(", ");
- }
- System.out.println();
+// UserFacade.getInstance().selectDevice("dev1");
+// System.out.print("devices:");
+// for(String device : UserFacade.getInstance().getDevices())
+// {
+// System.out.print(device);
+// System.out.print(", ");
+// }
+// System.out.println();
+//
+// UserFacade.getInstance().createPartition(0, 5000);
+// UserFacade.getInstance().createPartition(5000, 2000);
+// UserFacade.getInstance().createPartition(7000, 3000);
+//
+// System.out.print("partitions:\n");
+// for(Partition partition : UserFacade.getInstance().getPartitions())
+// {
+// System.out.print("\tstart="+partition.getStart());
+// System.out.print(" end="+partition.getEnd());
+// System.out.print(" size="+partition.getSize());
+// System.out.println(" used="+partition.isUsed());
+// }
+// System.out.println();
- UserFacade.getInstance().createPartition(0, 5000);
- UserFacade.getInstance().createPartition(5000, 2000);
- UserFacade.getInstance().createPartition(7000, 3000);
-
- System.out.print("partitions:\n");
- for(Partition partition : UserFacade.getInstance().getPartitions())
- {
- System.out.print("\tstart="+partition.getStart());
- System.out.print(" end="+partition.getEnd());
- System.out.print(" size="+partition.getSize());
- System.out.println(" used="+partition.isUsed());
- }
- System.out.println();
-*/
- final ErrorReporter errorReporter = JPartition.createViewFactory(args).createErrorReporter();
+ final ViewFactory vf = JPartition.createViewFactory(JPartition.CONSOLEUI, System.in, System.out, System.err);
+ final ErrorReporter errorReporter = vf.createErrorReporter();
new Thread()
{
public void run()
@@ -60,6 +59,8 @@
}
}
}.start();
+
+ DeviceUtils.createFakeDevice(new ErrorReporter());
JPartition.main(args);
}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2008-01-15 05:37:17 UTC (rev 3703)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2008-01-16 17:03:28 UTC (rev 3704)
@@ -9,6 +9,7 @@
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.swingview.FileDeviceView;
+import org.jnode.apps.jpartition.utils.BasicNameSpace;
import org.jnode.apps.vmware.disk.VMWareDisk;
import org.jnode.apps.vmware.disk.tools.DiskFactory;
import org.jnode.driver.Device;
@@ -17,8 +18,8 @@
import org.jnode.driver.DeviceNotFoundException;
import org.jnode.driver.DriverException;
import org.jnode.driver.bus.ide.IDEDevice;
-import org.jnode.emu.ShellEmu;
import org.jnode.naming.InitialNaming;
+import org.jnode.naming.NameSpace;
import org.jnode.test.fs.driver.stubs.StubDeviceManager;
import org.jnode.util.OsUtils;
@@ -32,11 +33,11 @@
{
try {
- ShellEmu.main(new String[0]);
- //NameSpace namespace = new BasicNameSpace();
- //InitialNaming.setNameSpace(namespace);
+ //ShellEmu.main(new String[0]);
+ NameSpace namespace = new BasicNameSpace();
+ InitialNaming.setNameSpace(namespace);
- //InitialNaming.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE);
+ InitialNaming.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE);
} catch (NameAlreadyBoundException e) {
throw new RuntimeException(e);
} catch (NamingException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2008-01-18 09:09:39
|
Revision: 3711
http://jnode.svn.sourceforge.net/jnode/?rev=3711&view=rev
Author: fduminy
Date: 2008-01-18 01:09:31 -0800 (Fri, 18 Jan 2008)
Log Message:
-----------
jpartition : work in progress for console view
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Labelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -23,6 +23,10 @@
this.errorReporter = errorReporter;
}
+ public boolean hasChanges() {
+ return !commands.isEmpty();
+ }
+
public synchronized void process()
{
try
@@ -31,43 +35,10 @@
{
running = true;
- while(!commands.isEmpty())
+ boolean quit = false;
+ while(!commands.isEmpty() && !quit)
{
- Command command = null;
- try
- {
- command = peekCommand();
-
- command.execute(this);
- }
- catch(CommandException e)
- {
- log.error("error in command processing", e);
- break;
- }
- catch(Throwable t)
- {
- log.error("unexpected error in command processing", t);
- break;
- }
- finally
- {
- if(command != null)
- {
- for(CommandProcessorListener l : listeners)
- {
- l.commandFinished(this, command);
- }
-
- try {
- removeCommand();
- }
- catch(Throwable t)
- {
- log.error("error in removeCommand", t);
- }
- }
- }
+ quit = processCommand();
}
running = false;
@@ -78,7 +49,49 @@
errorReporter.reportError(log, this, t);
}
}
+
+ private boolean processCommand()
+ {
+ boolean quit = false;
+ Command command = null;
+ try
+ {
+ command = peekCommand();
+ command.execute(this);
+ }
+ catch(CommandException e)
+ {
+ log.error("error in command processing", e);
+ quit = true;
+ }
+ catch(Throwable t)
+ {
+ log.error("unexpected error in command processing", t);
+ quit = true;
+ }
+ finally
+ {
+ if(command != null)
+ {
+ for(CommandProcessorListener l : listeners)
+ {
+ l.commandFinished(this, command);
+ }
+
+ try {
+ removeCommand();
+ }
+ catch(Throwable t)
+ {
+ log.error("error in removeCommand", t);
+ }
+ }
+ }
+
+ return quit;
+ }
+
public void addCommand(Command command)
{
if(command.getStatus() != CommandStatus.NOT_RUNNING)
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -8,20 +8,25 @@
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
import org.jnode.apps.jpartition.ErrorReporter;
+import org.jnode.apps.jpartition.consoleview.components.Component;
+import org.jnode.apps.jpartition.consoleview.components.Labelizer;
+import org.jnode.apps.jpartition.consoleview.components.NumberField;
import org.jnode.apps.jpartition.consoleview.components.Options;
import org.jnode.apps.jpartition.consoleview.components.YesNo;
+import org.jnode.apps.jpartition.model.Device;
import org.jnode.apps.jpartition.model.Partition;
import org.jnode.apps.jpartition.model.UserFacade;
+import org.jnode.util.NumberUtils;
-class ConsoleView {
+class ConsoleView extends Component {
private static final Logger log = Logger.getLogger(ConsoleView.class);
- private final Context context;
private final boolean install;
+ private Partition selectedPartition;
ConsoleView(InputStream in, PrintStream out, ErrorReporter errorReporter, boolean install)
{
- this.context = new Context(in, out, errorReporter);
+ super(new Context(in, out, errorReporter));
this.install = install;
try {
@@ -29,51 +34,91 @@
} catch (Throwable e) {
errorReporter.reportError(log, this, e);
}
+
+ println();
+ print("selectedPartition="+PartitionLabelizer.INSTANCE.getLabel(selectedPartition));
+ print(" on device "+DeviceLabelizer.INSTANCE.getLabel(UserFacade.getInstance().getSelectedDevice()));
}
private void start() throws Exception
{
selectDevice();
selectPartition();
+
+ if(UserFacade.getInstance().hasChanges())
+ {
+ YesNo yesNo = new YesNo(context);
+ boolean apply = yesNo.show("There is pending modifications. Would you like to apply them ?");
+ if(apply)
+ {
+ UserFacade.getInstance().applyChanges();
+ }
+ }
}
private void selectDevice() throws IOException
{
- String[] devices = UserFacade.getInstance().getDevices();
+ List<Device> devices = UserFacade.getInstance().getDevices();
Options devicesOpt = new Options(context);
- int choice = devicesOpt.show("Select a device", devices);
+ int choice = (int) devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE);
- String device = devices[choice - 1];
+ String device = devices.get(choice - 1).getName();
UserFacade.getInstance().selectDevice(device);
- System.err.println("device="+device);
+ println("device="+device);
}
private void selectPartition() throws Exception
{
+ selectedPartition = null;
+ if(install)
+ {
+ selectedPartition = selectPartitionForInstall();
+ }
+
+ if(selectedPartition == null)
+ {
+ selectedPartition = selectPartitionForDevice();
+ }
+ }
+
+ private Partition selectPartitionForDevice() throws Exception {
List<Partition> partitions = UserFacade.getInstance().getPartitions();
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select a partition", partitions, PartitionLabelizer.INSTANCE);
+
+ return partitions.get(choice - 1);
+ }
+
+ private Partition selectPartitionForInstall() throws Exception
+ {
+ List<Partition> partitions = UserFacade.getInstance().getPartitions();
Partition partition = null;
- if(install)
+ if((partitions.size() == 1) && !partitions.get(0).isUsed())
{
- if(partitions.isEmpty())
+ YesNo yesNo = new YesNo(context);
+ boolean create = yesNo.show("There is no partition. Would you like to create one ?");
+ if(create)
{
- //TODO
- YesNo createPart = new YesNo(context);
- boolean create = createPart.show("There is no partition. Would you liek to create one ?");
-
- partition = null; //TODO
+ partition = createPartition(partitions.get(0));
}
}
- if(partition == null)
+ return partition;
+ }
+
+ private Partition createPartition(Partition freePart) throws Exception {
+ long size = freePart.getSize();
+ String space = NumberUtils.toBinaryByte(size);
+ YesNo yesNo = new YesNo(context);
+ boolean allSpace = yesNo.show("Would you like to use all the free space ("+space+") ?");
+
+ if(!allSpace)
{
- Options partitionsOpt = new Options(context);
- int choice = partitionsOpt.show("Select a partition", partitions);
-
- partition = partitions.get(choice - 1);
- //UserFacade.getInstance().selectDevice(device);
+ NumberField sizeField = new NumberField(context);
+ size = sizeField.show("Size of the new partition ");
}
- //TODO return result of selection
+ return UserFacade.getInstance().createPartition(freePart.getStart(), size);
}
}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -0,0 +1,19 @@
+package org.jnode.apps.jpartition.consoleview;
+
+import org.jnode.apps.jpartition.consoleview.components.Labelizer;
+import org.jnode.apps.jpartition.model.Device;
+import org.jnode.apps.jpartition.model.Partition;
+import org.jnode.util.NumberUtils;
+
+class DeviceLabelizer implements Labelizer<Device>
+{
+ static final DeviceLabelizer INSTANCE = new DeviceLabelizer();
+
+ public String getLabel(Device device) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(device.getName());
+ sb.append(" (").append(NumberUtils.toBinaryByte(device.getSize())).append(')');
+
+ return sb.toString();
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -0,0 +1,20 @@
+package org.jnode.apps.jpartition.consoleview;
+
+import org.jnode.apps.jpartition.consoleview.components.Labelizer;
+import org.jnode.apps.jpartition.model.Partition;
+import org.jnode.util.NumberUtils;
+
+class PartitionLabelizer implements Labelizer<Partition>
+{
+ static final PartitionLabelizer INSTANCE = new PartitionLabelizer();
+
+ public String getLabel(Partition partition) {
+ StringBuilder sb = new StringBuilder();
+ sb.append('[').append(partition.getStart()).append(',').append(partition.getEnd()).append(']');
+ sb.append(" (").append(NumberUtils.toBinaryByte(partition.getSize())).append(") ");
+ String format = partition.isUsed() ? partition.getFormat() : "unused";
+ sb.append(format);
+
+ return sb.toString();
+ }
+}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -17,7 +17,11 @@
final protected void print(String s) {
context.getOut().print(s);
}
-
+
+ final protected void println() {
+ context.getOut().println();
+ }
+
final protected void println(String s) {
context.getOut().println(s);
}
@@ -49,12 +53,12 @@
return value;
}
- final protected int readInt(int defaultValue) throws IOException {
+ final protected long readInt(long defaultValue) throws IOException {
String line = context.getIn().readLine();
- int value = defaultValue;
+ long value = defaultValue;
try
{
- value = Integer.valueOf(line);
+ value = Long.valueOf(line);
}
catch(NumberFormatException e)
{
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Labelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Labelizer.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Labelizer.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -0,0 +1,5 @@
+package org.jnode.apps.jpartition.consoleview.components;
+
+public interface Labelizer<T> {
+ String getLabel(T value);
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -0,0 +1,35 @@
+package org.jnode.apps.jpartition.consoleview.components;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.Context;
+
+public class NumberField extends Component {
+ private static final Logger log = Logger.getLogger(NumberField.class);
+
+ public NumberField(Context context) {
+ super(context);
+ }
+
+ public long show(String question) throws IOException {
+ return show(question, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ public long show(String question, long min, long max) throws IOException {
+ checkNonNull("question", question);
+
+ print(question);
+
+ long value = readInt(-1);
+ while((value < min) || (value > max))
+ {
+ reportError(log, null, "invalid choice");
+ value = readInt(-1);
+ }
+
+ return value;
+ }
+}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -14,30 +14,34 @@
super(context);
}
- public int show(String question, String[] options) throws IOException {
+ public <T> long show(String question, T[] options) throws IOException {
+ return show(question, Arrays.asList(options), null);
+ }
+
+ public <T> long show(String question, T[] options, Labelizer<T> labelizer) throws IOException {
return show(question, Arrays.asList(options));
}
- public int show(String question, Collection<?> options) throws IOException {
+ @SuppressWarnings("unchecked")
+ public <T> long show(String question, Collection<T> options) throws IOException {
+ return show(question, Arrays.asList(options), null);
+ }
+
+ public <T> long show(String question, Collection<T> options, Labelizer<T> labelizer) throws IOException {
checkNonNull("question", question);
checkNonEmpty("options", options);
+ println();
println(question);
int i = 1;
- for(Object option : options)
+ for(T option : options)
{
- println(" " + i + " - "+option);
+ String label = (labelizer == null) ? String.valueOf(option) : labelizer.getLabel(option);
+ println(" " + i + " - "+label);
i++;
}
- print("Choice : ");
- int choice = readInt(-1);
- while((choice < 1) || (choice > options.size()))
- {
- reportError(log, null, "invalid choice");
- choice = readInt(-1);
- }
-
- return choice;
+ NumberField choice = new NumberField(context);
+ return choice.show("Choice : ", 1, options.size());
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -17,6 +17,7 @@
public boolean show(String question) throws IOException {
checkNonNull("question", question);
+ println();
print(question);
return readBoolean(false);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -79,13 +79,12 @@
return name.hashCode();
}
- final void addPartition(long start, long size)
+ final Partition addPartition(long start, long size)
{
final long end = (start + size - 1);
checkBounds(this, "start", start);
checkBounds(this, "end", end);
- Partition newPart = null;
int index = findPartition(start, false);
if(index < 0)
{
@@ -95,7 +94,7 @@
Partition oldPart = partitions.get(index);
checkBounds(oldPart, "end", end);
- newPart = new Partition(start, size, true);
+ Partition newPart = new Partition(start, size, true);
if(oldPart.getSize() == size)
{
// replace the unused partition
@@ -133,6 +132,8 @@
// after the new partition
partitions.add(index + 2, new Partition(end + 1, endSize, false));
}
+
+ return newPart;
}
final void removePartition(long offset)
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -2,15 +2,15 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Arrays;
import javax.naming.NameNotFoundException;
-import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.commands.CreatePartitionCommand;
import org.jnode.apps.jpartition.commands.FormatPartitionCommand;
@@ -113,22 +113,33 @@
return names;
}
- public String[] getDevices() {
+ public String[] getDeviceNames() {
String[] names = devices.keySet().toArray(new String[devices.size()]);
Arrays.sort(names);
return names;
}
+ public List<Device> getDevices() {
+ List<Device> devs = new ArrayList<Device>(devices.values());
+ Collections.sort(devs, new Comparator<Device>(){
+ public int compare(Device dev1, Device dev2) {
+ return dev1.getName().compareTo(dev2.getName());
+ }});
+ return devs;
+ }
+
public List<Partition> getPartitions() throws Exception {
checkSelectedDevice();
return selectedDevice.getPartitions();
}
- public void createPartition(long start, long size) throws Exception {
+ public Partition createPartition(long start, long size) throws Exception {
checkSelectedDevice();
- selectedDevice.addPartition(start, size);
+ Partition newPart = selectedDevice.addPartition(start, size);
cmdProcessor.addCommand(new CreatePartitionCommand((IDEDevice) selectedDevice.getDevice(), 0)); //TODO set parameters
+
+ return newPart;
}
public void removePartition(long offset) throws Exception {
@@ -159,6 +170,10 @@
refreshDevicesFromOS();
}
+ public boolean hasChanges() {
+ return cmdProcessor.hasChanges();
+ }
+
private void refreshDevicesFromOS()
{
devices.clear();
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -34,7 +34,7 @@
deviceView = new DeviceView(errorReporter);
add(deviceView, BorderLayout.CENTER);
- devices = new DefaultComboBoxModel(UserFacade.getInstance().getDevices());
+ devices = new DefaultComboBoxModel(UserFacade.getInstance().getDeviceNames());
final JComboBox cboDevices = new JComboBox(devices);
cboDevices.addItemListener(new ItemListener()
{
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -81,13 +81,14 @@
public void testAddPartitionAllFreeSpace()
{
final int nbPartitions = device.getPartitions().size();
- device.addPartition(getStartFreeSpace(), getFreeSpace());
+ Partition newPart = device.addPartition(getStartFreeSpace(), getFreeSpace());
+ assertEquals(getStartFreeSpace(), getFreeSpace(), true, newPart);
List<Partition> partitions = device.getPartitions();
Assert.assertEquals("must have only "+nbPartitions+" partition(s)", nbPartitions, partitions.size());
Partition part = partitions.get(getIndexFreeSpacePartition());
- assertEquals(getStartFreeSpace(), getFreeSpace(), true, part);
+ Assert.assertTrue("must return the same instance as addPartition", newPart == part);
}
@Test
@@ -96,14 +97,16 @@
final int nbPartitions = device.getPartitions().size();
final long begin = getStartFreeSpace();
final long size = getFreeSpace() - 1500;
- device.addPartition(begin, size);
+
+ Partition newPart = device.addPartition(begin, size);
+ assertEquals(begin, size, true, newPart);
List<Partition> partitions = device.getPartitions();
final int expectedNbPartitions = nbPartitions + 1;
Assert.assertEquals("must have only "+expectedNbPartitions+" partition(s)", expectedNbPartitions, partitions.size());
Partition part1 = partitions.get(getIndexFreeSpacePartition());
- assertEquals(begin, size, true, part1);
+ Assert.assertTrue("must return the same instance as addPartition", newPart == part1);
Partition part2 = partitions.get(getIndexFreeSpacePartition()+1);
long part2Size = getFreeSpace() - part1.getSize();
@@ -117,7 +120,9 @@
final long shift = 500;
final long begin = getStartFreeSpace() + shift;
final long size = getFreeSpace() - 1500;
- device.addPartition(begin, size);
+
+ Partition newPart = device.addPartition(begin, size);
+ assertEquals(begin, size, true, newPart);
List<Partition> partitions = device.getPartitions();
final int expectedNbPartitions = nbPartitions + 2;
@@ -127,7 +132,7 @@
assertEquals(getStartFreeSpace(), shift, false, part1);
Partition part2 = partitions.get(getIndexFreeSpacePartition()+1);
- assertEquals(begin, size, true, part2);
+ Assert.assertTrue("must return the same instance as addPartition", newPart == part2);
Partition part3 = partitions.get(getIndexFreeSpacePartition()+2);
long part3Size = getFreeSpace() - part1.getSize() - part2.getSize();
@@ -141,7 +146,9 @@
final long shift = 1500;
final long begin = getStartFreeSpace() + shift;
final long size = getFreeSpace() - shift;
- device.addPartition(begin, size);
+
+ Partition newPart = device.addPartition(begin, size);
+ assertEquals(begin, size, true, newPart);
List<Partition> partitions = device.getPartitions();
final int expectedNbPartitions = nbPartitions + 1;
@@ -151,7 +158,7 @@
assertEquals(getStartFreeSpace(), shift, false, part1);
Partition part2 = partitions.get(getIndexFreeSpacePartition()+1);
- assertEquals(begin, size, true, part2);
+ Assert.assertTrue("must return the same instance as addPartition", newPart == part1);
}
@Test
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java 2008-01-17 14:04:58 UTC (rev 3710)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java 2008-01-18 09:09:31 UTC (rev 3711)
@@ -9,7 +9,7 @@
@Before
public void setUp() throws Exception {
DeviceUtils.createFakeDevice(new ErrorReporter());
- UserFacade.getInstance().getDevices();
+ UserFacade.getInstance().getDeviceNames();
//selectedDevice = new Device("dev1", 10000);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2008-02-04 19:54:38
|
Revision: 3757
http://jnode.svn.sourceforge.net/jnode/?rev=3757&view=rev
Author: fduminy
Date: 2008-02-04 11:54:36 -0800 (Mon, 04 Feb 2008)
Log Message:
-----------
JPartition : work in progress
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceException.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSListener.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AbstractAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AddPartitionAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/FormatPartitionAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/RemovePartitionAction.java
trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestRemovePartitionFromDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacadeException.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/CustomDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/VMWareIDEDevice.java
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,27 +1,17 @@
package org.jnode.apps.jpartition;
-import java.io.InputStream;
-import java.io.PrintStream;
-
import org.jnode.apps.jpartition.model.UserFacade;
public class JPartition {
final private ViewFactory viewFactory;
- final private InputStream in;
- final private PrintStream out;
- final private PrintStream err;
final private boolean install;
-
- public JPartition(ViewFactory viewFactory, InputStream in,
- PrintStream out, PrintStream err, boolean install)
+
+ public JPartition(ViewFactory viewFactory, boolean install)
{
this.viewFactory = viewFactory;
- this.in = in;
- this.out = out;
- this.err = err;
this.install = install;
}
-
+
public final void launch() throws Exception
{
ErrorReporter errorReporter = viewFactory.createErrorReporter();
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -4,34 +4,19 @@
import java.io.PrintStream;
import org.jnode.apps.jpartition.consoleview.ConsoleViewFactory;
-import org.jnode.apps.jpartition.model.UserFacade;
import org.jnode.apps.jpartition.swingview.SwingViewFactory;
-import org.jnode.driver.console.ConsoleManager;
-import org.jnode.driver.console.TextConsole;
-import org.jnode.driver.console.swing.SwingTextScreenConsoleManager;
-import org.jnode.emu.ShellEmu;
-import org.jnode.naming.InitialNaming;
-import org.jnode.plugin.ExtensionPoint;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.CommandShell;
-import org.jnode.shell.ShellManager;
-import org.jnode.shell.alias.AliasManager;
-import org.jnode.shell.alias.def.DefaultAliasManager;
-import org.jnode.shell.def.DefaultShellManager;
import org.jnode.shell.help.Help;
import org.jnode.shell.help.Parameter;
import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.argument.FileArgument;
import org.jnode.shell.help.argument.OptionArgument;
import org.jnode.shell.help.argument.StringArgument;
-import charvax.swing.JLabel;
-
public class JPartitionCommand extends AbstractCommand {
- static public final String SWINGUI = "swing";
- static public final String CONSOLEUI = "console";
-
+ static public final String SWINGUI = "swing";
+ static public final String CONSOLEUI = "console";
+
static private final OptionArgument ARG_UI = new OptionArgument("ui",
"The type of GUI you want to use",
new OptionArgument.Option(SWINGUI, "use swing for UI"),
@@ -40,12 +25,12 @@
static private final StringArgument ARG_INSTALL = new StringArgument("install",
"select a partition (optionally being created/formatted)");
- public static Help.Info HELP_INFO = new Help.Info("jpartition", "partition disks",
- new Parameter[] {
+ public static Help.Info HELP_INFO = new Help.Info("jpartition", "partition disks",
+ new Parameter[] {
new Parameter(ARG_UI, Parameter.MANDATORY),
new Parameter(ARG_INSTALL, Parameter.OPTIONAL)
});
-
+
public static void main(String[] args) throws Exception
{
// testCharva(args);
@@ -54,15 +39,15 @@
}
public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception
+ PrintStream out, PrintStream err) throws Exception
{
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
+ ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
String ui = ARG_UI.getValue(cmdLine);
boolean install = (ARG_INSTALL.getValue(cmdLine) != null);
-
+
ViewFactory viewFactory = createViewFactory(ui, in, out, err);
-
- JPartition jpartition = new JPartition(viewFactory, in, out, err, install);
+
+ JPartition jpartition = new JPartition(viewFactory, install);
jpartition.launch();
}
@@ -72,13 +57,13 @@
ViewFactory viewFactory = null;
if(CONSOLEUI.equals(ui))
{
- viewFactory = new ConsoleViewFactory(in, out, err);
+ viewFactory = new ConsoleViewFactory(in, out, err);
}
else if(SWINGUI.equals(ui))
{
- viewFactory = new SwingViewFactory();
+ viewFactory = new SwingViewFactory();
}
-
+
return viewFactory;
}
@@ -103,7 +88,7 @@
sm.registerShell(cs);
new Thread(cs).start();
*/
-/*
+/*
charvax.swing.JFrame frm = new charvax.swing.JFrame("test");
JLabel label = new JLabel("test");
frm.add(label);
@@ -111,6 +96,6 @@
frm.setSize(20, 20);
frm.setVisible(true);
frm.setDefaultCloseOperation(charvax.swing.JFrame.EXIT_ON_CLOSE);
-*/
+*/
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,15 +1,12 @@
package org.jnode.apps.jpartition.commands;
-import java.io.IOException;
-
import org.jnode.apps.jpartition.commands.framework.CommandException;
import org.jnode.driver.bus.ide.IDEDevice;
-import org.jnode.partitions.command.PartitionHelper;
public class CreatePartitionCommand extends BasePartitionCommand {
final private long start;
final private long size;
-
+
public CreatePartitionCommand(IDEDevice device, int partitionNumber, long start, long size) {
super("create partition", device, partitionNumber);
this.start = start;
@@ -20,15 +17,15 @@
final protected void doExecute() throws CommandException {
// PartitionHelper helper = createPartitionHelper();
// try {
-//
+//
// helper.write();
// } catch (IOException e) {
// throw new CommandException(e);
// }
}
-
+
@Override
public String toString() {
return "create partition [" + start + ", " + (start+size-1) + "] on device " + device.getId();
- }
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -6,9 +6,9 @@
import org.jnode.fs.Formatter;
public class FormatPartitionCommand extends BasePartitionCommand {
- private final Formatter<? extends FileSystem> formatter;
-
- public FormatPartitionCommand(IDEDevice device, int partitionNumber, Formatter<? extends FileSystem> formatter) {
+ private final Formatter<? extends FileSystem<?>> formatter;
+
+ public FormatPartitionCommand(IDEDevice device, int partitionNumber, Formatter<? extends FileSystem<?>> formatter) {
super("format partition", device, partitionNumber);
this.formatter = formatter;
}
@@ -17,9 +17,9 @@
final protected void doExecute() throws CommandException {
// TODO Auto-generated method stub
}
-
+
@Override
public String toString() {
return "format partition " + partitionNumber + " on device " + device.getId() + " with " + formatter.getFileSystemType().getName();
- }
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,6 +1,8 @@
package org.jnode.apps.jpartition.commands.framework;
public class CommandException extends Exception {
+ private static final long serialVersionUID = -8340890789850970389L;
+
public CommandException(String s, Throwable cause) {
super(s, cause);
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -3,9 +3,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
+
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.ErrorReporter;
-import org.jnode.apps.jpartition.swingview.SwingErrorReporter;
public class CommandProcessor
{
@@ -27,7 +27,7 @@
{
return new ArrayList<Command>(commands);
}
-
+
public synchronized void process()
{
try
@@ -50,7 +50,7 @@
errorReporter.reportError(log, this, t);
}
}
-
+
private boolean processCommand()
{
boolean quit = false;
@@ -88,8 +88,8 @@
log.error("error in removeCommand", t);
}
}
- }
-
+ }
+
return quit;
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -19,23 +19,23 @@
class ConsoleView extends Component {
private static final Logger log = Logger.getLogger(ConsoleView.class);
-
+
private final boolean install;
private Partition selectedPartition;
-
+
ConsoleView(InputStream in, PrintStream out, ErrorReporter errorReporter, boolean install)
{
super(new Context(in, out, errorReporter));
this.install = install;
-
+
try {
start();
} catch (Throwable e) {
errorReporter.reportError(log, this, e);
}
-
+
println();
-
+
if(selectedPartition == null)
{
print("selectedPartition=none");
@@ -44,7 +44,7 @@
{
print("selectedPartition="+PartitionLabelizer.INSTANCE.getLabel(selectedPartition));
}
-
+
if(UserFacade.getInstance().getSelectedDevice() == null)
{
println(" on no device");
@@ -54,12 +54,18 @@
println(" on device "+DeviceLabelizer.INSTANCE.getLabel(UserFacade.getInstance().getSelectedDevice()));
}
}
-
+
private void start() throws Exception
{
selectDevice();
+ if(!UserFacade.getInstance().getSelectedDevice().hasPartititionTable())
+ {
+ println("device has no partition table");
+ return;
+ }
+
selectPartition();
-
+
List<Command> pendingCommands = UserFacade.getInstance().getPendingCommands();
if(!pendingCommands.isEmpty())
{
@@ -70,7 +76,7 @@
{
println("\t"+cmd);
}
-
+
boolean apply = yesNo.show("Would you like to apply them ?");
if(apply)
{
@@ -78,13 +84,13 @@
}
}
}
-
+
private void selectDevice() throws IOException
{
List<Device> devices = UserFacade.getInstance().getDevices();
Options devicesOpt = new Options(context);
int choice = (int) devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE);
-
+
String device = devices.get(choice - 1).getName();
UserFacade.getInstance().selectDevice(device);
println("device="+device);
@@ -102,17 +108,17 @@
selectedPartition = createPartition(partitions.get(0));
}
}
-
+
if(selectedPartition == null)
{
partitions = UserFacade.getInstance().getPartitions();
-
+
Options partitionsOpt = new Options(context);
int choice = (int) partitionsOpt.show("Select a partition", partitions, PartitionLabelizer.INSTANCE);
-
+
selectedPartition = partitions.get(choice - 1);
}
-
+
if(selectedPartition != null)
{
if(install)
@@ -125,20 +131,20 @@
}
}
}
-
+
private Partition createPartition(Partition freePart) throws Exception {
long size = freePart.getSize();
NumberField sizeField = new NumberField(context);
size = sizeField.show("Size of the new partition ", size, 1, size);
-
+
return UserFacade.getInstance().createPartition(freePart.getStart(), size);
}
-
+
private void modifyPartition(Partition partition) throws Exception {
if(partition.isUsed())
{
final String[] operations = new String[]{"format partition", "remove partition"};
-
+
Options partitionsOpt = new Options(context);
int choice = (int) partitionsOpt.show("Select an operation", operations);
switch(choice)
@@ -150,7 +156,7 @@
else
{
final String[] operations = new String[]{"add partition"};
-
+
Options partitionsOpt = new Options(context);
int choice = (int) partitionsOpt.show("Select an operation", operations);
switch(choice)
@@ -163,7 +169,7 @@
private void removePartition(Partition partition) throws Exception {
YesNo yesNo = new YesNo(context);
boolean remove = yesNo.show("Would like you to remove the partition ?");
-
+
if(remove)
{
UserFacade.getInstance().removePartition(partition.getStart() + 1);
@@ -175,9 +181,9 @@
Options partitionsOpt = new Options(context);
int choice = (int) partitionsOpt.show("Select a filesystem", formatters);
String formatter = formatters[choice];
-
+
UserFacade.getInstance().selectFormatter(formatter);
-
+
UserFacade.getInstance().formatPartition(partition.getStart() + 1);
- }
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -5,10 +5,9 @@
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.ViewFactory;
-import org.jnode.shell.help.ParsedArguments;
/**
- *
+ *
* @author Fabien Duminy
*
*/
@@ -16,14 +15,14 @@
private final InputStream in;
private final PrintStream out;
private final PrintStream err;
-
+
public ConsoleViewFactory(InputStream in, PrintStream out, PrintStream err)
{
this.in = in;
this.out = out;
this.err = err;
}
-
+
public Object createCommandProcessorView() {
return null; // nothing particular to create : work is done by createDeviceView
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -2,13 +2,12 @@
import org.jnode.apps.jpartition.consoleview.components.Labelizer;
import org.jnode.apps.jpartition.model.Device;
-import org.jnode.apps.jpartition.model.Partition;
import org.jnode.util.NumberUtils;
class DeviceLabelizer implements Labelizer<Device>
{
static final DeviceLabelizer INSTANCE = new DeviceLabelizer();
-
+
public String getLabel(Device device) {
if(device == null)
{
@@ -16,10 +15,10 @@
}
StringBuilder sb = new StringBuilder();
-
+
sb.append(device.getName());
sb.append(" (").append(NumberUtils.toBinaryByte(device.getSize())).append(')');
-
+
return sb.toString();
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,15 +1,10 @@
package org.jnode.apps.jpartition.consoleview.components;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
public class NumberField extends Component {
- private static final Logger log = Logger.getLogger(NumberField.class);
-
public NumberField(Context context) {
super(context);
}
@@ -25,19 +20,19 @@
public Long show(String question, Long defaultValue, long min, long max) throws IOException {
checkNonNull("question", question);
checkInBounds("min", min, "max", max, "defaultValue", defaultValue);
-
+
print(question);
if(defaultValue != null)
{
print(" ["+defaultValue+"]");
}
-
+
Long value = readInt(defaultValue, min, max);
- while((value == null) || (value < min) || (value > max))
+ while((value == null) || (value < min) || (value > max))
{
value = readInt(defaultValue);
}
-
+
return value;
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -4,12 +4,9 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
public class Options extends Component {
- private static final Logger log = Logger.getLogger(Options.class);
-
public Options(Context context) {
super(context);
}
@@ -21,16 +18,16 @@
public <T> long show(String question, T[] options, Labelizer<T> labelizer) throws IOException {
return show(question, Arrays.asList(options));
}
-
+
@SuppressWarnings("unchecked")
public <T> long show(String question, Collection<T> options) throws IOException {
return show(question, Arrays.asList(options), null);
}
-
+
public <T> long show(String question, Collection<T> options, Labelizer<T> labelizer) throws IOException {
checkNonNull("question", question);
checkNonEmpty("options", options);
-
+
println();
println(question);
int i = 1;
@@ -40,7 +37,7 @@
println(" " + i + " - "+label);
i++;
}
-
+
NumberField choice = new NumberField(context);
return choice.show("Choice : ", null, 1, options.size());
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,15 +1,10 @@
package org.jnode.apps.jpartition.consoleview.components;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
public class YesNo extends Component {
- private static final Logger log = Logger.getLogger(YesNo.class);
-
public YesNo(Context context) {
super(context);
}
@@ -17,31 +12,31 @@
public boolean show(String question) throws IOException {
return show(question, null);
}
-
+
public boolean show(String question, Boolean defaultValue) throws IOException {
checkNonNull("question", question);
-
+
println();
print(question);
-
+
if(defaultValue != null)
{
- String defaultValueStr = getValueStr(defaultValue);
+ String defaultValueStr = getValueStr(defaultValue);
print("["+defaultValueStr+"]");
}
-
+
Boolean value;
do
{
value = readBoolean(defaultValue);
-
+
if(value == null)
{
reportError("invalid value");
}
}
while(value == null);
-
+
return value;
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,30 +1,25 @@
package org.jnode.apps.jpartition.model;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.jnode.fs.FileSystem;
import org.jnode.fs.Formatter;
-public class Device implements Iterable<Partition>, Bounded {
+public class Device implements Bounded {
final private String name;
final private long size;
final private List<Partition> partitions;
final private org.jnode.driver.Device device;
+ final private boolean hasPartititionTable;
- Device(String name, long size) {
- this(name, size, null, new ArrayList<Partition>());
- partitions.add(new Partition(0L, size, false));
- }
-
Device(String name, long size, org.jnode.driver.Device device, List<Partition> partitions) {
this.name = name;
this.size = size;
this.partitions = partitions;
this.device = device;
+ this.hasPartititionTable = !partitions.isEmpty();
}
final public String getName() {
@@ -35,11 +30,12 @@
return size;
}
- final public Iterator<Partition> iterator() {
- return partitions.iterator();
+ final public boolean hasPartititionTable() {
+ return hasPartititionTable;
}
final public List<Partition> getPartitions() {
+ checkPartitionned();
return Collections.unmodifiableList(partitions);
}
@@ -62,14 +58,14 @@
return name.equals(other.name);
}
- final org.jnode.driver.Device getDevice()
+ final public int hashCode()
{
- return device;
+ return name.hashCode();
}
- final public int hashCode()
+ final org.jnode.driver.Device getDevice()
{
- return name.hashCode();
+ return device;
}
final Partition addPartition(long start, long size)
@@ -124,7 +120,7 @@
// after the new partition
partitions.add(index + 2, new Partition(end + 1, endSize, false));
}
-
+
return newPart;
}
@@ -139,7 +135,7 @@
Partition part = partitions.get(index);
long start = part.getStart();
long size = part.getSize();
-
+
if(index > 0)
{
Partition partBefore = partitions.get(index - 1);
@@ -167,7 +163,7 @@
partitions.set(index, new Partition(start, size, false));
}
- final void formatPartition(long offset, Formatter<? extends FileSystem> formatter)
+ final void formatPartition(long offset, Formatter<? extends FileSystem<?>> formatter)
{
int index = findPartition(offset, true);
if(index < 0)
@@ -179,38 +175,14 @@
part.format(formatter);
}
-/*
- public void moveStart(DevicePart part, long delta)
- {
- if(part.isUsed())
- {
- ((Partition) part).moveStart(delta);
- }
- }
-
- public void moveEnd(DevicePart part, long delta)
- {
- if(part.isUsed())
- {
- //TODO
- //((Partition) part).moveEnd(delta);
- }
- }
-
- public void move(DevicePart part, long delta)
- {
- moveStart(part, delta);
- moveEnd(part, delta);
- }
-*/
-
final private int findPartition(long offset, boolean used)
{
+ checkPartitionned();
checkOffset(offset);
int result = -1;
int index = 0;
- for(Partition currentPart : this)
+ for(Partition currentPart : partitions)
{
if(currentPart.contains(offset) && (currentPart.isUsed() == used))
{
@@ -230,6 +202,13 @@
}
}
+ final private void checkPartitionned()
+ {
+ if(!hasPartititionTable)
+ {
+ throw new DeviceException("device has no partition table");
+ }
+ }
final private void checkBounds(Bounded bounded, String valueName, long value) {
if(value < bounded.getStart())
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceException.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceException.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceException.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -3,6 +3,8 @@
public class DeviceException extends RuntimeException {
+ private static final long serialVersionUID = -6289552400638465023L;
+
public DeviceException() {
super();
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -25,8 +25,6 @@
INSTANCE = new OSFacade();
}
- private OSListener osListener;
-
private OSFacade()
{
}
@@ -36,11 +34,11 @@
return INSTANCE;
}
- final void setOSListener(final OSListener listener)
+ final void setOSListener(final OSListener listener) throws OSFacadeException
{
- if(this.osListener != null)
+ if(listener == null)
{
- throw new IllegalStateException("listener already set");
+ throw new NullPointerException("listener is null");
}
try {
@@ -48,10 +46,15 @@
public void deviceStarted(org.jnode.driver.Device device) {
if(device instanceof IDEDevice)
{
- Device dev = createDevice(device);
- if(dev != null)
- {
- listener.deviceAdded(dev);
+ Device dev = null;
+ try {
+ dev = createDevice(device);
+ if(dev != null)
+ {
+ listener.deviceAdded(dev);
+ }
+ } catch (OSFacadeException e) {
+ listener.errorHappened(e);
}
}
}
@@ -59,35 +62,43 @@
public void deviceStop(org.jnode.driver.Device device) {
if(device instanceof IDEDevice)
{
- Device dev = createDevice(device);
- if(dev != null)
- {
- listener.deviceRemoved(dev);
+ Device dev = null;
+ try {
+ dev = createDevice(device);
+ if(dev != null)
+ {
+ listener.deviceRemoved(dev);
+ }
+ } catch (OSFacadeException e) {
+ listener.errorHappened(e);
}
}
}});
} catch (NameNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ throw new OSFacadeException("error in setOSListener", e);
}
}
- final List<Device> getDevices() throws NameNotFoundException, ApiNotFoundException, IOException
+ final List<Device> getDevices(...
[truncated message content] |
|
From: <fd...@us...> - 2008-05-01 15:15:23
|
Revision: 4035
http://jnode.svn.sourceforge.net/jnode/?rev=4035&view=rev
Author: fduminy
Date: 2008-05-01 08:15:18 -0700 (Thu, 01 May 2008)
Log Message:
-----------
jpartition : work in progress
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -57,7 +57,12 @@
private void start() throws Exception
{
- selectDevice();
+ if(!selectDevice())
+ {
+ println("no device to partition");
+ return;
+ }
+
if(!UserFacade.getInstance().getSelectedDevice().hasPartititionTable())
{
println("device has no partition table");
@@ -85,15 +90,23 @@
}
}
- private void selectDevice() throws IOException
+ private boolean selectDevice() throws IOException
{
+ boolean deviceSelected = false;
+
List<Device> devices = UserFacade.getInstance().getDevices();
- Options devicesOpt = new Options(context);
- int choice = (int) devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE);
+ if((devices != null) && !devices.isEmpty())
+ {
+ Options devicesOpt = new Options(context);
+ int choice = (int) devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE);
- String device = devices.get(choice - 1).getName();
- UserFacade.getInstance().selectDevice(device);
- println("device="+device);
+ String device = devices.get(choice - 1).getName();
+ UserFacade.getInstance().selectDevice(device);
+ println("device="+device);
+ deviceSelected = true;
+ }
+
+ return deviceSelected;
}
private void selectPartition() throws Exception
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -2,11 +2,16 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import javax.naming.NameNotFoundException;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.DeviceAPI;
import org.jnode.driver.DeviceListener;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DeviceUtils;
@@ -19,6 +24,24 @@
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
public class OSFacade {
+ private static final Logger LOG = Logger.getLogger(OSFacade.class);
+
+ private static Comparator<Partition> PARTITION_COMPARATOR = new Comparator<Partition>()
+ {
+ public int compare(Partition p1, Partition p2) {
+ // we assume here that the partition doesn't intersect
+ return (int) (p1.getStart() - p2.getStart());
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ private static final Class<PartitionableBlockDeviceAPI> REQUIRED_API = PartitionableBlockDeviceAPI.class;
+
+ static
+ {
+ LOG.setLevel(Level.DEBUG);
+ }
+
private static final OSFacade INSTANCE;
static
{
@@ -86,7 +109,7 @@
DeviceManager devMan = org.jnode.driver.DeviceUtils
.getDeviceManager();
for (org.jnode.driver.Device dev : devMan
- .getDevicesByAPI(IDEDeviceAPI.class)) {
+ .getDevicesByAPI(REQUIRED_API)) {
Device device = createDevice(dev);
if (device != null) {
devices.add(device);
@@ -95,54 +118,46 @@
} catch (NameNotFoundException e) {
throw new OSFacadeException("error in getDevices", e);
}
+
return devices;
}
private Device createDevice(org.jnode.driver.Device dev) throws OSFacadeException
{
+ LOG.debug("createDevice: wrapping device "+dev.getId());
+
Device device = null;
List<IBMPartitionTableEntry> partitions = getPartitions(dev);
if(partitions != null) // null if not supported
{
+ LOG.debug("createDevice: nbPartitions="+partitions.size());
+
+ long devSize = 0;
+ try {
+ devSize = dev.getAPI(REQUIRED_API).getLength();
+ } catch (ApiNotFoundException e) {
+ throw new OSFacadeException("error in createDevice", e);
+ } catch (IOException e) {
+ throw new OSFacadeException("error in createDevice", e);
+ }
+
+ // one empty partition taking all place
List<Partition> devPartitions = new ArrayList<Partition>(partitions.size());
- Partition prevPartition = null;
+ devPartitions.add(new Partition(0L, devSize, false));
+ // add used partitions
+ device = new Device(dev.getId(), devSize, dev, devPartitions);
for(IBMPartitionTableEntry e : partitions)
{
IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
+
long start = pte.getStartLba();
long size = pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
-
- if(pte.isEmpty())
- {
- if((prevPartition != null) && !prevPartition.isUsed())
- {
- // current and previous partitions are empty
- prevPartition.mergeWithNextPartition(size);
- }
- else
- {
- // current partition is empty but not the previous one
- devPartitions.add(new Partition(start, size, false));
- }
- }
- else
- {
- // current partition is not empty
- devPartitions.add(new Partition(start, size, true));
- }
+ device.addPartition(start, size); // add a non-empty partition
}
-
- try {
- long devSize = dev.getAPI(IDEDeviceAPI.class).getLength();
- device = new Device(dev.getId(), devSize, dev, devPartitions);
- } catch (ApiNotFoundException e) {
- throw new OSFacadeException("error in createDevice", e);
- } catch (IOException e) {
- throw new OSFacadeException("error in createDevice", e);
- }
}
+ LOG.debug("createDevice: return device="+device);
return device;
}
@@ -152,24 +167,26 @@
List<IBMPartitionTableEntry> partitions = new ArrayList<IBMPartitionTableEntry>();
try {
- if (dev.implementsAPI(IDEDeviceAPI.class)) {
- if (dev.implementsAPI(PartitionableBlockDeviceAPI.class)) {
- PartitionableBlockDeviceAPI<?> api = dev
- .getAPI(PartitionableBlockDeviceAPI.class);
- boolean supportedPartitions = true;
+ if (dev.implementsAPI(REQUIRED_API)) {
+ PartitionableBlockDeviceAPI<?> api = dev
+ .getAPI(REQUIRED_API);
+ boolean supportedPartitions = true;
- for (PartitionTableEntry e : api.getPartitionTable()) {
- if (!(e instanceof IBMPartitionTableEntry)) {
- // non IBM partition tables are not handled for now
- supportedPartitions = false;
- break;
- }
+ for (PartitionTableEntry e : api.getPartitionTable()) {
+ if (!(e instanceof IBMPartitionTableEntry)) {
+ // non IBM partition tables are not handled for now
+ supportedPartitions = false;
+ break;
+ }
- partitions.add((IBMPartitionTableEntry) e);
+ IBMPartitionTableEntry entry = (IBMPartitionTableEntry) e;
+ if(entry.isValid() && !entry.isEmpty())
+ {
+ partitions.add(entry);
}
+ }
- supported = supportedPartitions;
- }
+ supported = supportedPartitions;
}
} catch (ApiNotFoundException e) {
throw new OSFacadeException("error in getPartitions", e);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -19,7 +19,7 @@
if(size < MIN_SIZE)
{
- throw new IllegalArgumentException("size must be > "+MIN_SIZE);
+ throw new IllegalArgumentException("size must be >= "+MIN_SIZE);
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.commands.CreatePartitionCommand;
@@ -26,8 +27,13 @@
import org.jnode.fs.jfat.ClusterSize;
public class UserFacade {
- private static final Logger log = Logger.getLogger(UserFacade.class);
+ private static final Logger LOG = Logger.getLogger(UserFacade.class);
+ static
+ {
+ LOG.setLevel(Level.DEBUG);
+ }
+
private static final UserFacade INSTANCE = new UserFacade();
final private Map<String, Device> devices = new HashMap<String, Device>();
@@ -107,7 +113,7 @@
public void errorHappened(OSFacadeException e) {
if(errorReporter != null)
{
- errorReporter.reportError(log, UserFacade.this, e);
+ errorReporter.reportError(LOG, UserFacade.this, e);
}
}
};
@@ -209,7 +215,7 @@
} catch (OSFacadeException e) {
if(errorReporter != null)
{
- errorReporter.reportError(log, this, e);
+ errorReporter.reportError(LOG, this, e);
}
}
}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -158,7 +158,7 @@
assertEquals(getStartFreeSpace(), shift, false, part1);
Partition part2 = partitions.get(getIndexFreeSpacePartition()+1);
- Assert.assertTrue("must return the same instance as addPartition", newPart == part1);
+ Assert.assertTrue("must return the same instance as addPartition", newPart == part2);
}
@Test
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -2,6 +2,7 @@
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.utils.device.DeviceUtils;
+import org.jnode.test.AnnotationTest.Test;
import org.junit.Before;
public class TestOSFacade extends AbstractTest {
@@ -12,4 +13,9 @@
UserFacade.getInstance().getDeviceNames();
//selectedDevice = new Device("dev1", 10000);
}
+
+ @Test
+ public void removeMe()
+ {
+ }
}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -18,8 +18,19 @@
import org.jnode.driver.DeviceNotFoundException;
import org.jnode.driver.DriverException;
import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.fs.service.FileSystemService;
+import org.jnode.fs.service.def.FileSystemPlugin;
import org.jnode.naming.InitialNaming;
import org.jnode.naming.NameSpace;
+import org.jnode.plugin.Extension;
+import org.jnode.plugin.ExtensionPoint;
+import org.jnode.plugin.Plugin;
+import org.jnode.plugin.PluginDescriptor;
+import org.jnode.plugin.PluginDescriptorListener;
+import org.jnode.plugin.PluginException;
+import org.jnode.plugin.PluginPrerequisite;
+import org.jnode.plugin.Runtime;
+import org.jnode.plugin.model.PluginDescriptorModel;
import org.jnode.test.fs.driver.stubs.StubDeviceManager;
import org.jnode.util.OsUtils;
@@ -38,6 +49,129 @@
InitialNaming.setNameSpace(namespace);
InitialNaming.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE);
+
+ PluginDescriptor desc = new PluginDescriptor()
+ {
+
+ public void addListener(PluginDescriptorListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean depends(String id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getCustomPluginClassName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ExtensionPoint getExtensionPoint(
+ String extensionPointId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ExtensionPoint[] getExtensionPoints() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Extension[] getExtensions() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getLicenseName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getLicenseUrl() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Plugin getPlugin() throws PluginException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ClassLoader getPluginClassLoader() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PluginPrerequisite[] getPrerequisites() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getPriority() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderUrl() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Runtime getRuntime() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getVersion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean hasCustomPluginClass() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isAutoStart() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isFragment() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isSystemPlugin() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ public void removeListener(PluginDescriptorListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ };
+ FileSystemService fss = new FileSystemPlugin(desc);
+ namespace.bind(FileSystemService.class, fss);
} catch (NameAlreadyBoundException e) {
throw new RuntimeException(e);
} catch (NamingException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2008-06-15 13:52:13
|
Revision: 4245
http://jnode.svn.sourceforge.net/jnode/?rev=4245&view=rev
Author: lsantha
Date: 2008-06-15 06:52:09 -0700 (Sun, 15 Jun 2008)
Log Message:
-----------
Codestyle fixes.
Modified Paths:
--------------
trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java
trunk/distr/src/apps/org/jnode/apps/charvabsh/CharvaBsh.java
trunk/distr/src/apps/org/jnode/apps/commander/CharvaCommander.java
trunk/distr/src/apps/org/jnode/apps/console/SwingConsole.java
trunk/distr/src/apps/org/jnode/apps/debug/ListElement.java
trunk/distr/src/apps/org/jnode/apps/debug/ListPanel.java
trunk/distr/src/apps/org/jnode/apps/debug/ObjectFieldPair.java
trunk/distr/src/apps/org/jnode/apps/debug/ObjectMethodPair.java
trunk/distr/src/apps/org/jnode/apps/debug/PropertiesPanel.java
trunk/distr/src/apps/org/jnode/apps/debug/RootObjectPanel.java
trunk/distr/src/apps/org/jnode/apps/debug/TC.java
trunk/distr/src/apps/org/jnode/apps/derby/DerbyCommand.java
trunk/distr/src/apps/org/jnode/apps/edit/EditCommand.java
trunk/distr/src/apps/org/jnode/apps/edit/Editor.java
trunk/distr/src/apps/org/jnode/apps/editor/LeedCommand.java
trunk/distr/src/apps/org/jnode/apps/editor/LeviCommand.java
trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java
trunk/distr/src/apps/org/jnode/apps/httpd/NanoHTTPDCommand.java
trunk/distr/src/apps/org/jnode/apps/jetty/JettyCommand.java
trunk/distr/src/emu/org/jnode/emu/DeviceManager.java
trunk/distr/src/emu/org/jnode/emu/DummyExtensionPoint.java
trunk/distr/src/emu/org/jnode/emu/EditEmu.java
trunk/distr/src/emu/org/jnode/emu/Emu.java
trunk/distr/src/emu/org/jnode/emu/ShellEmu.java
trunk/distr/src/install/org/jnode/install/AbstractInstaller.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/Main.java
trunk/distr/src/install/org/jnode/install/ProgressSupport.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/CommandLineInstaller.java
Modified: trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java
===================================================================
--- trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java 2008-06-15 13:19:31 UTC (rev 4244)
+++ trunk/distr/src/apps/fi/iki/elonen/NanoHTTPD.java 2008-06-15 13:52:09 UTC (rev 4245)
@@ -18,708 +18,669 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package fi.iki.elonen;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLEncoder;
-import java.util.*;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.TimeZone;
/**
* A simple, tiny, nicely embeddable HTTP 1.0 server in Java
- *
+ * <p/>
* <p> NanoHTTPD version 1.01,
* Copyright © 2001 Jarno Elonen (el...@ik..., http://iki.fi/elonen/)
- *
+ * <p/>
* <p><b>Features & limitations: </b><ul>
- *
- * <li> Only one Java file </li>
- * <li> Java 1.1 compatible </li>
- * <li> Released as open source, Modified BSD licence </li>
- * <li> No fixed config files, logging, authorization etc. (Implement yourself if you need them.) </li>
- * <li> Supports parameter parsing of GET and POST methods </li>
- * <li> Supports both dynamic content and file serving </li>
- * <li> Never caches anything </li>
- * <li> Doesn't limit bandwidth, request time or simultaneous connections </li>
- * <li> Default code serves files and shows all HTTP parameters and headers</li>
- * <li> File server supports directory listing, index.html and index.htm </li>
- * <li> File server does the 301 redirection trick for directories without '/'</li>
- * <li> File server supports simple skipping for files (continue download) </li>
- * <li> File server uses current directory as a web root </li>
- * <li> File server serves also very long files without memory overhead </li>
- * <li> Contains a built-in list of most common mime types </li>
- *
+ * <p/>
+ * <li> Only one Java file </li>
+ * <li> Java 1.1 compatible </li>
+ * <li> Released as open source, Modified BSD licence </li>
+ * <li> No fixed config files, logging, authorization etc. (Implement yourself if you need them.) </li>
+ * <li> Supports parameter parsing of GET and POST methods </li>
+ * <li> Supports both dynamic content and file serving </li>
+ * <li> Never caches anything </li>
+ * <li> Doesn't limit bandwidth, request time or simultaneous connections </li>
+ * <li> Default code serves files and shows all HTTP parameters and headers</li>
+ * <li> File server supports directory listing, index.html and index.htm </li>
+ * <li> File server does the 301 redirection trick for directories without '/'</li>
+ * <li> File server supports simple skipping for files (continue download) </li>
+ * <li> File server uses current directory as a web root </li>
+ * <li> File server serves also very long files without memory overhead </li>
+ * <li> Contains a built-in list of most common mime types </li>
+ * <p/>
* </ul>
- *
+ * <p/>
* <p><b>Ways to use: </b><ul>
- *
- * <li> Run as a standalone app, serves files from current directory and shows requests</li>
- * <li> Subclass serve() and embed to your own program </li>
- * <li> Call serveFile() from serve() with your own base directory </li>
- *
+ * <p/>
+ * <li> Run as a standalone app, serves files from current directory and shows requests</li>
+ * <li> Subclass serve() and embed to your own program </li>
+ * <li> Call serveFile() from serve() with your own base directory </li>
+ * <p/>
* </ul>
- *
+ * <p/>
* See the end of the source file for distribution license
* (Modified BSD licence)
*/
-public class NanoHTTPD
-{
- // ==================================================
- // API parts
- // ==================================================
+public class NanoHTTPD {
+ // ==================================================
+ // API parts
+ // ==================================================
- /**
- * Override this to customize the server.<p>
- *
- * (By default, this delegates to serveFile() and allows directory listing.)
- *
- * @parm uri Percent-decoded URI without parameters, for example "/index.cgi"
- * @parm method "GET", "POST" etc.
- * @parm parms Parsed, percent decoded parameters from URI and, in case of POST, data.
- * @parm header Header entries, percent decoded
- * @return HTTP response, see class Response for details
- */
- public Response serve( String uri, String method, Properties header, Properties parms )
- {
- System.out.println( method + " '" + uri + "' " );
-
- Enumeration e = header.propertyNames();
- while ( e.hasMoreElements())
- {
- String value = (String)e.nextElement();
- System.out.println( " HDR: '" + value + "' = '" +
- header.getProperty( value ) + "'" );
- }
- e = parms.propertyNames();
- while ( e.hasMoreElements())
- {
- String value = (String)e.nextElement();
- System.out.println( " PRM: '" + value + "' = '" +
- parms.getProperty( value ) + "'" );
- }
-
- return serveFile( uri, header, new File("."), true );
- }
-
- /**
- * HTTP response.
- * Return one of these from serve().
- */
- public class Response
- {
- /**
- * Default constructor: response = HTTP_OK, data = mime = 'null'
- */
- public Response()
- {
- this.status = HTTP_OK;
- }
-
- /**
- * Basic constructor.
- */
- public Response( String status, String mimeType, InputStream data )
- {
- this.status = status;
- this.mimeType = mimeType;
- this.data = data;
- }
+ /**
+ * Override this to customize the server.<p>
+ * <p/>
+ * (By default, this delegates to serveFile() and allows directory listing.)
+ *
+ * @return HTTP response, see class Response for details
+ * @parm uri Percent-decoded URI without parameters, for example "/index.cgi"
+ * @parm method "GET", "POST" etc.
+ * @parm parms Parsed, percent decoded parameters from URI and, in case of POST, data.
+ * @parm header Header entries, percent decoded
+ */
+ public Response serve(String uri, String method, Properties header, Properties parms) {
+ System.out.println(method + " '" + uri + "' ");
- /**
- * Convenience method that makes an InputStream out of
- * given text.
- */
- public Response( String status, String mimeType, String txt )
- {
- this.status = status;
- this.mimeType = mimeType;
- this.data = new ByteArrayInputStream( txt.getBytes());
- }
+ Enumeration e = header.propertyNames();
+ while (e.hasMoreElements()) {
+ String value = (String) e.nextElement();
+ System.out.println(" HDR: '" + value + "' = '" +
+ header.getProperty(value) + "'");
+ }
+ e = parms.propertyNames();
+ while (e.hasMoreElements()) {
+ String value = (String) e.nextElement();
+ System.out.println(" PRM: '" + value + "' = '" +
+ parms.getProperty(value) + "'");
+ }
- /**
- * Adds given line to the header.
- */
- public void addHeader( String name, String value )
- {
- header.put( name, value );
- }
-
- /**
- * HTTP status code after processing, e.g. "200 OK", HTTP_OK
- */
- public String status;
-
- /**
- * MIME type of content, e.g. "text/html"
- */
- public String mimeType;
-
- /**
- * Data of the response, may be null.
- */
- public InputStream data;
-
- /**
- * Headers for the HTTP response. Use addHeader()
- * to add lines.
- */
- public Properties header = new Properties();
- }
-
- /**
- * Some HTTP response status codes
- */
- public static final String
- HTTP_OK = "200 OK",
- HTTP_REDIRECT = "301 Moved Permanently",
- HTTP_FORBIDDEN = "403 Forbidden",
- HTTP_NOTFOUND = "404 Not Found",
- HTTP_BADREQUEST = "400 Bad Request",
- HTTP_INTERNALERROR = "500 Internal Server Error",
- HTTP_NOTIMPLEMENTED = "501 Not Implemented";
-
- /**
- * Common mime types for dynamic content
- */
- public static final String
- MIME_PLAINTEXT = "text/plain",
- MIME_HTML = "text/html",
- MIME_DEFAULT_BINARY = "application/octet-stream";
-
- // ==================================================
- // Socket & server code
- // ==================================================
-
- /**
- * Starts a HTTP server to given port.<p>
- * Throws an IOException if the socket is already in use
- */
- public NanoHTTPD( int port ) throws IOException
- {
- myTcpPort = port;
+ return serveFile(uri, header, new File("."), true);
+ }
- final ServerSocket ss = new ServerSocket( myTcpPort );
- Thread t = new Thread( new Runnable()
- {
- public void run()
- {
- try
- {
- while( true )
- new HTTPSession( ss.accept());
- }
- catch ( IOException ioe )
- {}
- }
- });
- t.setDaemon( true );
- t.start();
- }
-
- /**
- * Starts as a standalone file server and waits for Enter.
- */
- public static void main( String[] args )
- {
- System.out.println( "NanoHTTPD 1.0 (c) 2001 Jarno Elonen\n" +
- "(Command line options: [port] [--licence])\n" );
+ /**
+ * HTTP response.
+ * Return one of these from serve().
+ */
+ public class Response {
+ /**
+ * Default constructor: response = HTTP_OK, data = mime = 'null'
+ */
+ public Response() {
+ this.status = HTTP_OK;
+ }
- // Show licence if requested
- int lopt = -1;
- for ( int i=0; i<args.length; ++i )
- if ( args[i].toLowerCase().endsWith( "licence" ))
- {
- lopt = i;
- System.out.println( LICENCE + "\n" );
- }
-
- // Change port if requested
- int port = 80;
- if ( args.length > 0 && lopt != 0 )
- port = Integer.parseInt( args[0] );
-
- if ( args.length > 1 &&
- args[1].toLowerCase().endsWith( "licence" ))
- System.out.println( LICENCE + "\n" );
-
- NanoHTTPD nh = null;
- try
- {
- nh = new NanoHTTPD( port );
- }
- catch( IOException ioe )
- {
- System.err.println( "Couldn't start server:\n");
+ /**
+ * Basic constructor.
+ */
+ public Response(String status, String mimeType, InputStream data) {
+ this.status = status;
+ this.mimeType = mimeType;
+ this.data = data;
+ }
+
+ /**
+ * Convenience method that makes an InputStream out of
+ * given text.
+ */
+ public Response(String status, String mimeType, String txt) {
+ this.status = status;
+ this.mimeType = mimeType;
+ this.data = new ByteArrayInputStream(txt.getBytes());
+ }
+
+ /**
+ * Adds given line to the header.
+ */
+ public void addHeader(String name, String value) {
+ header.put(name, value);
+ }
+
+ /**
+ * HTTP status code after processing, e.g. "200 OK", HTTP_OK
+ */
+ public String status;
+
+ /**
+ * MIME type of content, e.g. "text/html"
+ */
+ public String mimeType;
+
+ /**
+ * Data of the response, may be null.
+ */
+ public InputStream data;
+
+ /**
+ * Headers for the HTTP response. Use addHeader()
+ * to add lines.
+ */
+ public Properties header = new Properties();
+ }
+
+ /**
+ * Some HTTP response status codes
+ */
+ public static final String HTTP_OK = "200 OK";
+ public static final String HTTP_REDIRECT = "301 Moved Permanently";
+ public static final String HTTP_FORBIDDEN = "403 Forbidden";
+ public static final String HTTP_NOTFOUND = "404 Not Found";
+ public static final String HTTP_BADREQUEST = "400 Bad Request";
+ public static final String HTTP_INTERNALERROR = "500 Internal Server Error";
+ public static final String HTTP_NOTIMPLEMENTED = "501 Not Implemented";
+
+ /**
+ * Common mime types for dynamic content
+ */
+ public static final String MIME_PLAINTEXT = "text/plain";
+ public static final String MIME_HTML = "text/html";
+ public static final String MIME_DEFAULT_BINARY = "application/octet-stream";
+
+ // ==================================================
+ // Socket & server code
+ // ==================================================
+
+ /**
+ * Starts a HTTP server to given port.<p>
+ * Throws an IOException if the socket is already in use
+ */
+ public NanoHTTPD(int port) throws IOException {
+ myTcpPort = port;
+
+ final ServerSocket ss = new ServerSocket(myTcpPort);
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ while (true)
+ new HTTPSession(ss.accept());
+ } catch (IOException ioe) {
+ //empty
+ }
+ }
+ });
+ t.setDaemon(true);
+ t.start();
+ }
+
+ /**
+ * Starts as a standalone file server and waits for Enter.
+ */
+ public static void main(String[] args) {
+ System.out.println("NanoHTTPD 1.0 (c) 2001 Jarno Elonen\n" +
+ "(Command line options: [port] [--licence])\n");
+
+ // Show licence if requested
+ int lopt = -1;
+ for (int i = 0; i < args.length; ++i)
+ if (args[i].toLowerCase().endsWith("licence")) {
+ lopt = i;
+ System.out.println(LICENCE + "\n");
+ }
+
+ // Change port if requested
+ int port = 80;
+ if (args.length > 0 && lopt != 0)
+ port = Integer.parseInt(args[0]);
+
+ if (args.length > 1 &&
+ args[1].toLowerCase().endsWith("licence"))
+ System.out.println(LICENCE + "\n");
+
+ NanoHTTPD nh = null;
+ try {
+ nh = new NanoHTTPD(port);
+ } catch (IOException ioe) {
+ System.err.println("Couldn't start server:\n");
ioe.printStackTrace();
- System.exit( -1 );
- }
- nh.myFileDir = new File("");
-
- System.out.println( "Now serving files in port " + port + " from \"" +
- new File("").getAbsolutePath() + "\"" );
- System.out.println( "Hit Enter to stop.\n" );
-
- try { System.in.read(); } catch( Throwable t ) {};
- }
-
- /**
- * Handles one session, i.e. parses the HTTP request
- * and returns the response.
- */
- private class HTTPSession implements Runnable
- {
- public HTTPSession( Socket s )
- {
- mySocket = s;
- Thread t = new Thread( this );
- t.setDaemon( true );
- t.start();
- }
-
- public void run()
- {
- try
- {
- InputStream is = mySocket.getInputStream();
- if ( is == null) return;
- BufferedReader in = new BufferedReader( new InputStreamReader( is ));
-
- // Read the request line
- StringTokenizer st = new StringTokenizer( in.readLine());
- if ( !st.hasMoreTokens())
- sendError( HTTP_BADREQUEST, "BAD REQUEST: Syntax error. Usage: GET /example/file.html" );
-
- String method = st.nextToken();
-
- if ( !st.hasMoreTokens())
- sendError( HTTP_BADREQUEST, "BAD REQUEST: Missing URI. Usage: GET /example/file.html" );
+ System.exit(-1);
+ }
+ nh.myFileDir = new File("");
- String uri = decodePercent( st.nextToken());
+ System.out.println("Now serving files in port " + port + " from \"" +
+ new File("").getAbsolutePath() + "\"");
+ System.out.println("Hit Enter to stop.\n");
- // Decode parameters from the URI
- Properties parms = new Properties();
- int qmi = uri.indexOf( '?' );
- if ( qmi >= 0 )
- {
- decodeParms( uri.substring( qmi+1 ), parms );
- uri = decodePercent( uri.substring( 0, qmi ));
- }
-
- // If there's another token, it's protocol version,
- // followed by HTTP headers. Ignore version but parse headers.
- Properties header = new Properties();
- if ( st.hasMoreTokens())
- {
- String line = in.readLine();
- while ( line.trim().length() > 0 )
- {
- int p = line.indexOf( ':' );
- header.put( line.substring(0,p).trim(), line.substring(p+1).trim());
- line = in.readLine();
- }
- }
-
- // If the method is POST, there may be parameters
- // in data section, too, read another line:
- if ( method.equalsIgnoreCase( "POST" ))
- decodeParms( in.readLine(), parms );
+ try {
+ System.in.read();
+ } catch (Throwable t) {
+ //empty
+ }
+ }
- // Ok, now do the serve()
- Response r = serve( uri, method, header, parms );
- if ( r == null )
- sendError( HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: Serve() returned a null response." );
- else
- sendResponse( r.status, r.mimeType, r.header, r.data );
-
- in.close();
- }
- catch ( IOException ioe )
- {
- try
- {
- sendError( HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
- }
- catch ( Throwable t ) {}
- }
- catch ( InterruptedException ie )
- {
- // Thrown by sendError, ignore and exit the thread.
- }
- }
-
- /**
- * Decodes the percent encoding scheme. <br/>
- * For example: "an+example%20string" -> "an example string"
- */
- private String decodePercent( String str ) throws InterruptedException
- {
- try
- {
- StringBuffer sb = new StringBuffer();
- for( int i=0; i<str.length(); i++ )
- {
- char c = str.charAt( i );
- switch ( c )
- {
- case '+':
- sb.append( ' ' );
- break;
- case '%':
- sb.append((char)Integer.parseInt( str.substring(i+1,i+3), 16 ));
- i += 2;
- break;
- default:
- sb.append( c );
- break;
- }
- }
- return new String( sb.toString().getBytes());
- }
- catch( Exception e )
- {
- sendError( HTTP_BADREQUEST, "BAD REQUEST: Bad percent-encoding." );
- return null;
- }
- }
-
- /**
- * Decodes parameters in percent-encoded URI-format
- * ( e.g. "name=Jack%20Daniels&pass=Single%20Malt" ) and
- * adds them to given Properties.
- */
- private void decodeParms( String parms, Properties p )
- throws InterruptedException
- {
- if ( parms == null )
- return;
-
- StringTokenizer st = new StringTokenizer( parms, "&" );
- while ( st.hasMoreTokens())
- {
- String e = st.nextToken();
- int sep = e.indexOf( '=' );
- if ( sep >= 0 )
- p.put( decodePercent( e.substring( 0, sep )).trim(),
- decodePercent( e.substring( sep+1 )));
- }
- }
-
- /**
- * Returns an error message as a HTTP response and
- * throws InterruptedException to stop furhter request processing.
- */
- private void sendError( String status, String msg ) throws InterruptedException
- {
- sendResponse( status, MIME_PLAINTEXT, null, new ByteArrayInputStream( msg.getBytes()));
- throw new InterruptedException();
- }
+ /**
+ * Handles one session, i.e. parses the HTTP request
+ * and returns the response.
+ */
+ private class HTTPSession implements Runnable {
+ public HTTPSession(Socket s) {
+ mySocket = s;
+ Thread t = new Thread(this);
+ t.setDaemon(true);
+ t.start();
+ }
- /**
- * Sends given response to the socket.
- */
- private void sendResponse( String status, String mime, Properties header, InputStream data )
- {
- try
- {
- if ( status == null )
- throw new Error( "sendResponse(): Status can't be null." );
- OutputStream out = mySocket.getOutputStream();
+ public void run() {
+ try {
+ InputStream is = mySocket.getInputStream();
+ if (is == null) return;
+ BufferedReader in = new BufferedReader(new InputStreamReader(is));
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ // Read the request line
+ StringTokenizer st = new StringTokenizer(in.readLine());
+ if (!st.hasMoreTokens())
+ sendError(HTTP_BADREQUEST, "BAD REQUEST: Syntax error. Usage: GET /example/file.html");
- PrintWriter pw = new PrintWriter( out , true);
+ String method = st.nextToken();
- pw.print("HTTP/1.0 " + status + " \r\n");
+ if (!st.hasMoreTokens())
+ sendError(HTTP_BADREQUEST, "BAD REQUEST: Missing URI. Usage: GET /example/file.html");
- if ( mime != null )
- pw.print("Content-Type: " + mime + "\r\n");
+ String uri = decodePercent(st.nextToken());
- if ( header == null || header.getProperty( "Date" ) == null )
- pw.print( "Date: " + gmtFrmt.format( new Date()) + "\r\n");
+ // Decode parameters from the URI
+ Properties parms = new Properties();
+ int qmi = uri.indexOf('?');
+ if (qmi >= 0) {
+ decodeParms(uri.substring(qmi + 1), parms);
+ uri = decodePercent(uri.substring(0, qmi));
+ }
- if ( header != null )
- {
- Enumeration e = header.keys();
- while ( e.hasMoreElements())
- {
- String key = (String)e.nextElement();
- String value = header.getProperty( key );
- pw.print( key + ": " + value + "\r\n");
- }
- }
+ // If there's another token, it's protocol version,
+ // followed by HTTP headers. Ignore version but parse headers.
+ Properties header = new Properties();
+ if (st.hasMoreTokens()) {
+ String line = in.readLine();
+ while (line.trim().length() > 0) {
+ int p = line.indexOf(':');
+ header.put(line.substring(0, p).trim(), line.substring(p + 1).trim());
+ line = in.readLine();
+ }
+ }
- pw.print("\r\n");
- pw.flush();
+ // If the method is POST, there may be parameters
+ // in data section, too, read another line:
+ if (method.equalsIgnoreCase("POST"))
+ decodeParms(in.readLine(), parms);
- if ( data != null )
- {
- byte[] buff = new byte[2048];
- int read = 2048;
+ // Ok, now do the serve()
+ Response r = serve(uri, method, header, parms);
+ if (r == null)
+ sendError(HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: Serve() returned a null response.");
+ else
+ sendResponse(r.status, r.mimeType, r.header, r.data);
- while ( read == 2048 )
- {
- read = data.read( buff, 0, 2048 );
+ in.close();
+ } catch (IOException ioe) {
+ try {
+ sendError(HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
+ } catch (Throwable t) {
+ //empty
+ }
+ } catch (InterruptedException ie) {
+ // Thrown by sendError, ignore and exit the thread.
+ }
+ }
- out.write( buff, 0, read );
- }
- }
+ /**
+ * Decodes the percent encoding scheme. <br/>
+ * For example: "an+example%20string" -> "an example string"
+ */
+ private String decodePercent(String str) throws InterruptedException {
+ try {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < str.length(); i++) {
+ char c = str.charAt(i);
+ switch (c) {
+ case '+':
+ sb.append(' ');
+ break;
+ case '%':
+ sb.append((char) Integer.parseInt(str.substring(i + 1, i + 3), 16));
+ i += 2;
+ break;
+ default:
+ sb.append(c);
+ break;
+ }
+ }
+ return new String(sb.toString().getBytes());
+ } catch (Exception e) {
+ sendError(HTTP_BADREQUEST, "BAD REQUEST: Bad percent-encoding.");
+ return null;
+ }
+ }
- out.write(byteArrayOutputStream.toByteArray());
+ /**
+ * Decodes parameters in percent-encoded URI-format
+ * ( e.g. "name=Jack%20Daniels&pass=Single%20Malt" ) and
+ * adds them to given Properties.
+ */
+ private void decodeParms(String parms, Properties p)
+ throws InterruptedException {
+ if (parms == null)
+ return;
- out.flush();
+ StringTokenizer st = new StringTokenizer(parms, "&");
+ while (st.hasMoreTokens()) {
+ String e = st.nextToken();
+ int sep = e.indexOf('=');
+ if (sep >= 0)
+ p.put(decodePercent(e.substring(0, sep)).trim(),
+ decodePercent(e.substring(sep + 1)));
+ }
+ }
- out.close();
+ /**
+ * Returns an error message as a HTTP response and
+ * throws InterruptedException to stop furhter request processing.
+ */
+ private void sendError(String status, String msg) throws InterruptedException {
+ sendResponse(status, MIME_PLAINTEXT, null, new ByteArrayInputStream(msg.getBytes()));
+ throw new InterruptedException();
+ }
- if ( data != null )
- data.close();
- }
- catch( IOException ioe )
- {
- // Couldn't write? No can do.
- try { mySocket.close(); } catch( Throwable t ) {}
- }
- }
-
- private Socket mySocket;
- private BufferedReader myIn;
- };
-
- /**
- * URL-encodes everything between "/"-characters.
- * Encodes spaces as '%20' instead of '+'.
- */
- private String encodeUri( String uri )
- {
- String newUri = "";
- StringTokenizer st = new StringTokenizer( uri, "/ ", true );
- while ( st.hasMoreTokens())
- {
- String tok = st.nextToken();
- if ( tok.equals( "/" ))
- newUri += "/";
- else if ( tok.equals( " " ))
- newUri += "%20";
- else
- newUri += URLEncoder.encode( tok );
- }
- return newUri;
- }
-
- private int myTcpPort;
- private File myFileDir;
-
- // ==================================================
- // File server code
- // ==================================================
-
- /**
- * Serves file from homeDir and its' subdirectories (only).
- * Uses only URI, ignores all headers and HTTP parameters.
- */
- public Response serveFile( String uri, Properties header, File homeDir,
- boolean allowDirectoryListing )
- {
- // Make sure we won't die of an exception later
- if ( !homeDir.isDirectory())
- return new Response( HTTP_INTERNALERROR, MIME_PLAINTEXT,
- "INTERNAL ERRROR: serveFile(): given homeDir is not a directory." );
+ /**
+ * Sends given response to the socket.
+ */
+ private void sendResponse(String status, String mime, Properties header, InputStream data) {
+ try {
+ if (status == null)
+ throw new Error("sendResponse(): Status can't be null.");
+ Output...
[truncated message content] |
|
From: <fd...@us...> - 2008-06-15 19:35:58
|
Revision: 4252
http://jnode.svn.sourceforge.net/jnode/?rev=4252&view=rev
Author: fduminy
Date: 2008-06-15 12:35:53 -0700 (Sun, 15 Jun 2008)
Log Message:
-----------
checkstyle fixes
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java
trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/Command.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandStatus.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Labelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Bounded.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceException.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacadeException.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSListener.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserListener.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/Constants.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AbstractAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AddPartitionAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/FormatPartitionAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/RemovePartitionAction.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/ExtentDeclaration.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/RandomAccessFileReader.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/AdapterType.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/CreateType.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Descriptor.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DiskDatabase.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Header.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Access.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Extent.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/ExtentType.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/FileDescriptor.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleDescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleIOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTableRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/EntryArray.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainDirectory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtent.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeader.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentIO.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseFileDescriptor.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java
trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTest.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/CustomDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestEmptyDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestNonEmptyDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestRemovePartitionFromDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/swingview/FileDeviceView.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/BasicNameSpace.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/VMWareIDEDevice.java
trunk/distr/src/test/org/jnode/apps/vmware/disk/test/BaseTest.java
trunk/distr/src/test/org/jnode/apps/vmware/disk/test/TestCreation.java
trunk/distr/src/test/org/jnode/apps/vmware/disk/test/Utils.java
trunk/distr/src/test/org/jnode/apps/vmware/disk/test/readwrite/BaseReadWriteTest.java
trunk/distr/src/test/org/jnode/apps/vmware/disk/test/readwrite/TestHeader.java
trunk/distr/src/test/org/jnode/apps/vmware/disk/test/readwrite/TestVMWareDisk.java
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/Context.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -5,30 +5,28 @@
import java.io.InputStreamReader;
import java.io.PrintStream;
-
public class Context {
- private final BufferedReader in;
- private final PrintStream out;
- private final ErrorReporter errorReporter;
-
- public Context(InputStream in, PrintStream out, ErrorReporter errorReporter)
- {
- InputStreamReader r = new InputStreamReader(in);
- this.in = new BufferedReader(r);
-
- this.out = out;
- this.errorReporter = errorReporter;
- }
+ private final BufferedReader in;
+ private final PrintStream out;
+ private final ErrorReporter errorReporter;
- final public PrintStream getOut() {
- return out;
- }
+ public Context(InputStream in, PrintStream out, ErrorReporter errorReporter) {
+ InputStreamReader r = new InputStreamReader(in);
+ this.in = new BufferedReader(r);
- final public BufferedReader getIn() {
- return in;
- }
+ this.out = out;
+ this.errorReporter = errorReporter;
+ }
- final public ErrorReporter getErrorReporter() {
- return errorReporter;
- }
+ public final PrintStream getOut() {
+ return out;
+ }
+
+ public final BufferedReader getIn() {
+ return in;
+ }
+
+ public final ErrorReporter getErrorReporter() {
+ return errorReporter;
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -3,38 +3,30 @@
import org.apache.log4j.Logger;
public class ErrorReporter {
- final public void reportError(Logger log, Object source, Throwable t)
- {
- reportError(log, source, (Object) t);
- }
+ public final void reportError(Logger log, Object source, Throwable t) {
+ reportError(log, source, (Object) t);
+ }
- final public void reportError(Logger log, Object source, String message)
- {
- reportError(log, source, (Object) message);
- }
+ public final void reportError(Logger log, Object source, String message) {
+ reportError(log, source, (Object) message);
+ }
- protected void displayError(Object source, String message)
- {
- // by default display nothing
- }
+ protected void displayError(Object source, String message) {
+ // by default display nothing
+ }
- final private void reportError(Logger log, Object source, Object message)
- {
- Throwable t = (message instanceof Throwable) ? (Throwable) message : null;
+ private final void reportError(Logger log, Object source, Object message) {
+ Throwable t = (message instanceof Throwable) ? (Throwable) message : null;
- String msg = (t == null) ? String.valueOf(message) : t.getMessage();
- displayError(source, msg);
+ String msg = (t == null) ? String.valueOf(message) : t.getMessage();
+ displayError(source, msg);
- if(log != null)
- {
- if(t != null)
- {
- log.error(msg, t);
- }
- else
- {
- log.error(msg);
- }
- }
- }
+ if (log != null) {
+ if (t != null) {
+ log.error(msg, t);
+ } else {
+ log.error(msg);
+ }
+ }
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -3,24 +3,22 @@
import org.jnode.apps.jpartition.model.UserFacade;
public class JPartition {
- final private ViewFactory viewFactory;
- final private boolean install;
+ private final ViewFactory viewFactory;
+ private final boolean install;
- public JPartition(ViewFactory viewFactory, boolean install)
- {
- this.viewFactory = viewFactory;
- this.install = install;
- }
+ public JPartition(ViewFactory viewFactory, boolean install) {
+ this.viewFactory = viewFactory;
+ this.install = install;
+ }
- public final void launch() throws Exception
- {
- ErrorReporter errorReporter = viewFactory.createErrorReporter();
- UserFacade.getInstance().setErrorReporter(errorReporter);
+ public final void launch() throws Exception {
+ ErrorReporter errorReporter = viewFactory.createErrorReporter();
+ UserFacade.getInstance().setErrorReporter(errorReporter);
// CommandProcessor
Object cmdProcessorView = viewFactory.createCommandProcessorView();
// Device
viewFactory.createDeviceView(errorReporter, cmdProcessorView, install);
- }
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -10,34 +10,32 @@
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
-
public class JPartitionCommand extends AbstractCommand {
- private final FlagArgument FLAG_SWING =
- new FlagArgument("swing", Argument.OPTIONAL, "if set, use the Swing (graphic) UI");
-
- private final FlagArgument FLAG_CONSOLE =
- new FlagArgument("console", Argument.OPTIONAL, "if set, use the console (text) UI");
+ private final FlagArgument FLAG_SWING =
+ new FlagArgument("swing", Argument.OPTIONAL, "if set, use the Swing (graphic) UI");
- private final FlagArgument ARG_INSTALL = new FlagArgument(
- "install", Argument.OPTIONAL, "if set, format the partition(s)");
-
- public JPartitionCommand() {
+ private final FlagArgument FLAG_CONSOLE =
+ new FlagArgument("console", Argument.OPTIONAL, "if set, use the console (text) UI");
+
+ private final FlagArgument ARG_INSTALL =
+ new FlagArgument("install", Argument.OPTIONAL, "if set, format the partition(s)");
+
+ public JPartitionCommand() {
super("interactive disk partitioning tool");
registerArguments(FLAG_CONSOLE, FLAG_SWING, ARG_INSTALL);
}
- public static void main(String[] args) throws Exception {
- new JPartitionCommand().execute(args);
- }
+ public static void main(String[] args) throws Exception {
+ new JPartitionCommand().execute(args);
+ }
- public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err)
- throws Exception {
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws Exception {
boolean install = ARG_INSTALL.isSet();
- ViewFactory viewFactory = FLAG_CONSOLE.isSet() ?
- new ConsoleViewFactory(in, out, err) :
- FLAG_SWING.isSet() ? new SwingViewFactory() : null;
+ ViewFactory viewFactory =
+ FLAG_CONSOLE.isSet() ? new ConsoleViewFactory(in, out, err)
+ : FLAG_SWING.isSet() ? new SwingViewFactory() : null;
if (viewFactory == null) {
err.println("No UI selected");
exit(1);
@@ -45,5 +43,5 @@
JPartition jpartition = new JPartition(viewFactory, install);
jpartition.launch();
- }
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -1,11 +1,10 @@
package org.jnode.apps.jpartition;
-
public interface ViewFactory {
- Object createDeviceView(ErrorReporter errorReporter, Object cmdProcessorView, boolean install)
- throws Exception;
+ Object createDeviceView(ErrorReporter errorReporter, Object cmdProcessorView, boolean install)
+ throws Exception;
- Object createCommandProcessorView();
+ Object createCommandProcessorView();
- ErrorReporter createErrorReporter();
+ ErrorReporter createErrorReporter();
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -9,37 +9,34 @@
import org.jnode.driver.bus.ide.IDEDevice;
import org.jnode.partitions.command.PartitionHelper;
-abstract public class BaseDeviceCommand extends BaseCommand {
- protected final IDEDevice device;
+public abstract class BaseDeviceCommand extends BaseCommand {
+ protected final IDEDevice device;
- public BaseDeviceCommand(String name, IDEDevice device)
- {
- super(name);
- if(device == null)
- {
- throw new NullPointerException("device is null");
- }
+ public BaseDeviceCommand(String name, IDEDevice device) {
+ super(name);
+ if (device == null) {
+ throw new NullPointerException("device is null");
+ }
- this.device = device;
- }
-
- final protected PartitionHelper createPartitionHelper() throws CommandException
- {
- try {
- return new PartitionHelper(device);
- } catch (DeviceNotFoundException e) {
- throw new CommandException(e);
- } catch (ApiNotFoundException e) {
- throw new CommandException(e);
- } catch (IOException e) {
- throw new CommandException(e);
- }
- }
+ this.device = device;
+ }
- abstract protected void doExecute() throws CommandException;
+ protected final PartitionHelper createPartitionHelper() throws CommandException {
+ try {
+ return new PartitionHelper(device);
+ } catch (DeviceNotFoundException e) {
+ throw new CommandException(e);
+ } catch (ApiNotFoundException e) {
+ throw new CommandException(e);
+ } catch (IOException e) {
+ throw new CommandException(e);
+ }
+ }
- @Override
- public String toString() {
- return super.toString() + " - " + device.getId();
- }
+ protected abstract void doExecute() throws CommandException;
+
+ @Override
+ public String toString() {
+ return super.toString() + " - " + device.getId();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -3,19 +3,18 @@
import org.jnode.apps.jpartition.commands.framework.CommandException;
import org.jnode.driver.bus.ide.IDEDevice;
-abstract public class BasePartitionCommand extends BaseDeviceCommand {
- protected final int partitionNumber;
+public abstract class BasePartitionCommand extends BaseDeviceCommand {
+ protected final int partitionNumber;
- public BasePartitionCommand(String name, IDEDevice device, int partitionNumber)
- {
- super(name, device);
- this.partitionNumber = partitionNumber;
- }
+ public BasePartitionCommand(String name, IDEDevice device, int partitionNumber) {
+ super(name, device);
+ this.partitionNumber = partitionNumber;
+ }
- abstract protected void doExecute() throws CommandException;
+ protected abstract void doExecute() throws CommandException;
- @Override
- public String toString() {
- return super.toString() + " - partition " + partitionNumber;
- }
+ @Override
+ public String toString() {
+ return super.toString() + " - partition " + partitionNumber;
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -4,28 +4,29 @@
import org.jnode.driver.bus.ide.IDEDevice;
public class CreatePartitionCommand extends BasePartitionCommand {
- final private long start;
- final private long size;
+ private final long start;
+ private final long size;
- public CreatePartitionCommand(IDEDevice device, int partitionNumber, long start, long size) {
- super("create partition", device, partitionNumber);
- this.start = start;
- this.size = size;
- }
+ public CreatePartitionCommand(IDEDevice device, int partitionNumber, long start, long size) {
+ super("create partition", device, partitionNumber);
+ this.start = start;
+ this.size = size;
+ }
- @Override
- final protected void doExecute() throws CommandException {
-// PartitionHelper helper = createPartitionHelper();
-// try {
-//
-// helper.write();
-// } catch (IOException e) {
-// throw new CommandException(e);
-// }
- }
+ @Override
+ protected final void doExecute() throws CommandException {
+ // PartitionHelper helper = createPartitionHelper();
+ // try {
+ //
+ // helper.write();
+ // } catch (IOException e) {
+ // throw new CommandException(e);
+ // }
+ }
- @Override
- public String toString() {
- return "create partition [" + start + ", " + (start+size-1) + "] on device " + device.getId();
- }
+ @Override
+ public String toString() {
+ return "create partition [" + start + ", " + (start + size - 1) + "] on device " +
+ device.getId();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -6,20 +6,22 @@
import org.jnode.fs.Formatter;
public class FormatPartitionCommand extends BasePartitionCommand {
- private final Formatter<? extends FileSystem<?>> formatter;
+ private final Formatter<? extends FileSystem<?>> formatter;
- public FormatPartitionCommand(IDEDevice device, int partitionNumber, Formatter<? extends FileSystem<?>> formatter) {
- super("format partition", device, partitionNumber);
- this.formatter = formatter;
- }
+ public FormatPartitionCommand(IDEDevice device, int partitionNumber,
+ Formatter<? extends FileSystem<?>> formatter) {
+ super("format partition", device, partitionNumber);
+ this.formatter = formatter;
+ }
- @Override
- final protected void doExecute() throws CommandException {
- // TODO Auto-generated method stub
- }
+ @Override
+ protected final void doExecute() throws CommandException {
+ // TODO Auto-generated method stub
+ }
- @Override
- public String toString() {
- return "format partition " + partitionNumber + " on device " + device.getId() + " with " + formatter.getFileSystemType().getName();
- }
+ @Override
+ public String toString() {
+ return "format partition " + partitionNumber + " on device " + device.getId() + " with " +
+ formatter.getFileSystemType().getName();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -6,18 +6,18 @@
public class InitMbrCommand extends BaseDeviceCommand {
- public InitMbrCommand(IDEDevice device) {
- super("init MBR", device);
- }
+ public InitMbrCommand(IDEDevice device) {
+ super("init MBR", device);
+ }
- @Override
- protected void doExecute() throws CommandException {
- PartitionHelper helper;
- try {
- helper = new PartitionHelper(device);
- helper.initMbr();
- } catch (Throwable t) {
- throw new CommandException(t);
- }
- }
+ @Override
+ protected void doExecute() throws CommandException {
+ PartitionHelper helper;
+ try {
+ helper = new PartitionHelper(device);
+ helper.initMbr();
+ } catch (Throwable t) {
+ throw new CommandException(t);
+ }
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -5,18 +5,18 @@
public class RemovePartitionCommand extends BasePartitionCommand {
- public RemovePartitionCommand(IDEDevice device, int partitionNumber) {
- super("remove partition", device, partitionNumber);
- }
+ public RemovePartitionCommand(IDEDevice device, int partitionNumber) {
+ super("remove partition", device, partitionNumber);
+ }
- @Override
- final protected void doExecute() throws CommandException {
- // TODO Auto-generated method stub
- }
-
- @Override
- public String toString() {
- return "remove partition " + partitionNumber + " on device" + device.getId();
- }
-
+ @Override
+ protected final void doExecute() throws CommandException {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public String toString() {
+ return "remove partition " + partitionNumber + " on device" + device.getId();
+ }
+
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java 2008-06-15 17:12:49 UTC (rev 4251)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java 2008-06-15 19:35:53 UTC (rev 4252)
@@ -2,51 +2,42 @@
import org.apache.log4j.Logger;
-abstract public class BaseCommand implements Command
-{
- private static final Logger log = Logger.getLogger(BaseCommand.class);
+public abstract class BaseCommand implements Command {
+ private static final Logger log = Logger.getLogger(BaseCommand.class);
- private CommandStatus status = CommandStatus.NOT_RUNNING;
- final private String name;
+ private CommandStatus status = CommandStatus.NOT_RUNNING;
+ private final String name;
- protected BaseCommand(String name)
- {
- this.name = name;
- }
+ protected BaseCommand(String name) {
+ this.name = name;
+ }
- final public void execute(CommandProcessor processor) throws CommandException
- {
- try
- {
- status = CommandStatus.RUNNING;
- processor.commandStarted(this);
+ public final void execute(CommandProcessor processor) throws CommandException {
+ try {
+ status = CommandStatus.RUNNING;
+ processor.commandStarted(this);
- doExecute();
- status = CommandStatus.SUCCESS;
- }
- catch(CommandException e)
- {
- log.error("command failed", e);
- status = CommandStatus.FAILED;
- throw e;
- }
- catch(Throwable t)
- {
- log.error("command failed", t);
- status = CommandStatus.FAILED;
- throw new CommandException("command failed", t);
- }
- }
+ doExecute();
+ status = CommandStatus.SUCCESS;
+ } catch (CommandException e) {
+ log.error("command failed", e);
+ status = CommandStatus.FAILED;
+ throw e;
+ } catch (Throwable t) {
+ log.error("command failed", t);
+ status = CommandStatus.FAILED;
+ throw new CommandException("command failed", t);
+ }
+ }
- final public CommandStatus getStatus()
- {
- return status;
- }
+ public final CommandStatus getStatus() {
+ return status;
+ }
- abstract protected void doExecute() throws CommandException;
+ protected abstract void doExecute() throws CommandException;
- @Override
- public String toString() {
- return status + " - " + name;
- }
+ @Override
+...
[truncated message content] |