From: <fd...@us...> - 2009-04-19 19:42:08
|
Revision: 5317 http://jnode.svn.sourceforge.net/jnode/?rev=5317&view=rev Author: fduminy Date: 2009-04-19 19:42:05 +0000 (Sun, 19 Apr 2009) Log Message: ----------- fixed various bugs in JPartition/JPartitionTest Modified Paths: -------------- trunk/core/src/driver/org/jnode/driver/AbstractDeviceManager.java trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubDeviceManager.java Modified: trunk/core/src/driver/org/jnode/driver/AbstractDeviceManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/AbstractDeviceManager.java 2009-04-19 19:38:27 UTC (rev 5316) +++ trunk/core/src/driver/org/jnode/driver/AbstractDeviceManager.java 2009-04-19 19:42:05 UTC (rev 5317) @@ -87,8 +87,16 @@ * Create a new instance */ public AbstractDeviceManager() { - cmdLine = (String) AccessController.doPrivileged(new GetPropertyAction( - "jnode.cmdline", "")); + this((String) AccessController.doPrivileged(new GetPropertyAction( + "jnode.cmdline", ""))); + } + + /** + * Create a new instance + * @param commandLine command line or an empty string + */ + protected AbstractDeviceManager(String commandLine) { + this.cmdLine = commandLine; this.systemBus = new SystemBus(); } @@ -143,7 +151,7 @@ * startup is delayed. * <li>Connect the driver to the device, if a driver is found * <li>Attempt to start the device. If this fails an exception is printed - * in the log. You can test if the device was started succesfully, by read + * in the log. You can test if the device was started successfully, by read * the <code>isStarted</code> status. * </ul> * Note that if the device already has a driver connected to it, the first Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2009-04-19 19:38:27 UTC (rev 5316) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartitionCommand.java 2009-04-19 19:42:05 UTC (rev 5317) @@ -54,15 +54,22 @@ InputStream in = getInput().getInputStream(); PrintStream out = getOutput().getPrintStream(); PrintStream err = getError().getPrintStream(); + + boolean consoleView = FLAG_CONSOLE.isSet(); + boolean swingView = FLAG_SWING.isSet(); + doExecute(install, in, out, err, consoleView, swingView); + } + + public void doExecute(boolean install, InputStream in, PrintStream out, PrintStream err, boolean consoleView, boolean swingView) throws Exception { ViewFactory viewFactory = - FLAG_CONSOLE.isSet() ? new ConsoleViewFactory(in, out, err) - : FLAG_SWING.isSet() ? new SwingViewFactory() : null; + consoleView ? new ConsoleViewFactory(in, out, err) + : swingView ? new SwingViewFactory() : null; if (viewFactory == null) { err.println("No UI selected"); exit(1); } - + JPartition jpartition = new JPartition(viewFactory, install); jpartition.launch(); - } + } } Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2009-04-19 19:38:27 UTC (rev 5316) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2009-04-19 19:42:05 UTC (rev 5317) @@ -104,10 +104,10 @@ List<Device> devices = UserFacade.getInstance().getDevices(); if ((devices != null) && !devices.isEmpty()) { Options devicesOpt = new Options(context); - int choice = - (int) devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE); + Device choice = + devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE); - String device = devices.get(choice - 1).getName(); + String device = choice.getName(); UserFacade.getInstance().selectDevice(device); println("device=" + device); deviceSelected = true; @@ -130,11 +130,9 @@ partitions = UserFacade.getInstance().getPartitions(); Options partitionsOpt = new Options(context); - int choice = - (int) partitionsOpt.show("Select a partition", partitions, + selectedPartition = + partitionsOpt.show("Select a partition", partitions, PartitionLabelizer.INSTANCE); - - selectedPartition = partitions.get(choice - 1); } if (selectedPartition != null) { @@ -154,31 +152,49 @@ return UserFacade.getInstance().createPartition(freePart.getStart(), size); } + private enum Operation { + FORMAT_PARTITION("format partition") { + @Override + public void execute(ConsoleView view, Partition partition) throws Exception { + view.formatPartition(partition); + } + }, + ADD_PARTITION("add partition") { + @Override + public void execute(ConsoleView view, Partition partition) throws Exception { + view.createPartition(partition); + } + }, + REMOVE_PARTITION("remove partition") { + @Override + public void execute(ConsoleView view, Partition partition) throws Exception { + view.removePartition(partition); + } + }; + + private String label; + + private Operation(String label) { + this.label = label; + } + + @Override + public String toString() { + return label; + } + + public abstract void execute(ConsoleView view, Partition partition) throws Exception; + } private void modifyPartition(Partition partition) throws Exception { + Operation[] choices; 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) { - case 0: - formatPartition(partition); - break; - case 1: - removePartition(partition); - break; - } + choices = new Operation[] {Operation.FORMAT_PARTITION, Operation.REMOVE_PARTITION}; } else { - final String[] operations = new String[] {"add partition"}; - - Options partitionsOpt = new Options(context); - int choice = (int) partitionsOpt.show("Select an operation", operations); - switch (choice) { - case 0: - createPartition(partition); - break; - } + choices = new Operation[] {Operation.ADD_PARTITION}; } + Options partitionsOpt = new Options(context); + Operation choice = partitionsOpt.show("Select an operation", choices); + choice.execute(this, partition); } private void removePartition(Partition partition) throws Exception { @@ -193,8 +209,7 @@ private void formatPartition(Partition partition) throws Exception { String[] formatters = UserFacade.getInstance().getFormatters(); Options partitionsOpt = new Options(context); - int choice = (int) partitionsOpt.show("Select a filesystem", formatters); - String formatter = formatters[choice]; + String formatter = partitionsOpt.show("Select a filesystem", formatters); UserFacade.getInstance().selectFormatter(formatter); 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 2009-04-19 19:38:27 UTC (rev 5316) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2009-04-19 19:42:05 UTC (rev 5317) @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; +import java.util.List; import org.jnode.apps.jpartition.Context; @@ -31,20 +32,20 @@ super(context); } - public <T> long show(String question, T[] options) throws IOException { + public <T> T 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 { + public <T> T 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> T show(String question, List<T> options) throws IOException { + return show(question, options, null); } - public <T> long show(String question, Collection<T> options, Labelizer<T> labelizer) + public <T> T show(String question, List<T> options, Labelizer<T> labelizer) throws IOException { checkNonNull("question", question); checkNonEmpty("options", options); @@ -60,6 +61,7 @@ } NumberField choice = new NumberField(context); - return choice.show("Choice : ", null, 1, options.size()); + int index = choice.show("Choice : ", null, 1, options.size()).intValue() - 1; + return options.get(index); } } Modified: trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java =================================================================== --- trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java 2009-04-19 19:38:27 UTC (rev 5316) +++ trunk/distr/src/test/org/jnode/apps/jpartition/JPartitionTest.java 2009-04-19 19:42:05 UTC (rev 5317) @@ -33,6 +33,7 @@ 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.driver.bus.ide.IDEDevice; import org.jnode.fs.jfat.command.JGrub; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -61,8 +62,10 @@ * @throws Throwable */ public static void main(String[] args) throws Throwable { + final ViewFactory vf = new ConsoleViewFactory(System.in, System.out, System.err); final ErrorReporter errorReporter = vf.createErrorReporter(); +/* final Thread t = new Thread() { public void run() { try { @@ -73,12 +76,13 @@ } }; t.start(); - +*/ // DeviceUtils.createFakeDevice(new ErrorReporter()); - AbstractIDEDevice dev = DeviceUtils.createFileDevice(); + IDEDevice dev = DeviceUtils.createFileDevice(errorReporter); JGrub jgrub = new JGrub(new PrintWriter(new OutputStreamWriter(System.out)), dev); - jgrub.install(); - - JPartitionCommand.main(args); + +// jgrub.install(); + + new JPartitionCommand().doExecute(true, System.in, System.out, System.err, true, false); } } 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 2009-04-19 19:38:27 UTC (rev 5316) +++ trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2009-04-19 19:42:05 UTC (rev 5317) @@ -37,6 +37,7 @@ import org.jnode.driver.DeviceNotFoundException; import org.jnode.driver.DriverException; import org.jnode.driver.bus.ide.IDEDevice; +import org.jnode.emu.naming.BasicNameSpace; import org.jnode.emu.plugin.model.DummyConfigurationElement; import org.jnode.emu.plugin.model.DummyExtension; import org.jnode.emu.plugin.model.DummyExtensionPoint; @@ -44,6 +45,8 @@ 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.test.fs.driver.stubs.StubDeviceManager; import org.jnode.test.fs.filesystem.config.FSType; import org.jnode.util.OsUtils; @@ -55,18 +58,13 @@ private static boolean coreInitialized = false; public static final void initJNodeCore() { - if (!OsUtils.isJNode() && !coreInitialized) { + if (!coreInitialized && !OsUtils.isJNode()) { try { -// // ShellEmu.main(new String[0]); -// NameSpace namespace = new BasicNameSpace(); -// InitialNaming.setNameSpace(namespace); -// -// InitialNaming.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE); -// -// PluginDescriptor desc = new DummyPluginDescriptor(true); -// FileSystemService fss = new FileSystemPlugin(desc); -// namespace.bind(FileSystemService.class, fss); + // ShellEmu.main(new String[0]); + NameSpace namespace = new BasicNameSpace(); + InitialNaming.setNameSpace(namespace); + InitialNaming.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE); // Build a plugin descriptor that is sufficient for the FileSystemPlugin to // configure file system types for testing. @@ -93,6 +91,36 @@ } coreInitialized = true; } + + +// if (!coreInitialized && !OsUtils.isJNode()) { +// // We are not running in JNode, emulate a JNode environment. +// +// InitialNaming.setNameSpace(new BasicNameSpace()); +// +// // Build a plugin descriptor that is sufficient for the FileSystemPlugin to +// // configure file system types for testing. +// DummyPluginDescriptor desc = new DummyPluginDescriptor(true); +// DummyExtensionPoint ep = new DummyExtensionPoint("types", "org.jnode.fs.types", "types"); +// desc.addExtensionPoint(ep); +// for (FSType fsType : FSType.values()) { +// DummyExtension extension = new DummyExtension(); +// DummyConfigurationElement element = new DummyConfigurationElement(); +// element.addAttribute("class", fsType.getFsTypeClass().getName()); +// extension.addElement(element); +// ep.addExtension(extension); +// } +// +// FileSystemService fss = new FileSystemPlugin(desc); +// try { +// InitialNaming.bind(FileSystemService.class, fss); +// } catch (NameAlreadyBoundException e) { +// throw new RuntimeException(e); +// } catch (NamingException e) { +// throw new RuntimeException(e); +// } +// coreInitialized = true; +// } } public static IDEDevice createFakeDevice(ErrorReporter errorReporter) { @@ -129,6 +157,23 @@ return device; } + public static IDEDevice createFileDevice(ErrorReporter errorReporter) { + IDEDevice device = null; + + try { + AbstractIDEDevice fd = createFileDevice(); + if (addDevice(fd)) { + device = fd; + } else { + errorReporter.reportError(log, DeviceUtils.class.getName(), "failed to add device"); + } + } catch (Exception e) { + log.error(e); + } + + return device; + } + private static AbstractIDEDevice createVMWareDevice() throws Exception { File tmpFile = File.createTempFile("disk", ""); File directory = tmpFile.getParentFile(); @@ -141,7 +186,7 @@ return dev; } - public static AbstractIDEDevice createFileDevice() throws Exception { + private static AbstractIDEDevice createFileDevice() throws Exception { File tmpFile = File.createTempFile("disk", ""); File directory = tmpFile.getParentFile(); String name = tmpFile.getName(); Modified: trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubDeviceManager.java =================================================================== --- trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubDeviceManager.java 2009-04-19 19:38:27 UTC (rev 5316) +++ trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubDeviceManager.java 2009-04-19 19:42:05 UTC (rev 5317) @@ -45,6 +45,7 @@ private List<DeviceToDriverMapper> mappers = new ArrayList<DeviceToDriverMapper>(); private StubDeviceManager() { + super(""); } public void removeAll() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |