|
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() throws OSFacadeException
{
List<Device> devices = new ArrayList<Device>();
- DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
- for(org.jnode.driver.Device dev : devMan.getDevicesByAPI(IDEDeviceAPI.class))
- {
- Device device = createDevice(dev);
- if(device != null)
- {
- devices.add(device);
+ try {
+ DeviceManager devMan = org.jnode.driver.DeviceUtils
+ .getDeviceManager();
+ for (org.jnode.driver.Device dev : devMan
+ .getDevicesByAPI(IDEDeviceAPI.class)) {
+ Device device = createDevice(dev);
+ if (device != null) {
+ devices.add(device);
+ }
}
+ } catch (NameNotFoundException e) {
+ throw new OSFacadeException("error in getDevices", e);
}
return devices;
}
- private Device createDevice(org.jnode.driver.Device dev)
+ private Device createDevice(org.jnode.driver.Device dev) throws OSFacadeException
{
Device device = null;
List<IBMPartitionTableEntry> partitions = getPartitions(dev);
@@ -125,19 +136,17 @@
try {
long devSize = dev.getAPI(IDEDeviceAPI.class).getLength();
device = new Device(dev.getId(), devSize, dev, devPartitions);
- } catch (ApiNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ } catch (ApiNotFoundException e) {
+ throw new OSFacadeException("error in createDevice", e);
+ } catch (IOException e) {
+ throw new OSFacadeException("error in createDevice", e);
}
}
return device;
}
- private List<IBMPartitionTableEntry> getPartitions(org.jnode.driver.Device dev)
+ private List<IBMPartitionTableEntry> getPartitions(org.jnode.driver.Device dev) throws OSFacadeException
{
boolean supported = false;
List<IBMPartitionTableEntry> partitions = new ArrayList<IBMPartitionTableEntry>();
@@ -163,11 +172,9 @@
}
}
} catch (ApiNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ throw new OSFacadeException("error in getPartitions", e);
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ throw new OSFacadeException("error in getPartitions", e);
}
return supported ? partitions : null;
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacadeException.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacadeException.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacadeException.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -0,0 +1,24 @@
+package org.jnode.apps.jpartition.model;
+
+
+public class OSFacadeException extends Exception {
+
+ private static final long serialVersionUID = -8873083906081960569L;
+
+ public OSFacadeException() {
+ super();
+ }
+
+ public OSFacadeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public OSFacadeException(String message) {
+ super(message);
+ }
+
+ public OSFacadeException(Throwable cause) {
+ super(cause);
+ }
+
+}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSListener.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSListener.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSListener.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -6,4 +6,5 @@
void deviceRemoved(Device removedDevice);
+ void errorHappened(OSFacadeException 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-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,8 +1,5 @@
package org.jnode.apps.jpartition.model;
-import java.util.ArrayList;
-import java.util.List;
-
import org.jnode.fs.FileSystem;
import org.jnode.fs.Formatter;
@@ -13,7 +10,7 @@
private long start;
private long size;
private boolean used;
- private Formatter<? extends FileSystem> formatter;
+ private Formatter<? extends FileSystem<?>> formatter;
Partition(long start, long size, boolean used) {
this.start = start;
@@ -65,13 +62,13 @@
}
return format;
}
-
+
final void setSize(long size) {
this.size = size;
}
void mergeWithNextPartition(long nextPartitionSize) {
- this.size += nextPartitionSize;
+ this.size += nextPartitionSize;
}
final boolean contains(long offset) {
@@ -98,7 +95,7 @@
this.size = size;
}
- final void format(Formatter<? extends FileSystem> formatter) {
+ final void format(Formatter<? extends FileSystem<?>> formatter) {
this.formatter = formatter;
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -1,6 +1,5 @@
package org.jnode.apps.jpartition.model;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -9,8 +8,7 @@
import java.util.List;
import java.util.Map;
-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;
@@ -18,7 +16,6 @@
import org.jnode.apps.jpartition.commands.framework.Command;
import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
import org.jnode.apps.jpartition.commands.framework.CommandProcessorListener;
-import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.bus.ide.IDEDevice;
import org.jnode.fs.FileSystem;
import org.jnode.fs.Formatter;
@@ -29,14 +26,17 @@
import org.jnode.fs.jfat.ClusterSize;
public class UserFacade {
+ private static final Logger log = Logger.getLogger(UserFacade.class);
+
private static final UserFacade INSTANCE = new UserFacade();
final private Map<String, Device> devices = new HashMap<String, Device>();
private Device selectedDevice;
private UserListener userListener;
- final private Map<String, Formatter<? extends FileSystem>> formatters = new HashMap<String, Formatter<? extends FileSystem>>();
- private Formatter<? extends FileSystem> selectedFormatter;
+ final private Map<String, Formatter<? extends FileSystem<?>>> formatters = new HashMap<String, Formatter<? extends FileSystem<?>>>();
+ private Formatter<? extends FileSystem<?>> selectedFormatter;
+ private ErrorReporter errorReporter;
private CommandProcessor cmdProcessor;
@@ -55,6 +55,7 @@
public void setErrorReporter(ErrorReporter errorReporter)
{
+ this.errorReporter = errorReporter;
cmdProcessor = new CommandProcessor(errorReporter);
}
@@ -86,7 +87,8 @@
{
this.userListener = listener;
- OSFacade.getInstance().setOSListener(new OSListener(){
+ OSListener osListener = new OSListener()
+ {
public void deviceAdded(Device addedDevice) {
devices.put(addedDevice.getName(), addedDevice);
userListener.deviceAdded(addedDevice.getName());
@@ -100,7 +102,21 @@
{
selectDevice(null, true); // not called by user => need to notify
}
- }});
+ }
+
+ public void errorHappened(OSFacadeException e) {
+ if(errorReporter != null)
+ {
+ errorReporter.reportError(log, UserFacade.this, e);
+ }
+ }
+ };
+
+ try {
+ OSFacade.getInstance().setOSListener(osListener);
+ } catch (OSFacadeException e) {
+ osListener.errorHappened(e);
+ }
}
public void addCommandProcessorListener(CommandProcessorListener listener)
@@ -154,7 +170,7 @@
checkSelectedDevice();
checkSelectedFormatter();
- Formatter<? extends FileSystem> formatter = selectedFormatter.clone();
+ Formatter<? extends FileSystem<?>> formatter = selectedFormatter.clone();
selectedDevice.formatPartition(offset, formatter);
Command cmd = new FormatPartitionCommand((IDEDevice) selectedDevice.getDevice(), 0, formatter); //TODO set parameters
cmdProcessor.addCommand(cmd);
@@ -190,15 +206,11 @@
}
selectDevice(selectedDev, true); // not called by user => need to notify
- } catch (NameNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ApiNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ } catch (OSFacadeException e) {
+ if(errorReporter != null)
+ {
+ errorReporter.reportError(log, this, e);
+ }
}
}
@@ -218,7 +230,7 @@
}
}
- private void addFormatter(Formatter<? extends FileSystem> formatter)
+ private void addFormatter(Formatter<? extends FileSystem<?>> formatter)
{
formatters.put(formatter.getFileSystemType().getName(), formatter);
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -11,7 +11,6 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;
-import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.commands.framework.Command;
import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
import org.jnode.apps.jpartition.commands.framework.CommandProcessorListener;
@@ -20,7 +19,10 @@
public class CommandProcessorView extends JPanel
implements CommandProcessorListener
{
- private static final Logger log = Logger.getLogger(CommandProcessorView.class);
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4411987954528000167L;
private DefaultListModel commands = new DefaultListModel();
private JList commandsUI = new JList(commands);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -15,6 +15,8 @@
public class DeviceView extends DiskAreaView<Device>
{
+ private static final long serialVersionUID = 4961328945650444476L;
+
public DeviceView(ErrorReporter errorReporter)
{
super(errorReporter);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -19,6 +19,8 @@
abstract public class DiskAreaView<T extends Bounded> extends JComponent
{
+ private static final long serialVersionUID = -506634580666065291L;
+
final private int DEFAULT_PIXELS_PER_BYTE = 1;
final protected int borderWidth = 5;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -11,14 +11,13 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
-import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.model.Device;
import org.jnode.apps.jpartition.model.UserFacade;
import org.jnode.apps.jpartition.model.UserListener;
public class MainView extends JFrame {
- private static final Logger log = Logger.getLogger(DeviceView.class);
+ private static final long serialVersionUID = -7377987617244339590L;
final private DefaultComboBoxModel devices;
final private DeviceView deviceView;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AbstractAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AbstractAction.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AbstractAction.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -6,6 +6,8 @@
import org.jnode.apps.jpartition.swingview.DiskAreaView;
abstract class AbstractAction<T extends DiskAreaView<? extends Bounded>> extends javax.swing.AbstractAction {
+ private static final long serialVersionUID = -8091888570743940797L;
+
protected final Logger log = Logger.getLogger(getClass());
protected final ErrorReporter errorReporter;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AddPartitionAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AddPartitionAction.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/AddPartitionAction.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -12,13 +12,14 @@
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
-import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.model.Device;
import org.jnode.apps.jpartition.model.UserFacade;
import org.jnode.apps.jpartition.swingview.PartitionView;
public class AddPartitionAction extends AbstractAction<PartitionView> {
+ private static final long serialVersionUID = 1240081461305707910L;
+
public AddPartitionAction(ErrorReporter errorReporter, PartitionView view) {
super("add a partition", errorReporter, view);
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/FormatPartitionAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/FormatPartitionAction.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/FormatPartitionAction.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -12,6 +12,8 @@
import org.jnode.apps.jpartition.swingview.PartitionView;
public class FormatPartitionAction extends AbstractAction<PartitionView> {
+ private static final long serialVersionUID = 4100228292937417784L;
+
public FormatPartitionAction(ErrorReporter errorReporter, PartitionView view) {
super("format the partition", errorReporter, view);
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -5,11 +5,12 @@
import javax.swing.AbstractAction;
import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
-import org.jnode.apps.jpartition.model.UserFacade;
import org.jnode.driver.bus.ide.IDEDevice;
public class InitMbrAction extends AbstractAction
{
+ private static final long serialVersionUID = -8121457813730139127L;
+
public InitMbrAction(IDEDevice device, CommandProcessor processor) {
super("init MBR");
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/RemovePartitionAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/RemovePartitionAction.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/RemovePartitionAction.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -5,11 +5,12 @@
import javax.swing.SwingUtilities;
import org.jnode.apps.jpartition.ErrorReporter;
-import org.jnode.apps.jpartition.model.Device;
import org.jnode.apps.jpartition.model.UserFacade;
import org.jnode.apps.jpartition.swingview.PartitionView;
public class RemovePartitionAction extends AbstractAction<PartitionView> {
+ private static final long serialVersionUID = -6500251696985382641L;
+
public RemovePartitionAction(ErrorReporter errorReporter, PartitionView view) {
super("remove partition", errorReporter, view);
}
@@ -18,8 +19,9 @@
SwingUtilities.invokeLater(new Runnable()
{
public void run() {
- final Device dev = UserFacade.getInstance().getSelectedDevice();
+ //final Device dev = UserFacade.getInstance().getSelectedDevice();
try {
+ //TODO select the device before
UserFacade.getInstance().removePartition(view.getPartition().getStart()+1);
view.getDeviceView().update();
} catch (Exception e) {
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -7,7 +7,9 @@
import org.jnode.apps.jpartition.model.TestOSFacade;
import org.jnode.apps.jpartition.model.TestRemovePartitionFromDevice;
import org.jnode.apps.jpartition.swingview.FileDeviceView;
+import org.jnode.apps.jpartition.utils.device.AbstractIDEDevice;
import org.jnode.apps.jpartition.utils.device.DeviceUtils;
+import org.jnode.fs.jfat.command.JGrub;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -23,29 +25,6 @@
}
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().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 ViewFactory vf = JPartitionCommand.createViewFactory(JPartitionCommand.CONSOLEUI, System.in, System.out, System.err);
final ErrorReporter errorReporter = vf.createErrorReporter();
new Thread()
@@ -60,53 +39,11 @@
}
}.start();
- DeviceUtils.createFakeDevice(new ErrorReporter());
+ //DeviceUtils.createFakeDevice(new ErrorReporter());
+ AbstractIDEDevice dev = DeviceUtils.createFileDevice();
+ JGrub jgrub = new JGrub(System.out, System.err, dev);
+ jgrub.install();
+
JPartitionCommand.main(args);
}
-
-// public static TestSuite suite()
-// {
-// TestSuite suite = new TestSuite();
-// suite.addTestSuite(TestNonEmptyDevice.class);
-// suite.addTestSuite(TestEmptyDevice.class);
-// suite.addTestSuite(TestRemovePartitionFromDevice.class);
-// suite.addTestSuite(TestOSFacade.class);
-// return suite;
-// }
-
-/*
- private TestModelFacade modelFacade;
-
- @Override
- protected void setUp() throws Exception {
- modelFacade = new TestModelFacade();
- modelFacade.addDevice(new Device("dev1", 5000));
- }
-
- public void test1()
- {
- 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(DevicePart 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();
- }
-*/
}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -24,7 +24,7 @@
@Before
public void setUp() throws Exception {
- device = new Device("dev1", DEVICE_SIZE);
+ device = new CustomDevice("dev1", DEVICE_SIZE);
}
@Test
@@ -97,7 +97,7 @@
final int nbPartitions = device.getPartitions().size();
final long begin = getStartFreeSpace();
final long size = getFreeSpace() - 1500;
-
+
Partition newPart = device.addPartition(begin, size);
assertEquals(begin, size, true, newPart);
@@ -106,7 +106,7 @@
Assert.assertEquals("must have only "+expectedNbPartitions+" partition(s)", expectedNbPartitions, partitions.size());
Partition part1 = partitions.get(getIndexFreeSpacePartition());
- Assert.assertTrue("must return the same instance as addPartition", newPart == part1);
+ Assert.assertTrue("must return the same instance as addPartition", newPart == part1);
Partition part2 = partitions.get(getIndexFreeSpacePartition()+1);
long part2Size = getFreeSpace() - part1.getSize();
@@ -120,7 +120,7 @@
final long shift = 500;
final long begin = getStartFreeSpace() + shift;
final long size = getFreeSpace() - 1500;
-
+
Partition newPart = device.addPartition(begin, size);
assertEquals(begin, size, true, newPart);
@@ -132,7 +132,7 @@
assertEquals(getStartFreeSpace(), shift, false, part1);
Partition part2 = partitions.get(getIndexFreeSpacePartition()+1);
- Assert.assertTrue("must return the same instance as addPartition", newPart == 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();
@@ -146,7 +146,7 @@
final long shift = 1500;
final long begin = getStartFreeSpace() + shift;
final long size = getFreeSpace() - shift;
-
+
Partition newPart = device.addPartition(begin, size);
assertEquals(begin, size, true, newPart);
@@ -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 == part1);
}
@Test
Added: trunk/distr/src/test/org/jnode/apps/jpartition/model/CustomDevice.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/CustomDevice.java (rev 0)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/CustomDevice.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -0,0 +1,17 @@
+package org.jnode.apps.jpartition.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CustomDevice extends Device {
+ CustomDevice(String name, long size) {
+ super(name, size, null, asList(new Partition(0L, size, false)));
+ }
+
+ private static List<Partition> asList(Partition partition)
+ {
+ List<Partition> list = new ArrayList<Partition>();
+ list.add(partition);
+ return list;
+ }
+}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/TestRemovePartitionFromDevice.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/TestRemovePartitionFromDevice.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/TestRemovePartitionFromDevice.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -16,7 +16,7 @@
@Test
public void testRemovePartitionBetweenNonFreeSpaces()
{
- final Device device = new Device("dev1", DEVICE_SIZE);
+ final Device device = new CustomDevice("dev1", DEVICE_SIZE);
device.addPartition(device.getStart(), beginSpace);
device.addPartition(beginSpace, sizeSpace);
device.addPartition(2500, 2500);
@@ -39,7 +39,7 @@
@Test
public void testRemovePartitionAfterAFreeSpace()
{
- final Device device = new Device("dev1", DEVICE_SIZE);
+ final Device device = new CustomDevice("dev1", DEVICE_SIZE);
device.addPartition(beginSpace, sizeSpace);
device.addPartition(2500, 2500);
@@ -58,7 +58,7 @@
@Test
public void testRemovePartitionBeforeAFreeSpace()
{
- final Device device = new Device("dev1", DEVICE_SIZE);
+ final Device device = new CustomDevice("dev1", DEVICE_SIZE);
device.addPartition(device.getStart(), beginSpace);
device.addPartition(beginSpace, sizeSpace);
@@ -76,7 +76,7 @@
@Test
public void testRemovePartitionBetweenTwoFreeSpaces()
{
- final Device device = new Device("dev1", DEVICE_SIZE);
+ final Device device = new CustomDevice("dev1", DEVICE_SIZE);
device.addPartition(beginSpace, sizeSpace);
device.removePartition(beginSpace + 5);
@@ -90,7 +90,7 @@
@Test
public void testRemoveSinglePartition()
{
- final Device device = new Device("dev1", DEVICE_SIZE);
+ final Device device = new CustomDevice("dev1", DEVICE_SIZE);
device.addPartition(0, DEVICE_SIZE);
device.removePartition(5);
@@ -104,7 +104,7 @@
@Test
public void testRemovePartitionAtBegin()
{
- final Device device = new Device("dev1", DEVICE_SIZE);
+ final Device device = new CustomDevice("dev1", DEVICE_SIZE);
device.addPartition(0, sizeSpace);
device.addPartition(sizeSpace, DEVICE_SIZE - sizeSpace);
@@ -123,7 +123,7 @@
@Test
public void testRemovePartitionAtEnd()
{
- final Device device = new Device("dev1", DEVICE_SIZE);
+ final Device device = new CustomDevice("dev1", DEVICE_SIZE);
device.addPartition(0, sizeSpace);
device.addPartition(sizeSpace, DEVICE_SIZE - sizeSpace);
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java 2008-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -2,37 +2,55 @@
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;
import org.jnode.driver.bus.ide.IDEDevice;
import org.jnode.driver.bus.ide.IDEDeviceAPI;
import org.jnode.partitions.PartitionTable;
-import org.jnode.partitions.PartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTable;
+import org.jnode.partitions.ibm.IBMPartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTableType;
-abstract public class AbstractIDEDevice<PTE extends PartitionTableEntry> extends IDEDevice
- implements IDEDeviceAPI<PTE>
+abstract public class AbstractIDEDevice extends IDEDevice
+ implements IDEDeviceAPI<IBMPartitionTableEntry>
{
- protected PartitionTable pt;
+ private PartitionTable<IBMPartitionTableEntry> pt;
public AbstractIDEDevice(String name,
- boolean primary, boolean master)
+ boolean primary, boolean master) throws DriverException, NameNotFoundException, IOException
{
super(null, primary, master, name, null, null);
+
+ registerAPI(PartitionableBlockDeviceAPI.class, this);
+ registerAPI(IDEDeviceAPI.class, this);
+
+ setDriver(new FileIDEDeviceDriver());
}
- public PartitionTable getPartitionTable() throws IOException {
+ final public PartitionTable<IBMPartitionTableEntry> getPartitionTable() throws IOException {
+ if(pt == null)
+ {
+ try {
+ pt = buildPartitionTable();
+ } catch (NameNotFoundException e) {
+ throw new IOException(e);
+ } catch (DriverException e) {
+ throw new IOException(e);
+ }
+ }
+
return pt;
}
- public int getSectorSize() throws IOException {
+ final public int getSectorSize() throws IOException {
return IDEConstants.SECTOR_SIZE;
}
- protected PartitionTable buildPartitionTable() throws DriverException,
+ final private PartitionTable<IBMPartitionTableEntry> buildPartitionTable() throws DriverException,
IOException, NameNotFoundException
{
// Read the bootsector
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-02-04 19:31:22 UTC (rev 3756)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2008-02-04 19:54:36 UTC (rev 3757)
@@ -24,7 +24,7 @@
import org.jnode.util.OsUtils;
public class DeviceUtils {
- private static final long DEFAULT_FILE_SIZE = 1000;
+ private static final long DEFAULT_FILE_SIZE = 1024*1024;
private static final Logger log = Logger.getLogger(FileDeviceView.class);
private static boolean coreInitialized = false;
@@ -55,7 +5...
[truncated message content] |