[Esbox-commits] r2333 - branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences

eswartz at garage.maemo.org eswartz at garage.maemo.org
Wed Oct 21 19:11:17 EEST 2009


Author: eswartz
Date: 2009-10-21 19:11:17 +0300 (Wed, 21 Oct 2009)
New Revision: 2333

Modified:
   branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/BuildMachinePreferencePage.java
   branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/ValidateMachineRunner.java
Log:
-- Initial support for unmounting shares (only done when releasing machine)
-- Allow restarting when using "Launch machine" on running machine
-- Use "-o soft" option for shares in OS X
-- Fix bug in SSH filesystem #refresh

Modified: branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/BuildMachinePreferencePage.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/BuildMachinePreferencePage.java	2009-10-21 12:57:34 UTC (rev 2332)
+++ branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/BuildMachinePreferencePage.java	2009-10-21 16:11:17 UTC (rev 2333)
@@ -754,13 +754,21 @@
 							monitor.beginTask("Launching machine...", 2);
 							
 							if (controller.isMachineRunning()) {
-								DialogUtils.showWarningDialog(shell, "Already Running", 
-										"This machine is already running.");
-								return;
+								boolean restart = DialogUtils.showQuestionDialog(
+										shell, "Already Running", 
+										"This machine is already running.  Would you like to restart it?",
+										"Restart", "Leave alone");
+								if (!restart)
+									return;
+								
+								MachineManager.getInstance().releaseMachine(
+										machineToLaunch, new SubProgressMonitor(monitor, 1));
+								if (monitor.isCanceled())
+									return;
+							} else {
+								shutDownMachinesBeforeSwitchingTo(machineToLaunch);
 							}
-
-							shutDownMachinesBeforeSwitchingTo(machineToLaunch);
-
+							
 							monitor.worked(1);
 							if (monitor.isCanceled())
 								return;

Modified: branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/ValidateMachineRunner.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/ValidateMachineRunner.java	2009-10-21 12:57:34 UTC (rev 2332)
+++ branches/work_Ed/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/api/maemosdk/ui/preferences/ValidateMachineRunner.java	2009-10-21 16:11:17 UTC (rev 2333)
@@ -12,12 +12,14 @@
 package org.maemo.esbox.internal.api.maemosdk.ui.preferences;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.filesystem.IFileInfo;
@@ -32,12 +34,14 @@
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.maemo.esbox.internal.maemosdk.ui.UIActivator;
+import org.maemo.mica.common.core.HostUtils;
 import org.maemo.mica.common.core.MicaCanceledException;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.Policy;
 import org.maemo.mica.common.core.filesystem.ISharedFilesystemProvider;
 import org.maemo.mica.common.core.filesystem.ISharedFolder;
 import org.maemo.mica.common.core.filesystem.SharedFolderManager;
+import org.maemo.mica.common.core.filesystem.SharedFolderState;
 import org.maemo.mica.common.core.machine.IMachine;
 import org.maemo.mica.common.core.machine.MachineRegistry;
 import org.maemo.mica.common.core.machine.MachineUtils;
@@ -196,7 +200,7 @@
 		IPath workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocation();
 		IPath remoteWorkspace = machine.getFileSystemMapping().convertHostToTargetPath(workspaceRoot);
 		if (remoteWorkspace == null) {
-			warn("Could not access the workspace root on the build machine.\n\nThis will usually complicate new project creation, but it is allowed.\n\nPlace the workspace somewhere under one of your shares for best results.");
+			warn("Could not access the workspace root on the build machine.\n\nThis will force new projects to be created outside the workspace, but it is allowed.\n\nPlace the workspace somewhere under one of your shares for best results.");
 		}
 		monitor.worked(1);
 		
@@ -218,45 +222,97 @@
 			return true;
 		
 		List<ISharedFolder> sharedFolders = sharedFilesystemProvider.getSharedFolders();
-		monitor.beginTask("", sharedFolders.size() + 1);
+		if (sharedFolders.size() == 0) {
+			warn("No shared folders are defined or available\nfor the machine... typically this won't work very well.");
+			return true;
+		}
+
+		monitor.beginTask("", 2 + sharedFolders.size());
+		
 		step(monitor, "Checking shared folders");
 		
 		// ping them all
