[Esbox-commits] r1881 - branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware
raul at garage.maemo.org
raul at garage.maemo.org
Mon Jul 20 18:25:27 EEST 2009
Author: raul
Date: 2009-07-20 18:25:26 +0300 (Mon, 20 Jul 2009)
New Revision: 1881
Modified:
branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java
branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java
branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java
Log:
Image is properly uncompressed and things are correctly installed. Error messages still have to be checked.
Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java 2009-07-19 04:16:42 UTC (rev 1880)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadExecution.java 2009-07-20 15:25:26 UTC (rev 1881)
@@ -84,14 +84,14 @@
public void downloadFile() throws MicaException {
MicaException error = null;
+ IStatus status = null;
for (int i = 1; i <= DOWNLOAD_TRIES; i++) {
try {
Thread.sleep(i * DOWNLOAD_WAIT);
} catch (InterruptedException e) {
}
-
- IStatus status = null;
+
try {
status = DownloadUtility.downloadMaemoSDKImageTool(downloadFile, progressMonitor);
} catch (MicaException e) {
@@ -108,7 +108,7 @@
throw error;
} else {
// Should not come here.
- throw new MicaException("Download of Maemo SDK virtual image was cancelled.");
+ throw new MicaException(status.getMessage());
}
}
Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java 2009-07-19 04:16:42 UTC (rev 1880)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DownloadUtility.java 2009-07-20 15:25:26 UTC (rev 1881)
@@ -42,6 +42,13 @@
*/
public class DownloadUtility {
+ /**
+ *
+ * @param downloadFile
+ * @param progressMonitor
+ * @return
+ * @throws MicaException
+ */
private static URL getRemoteFileURL(FileDownload downloadFile, IProgressMonitor progressMonitor) throws MicaException {
URL connectionURL = null;
try {
@@ -125,6 +132,12 @@
}
}
+ /**
+ *
+ * @param conn
+ * @return
+ * @throws MicaException
+ */
private static String getResponse(HttpURLConnection conn) throws MicaException {
// TODO refactor flasher on Mica so methods can be reused here.
if (conn == null) {
@@ -203,6 +216,11 @@
return (new Path(localPath.getFile())).append(fileName).toOSString();
}
+ /**
+ *
+ * @param localFileName
+ * @return
+ */
private static long getPreviousDownloadSize(String localFileName) {
File previousFile = new File(localFileName);
if (previousFile.exists()) {
@@ -218,6 +236,15 @@
return 0L;
}
+ /**
+ *
+ * @param downloadFile
+ * @param remoteURL
+ * @param monitor
+ * @return
+ * @throws IOException
+ * @throws MicaException
+ */
private static IStatus fileDownloader(FileDownload downloadFile, URL remoteURL, IProgressMonitor monitor) throws IOException, MicaException {
// Check if file was downloaded before
monitor.subTask("Checking information about file to be downloaded ...");
@@ -250,7 +277,7 @@
int contentLength = connection.getContentLength();
- if (!checkAvailableFreeSpace(contentLength,downloadFile.getLocalURL())) {
+ if (!haveEnoughtFreeSpace(contentLength,downloadFile.getLocalURL())) {
cancelDownload(downloadFile, monitor);
return errorStatus("There is not enought space to save Maemo SDK virtual machine in your computer.");
}
@@ -308,21 +335,44 @@
return Status.OK_STATUS;
}
+ /**
+ *
+ * @param message
+ * @return
+ */
private static IStatus errorStatus(String message) {
return Activator.createStatus(IStatus.ERROR, message);
}
+ /**
+ *
+ * @param fileDownload
+ * @param monitor
+ */
private static void cancelDownload(FileDownload fileDownload, IProgressMonitor monitor) {
fileDownload.error();
monitor.setCanceled(true);
monitor.done();
}
- private static boolean checkAvailableFreeSpace(int fileSize, URL localURL) throws IOException {
+ /**
+ *
+ * @param fileSize
+ * @param localURL
+ * @return
+ * @throws IOException
+ */
+ private static boolean haveEnoughtFreeSpace(int fileSize, URL localURL) throws IOException {
long freeSpace = FilesystemUtils.freeSpaceOS(new Path(localURL.getPath()),false);
- return freeSpace <= fileSize;
+ return freeSpace > fileSize;
}
+ /**
+ *
+ * @param connection
+ * @return
+ * @throws IOException
+ */
private static IStatus validateConnection(HttpURLConnection connection) throws IOException {
// Make sure response code is in the 200 range
if (connection.getResponseCode() / 100 != 2) {
@@ -337,6 +387,13 @@
return Status.OK_STATUS;
}
+ /**
+ *
+ * @param downloadFile
+ * @param progressMonitor
+ * @return
+ * @throws MicaException
+ */
public static IStatus downloadMaemoSDKImageTool(FileDownload downloadFile, IProgressMonitor progressMonitor) throws MicaException {
try {
CookieHandler.setDefault(new SessionHandler());
Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java 2009-07-19 04:16:42 UTC (rev 1880)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java 2009-07-20 15:25:26 UTC (rev 1881)
@@ -17,15 +17,14 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.Locale;
-import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.window.Window;
@@ -43,7 +42,11 @@
import org.maemo.mica.common.core.machine.IBuildMachine;
import org.maemo.mica.common.core.machine.IMachine;
import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
+import org.maemo.mica.common.core.sdk.SDKManager;
import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
+import org.maemo.mica.internal.api.linux.packages.core.aptinstall.AptInstallerHelper;
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
@@ -87,7 +90,8 @@
status = this.downloadVM(shell, monitor);
}
- status = this.uncompressVM(shell, monitor);
+ if (canProceed(status))
+ status = this.uncompressVM(shell, monitor);
if (canProceed(status) && installData.canInstallSbox()) {
promptPreferencesDialog(shell);
@@ -98,7 +102,7 @@
status = this.installScratchboxTargets(shell,monitor);
}
- if (canProceed(status) && (installData.canInstallCppEnv() || installData.canInstallPythonEnv())) {
+ if (canProceed(status) && ((installData.canInstallCppEnv() || installData.canInstallPythonEnv()))) {
status = this.installPackages(timeout, shell, monitor);
}
@@ -154,7 +158,6 @@
* @return the result of process as IStatus.
*/
public IStatus uncompressVM(final Shell shell, IProgressMonitor monitor) {
-
monitor.subTask("Uncompressing image...");
reporter.logInfo("Uncompressing Maemo SDK virtual image...");
@@ -164,6 +167,10 @@
final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "File " + fileName
+ " was properly uncompressed into " + destinationPath) } ;
+ if (!haveEnoughtFreeSpace(fileName,destinationPath)) {
+ return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+ }
+
shell.getDisplay().syncExec(new Runnable() {
public void run() {
@@ -182,7 +189,7 @@
FileOutputStream fileOutputStream = null;
try {
- zipInputStream = new ZipInputStream(new FileInputStream(fileName));
+ zipInputStream = new ZipInputStream(new FileInputStream(fileName));
zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {
@@ -386,21 +393,38 @@
IStatus status = Policy.getCancelStatus(Activator.getDefault());
- Set<String> packagesToInstall = new HashSet<String>();
+ ISDKTarget[] sdkTargets = getBuildMachineTargets();
- if (installData.canInstallCppEnv() || installData.canInstallPythonEnv()) {
- packagesToInstall.add("maemo-debug-scripts");
- packagesToInstall.add("maemo-c-debug-tools");
- if (installData.canInstallCppEnv())
- packagesToInstall.add("maemo-cplusplus-env");
- else
- packagesToInstall.add("maemo-python-env");
- }
+ String[] packages = checkPackagesToInstall();
+ status = AptInstallerHelper.installPackages(sdkTargets, packages, true, shell, reporter, monitor);
+
return status;
}
/**
+ * Get targets of current build machine.
+ * @return
+ */
+ private ISDKTarget[] getBuildMachineTargets() {
+ IMachine currentMachine = getBuildMachine();
+
+ if (currentMachine == null)
+ return new ISDKTarget[0];
+
+ List<ISDKTarget> machineTargets = new ArrayList<ISDKTarget>();
+
+ ISDKTarget[] sdkTargets = SDKManager.getInstance().getAllSDKTargets();
+ for (ISDKTarget target : sdkTargets) {
+ IMachine targetMachine = target.getMachine();
+ if (targetMachine.getName().equals(currentMachine.getName()))
+ machineTargets.add(target);
+ }
+
+ return machineTargets.toArray(new ISDKTarget[machineTargets.size()]);
+ }
+
+ /**
* Get current build machine.
* @return
*/
@@ -417,4 +441,45 @@
return machine;
}
+ private String[] checkPackagesToInstall() {
+ List<String> packagesToInstall = new ArrayList<String>();
+
+ if (installData.canInstallCppEnv() || installData.canInstallPythonEnv()) {
+ packagesToInstall.add("maemo-debug-scripts");
+ packagesToInstall.add("maemo-c-debug-tools");
+ if (installData.canInstallCppEnv())
+ packagesToInstall.add("maemo-cplusplus-env");
+ if (installData.canInstallPythonEnv())
+ packagesToInstall.add("maemo-python-env");
+ }
+
+ return packagesToInstall.toArray(new String[packagesToInstall.size()]);
+ }
+
+ private static boolean haveEnoughtFreeSpace(String fileName, String destinationPath) {
+ ZipInputStream zipInputStream = null;
+ ZipEntry zipEntry;
+
+ try {
+ long fileSize = 0;
+ zipInputStream = new ZipInputStream(new FileInputStream(fileName));
+
+ while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+ fileSize += zipEntry.getSize();
+ }
+
+ long freeSpace = FilesystemUtils.freeSpaceOS(new Path(destinationPath),false);
+ System.out.println("++ " + freeSpace + " -- " + fileSize);
+ return freeSpace > fileSize;
+ } catch (IOException e) {
+ Activator.getErrorLogger().logError("Cannot retrieve information about zipped Maemo SDK virtual image. I/O error", e);
+ return false;
+
+ } finally {
+ Policy.close(zipInputStream);
+ }
+
+
+ }
+
}
Modified: branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java
===================================================================
--- branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java 2009-07-19 04:16:42 UTC (rev 1880)
+++ branches/work_Raul/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/RandomFileOutputStream.java 2009-07-20 15:25:26 UTC (rev 1881)
@@ -21,18 +21,40 @@
protected RandomAccessFile randomFile;
protected boolean sync;
+ /**
+ *
+ * @param fnm
+ * @throws IOException
+ */
public RandomFileOutputStream(String fnm) throws IOException {
this(fnm, false);
}
+ /**
+ *
+ * @param fnm
+ * @param syn
+ * @throws IOException
+ */
public RandomFileOutputStream(String fnm, boolean syn) throws IOException {
this(new File(fnm), syn);
}
+ /**
+ *
+ * @param fil
+ * @throws IOException
+ */
public RandomFileOutputStream(File fil) throws IOException {
this(fil, false);
}
+ /**
+ *
+ * @param fil
+ * @param syn
+ * @throws IOException
+ */
public RandomFileOutputStream(File fil, boolean syn) throws IOException {
super();
@@ -48,6 +70,10 @@
sync = syn;
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.OutputStream#write(int)
+ */
public void write(int val) throws IOException {
randomFile.write(val);
if (sync) {
@@ -55,6 +81,10 @@
}
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.OutputStream#write(byte[])
+ */
public void write(byte[] val) throws IOException {
randomFile.write(val);
if (sync) {
@@ -62,6 +92,10 @@
}
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.OutputStream#write(byte[], int, int)
+ */
public void write(byte[] val, int off, int len) throws IOException {
randomFile.write(val, off, len);
if (sync) {
@@ -69,32 +103,65 @@
}
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.OutputStream#flush()
+ */
public void flush() throws IOException {
if (sync) {
randomFile.getFD().sync();
}
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.OutputStream#close()
+ */
public void close() throws IOException {
randomFile.close();
}
+ /**
+ *
+ * @return
+ * @throws IOException
+ */
public long getFilePointer() throws IOException {
return randomFile.getFilePointer();
}
+ /**
+ *
+ * @param pos
+ * @throws IOException
+ */
public void setFilePointer(long pos) throws IOException {
randomFile.seek(pos);
}
+ /**
+ *
+ * @return
+ * @throws IOException
+ */
public long getFileSize() throws IOException {
return randomFile.length();
}
+ /**
+ *
+ * @param len
+ * @throws IOException
+ */
public void setFileSize(long len) throws IOException {
randomFile.setLength(len);
}
+ /**
+ *
+ * @return
+ * @throws IOException
+ */
public FileDescriptor getFD() throws IOException {
return randomFile.getFD();
}
More information about the Esbox-commits
mailing list