-		IStatus status = SharedFolderManager.getInstance().validateShares(
-				MachineRegistry.getInstance().getLocalMachine(), machine, 
+		SharedFolderState state = SharedFolderManager.getInstance().analyzeSharedFolderState( 
+				MachineRegistry.getInstance().getLocalMachine(), machine,
+				sharedFolders, 
 				new SubProgressMonitor(monitor, 1));
+
+		boolean reported = false;
 		
-		if (status.getSeverity() == IStatus.WARNING)
-			reporter.log(status);
-		else if (status.getSeverity() == IStatus.ERROR) {
-			reporter.log(status);
-			return false;
+		for (Map.Entry<ISharedFolder, IStatus> entry : state.getSharedFolderStatuses().entrySet()) {
+			IStatus status = entry.getValue();
+			if (!status.isOK()) {
+				if (!reported) {
+					reporter.logInfo("Current problems:");
+					reported = true;
+				}
+				reporter.log(createReportableFolderStatus(entry.getKey(), status));
+			}
 		}
 		
+		// now validate
+		reporter.logInfo("(Re-)mounting shares...");
+		SharedFolderState newState = SharedFolderManager.getInstance().mountShares(
+				state, new SubProgressMonitor(monitor, 1));
+
 		boolean succeeded = true;
-		if (sharedFolders.size() == 0) {
-			warn("No shared folders are defined or available\nfor the machine... typically this won't work very well.");
-			succeeded = false;
+		
+		reporter.logInfo("Testing shares:");
+		for (Map.Entry<ISharedFolder, IStatus> entry : newState.getSharedFolderStatuses().entrySet()) {
+			ISharedFolder sharedFolder = entry.getKey();
+			IStatus status = entry.getValue();
+			boolean isShareOk = status.getSeverity() != IStatus.ERROR;
+			succeeded &= isShareOk;
+			
+			if (!status.isOK()) {
+				IStatus newStatus = createReportableFolderStatus(sharedFolder,
+						status);
+				reporter.log(newStatus);
+			}
+			
+			if (isShareOk) {
+				if (sharedFolder.isHostProvidedShare())
+					succeeded &= testSharedFolderWriting(new SubProgressMonitor(monitor, 1), sharedFolder);
+				else
+					succeeded &= testSharedFolderReading(new SubProgressMonitor(monitor, 1), sharedFolder);
+			}
 		}
-		for (ISharedFolder share : sharedFolders) {
-			succeeded &= testSharedFolder(new SubProgressMonitor(monitor, 1), share);
-		}
+		
 		monitor.done();
 		return succeeded;
 	}
 
-	private boolean testSharedFolder(IProgressMonitor monitor, ISharedFolder share) {
+	private IStatus createReportableFolderStatus(ISharedFolder sharedFolder,
+			IStatus status) {
+		IStatus newStatus;
+		if (status.isOK())
+			newStatus = UIActivator.createStatus(
+					status.getSeverity(),
+					sharedFolder.toString() + ": OK");
+		else
+			newStatus = UIActivator.createStatus(
+				status.getSeverity(),
+				sharedFolder.toString(),
+				new CoreException(status));
+		return newStatus;
+	}
+
+	/**
+	 * Test writes from the local side to the target.
+	 * @param monitor
+	 * @param share
+	 * @return
+	 */
+	private boolean testSharedFolderWriting(IProgressMonitor monitor, ISharedFolder share) {
 		IPath shared = share.getSharePath();
 		IPath mounted = share.getMountPath();
 		
 		// check the shared folder
 		monitor.beginTask("", 5);
-		step(monitor, "Checking " + shared + " -> " + mounted);
+		step(monitor, "Checking writes in " + shared + " -> " + mounted);
 		
-		// look at the actual shared folder ("local" from the POV of who provides the share)
-		IFileStore shareProviderStore = share.isHostProvidedShare() 
-			? EFS.getLocalFileSystem().getStore(shared) : machine.getFileSystemAccess().getFileStore(shared);
-
+		// look at the actual shared folder
+		IFileStore shareProviderStore = EFS.getLocalFileSystem().getStore(shared);
 		// check
 		boolean fileExists = checkFileExists(new SubProgressMonitor(monitor, 1), shareProviderStore);
 		if (!fileExists) {
@@ -269,8 +325,8 @@
 		// work with a file inside the share
 		shareProviderStore = shareProviderStore.getChild("__testfile.txt");
 		IPath shareUserFilePath = mounted.append("__testfile.txt"); 
-		IFileStore shareUserStore = share.isHostProvidedShare() ? machine.getFileSystemAccess().getFileStore(
-				shareUserFilePath) : EFS.getLocalFileSystem().getStore(shareUserFilePath);
+		IFileStore shareUserStore = machine.getFileSystemAccess().getFileStore(
+				shareUserFilePath);
 		monitor.worked(1);
 		if (monitor.isCanceled())
 			return false;
@@ -313,30 +369,32 @@
 		if (monitor.isCanceled())
 			return false;
 		
-		// wait a little while for samba to notice, or else it looks like the file doesn't exist (:p !!!)
-		int sleepLeft = 1000 * 10;
+		// it can take a little while for samba to notice, or else it looks like the file doesn't exist (:p !!!)
+		long deadline = System.currentTimeMillis() + 1000 * 30;
 		do {
-			shareUserStore = share.isHostProvidedShare() 
-					? machine.getFileSystemAccess().getFileStore(shareUserFilePath)
-					: EFS.getLocalFileSystem().getStore(shareUserFilePath);
-					
+			// Samba has horrible syncing, esp. on OS X
+			if (HostUtils.isOSX() || !HostUtils.isWindows()) {
+				try {
+					Runtime.getRuntime().exec("sync");
+				} catch (IOException e) {
+				}
+			}
+			
+			shareUserStore = machine.getFileSystemAccess().getFileStore(shareUserFilePath);
+			
 			fileExists = checkFileExists(new SubProgressMonitor(monitor, 1), shareUserStore);
 			if (!fileExists) {
 				try {
 					Thread.sleep(1000);
-					sleepLeft -= 1000;
 				} catch (InterruptedException e1) {
 				}
 			}
-		} while (!fileExists && sleepLeft > 0);
+		} while (!fileExists && deadline > System.currentTimeMillis());
 		
 		if (!fileExists) {
 			fail("Could not access {0} over SSH filesystem.\n\n"+
-					"If the share is mounted, then this file should be visible "
-					+"since we created it on the sharing machine "
-					+"and this location is assumed to be shared at {1}. \n \n"+
-					"Make sure the host and target paths match, and that a different share "
-					+"is not already mounted there.",
+					"This location is assumed to be visible locally at {1}. \n \n"+
+					"Make sure the share is really mounted and functional.",
 					shareUserStore, shareProviderStore);
 			return false;
 		}
@@ -361,19 +419,79 @@
 		return true;
 	}
 
+
+	/**
+	 * Test reads from the share into the host.
+	 * @param monitor
+	 * @param share
+	 * @return
+	 */
+	private boolean testSharedFolderReading(IProgressMonitor monitor, ISharedFolder share) {
+		IPath shared = share.getSharePath();
+		IPath mounted = share.getMountPath();
+		
+		// check the shared folder
+		monitor.beginTask("", 2);
+		step(monitor, "Checking reads in " + shared + " -> " + mounted);
+		
+		// look at the actual shared folder
+		IFileStore shareProviderStore = machine.getFileSystemAccess().getFileStore(shared);
+
+		// check
+		boolean fileExists = checkFileExists(new SubProgressMonitor(monitor, 1), shareProviderStore);
+		if (!fileExists) {
+			fail("The share ''{0}'' does not exist on the share host ({1}).\n\nPlease create it or modify the Shared Folders preferences.",
+					shared.toPortableString(),
+					share.isHostProvidedShare() ? "this machine" : machine.getName());
+			return false;
+		}
+		
+		IFileStore[] childStores;
+		try {
+			childStores = shareProviderStore.childStores(0, new SubProgressMonitor(monitor, 1));
+		} catch (CoreException e2) {
+			fail("Failed to fetch children from '{0}':\n{1}", shareProviderStore, e2.getStatus());
+			return false;
+		}
+
+		for (IFileStore child : childStores) {
+			IFileInfo info = child.fetchInfo();
+			if (info.exists() && !info.getAttribute(EFS.ATTRIBUTE_SYMLINK)) {
+				IFileStore local = EFS.getLocalFileSystem().getStore(
+						mounted.append(child.getName()));
+				IFileInfo localInfo = local.fetchInfo();
+				
+				if (!localInfo.exists()
+						|| (!info.isDirectory() && localInfo.getLength() != info.getLength())) {
+					fail("Did not match attributes of remote '{0}' with local '{1}'.  Be sure the share is really mounted and configured correctly.", 
+							child, local);
+				}
+			}
+			monitor.worked(0);
+			if (monitor.isCanceled())
+				return false;
+		}
+		
+		monitor.worked(1);
+		monitor.done();
+	
+		return true;
+	}
+
 	private boolean checkFileExists(IProgressMonitor monitor,
 			IFileStore remoteStore) {
 		boolean fileExists = false;
 		
-		// HACK: localfile implementation can be buggy and have a long cache life
-		if (remoteStore.toURI().getScheme().equals("file")) {
-			File file = new File(remoteStore.toURI().getPath());
-			fileExists = file.exists();
-			return fileExists;
-		}
 		try {
 			IFileInfo info = remoteStore.fetchInfo(0, new SubProgressMonitor(monitor, 1));
 			fileExists = info.exists();
+			
+			// HACK: localfile implementation can be buggy and have a long cache life
+			if (remoteStore.toURI().getScheme().equals("file")) {
+				File file = new File(remoteStore.toURI().getPath());
+				fileExists |= file.exists();
+			}
+
 		} catch (CoreException e) {
 			fail(e.getStatus().getMessage());
 			fileExists = false;
@@ -429,6 +547,8 @@
 			RefreshSDKManagerJob job = new RefreshSDKManagerJob(machine, true);
 			job.run(monitor);
 			
+			monitor.setTaskName("");
+			
 			List<ISDKTarget> sdktargetsList = new ArrayList<ISDKTarget>();
 			for (ISDK sdk : job.getSDKs()) {
 				sdktargetsList.addAll(Arrays.asList(sdk.getSDKTargets()));



More information about the Esbox-commits mailing list