[Esbox-commits] r2137 - in branches/2.0.0-prefinal: org.maemo.esbox.help org.maemo.esbox.help/html/concepts org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards
eswartz at garage.maemo.org
eswartz at garage.maemo.org
Thu Sep 10 01:54:45 EEST 2009
Author: eswartz
Date: 2009-09-10 01:54:44 +0300 (Thu, 10 Sep 2009)
New Revision: 2137
Added:
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
Modified:
branches/2.0.0-prefinal/org.maemo.esbox.help/html/concepts/MaemoTargets.html
branches/2.0.0-prefinal/org.maemo.esbox.help/tocconcepts.xml
branches/2.0.0-prefinal/org.maemo.esbox.help/toctasks.xml
branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1SDKWizard.java
branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java
branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
Log:
Merge revs 2129, 2132, 2136 from trunk
Modified: branches/2.0.0-prefinal/org.maemo.esbox.help/html/concepts/MaemoTargets.html
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.help/html/concepts/MaemoTargets.html 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.help/html/concepts/MaemoTargets.html 2009-09-09 22:54:44 UTC (rev 2137)
@@ -66,7 +66,7 @@
<li><a href="../tasks/InstallingScratchbox1.html">Installing Scratchbox 1</a></li>
<li><a href="../tasks/InstallingScratchbox1Targets.html">Installing Scratchbox 1 Targets</a></li>
<li><a href="../tasks/InstallingScratchbox2Targets.html">Installing Scratchbox 2 Targets</a></li>
- <li><a href="../gettingstarted/SettingPreferences.html#installed_targets">Maemo > Installed Targets Preference Settings</a></li>
+ <li><a href="../tasks/SettingPreferences.html#installed_targets">Maemo > Installed Targets Preference Settings</a></li>
</ul>
</body>
</html>
\ No newline at end of file
Modified: branches/2.0.0-prefinal/org.maemo.esbox.help/tocconcepts.xml
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.help/tocconcepts.xml 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.help/tocconcepts.xml 2009-09-09 22:54:44 UTC (rev 2137)
@@ -20,4 +20,6 @@
</topic>
<topic label="Profiling Applications" href="html/concepts/ProfilingApplications.html">
</topic>
+ <topic label="Environment Variables" href="html/concepts/Environment.html">
+ </topic>
</toc>
Modified: branches/2.0.0-prefinal/org.maemo.esbox.help/toctasks.xml
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.help/toctasks.xml 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.help/toctasks.xml 2009-09-09 22:54:44 UTC (rev 2137)
@@ -46,4 +46,12 @@
</topic>
<topic label="Profiling Maemo Applications" href="html/tasks/ProfilingMaemoApplications.html">
</topic>
+ <topic label="Creating a Make Target" href="html/tasks/CreateMakeTarget.html">
+ </topic>
+ <topic label="Installing Maemo SDK Virtual Image" href="html/tasks/InstallingMaemoSDKVMImage.html">
+ </topic>
+ <topic label="Installing PC-Connectivity" href="html/tasks/InstallingPCConnectivity.html">
+ </topic>
+ <topic label="Using SDK and Target Context Menus" href="html/tasks/UsingTargetContextMenus.html">
+ </topic>
</toc>
Modified: branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1SDKWizard.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1SDKWizard.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1SDKWizard.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -139,6 +139,7 @@
targetPage = new Scratchbox1SDKInstallerSelectionWizardPage(buildMachine);
addPage(targetPage);
+ setForcePreviousAndNextButtons(true);
}
/**
@@ -190,11 +191,13 @@
"SDK Installation Results", message, status, true)
&& !status.matches(IStatus.CANCEL);
+ this.success = status.isOK() || status.matches(IStatus.INFO);
+ if (success) {
+ patchAutotools();
+ }
if (installedNew) {
- patchAutotools();
doReboot();
}
- this.success = installedNew;
return goOn;
}
@@ -328,7 +331,6 @@
StructuredSelection.EMPTY);
Shell parent = activeWorkbenchWindow.getShell();
WizardDialog dialog = new WizardDialog(parent, wizard);
- dialog.create();
dialog.open();
if (!wizard.isSuccess())
return Activator.createStatus(IStatus.CANCEL, "Scratchbox 1 SDK installation was canceled");
Modified: branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -190,7 +190,7 @@
* @param synchronous controls whether the wizard is launched synchronously or not.
* This is used in automatic invocations of the target wizard.
*/
- private void promptInstallNokiaBinaries(boolean synchronous) {
+ public void promptInstallNokiaBinaries(boolean synchronous) {
//calls Nokia-closed binaries wizard
if (DialogUtils.showQuestionDialog(DialogUtils.getShell(),
"Nokia-closed binaries installation",
@@ -267,7 +267,7 @@
* @param defaultTargets If not null the default selected targets will be these
*
*/
- public static IStatus startWizard() {
+ public static IStatus startWizard(NewScratchbox1TargetWizard wizard) {
IWorkbenchWindow activeWorkbenchWindow = Activator.getDefault()
.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
@@ -275,19 +275,13 @@
return Activator.createStatus(IStatus.ERROR, "Cannot open Scratchbox 1 SDK wizard");
}
- NewScratchbox1TargetWizard wizard = new NewScratchbox1TargetWizard();
wizard.init(activeWorkbenchWindow.getWorkbench(),
StructuredSelection.EMPTY);
- wizard.setSuppressNokiaBinariesWizard(true);
Shell parent = activeWorkbenchWindow.getShell();
WizardDialog dialog = new WizardDialog(parent, wizard);
- dialog.create();
dialog.open();
if (!wizard.isSuccess())
return Activator.createStatus(IStatus.CANCEL, "Scratchbox 1 target installation was canceled");
-
- // now install Nokia binaries synchronously
- wizard.promptInstallNokiaBinaries(true);
return Activator.createStatus(IStatus.OK, "Scratchbox 1 target installation has finished");
}
Modified: branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -109,36 +109,16 @@
cputranspExpected
.add("/scratchbox/devkits/cputransp/bin/qemu-arm-0.8.2-sb2");
cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-armeb-0.8.1-sb2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-armeb-0.8.2-sb2");
- cputranspExpected
.add("/scratchbox/devkits/cputransp/bin/qemu-i386-0.7.0-sb2");
cputranspExpected
.add("/scratchbox/devkits/cputransp/bin/qemu-i386-0.8.1-sb2");
cputranspExpected
.add("/scratchbox/devkits/cputransp/bin/qemu-i386-0.8.2-sb2");
cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-mips-0.8.1-sb2");
+ .add("/scratchbox/devkits/qemu/bin/qemu-arm-sb");
cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-mips-0.8.2-sb2");
+ .add("/scratchbox/devkits/qemu/bin/qemu-i386-sb");
cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-mipsel-0.8.1-sb2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-mipsel-0.8.2-sb2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-ppc-0.7.0-sb2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-ppc-0.8.0-m2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-ppc-0.8.1-sb2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-ppc-0.8.2-sb2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-sparc-0.7.0-sb2");
- cputranspExpected
- .add("/scratchbox/devkits/cputransp/bin/qemu-sparc-0.8.1-sb2");
- cputranspExpected
.add("/scratchbox/devkits/cputransp/bin/qemu-sparc-0.8.2-sb2");
cputranspExpected.add("/scratchbox/devkits/cputransp/bin/sbrsh");
@@ -279,7 +259,7 @@
List<String> compilers = getCompilers();
String compiler = "host-gcc";
for (String c : compilers) {
- if (c.matches("cs2005.*arm")) {
+ if (c.matches("cs200[5-9].*arm.*")) {
compiler = c;
break;
}
@@ -287,7 +267,7 @@
List<String> cputransps = getCputransps();
String cputransp = "sbrsh";
for (String c : cputransps) {
- if (c.matches("qemu.*arm.*sb2")) {
+ if (c.matches("qemu.*arm.*sb.*")) {
cputransp = c;
break;
}
@@ -296,7 +276,7 @@
sdk.createTarget(
TARGET_NAME,
compiler,
- "doctools:cputransp",
+ "doctools:perl",
cputransp);
List<String> targetsAvailable;//ScratchboxFacade.getInstance().getTargets(sdk);
@@ -404,53 +384,4 @@
// fail("Not yet implemented");
}
- /**
- * Test method for
- * {@link org.maemo.esbox.common.core.scratchbox.ScratchboxFacade#showTarget(java.lang.String)}.
- *
- * @throws ESboxException
- */
- /*
- @Test
- public void testShowTarget() throws ESboxException {
- final String TARGET_ARMEL = "SDK_ARMEL";
-
- ScratchboxTarget target = ScratchboxFacade.getInstance().showTarget(sdk,
- TARGET_ARMEL);
-
- assertEquals(TARGET_ARMEL, target.getName());
- assertEquals("cs2005q3.2-glibc-arm", target.getCompiler());
- assertEquals("/scratchbox/devkits/cputransp/bin/qemu-arm-0.8.2-sb2",
- target.getCputransp());
-
- List<String> devkitsExpected = new ArrayList<String>();
- devkitsExpected.add("perl");
- devkitsExpected.add("maemo3-tools");
- devkitsExpected.add("doctools");
- devkitsExpected.add("debian-sarge");
- devkitsExpected.add("maemo3-debian");
- devkitsExpected.add("cputransp");
-
- List<String> devkitsActual = target.getDevkits();
- for (String devkit : devkitsActual) {
- assertTrue(devkitsExpected.contains(devkit));
- }
- }
- */
-
- /**
- * Test method for
- * {@link org.maemo.esbox.common.core.scratchbox.ScratchboxFacade#execSimpleCommand(java.lang.String)}.
- *
- * @throws ESboxException
- */
-// @Test
-// public void testExecSimpleCommand() throws ESboxException {
-// ISDKTarget sdkTarget = sdk.getSDKTargets()[0];
-// List<String> currentTarget = ScratchboxFacade.getInstance().execSimpleCommand(
-// sdkTarget,
-// CommandLineArguments.createFromVarArgs("sb-conf", "current"));
-// assertEquals(sdkTarget.getName(), currentTarget.get(0));
-// }
-
}
Copied: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java (from rev 2129, trunk/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java)
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java (rev 0)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/DefaultVMZipExtractor.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -0,0 +1,362 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fabrício S Epaminondas
+ *
+ *******************************************************************************/
+package org.maemo.esbox.internal.api.vm.vmware;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.text.DecimalFormat;
+import java.util.Locale;
+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.core.runtime.Status;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.Policy;
+import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.internal.api.common.core.filesystem.FilesystemUtils;
+
+/**
+ * @author Fabrício S Epaminondas
+ *
+ */
+final class DefaultVMZipExtractor {
+ public static int SINGLE_FILE_PART = 1;
+ public final static int DECOMPRESS_FACTOR = 4;
+
+ /**
+ * Extracts the compressed VM file on local machine
+ * @param fileName
+ * @param shell
+ * @param destinationPath
+ * @param reporter
+ * @return
+ */
+ public static IStatus extract(final String fileName, final Shell shell,
+ final String destinationPath, final IProgressReporter reporter) {
+ final IStatus[] status = { Status.OK_STATUS };
+
+ Display.getDefault().syncExec(new ZipExtractor(status, shell, reporter, fileName, destinationPath));
+ return status[0];
+ }
+
+ /**
+ * Check if there is enough space to uncompress the Maemo SDK virtual image.
+ *
+ * @param fileName
+ * the name of Maemo SDK virtual image.
+ * @param destinationPath
+ * the destination path to uncompress the Maemo SDK virtual
+ * image.
+ * @return boolean if there is enough space to uncompress the Maemo SDK
+ * virtual image (if the free space available on disk is bigger than
+ * the size of uncompressed Maemo SDK virtual image); false,
+ * otherwise.
+ */
+ public static boolean haveEnoughFreeSpace(String fileName,
+ String destinationPath) {
+ ZipInputStream zipInputStream = null;
+ ZipEntry zipEntry;
+
+ try {
+ long fileSize = 0;
+ zipInputStream = new ZipInputStream(new FileInputStream(fileName));
+
+ // check the total size of zip file. It is necessary to check the
+ // size of each zip file entry.
+ while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+ fileSize += zipEntry.getSize();
+ }
+ long freeSpace = getFreeSpaceSize(destinationPath);
+ 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);
+ }
+ }
+
+ /**
+ * @param fileName
+ * @param numParts
+ * @return the size in bytes
+ */
+ public static long getEstimatedDecompressedSize(String fileName,
+ int numParts) {
+ return getCompressedSize(fileName, numParts) * DECOMPRESS_FACTOR;
+ }
+
+ /**
+ * The compressed size
+ *
+ * @param fileName
+ * @param numParts
+ * @return size in bytes
+ */
+ public static long getCompressedSize(String fileName,
+ int numParts) {
+ File localFile = new File(fileName);
+ long totalSize = 0L;
+
+ if(numParts > DefaultVMZipExtractor.SINGLE_FILE_PART){
+ for(File f: DefaultVMZipExtractor.getMultipartFiles(fileName, numParts)){
+ totalSize += f.length();
+ }
+ }else{
+ totalSize = localFile.length();
+ }
+ return totalSize;
+ }
+
+ /**
+ * the free space available on file location
+ * @param fileName
+ * @return the size in bytes
+ */
+ public static long getFreeSpaceSize(String path) {
+ long freeSpace = 0L;
+
+ try {
+ freeSpace = FilesystemUtils.freeSpaceOS(new Path(path), false);
+ } catch (IOException e) {
+ Activator
+ .getErrorLogger()
+ .logError(
+ "Cannot retrieve information about zipped Maemo SDK virtual image. I/O error",
+ e);
+ }
+ return freeSpace;
+ }
+
+ /**
+ * Get the progress value of uncompressing process.
+ *
+ * @param total
+ * @param read
+ * @return
+ */
+ static float getProgress(long total, long read) {
+ return ((float) read / total) * 100;
+ }
+
+
+
+ /**
+ * Return the array of files if this file is a multipart file
+ * @param fileName
+ * @param numParts
+ * @return
+ */
+ public static File[] getMultipartFiles(String fileName, int numParts){
+ if(numParts <= SINGLE_FILE_PART)
+ return new File[]{new File(fileName)};
+
+ File[] files = new File[numParts];
+ for(int i =0; i < numParts; i++){
+ String name = getFilePartName(fileName,i+1);
+ files[i] = new File(name);
+ }
+
+ return files;
+ }
+
+ /**
+ * The name of file part
+ * @param fileName
+ * @param nPart
+ * @return
+ */
+ public static String getFilePartName(String fileName, int nPart) {
+ String name = fileName;
+ int i = name.lastIndexOf('.');
+ if(i != -1)
+ name = name.substring(0,i);
+ DecimalFormat df = new DecimalFormat( "000");
+ String part = df.format(nPart);
+ name= name + '.' + part;
+ return name;
+ }
+
+
+ static final class ZipExtractor implements Runnable {
+ private final IStatus[] status;
+ private final Shell shell;
+ private final IProgressReporter reporter;
+ private final String fileName;
+ private final String destinationPath;
+
+ ZipExtractor(IStatus[] status, Shell shell, IProgressReporter reporter,
+ String fileName, String destinationPath) {
+ this.status = status;
+ this.shell = shell;
+ this.reporter = reporter;
+ this.fileName = fileName;
+ this.destinationPath = destinationPath;
+ }
+
+ public void run() {
+ try {
+ ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(
+ shell);
+ progressMonitor.run(true, true,
+ new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException,
+ InterruptedException {
+
+ File file = new File(fileName);
+
+ if (file.length() >= 4L * 1024L * 1024L * 1024L) {
+ status[0] = Activator
+ .createErrorStatus(
+ "JDK only supports uncompression of files smaller than 4Gb.",
+ null);
+ }
+
+ byte[] buf = new byte[1024];
+ ZipInputStream zipInputStream = null;
+ ZipEntry zipEntry = null;
+ FileOutputStream fileOutputStream = null;
+
+ try {
+ zipInputStream = new ZipInputStream(
+ new FileInputStream(file));
+ zipEntry = zipInputStream
+ .getNextEntry();
+
+ if (zipEntry == null) {
+ status[0] = Activator
+ .createErrorStatus(
+ "Cannot uncompress Maemo SDK virtual image, no zip entry was found.",
+ null);
+ }
+
+ while (zipEntry != null) {
+
+ // for each entry to be extracted
+ String entryName = zipEntry
+ .getName();
+
+ monitor
+ .beginTask(
+ "Uncompressing Maemo SDK virtual image",
+ 100);
+
+ long lenght = zipEntry.getSize();
+
+ File newFile = new File(entryName);
+ String directory = newFile
+ .getParent();
+ if (directory == null) {
+ if (newFile.isDirectory())
+ break;
+ }
+
+ fileOutputStream = new FileOutputStream(
+ destinationPath
+ + File.separator
+ + entryName);
+ int n;
+ long totalRead = 0;
+ int previousProgressValue = 0;
+ while ((n = zipInputStream.read(
+ buf, 0, 1024)) > -1) {
+ // write on file
+ fileOutputStream.write(buf, 0,
+ n);
+
+ // update progress monitor bar
+ totalRead += n;
+ int progressValue = ((int) getProgress(
+ lenght, totalRead));
+ if (previousProgressValue < progressValue) {
+ previousProgressValue = progressValue;
+ monitor.worked(1);
+ }
+ if (monitor.isCanceled())
+ break;
+ monitor
+ .subTask("Uncompressing "
+ + zipEntry
+ + "\t\t"
+ + String
+ .format(
+ Locale.US,
+ "%.2f",
+ getProgress(
+ lenght,
+ totalRead))
+ + "%");
+
+ }
+ fileOutputStream.close();
+ zipInputStream.closeEntry();
+
+ if (monitor.isCanceled()) {
+ status[0] = Activator
+ .createErrorStatus(
+ "Installation was cancelled.",
+ null);
+ return;
+ } else {
+ zipEntry = zipInputStream
+ .getNextEntry();
+ }
+ }
+
+ } catch (IOException ioe) {
+ status[0] = Activator
+ .createErrorStatus(
+ "Cannot uncompress Maemo SDK virtual image: I/O error",
+ ioe);
+ reporter
+ .appendStreamText(
+ "Cannot uncompress Maemo SDK virtual image.",
+ true);
+ } finally {
+
+ Policy.close(zipInputStream);
+
+ Policy.close(fileOutputStream);
+
+ }
+
+ }
+
+ });
+ } catch (Exception e) {
+ status[0] = Activator.createErrorStatus(
+ "Cannot uncompress Maemo SDK virtual image.", e);
+ reporter
+ .appendStreamText(
+ "Cannot procced with Maemo SDK virtual image uncompressing.",
+ true);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMDownloader.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -20,10 +20,10 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
@@ -60,10 +60,12 @@
/**
* Get URL and size of remote file.
+ * @param nPart the number of the part to get info, null if it not is a multipart file
* @return URL and size of remote file.
* @throws MicaException
+ * @throws IOException
*/
- private Tuple getRemoteFileInfo() throws MicaException {
+ private Tuple getRemoteFileInfo(Integer nPart) throws MicaException, IOException {
URL connectionURL = null;
try {
connectionURL = new URL(MaemoSDKVMInfo.DOWNLOAD_PAGE);
@@ -78,17 +80,29 @@
URL remoteURL;
int fileSize = 0;
try {
- fileSize = getSizeFor(downloadPage, downloadFile.getDescriptor().getName());
remoteURL = getLinkFor(downloadPage, downloadFile.getDescriptor().getName());
+
+ if (remoteURL == null) {
+ throw new MicaException("Cannot locate ''" + downloadFile.getDescriptor().getName()
+ + "'' on " + MaemoSDKVMInfo.DOWNLOAD_PAGE);
+ }
+
+ if(downloadFile.isMultipart() && nPart != null){
+ String url = remoteURL.toExternalForm();
+ int i = url.lastIndexOf('.');
+ if(i != -1)
+ url = url.substring(0,i);
+ DecimalFormat df = new DecimalFormat( "000");
+ String part = df.format(nPart);
+ remoteURL = new URL(url + '.' + part);
+ }
+
+ HttpURLConnection conn = (HttpURLConnection) remoteURL.openConnection();
+ fileSize = conn.getContentLength();
} catch (MalformedURLException e) {
throw new MicaException("Invalid file URL on " + MaemoSDKVMInfo.DOWNLOAD_PAGE, e);
}
- if (remoteURL == null) {
- throw new MicaException("Cannot locate ''" + downloadFile.getDescriptor().getName()
- + "'' on " + MaemoSDKVMInfo.DOWNLOAD_PAGE);
- }
-
return new Tuple(remoteURL, fileSize);
}
@@ -215,7 +229,7 @@
if (matcherLink.find()) {
String link = matcherLink.group(1);
return (new URL(MaemoSDKVMInfo.DOWNLOAD_PAGE
- + link.substring(link.indexOf("?"))));
+ + (link.contains("?")?link.substring(link.indexOf("?")): link)));
}
}
@@ -223,45 +237,18 @@
return null;
}
- /**
- * Get the size of a certain remote file. The file is retrieved from html page description.
- * @param htmlPage
- * @param downloadFileDescription
- * @return
- */
- private int getSizeFor(String htmlPage, String downloadFileDescription) {
- final String DOWNLOAD_FILE_PATTERN = "<tr>\\s*<td class=\"filename\">(.*?)</td>\\s*</tr>";
- final String SIZE_PATTERN = "<td class=\"filesize\">(.*?)</td>";
- Pattern fileEntryPattern = Pattern.compile(DOWNLOAD_FILE_PATTERN,
- Pattern.DOTALL | Pattern.UNIX_LINES);
- Matcher matcher = fileEntryPattern.matcher(htmlPage);
- while (matcher.find()) {
- String fileInfo = matcher.group(0);
- if (fileInfo.contains(downloadFileDescription)) {
- Pattern sizePattern = Pattern.compile(SIZE_PATTERN,
- Pattern.DOTALL | Pattern.UNIX_LINES);
- Matcher matcherLink = sizePattern.matcher(fileInfo);
- if (matcherLink.find()) {
- String size = matcherLink.group(1);
- return Integer.parseInt(size);
- }
- }
-
- }
- return 0;
- }
/**
- * Get file name of download file to be saved locally
+ * Get local file to download file
*
* @param remoteURL
- * @param localPath
+ * @param installLocation
* @return the name of file to be saved locally
*/
- private String getFileName(URL remoteURL, URL localPath) {
+ private File getLocalFile(URL remoteURL, URL installLocation) {
String fileName = (new Path(remoteURL.getFile())).lastSegment();
fileName = fileName.substring(fileName.lastIndexOf("=") + 1);
- return (new Path(localPath.getFile())).append(fileName).toOSString();
+ return new File ((new Path(installLocation.getFile())).append(fileName).toOSString());
}
/**
@@ -269,15 +256,14 @@
* @param localFileName
* @return
*/
- private long getPreviousDownloadSize(String localFileName) {
- File previousFile = new File(localFileName);
- if (previousFile.exists()) {
+ private long getPreviousDownloadSize(File localFile) {
+ if (localFile.exists()) {
boolean canResumeDownload = DialogUtils.showQuestionDialog(DialogUtils.getShell(),
- "Previous download file founded", "The file " + localFileName + " already exists. Would you like to resume download?");
+ "Previous download file founded", "The file " + localFile + " already exists. Would you like to resume download?");
if (canResumeDownload) {
- return previousFile.length();
+ return localFile.length();
} else {
- previousFile.delete();
+ localFile.delete();
return 0L;
}
}
@@ -293,100 +279,234 @@
private IStatus fileDownloader() throws IOException, MicaException {
// Check if file was downloaded before
monitor.subTask("Checking information about file to be downloaded ...");
+
+ if(downloadFile.isMultipart()){
+ //download multipar file
+ return downloadMultiple();
+ }else{
+ //download single file
+ return downloadSingle();
+ }
+ }
+
+ protected IStatus downloadMultiple() throws MicaException, IOException {
+
+ for(int nPart = 1; nPart <= downloadFile.getNumParts(); nPart++){
+ Tuple remoteFileInfo = getRemoteFileInfo(nPart);
+ URL remoteURL = (URL) remoteFileInfo.get(0);
+
+ // Get link of remote file
+ File localFile = getLocalFile(remoteURL, downloadFile.getInstallLocation());
+ if(nPart ==1)
+ downloadFile.setFileName(localFile.getName());
+
+ downloadFile.setDownloadedSize(getPreviousDownloadSize(localFile));
+ Integer remoteFileSize = (Integer) remoteFileInfo.get(1);;
+
+ if (downloadFile.getDownloadedSize() == remoteFileSize.intValue()){
- Tuple remoteFileInfo = getRemoteFileInfo();
+ if(nPart == downloadFile.getNumParts()){
+ downloadFile.complete();
+ return Activator.createStatus(Status.OK, "Maemo SDK virtual image is already downloaded.");
+ }else
+ continue; //check next part
+ }
+
+ HttpURLConnection connection = null;
+ RandomFileOutputStream out = null;
+ InputStream in = null;
+
+ try {
+
+ // Open connection to URL.
+ monitor.subTask("Establishing connection with " + remoteURL.getHost());
+ connection = (HttpURLConnection) remoteURL.openConnection();
+
+ // Specify what portion of file to download
+ connection.setRequestProperty("Range", "bytes=" + downloadFile.getDownloadedSize() + "-");
+
+ // Connect to server
+ connection.connect();
+ monitor.subTask("Connected with " + remoteURL.getHost());
+
+ IStatus connectionStatus = validateConnection(connection);
+ if (!connectionStatus.isOK()) {
+ cancelDownload(downloadFile,monitor);
+ return errorStatus(connectionStatus.getMessage());
+ }
+
+ int contentLength = connection.getContentLength();
+ if (!haveEnoughtFreeSpace(contentLength/1024, localFile)) {
+ cancelDownload(downloadFile, monitor);
+ return errorStatus("There is not enought space to save Maemo SDK virtual machine in your computer.");
+ }
+
+ // set the size for this download if it hasn't been already set.
+ if (downloadFile.getSize() == -1) {
+ downloadFile.setSize(contentLength);
+ }
+
+ CopyProgressMonitor progressMonitor = new CopyProgressMonitor(
+ "Downloading Maemo SDK virtual image", remoteFileSize, monitor);
+ progressMonitor.setExistingSize(downloadFile.getDownloadedSize());
+ progressMonitor.start();
+
+ out = new RandomFileOutputStream(localFile,true);
+ out.setFilePointer(downloadFile.getDownloadedSize());
+ in = connection.getInputStream();
+
+ // create and start to download
+ monitor.beginTask(remoteURL.getFile(), remoteFileSize != 0 ? remoteFileSize : IProgressMonitor.UNKNOWN);
+ monitor.worked((int)downloadFile.getDownloadedSize());
+
+ int bufferSize = 64*1024;//64KB
+ DownloadingThread thread = new DownloadingThread(in, out,bufferSize , progressMonitor, monitor);
+ thread.start();
+
+ while (!thread.isInterrupted() && thread.isAlive() ) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ continue;
+ }
+
+ if (monitor.isCanceled()) {
+ thread.stopDownloading();
+ downloadFile.cancel();
+ return Status.CANCEL_STATUS;
+ }
+
+ if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED){
+ thread.doPause();
+ }
+
+ if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING){
+ if(thread.isPaused()) thread.doResume();
+ }
+ }
+
+ if (thread.isCompleted() && nPart == downloadFile.getNumParts()) {
+ downloadFile.complete();
+ }
+
+ if (thread.getErrorMessage() != null) {
+ downloadFile.error();
+ throw new IOException(thread.getErrorMessage());
+ }
+ } finally {
+
+ // Close connection to server.
+ if (in != null) {
+ in.close();
+ }
+
+ if (connection != null)
+ connection.disconnect();
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ protected IStatus downloadSingle() throws MicaException, IOException {
+ Tuple remoteFileInfo = getRemoteFileInfo(null);
URL remoteURL = (URL) remoteFileInfo.get(0);
-
+
// Get link of remote file
- String fileName = getFileName(remoteURL, downloadFile.getLocalURL());
- downloadFile.setLocalURL(new File(fileName).toURL());
-
- downloadFile.setDownloadedSize(getPreviousDownloadSize(fileName));
+ File localFile = getLocalFile(remoteURL, downloadFile.getInstallLocation());
+ downloadFile.setFileName(localFile.getName());
+
+ downloadFile.setDownloadedSize(getPreviousDownloadSize(localFile));
Integer remoteFileSize = (Integer) remoteFileInfo.get(1);
-
+
if (downloadFile.getDownloadedSize() == remoteFileSize.intValue()){
downloadFile.complete();
- return Activator.createStatus(Status.OK, "Maemo SDK virtual image is already downloaded.");
+ return Activator.createStatus(Status.OK,
+ "Maemo SDK virtual image is already downloaded.");
}
-
+
HttpURLConnection connection = null;
RandomFileOutputStream out = null;
InputStream in = null;
-
+
try {
-
+
// Open connection to URL.
- monitor.subTask("Establishing connection with " + remoteURL.getHost());
+ monitor.subTask("Establishing connection with "
+ + remoteURL.getHost());
connection = (HttpURLConnection) remoteURL.openConnection();
-
+
// Specify what portion of file to download
- connection.setRequestProperty("Range", "bytes=" + downloadFile.getDownloadedSize() + "-");
-
+ connection.setRequestProperty("Range", "bytes="
+ + downloadFile.getDownloadedSize() + "-");
+
// Connect to server
connection.connect();
monitor.subTask("Connected with " + remoteURL.getHost());
-
+
IStatus connectionStatus = validateConnection(connection);
if (!connectionStatus.isOK()) {
- cancelDownload(downloadFile,monitor);
+ cancelDownload(downloadFile, monitor);
return errorStatus(connectionStatus.getMessage());
}
-
- Path filePath = new Path(downloadFile.getLocalURL().getPath());
- int contentLength = connection.getContentLength();
- if (!haveEnoughtFreeSpace(contentLength/1024, filePath.removeLastSegments(1))) {
+
+ int contentLength = connection.getContentLength();
+ if (!haveEnoughtFreeSpace(contentLength / 1024, localFile)) {
cancelDownload(downloadFile, monitor);
return errorStatus("There is not enought space to save Maemo SDK virtual machine in your computer.");
}
-
+
// set the size for this download if it hasn't been already set.
if (downloadFile.getSize() == -1) {
downloadFile.setSize(contentLength);
}
-
+
CopyProgressMonitor progressMonitor = new CopyProgressMonitor(
- "Downloading Maemo SDK virtual image", remoteFileSize, monitor);
+ "Downloading Maemo SDK virtual image", remoteFileSize,
+ monitor);
progressMonitor.setExistingSize(downloadFile.getDownloadedSize());
progressMonitor.start();
-
- out = new RandomFileOutputStream(fileName,true);
- out.setFilePointer(downloadFile.getDownloadedSize());
+
+ out = new RandomFileOutputStream(localFile, true);
+ out.setFilePointer(downloadFile.getDownloadedSize());
in = connection.getInputStream();
-
+
// create and start to download
- monitor.beginTask(remoteURL.getFile(), remoteFileSize != 0 ? remoteFileSize : IProgressMonitor.UNKNOWN);
- monitor.worked((int)downloadFile.getDownloadedSize());
-
- int bufferSize = 64*1024;//64KB
- DownloadingThread thread = new DownloadingThread(in, out,bufferSize , progressMonitor, monitor);
+ monitor.beginTask(remoteURL.getFile(),
+ remoteFileSize != 0 ? remoteFileSize
+ : IProgressMonitor.UNKNOWN);
+ monitor.worked((int) downloadFile.getDownloadedSize());
+
+ int bufferSize = 64 * 1024;// 64KB
+ DownloadingThread thread = new DownloadingThread(in, out,
+ bufferSize, progressMonitor, monitor);
thread.start();
- while (!thread.isInterrupted() && thread.isAlive() ) {
+ while (!thread.isInterrupted() && thread.isAlive()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
continue;
}
-
+
if (monitor.isCanceled()) {
thread.stopDownloading();
- downloadFile.cancel();
+ downloadFile.cancel();
return Status.CANCEL_STATUS;
}
-
- if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED){
+
+ if (downloadFile.getStatus() == MaemoSDKVMInfo.Status.PAUSED) {
thread.doPause();
}
-
- if(downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING){
+
+ if (downloadFile.getStatus() == MaemoSDKVMInfo.Status.DOWNLOADING) {
thread.doResume();
}
}
-
+
if (thread.isCompleted()) {
downloadFile.complete();
}
-
+
if (thread.getErrorMessage() != null) {
downloadFile.error();
throw new IOException(thread.getErrorMessage());
@@ -401,10 +521,9 @@
if (connection != null)
connection.disconnect();
}
-
return Status.OK_STATUS;
}
-
+
/**
* Creates an error status based with the given message.
* @param message
@@ -432,8 +551,8 @@
* @return boolean if there is enough space to uncompress the Maemo SDK virtual image (if the free space
* available on disk is bigger than the size of uncompressed Maemo SDK virtual image); false, otherwise.
*/
- private static boolean haveEnoughtFreeSpace(int fileSize, IPath localURL) throws IOException {
- long freeSpace = FilesystemUtils.freeSpaceOS(localURL,true);
+ private static boolean haveEnoughtFreeSpace(int fileSize, File localFile) throws IOException {
+ long freeSpace = FilesystemUtils.freeSpaceOS(new Path(localFile.getAbsolutePath()),true);
return freeSpace > fileSize;
}
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.maemo.esbox.internal.api.vm.vmware;
+import java.io.File;
+import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -20,7 +22,7 @@
*
*/
public class MaemoSDKVMInfo implements Comparable<MaemoSDKVMInfo> {
-
+//XXX REMOVE ME public static final String DOWNLOAD_PAGE = "http://localhost:8080/nokia/";
public static final String DOWNLOAD_PAGE = "http://tablets-dev.nokia.com/maemo-dev-env-downloads.php";
// status for the file
@@ -40,9 +42,10 @@
private Status status;
// urls for download and storage
- private URL localPathURL;
+ private URL installLocaltion;
+ private String fileName;
- private boolean hasMoreParts;
+ private int numParts;
/**
* Constructor.
@@ -57,11 +60,12 @@
* @param url
*/
public MaemoSDKVMInfo(URL localURL) {
- this.localPathURL = localURL;
+ this.installLocaltion = localURL;
size = -1;
downloaded = 0;
descriptor = null;
status = Status.DOWNLOADING;
+ numParts = DefaultVMZipExtractor.SINGLE_FILE_PART;
}
/**
@@ -88,8 +92,8 @@
*
* @return
*/
- public URL getLocalURL() {
- return localPathURL;
+ public URL getInstallLocation() {
+ return installLocaltion;
}
/**
@@ -97,11 +101,38 @@
*
* @return
*/
- public void setLocalURL(URL localURL) {
- this.localPathURL = localURL;
+ public void setInstallLocation(URL localURL) {
+ this.installLocaltion = localURL;
}
+
+ /**
+ * The name of the file
+ * @return
+ */
+ public String getFileName(){
+ return this.fileName;
+ }
+
+ /**
+ * @return returns the local downloaded file name, it can be null
+ */
+ public File resolveLocalFile() {
+ return internalResolveLocalFile(getFileName());
+ }
+ private File internalResolveLocalFile(String fileName) {
+ String path = getInstallLocation().getPath();
+ return new File(path, fileName);
+ }
+
/**
+ * @param fileName the fileName to set
+ */
+ public void setFileName(String fileName){
+ this.fileName = fileName;
+ }
+
+ /**
* Get this download's size.
*
* @return
@@ -205,8 +236,8 @@
*
* @return true, if the file has more than one part; false, otherwise.
*/
- public boolean hasMoreParts() {
- return this.hasMoreParts;
+ public boolean isMultipart() {
+ return this.numParts > DefaultVMZipExtractor.SINGLE_FILE_PART;
}
/**
@@ -214,11 +245,17 @@
*
* @param hasMoreParts
*/
- public void setHasMoreParts(boolean hasMoreParts) {
- this.hasMoreParts = hasMoreParts;
+ public void setNumberOfParts(int number) {
+ this.numParts = number;
}
/**
+ * @return
+ */
+ public int getNumParts(){
+ return numParts;
+ }
+ /**
* Download the file.
*
* @return the runnable process
Property changes on: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -11,24 +11,18 @@
package org.maemo.esbox.internal.api.vm.vmware;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Locale;
-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.preference.PreferenceDialog;
import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.maemo.esbox.internal.api.maemosdk.ui.preferences.MaemoSDKPreferenceIds;
@@ -47,7 +41,9 @@
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.common.ui.dialogs.DialogUtils;
+import org.maemo.mica.common.ui.dialogs.StyledTextProgressDialog;
+import org.maemo.mica.internal.api.common.core.GeneralUtils;
import org.maemo.mica.internal.api.common.core.sdk.SDKManagerInternal;
import org.maemo.mica.internal.api.linux.packages.core.aptinstall.AptInstallerHelper;
@@ -61,7 +57,6 @@
public class MaemoSDKVMInstaller {
private MaemoSDKVMInstallData installData;
- private IProgressReporter reporter;
/**
* Constructor.
@@ -71,10 +66,8 @@
* @param reporter
* the progress reporter
*/
- public MaemoSDKVMInstaller(MaemoSDKVMInstallData installData,
- IProgressReporter reporter) {
+ public MaemoSDKVMInstaller(MaemoSDKVMInstallData installData) {
this.installData = installData;
- this.reporter = reporter;
}
/**
@@ -94,7 +87,7 @@
status = this.uncompressVM(shell, monitor);
if (canProceed(status))
- status = promptPreferencesDialog(shell, monitor);
+ status = promptPreferencesDialog(shell, monitor);
if (canProceed(status) && installData.canInstallSbox())
status = this.installScratchbox(shell,monitor);
@@ -125,9 +118,9 @@
*/
public IStatus downloadVM(final Shell shell, IProgressMonitor monitor) {
monitor.subTask("Downloading image...");
- reporter.logInfo("Downloading Maemo SDK virtual image...");
+ //reporter.reportStep("Downloading Maemo SDK virtual image...");
- shell.getDisplay().syncExec(new Runnable() {
+ Display.getDefault().syncExec(new Runnable() {
public void run() {
MaemoSDKVMInfo fileDownload = installData.getFileToDownload();
@@ -162,112 +155,104 @@
* @return the result of process as IStatus.
*/
public IStatus uncompressVM(final Shell shell, IProgressMonitor monitor) {
+ final StyledTextProgressDialog dialog = new StyledTextProgressDialog(shell, "Uncompressing Image");
+ dialog.setBlockOnOpen(false);
+
+ dialog.open();
+
+ final IStatus[] statuses = { Policy.getCancelStatus(Activator.getDefault()) };
+ final IProgressReporter reporter = dialog.getProgressReporter();
+ try {
+ dialog.run(true, true, new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ statuses[0] = doUncompressVM(dialog.getShell(), reporter, monitor);
+ }
+ });
+
+ reporter.log(statuses[0]);
+
+ if (statuses[0].isOK() || statuses[0].getSeverity() == IStatus.INFO) {
+ dialog.close();
+ }
+
+ return statuses[0];
+ } catch (Exception e) {
+ Throwable t;
+ if (e instanceof InvocationTargetException)
+ t = ((InvocationTargetException) e).getCause();
+ else
+ t = e;
+ IStatus status = Activator.createErrorStatus("Failed to extract image", t);
+ Activator.getErrorLogger().log(status);
+ return status;
+ }
+ }
+
+ /**
+ * Uncompress the Maemo SDK virtual image.
+ *
+ * @return the result of process as IStatus.
+ */
+ private IStatus doUncompressVM(final Shell shell, IProgressReporter reporter, IProgressMonitor monitor) {
monitor.subTask("Uncompressing image...");
reporter.logInfo("Uncompressing Maemo SDK virtual image...");
- final String fileName = installData.getPathOfExistentVM() == null ? installData.getFileToDownload().getLocalURL().getFile() :
- installData.getPathOfExistentVM();
- final String destinationPath = installData.getInstallationPath();
+ String fileName = null;
+ MaemoSDKVMInfo fileToDownload = installData.getFileToDownload();
- final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "File " + fileName
- + " was properly uncompressed into " + destinationPath) } ;
+ if(installData.getPathOfExistentVM() == null){
+ File resolvedLocalFile = fileToDownload.resolveLocalFile();
+ if (resolvedLocalFile == null ) {
+ return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
+ }
+ fileName = resolvedLocalFile.getAbsolutePath();
+ }else{
+ fileName = installData.getPathOfExistentVM();
+ }
- if (fileName == null || !haveEnoughFreeSpace(fileName,destinationPath) ) {
+ if (fileName == null ) {
return Activator.createStatus(IStatus.ERROR,"Cannot retrieve information about zipped Maemo SDK virtual image.");
- }
+ }
- shell.getDisplay().syncExec(new Runnable() {
-
- public void run() {
- try {
- ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(shell);
- progressMonitor.run(true, true, new IRunnableWithProgress() {
-
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
-
-
- byte[] buf = new byte[1024];
- ZipInputStream zipInputStream = null;
- ZipEntry zipEntry = null;
- FileOutputStream fileOutputStream = null;
-
- try {
- zipInputStream = new ZipInputStream(new FileInputStream(fileName));
- zipEntry = zipInputStream.getNextEntry();
- while (zipEntry != null) {
-
- // for each entry to be extracted
- String entryName = zipEntry.getName();
-
- monitor.beginTask("Uncompressing Maemo SDK virtual image", 100);
-
- long lenght = zipEntry.getSize();
-
- File newFile = new File(entryName);
- String directory = newFile.getParent();
- if (directory == null) {
- if (newFile.isDirectory())
- break;
- }
-
- fileOutputStream = new FileOutputStream(destinationPath
- + File.separator + entryName);
- int n;
- long totalRead = 0;
- int previousProgressValue = 0;
- while ((n = zipInputStream.read(buf, 0, 1024)) > -1) {
- // write on file
- fileOutputStream.write(buf, 0, n);
-
- // update progress monitor bar
- totalRead += n;
- int progressValue = ((int) getProgress(lenght,totalRead));
- if (previousProgressValue < progressValue) {
- previousProgressValue = progressValue;
- monitor.worked(1);
- }
- if (monitor.isCanceled())
- break;
- monitor.subTask("Uncompressing " + zipEntry
- + "\t\t"
- + String.format(Locale.US, "%.2f", getProgress(lenght,totalRead)) + "%");
-
- }
- fileOutputStream.close();
- zipInputStream.closeEntry();
-
- if (monitor.isCanceled()) {
- statuses[0] = Activator.createErrorStatus("Installation was cancelled.", null);
- return;
- } else {
- zipEntry = zipInputStream.getNextEntry();
- }
- }
-
- } catch (IOException ioe) {
- statuses[0] = Activator.createErrorStatus("Cannot uncompress Maemo SDK virtual image: I/O error", ioe);
- reporter.appendStreamText("Cannot uncompress Maemo SDK virtual image.", true);
- } finally {
-
- Policy.close(zipInputStream);
-
- Policy.close(fileOutputStream);
-
- }
-
- }
-
- });
- } catch (Exception e) {
- statuses[0] = Activator.createErrorStatus("Cannot uncompress Maemo SDK virtual image.", e);
- reporter.appendStreamText("Cannot procced with Maemo SDK virtual image uncompressing.",true);
- }
- }
- });
+ final String destinationPath = installData.getInstallationPath();
- return statuses[0];
+ IStatus status = Activator.createStatus(IStatus.OK, "File " + fileName
+ + " was properly uncompressed into " + destinationPath) ;
+
+
+ int numParts = fileToDownload.getNumParts();
+ long requiredSpace = DefaultVMZipExtractor.getEstimatedDecompressedSize(fileName, numParts);
+ long freeSpace = DefaultVMZipExtractor.getFreeSpaceSize(fileName);
+
+ if(installData.getUncompressToolPath() == null){
+ if (!DefaultVMZipExtractor.haveEnoughFreeSpace(fileName,destinationPath) ) {
+ return Activator.createStatus(IStatus.ERROR,"There is not enough free space to uncompress the Maemo SDK virtual image files.");
+ }
+ status = DefaultVMZipExtractor.extract(fileName, shell, destinationPath, reporter);
+ }else{
+ Tool7zip tool = new Tool7zip(installData.getUncompressToolPath());
+
+ if (freeSpace <= requiredSpace ) {
+ reporter.log(Activator.createStatus(IStatus.WARNING, "Low disk space warning, perform a disk cleanup."));
+ if(!DialogUtils
+ .showQuestionDialog(
+ DialogUtils.getShell(),
+ "Low Disk Space Warning",
+ MessageFormat.format(
+ "The disk might not have enough free space to uncompress the" +
+ " Maemo SDK virtual image files.\n" +
+ "(Estimated size: {0}, Free space: {1}) \n" +
+ " Do you want to proceed anyway?",
+ GeneralUtils.getFormattedString(requiredSpace),
+ GeneralUtils.getFormattedString(freeSpace))) ) {
+ return Activator.createStatus(IStatus.ERROR,"There is not enough free space to uncompress the Maemo SDK virtual image files.");
+ }
+ }
+ status = tool.extractAndGetStatus(fileName, destinationPath, reporter, monitor);
+ }
+ return status;
}
/**
@@ -278,11 +263,11 @@
*/
private IStatus installScratchbox(final Shell shell, IProgressMonitor monitor) {
monitor.subTask("Installing Scratchbox 1...");
- reporter.logInfo("Installing Scratchbox 1 on Maemo SDK virtual image. This operation will take several minutes.");
+ //reporter.queryToContinue("Installing Scratchbox 1 on Maemo SDK virtual image. This operation will take several minutes.");
final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox was properly installed on Maemo SDK virtual image.") } ;
- shell.getDisplay().syncExec(new Runnable() {
+ Display.getDefault().syncExec(new Runnable() {
public void run() {
statuses[0] = NewScratchbox1SDKWizard.startWizard();
@@ -301,32 +286,37 @@
*/
private IStatus installScratchboxTargets(final Shell shell, IProgressMonitor monitor) {
monitor.subTask("Installing Scratchbox 1 targets...");
- reporter.logInfo("Installing Scratchbox 1 Targets on Maemo SDK virtual image. This operation will take several minutes.");
+ //reporter.logInfo("Installing Scratchbox 1 Targets on Maemo SDK virtual image. This operation will take several minutes.");
final IStatus[] statuses = { Activator.createStatus(IStatus.OK, "Scratchbox targets were properly installed on Maemo SDK virtual image.") } ;
- shell.getDisplay().syncExec(new Runnable() {
+ final NewScratchbox1TargetWizard wizard = new NewScratchbox1TargetWizard();
+ wizard.setSuppressNokiaBinariesWizard(true);
+
+ Display.getDefault().syncExec(new Runnable() {
public void run() {
- statuses[0] = NewScratchbox1TargetWizard.startWizard();
+ statuses[0] = NewScratchbox1TargetWizard.startWizard(wizard);
}
});
+ // need to break out of syncexec to launch a new wizard on OS X
+ if (statuses[0].getSeverity() == IStatus.OK
+ || statuses[0].getSeverity() == IStatus.INFO) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ // now install Nokia binaries synchronously
+ wizard.promptInstallNokiaBinaries(true);
+ }
+ });
+ }
+
return statuses[0];
}
/**
- * Get the progress value of uncompressing process.
- * @param total
- * @param read
- * @return
- */
- private float getProgress(long total, long read) {
- return ((float) read / total) * 100;
- }
-
- /**
* Show a preference dialog that points to virtual image preference page. It is necessary
* to configure the new virtual image so the installation process can proceeed.
* @param shell
@@ -334,7 +324,7 @@
*/
private IStatus promptPreferencesDialog(final Shell shell, IProgressMonitor monitor) {
monitor.subTask("Configuring Maemo SDK virtual image...");
- reporter.logInfo("Configuring Maemo SDK virtual image...");
+ //reporter.logInfo("Configuring Maemo SDK virtual image...");
final IStatus statuses[] = new IStatus[] {Policy.getCancelStatus(Activator.getDefault())};
@@ -342,7 +332,7 @@
if (!vmLocation.trim().equals("")) {
- shell.getDisplay().syncExec(new Runnable() {
+ Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
@@ -452,7 +442,7 @@
*/
private IStatus installPackages(Shell shell, IProgressMonitor monitor) {
monitor.subTask("Installing programming environment...");
- reporter.logInfo("Installing Python/C++ programming environment on Maemo SDK virtual image. This operation may take several minutes.");
+ //reporter.logInfo("Installing Python/C++ programming environment on Maemo SDK virtual image. This operation may take several minutes.");
IStatus status = Policy.getCancelStatus(Activator.getDefault());
@@ -460,7 +450,10 @@
String[] packages = checkPackagesToInstall();
- status = AptInstallerHelper.installPackages(sdkTargets, packages, true, shell, reporter, monitor);
+ status = AptInstallerHelper.installPackages(sdkTargets, packages, true, shell,
+ "Install C++ and Python Programming Environment",
+ "Install the C++ and Python development metapackages now?",
+ null /*reporter*/, null /*monitor*/);
return status;
}
@@ -523,37 +516,4 @@
return packagesToInstall.toArray(new String[packagesToInstall.size()]);
}
- /**
- * Check if there is enough space to uncompress the Maemo SDK virtual image.
- * @param fileName the name of Maemo SDK virtual image.
- * @param destinationPath the destination path to uncompress the Maemo SDK virtual image.
- * @return boolean if there is enough space to uncompress the Maemo SDK virtual image (if the free space
- * available on disk is bigger than the size of uncompressed Maemo SDK virtual image); false, otherwise.
- */
- private static boolean haveEnoughFreeSpace(String fileName, String destinationPath) {
- ZipInputStream zipInputStream = null;
- ZipEntry zipEntry;
-
- try {
- long fileSize = 0;
- zipInputStream = new ZipInputStream(new FileInputStream(fileName));
-
- // check the total size of zip file. It is necessary to check the size of each zip file entry.
- while ((zipEntry = zipInputStream.getNextEntry()) != null) {
- fileSize += zipEntry.getSize();
- }
- fileSize = fileSize / 1024; //Kb
- long freeSpace = FilesystemUtils.freeSpaceOS(new Path(destinationPath),true);
- 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);
- }
-
-
- }
-
}
Property changes on: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/MaemoSDKVMInstaller.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java (from rev 2129, trunk/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java)
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java (rev 0)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -0,0 +1,141 @@
+package org.maemo.esbox.internal.api.vm.vmware;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.machine.MachineUtils;
+import org.maemo.mica.common.core.process.CommandLineArguments;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.process.IStreamMonitor;
+import org.maemo.mica.common.core.process.ProcessLauncherParameters;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils;
+import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.common.core.ui.ProgressReporterStreamTextMonitor;
+
+/**
+ * @author Fabrício S Epaminondas
+ *
+ */
+public class Tool7zip {
+ /**
+ * No error
+ */
+ public static int EXIT_CODE_NO_ERROR = 0;
+ /**
+ * Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
+ */
+ public static int EXIT_CODE_WARNING = 1;
+ /**
+ * Fatal error
+ */
+ public static int EXIT_CODE_FATAL = 2;
+ /**
+ * Command line error
+ */
+ public static int EXIT_CODE_ERROR = 7;
+ /**
+ * Not enough memory for operation
+ */
+ public static int EXIT_CODE_NOT_ENOUGH_MEMORY = 8;
+ /**
+ * User stopped the process
+ */
+ public static int EXIT_CODE_STOPPED = 255;
+
+ private String path;
+ private final IMachine machine;
+
+
+ /**
+ * Creates a 7z tool reference using default path
+ */
+ public Tool7zip() {
+ super();
+ this.machine = MachineRegistry.getInstance().getLocalMachine();
+ IPath path = MachineUtils.findProgramOnPath(machine, "7z");
+
+ if(path ==null)
+ throw new IllegalArgumentException("7zip could not be found on machine.");
+ this.path = path.toOSString();
+
+ }
+ /**
+ * Creates a 7z tool reference using the passed path
+ * @param path
+ * @param machine
+ * @throws MicaException
+ */
+ public Tool7zip(String path) {
+ super();
+ this.machine = MachineRegistry.getInstance().getLocalMachine();
+
+ if(!machine.getFileSystemAccess().getFileStore(new Path(path)).fetchInfo().exists())
+ throw new IllegalArgumentException("7zip could not be found on machine.");
+ this.path = path;
+ }
+
+
+ /**
+ * @param machine
+ * @param fileName
+ * @param destinationPath
+ * @param monitor
+ * @return
+ * @throws MicaException
+ */
+ public int extract(String fileName,
+ String destinationPath, final IProgressReporter reporter, IProgressMonitor monitor) throws MicaException {
+ String[] commandArray = new String[] {path, "-y", "x", "-o" +destinationPath, fileName};
+ IProcessLauncherFactory factory = machine.getProcessLauncherFactory();
+ IProcessLauncher launcher = factory.createProcessLauncher(ProcessLauncherParameters.create(
+ new Path(new File(fileName).getParent()),
+ CommandLineArguments.createFromArray(commandArray)));
+
+ return ProcessLauncherUtils.launchAndMonitorStandardStreams(launcher,
+ new IStreamMonitor[] { new ProgressReporterStreamTextMonitor(reporter)}, monitor);
+ }
+
+
+ /**
+ * @param machine
+ * @param fileName
+ * @param destinationPath
+ * @param monitor
+ * @return
+ * @throws MicaException
+ */
+ public IStatus extractAndGetStatus(String fileName,
+ String destinationPath, IProgressReporter reporter, IProgressMonitor monitor) {
+ IStatus status = Activator.createStatus(IStatus.OK, "No error.");
+ try {
+ int exit = extract(fileName, destinationPath, reporter, monitor);
+ if(exit == EXIT_CODE_NO_ERROR){
+ //Ok, no error
+ }else if(exit == -1){
+ status = Activator.createStatus(IStatus.ERROR, "The file could not be uncompressed.");
+ }else if(exit == EXIT_CODE_WARNING){
+ status = Activator.createStatus(IStatus.WARNING, "One or more files can be locked by some other application, so they were not compressed.");
+ }else if(exit == EXIT_CODE_FATAL){
+ status = Activator.createStatus(IStatus.ERROR, "Fatal error.");
+ }else if(exit == EXIT_CODE_ERROR){
+ status = Activator.createStatus(IStatus.ERROR, "Command line error.");
+ }else if(exit == EXIT_CODE_NOT_ENOUGH_MEMORY){
+ status = Activator.createStatus(IStatus.CANCEL, "Not enough memory for operation.");
+ }else if(exit == EXIT_CODE_STOPPED){
+ status = Activator.createStatus(IStatus.CANCEL, "User stopped the process.");
+ }
+ } catch (MicaException e) {
+ status = Activator.createErrorStatus("Uncompression failed.", e);
+ }
+
+ return status;
+ }
+}
Property changes on: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/api/vm/vmware/Tool7zip.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMConfigurationWizardPage.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -47,6 +47,8 @@
private Button installCPPEnv;
private Button installPythonEnv;
+ private boolean hasBeenSeen;
+
/**
* Constructor.
*
@@ -291,7 +293,10 @@
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
- setValues();
+ if (!hasBeenSeen && visible) {
+ setInitialValues();
+ hasBeenSeen = true;
+ }
}
/**
@@ -314,7 +319,7 @@
/**
* Set default values based on virtual image.
*/
- private void setValues() {
+ private void setInitialValues() {
MaemoSDKVMInstallData installData = ((NewMaemoSDKVMWizard)getWizard()).getInstallData();
// if use previous installation, it takes Server default values
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallData.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -1,204 +1,219 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-
-/**
- * This is a wrapper that contains information about Maemo SDK virtual image
- * installation process.
- *
- * @author raulherbster
- *
- */
-public class MaemoSDKVMInstallData {
-
- private MaemoSDKVMInfo fileToDownload;
- private boolean usePreviousInstallation;
- private String installationPath;
- private String pathOfExistentVM;
- private boolean licenseTermsAgreed;
- private boolean installSbox;
- private boolean installTargets;
- private boolean installCppEnv;
- private boolean installPythonEnv;
-
- /**
- * Constructor.
- */
- public MaemoSDKVMInstallData() {
- fileToDownload = new MaemoSDKVMInfo();
- }
-
- /**
- * Set the file to download.
- *
- * @param downloadFile
- */
- public void setFileToDownload(MaemoSDKVMInfo downloadFile) {
- if (downloadFile == null)
- return;
- this.fileToDownload = downloadFile;
- if (fileToDownload.getLocalURL() == null && installationPath != null)
- try {
- fileToDownload.setLocalURL(new File(installationPath).toURL());
- } catch (MalformedURLException e) {
- Activator.getErrorLogger().logAndShowError(
- "Cannot get location for file "
- + downloadFile.getDescriptor(), e);
- }
- }
-
- /**
- * Return the file to download.
- *
- * @return
- */
- public MaemoSDKVMInfo getFileToDownload() {
- return fileToDownload;
- }
-
- /**
- * @return the usePreviousInstallation
- */
- public boolean canUsePreviousInstallation() {
- return usePreviousInstallation;
- }
-
- /**
- * @param usePreviousInstallation
- * the usePreviousInstallation to set
- */
- public void setUsePreviousInstallation(boolean usePreviousInstallation) {
- this.usePreviousInstallation = usePreviousInstallation;
- }
-
- /**
- * @return the installationPath
- */
- public String getInstallationPath() {
- return installationPath;
- }
-
- /**
- * @param installationPath
- * the installationPath to set
- */
- public void setInstallationPath(String installationPath) {
- this.installationPath = installationPath;
- try {
- fileToDownload.setLocalURL(new File(installationPath).toURL());
- } catch (MalformedURLException e) {
- Activator.getErrorLogger().logAndShowError(
- "Cannot get location for file "
- + fileToDownload.getDescriptor(), e);
- }
-
- }
-
- /**
- * @return the pathOfExistentVM
- */
- public String getPathOfExistentVM() {
- return pathOfExistentVM;
- }
-
- /**
- * @param pathOfExistentVM
- * the pathOfExistentVM to set
- */
- public void setPathOfExistentVM(String pathOfExistentVM) {
- this.pathOfExistentVM = pathOfExistentVM;
- }
-
- /**
- * @return the installSbox
- */
- public boolean canInstallSbox() {
- return installSbox;
- }
-
- /**
- * @param installSbox
- * the installSbox to set
- */
- public void setInstallSbox(boolean installSbox) {
- this.installSbox = installSbox;
- }
-
- /**
- * @return the installTargets
- */
- public boolean canInstallTargets() {
- return installTargets;
- }
-
- /**
- * @param installTargets
- * the installTargets to set
- */
- public void setInstallTargets(boolean installTargets) {
- this.installTargets = installTargets;
- }
-
- /**
- * @return true, if it is necessary to install Python programming
- * environment; false, otherwise.
- */
- public boolean canInstallPythonEnv() {
- return installPythonEnv;
- }
-
- /**
- * @param installTargets
- * the installTargets to set
- */
- public void setInstallPythonEnv(boolean installPythonEnv) {
- this.installPythonEnv = installPythonEnv;
- }
-
- /**
- *
- * @return true, if it is necessary to install CPP programming environment;
- * false, otherwise.
- */
- public boolean canInstallCppEnv() {
- return installCppEnv;
- }
-
- /**
- * @param installCppEnv
- * the installTargets to set
- */
- public void setInstallCppEnv(boolean installCppEnv) {
- this.installCppEnv = installCppEnv;
- }
-
- /**
- * @return true, if license terms were agreed; false, otherwise.
- */
- public boolean isLicenseTermsAgreed() {
- return licenseTermsAgreed;
- }
-
- /**
- * @param licenseTermsAgreed
- * the licenseTermsAgreed to set
- */
- public void setLicenseTermsAgreed(boolean licenseTermsAgreed) {
- this.licenseTermsAgreed = licenseTermsAgreed;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+
+/**
+ * This is a wrapper that contains information about Maemo SDK virtual image
+ * installation process.
+ *
+ * @author raulherbster
+ *
+ */
+public class MaemoSDKVMInstallData {
+
+ private MaemoSDKVMInfo fileToDownload;
+ private boolean usePreviousInstallation;
+ private String installationPath;
+ private String pathOfExistentVM;
+ private String uncompressToolPath;
+ private boolean licenseTermsAgreed;
+ private boolean installSbox;
+ private boolean installTargets;
+ private boolean installCppEnv;
+ private boolean installPythonEnv;
+
+ /**
+ * Constructor.
+ */
+ public MaemoSDKVMInstallData() {
+ fileToDownload = new MaemoSDKVMInfo();
+ }
+
+ /**
+ * Set the file to download.
+ *
+ * @param downloadFile
+ */
+ public void setFileToDownload(MaemoSDKVMInfo downloadFile) {
+ if (downloadFile == null)
+ return;
+ this.fileToDownload = downloadFile;
+ if (fileToDownload.getInstallLocation() == null && installationPath != null)
+ try {
+ fileToDownload.setInstallLocation(new File(installationPath).toURL());
+ } catch (MalformedURLException e) {
+ Activator.getErrorLogger().logAndShowError(
+ "Cannot get location for file "
+ + downloadFile.getDescriptor(), e);
+ }
+ }
+
+ /**
+ * Return the file to download.
+ *
+ * @return
+ */
+ public MaemoSDKVMInfo getFileToDownload() {
+ return fileToDownload;
+ }
+
+ /**
+ * @return the usePreviousInstallation
+ */
+ public boolean canUsePreviousInstallation() {
+ return usePreviousInstallation;
+ }
+
+ /**
+ * @param usePreviousInstallation
+ * the usePreviousInstallation to set
+ */
+ public void setUsePreviousInstallation(boolean usePreviousInstallation) {
+ this.usePreviousInstallation = usePreviousInstallation;
+ }
+
+ /**
+ * @return the installationPath
+ */
+ public String getInstallationPath() {
+ return installationPath;
+ }
+
+ /**
+ * @param installationPath
+ * the installationPath to set
+ */
+ public void setInstallationPath(String installationPath) {
+ this.installationPath = installationPath;
+ try {
+ fileToDownload.setInstallLocation(new File(installationPath).toURL());
+ } catch (MalformedURLException e) {
+ Activator.getErrorLogger().logAndShowError(
+ "Cannot get location for file "
+ + fileToDownload.getDescriptor(), e);
+ }
+
+ }
+
+ /**
+ * @return the pathOfExistentVM
+ */
+ public String getPathOfExistentVM() {
+ return pathOfExistentVM;
+ }
+
+ /**
+ * @return the path of uncompress tool to be used.
+ */
+ public String getUncompressToolPath() {
+ return uncompressToolPath;
+ }
+
+ /**
+ * @param pathOfExistentVM
+ * the pathOfExistentVM to set
+ */
+ public void setPathOfExistentVM(String pathOfExistentVM) {
+ this.pathOfExistentVM = pathOfExistentVM;
+ }
+
+ /**
+ * @return the installSbox
+ */
+ public boolean canInstallSbox() {
+ return installSbox;
+ }
+
+ /**
+ * @param installSbox
+ * the installSbox to set
+ */
+ public void setInstallSbox(boolean installSbox) {
+ this.installSbox = installSbox;
+ }
+
+ /**
+ * @return the installTargets
+ */
+ public boolean canInstallTargets() {
+ return installTargets;
+ }
+
+ /**
+ * @param installTargets
+ * the installTargets to set
+ */
+ public void setInstallTargets(boolean installTargets) {
+ this.installTargets = installTargets;
+ }
+
+ /**
+ * @return true, if it is necessary to install Python programming
+ * environment; false, otherwise.
+ */
+ public boolean canInstallPythonEnv() {
+ return installPythonEnv;
+ }
+
+ /**
+ * @param installTargets
+ * the installTargets to set
+ */
+ public void setInstallPythonEnv(boolean installPythonEnv) {
+ this.installPythonEnv = installPythonEnv;
+ }
+
+ /**
+ *
+ * @return true, if it is necessary to install CPP programming environment;
+ * false, otherwise.
+ */
+ public boolean canInstallCppEnv() {
+ return installCppEnv;
+ }
+
+ /**
+ * @param installCppEnv
+ * the installTargets to set
+ */
+ public void setInstallCppEnv(boolean installCppEnv) {
+ this.installCppEnv = installCppEnv;
+ }
+
+ /**
+ * @return true, if license terms were agreed; false, otherwise.
+ */
+ public boolean isLicenseTermsAgreed() {
+ return licenseTermsAgreed;
+ }
+
+ /**
+ * @param licenseTermsAgreed
+ * the licenseTermsAgreed to set
+ */
+ public void setLicenseTermsAgreed(boolean licenseTermsAgreed) {
+ this.licenseTermsAgreed = licenseTermsAgreed;
+ }
+
+ /**
+ * @param path the path of the uncompress tool to be used during virtual image uncompressing.
+ */
+ public void setUncompressToolPath(String path) {
+ this.uncompressToolPath = path;
+ }
+
+}
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMInstallerContentLabelProvider.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -1,271 +1,271 @@
-/*******************************************************************************
- * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Raul Herbster (INdT) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.swt.graphics.Image;
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMDescription;
-import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
-import org.maemo.esbox.internal.vm.vmware.Activator;
-import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
-
-import com.nokia.cpp.internal.api.utils.core.FileUtils;
-
-/**
- * Content and label provider for table that shows available Maemo SDK virtual
- * images.
- *
- * @author raulherbster
- *
- */
-public class MaemoSDKVMInstallerContentLabelProvider extends
- LazyLoadingThreadTableContentProvider {
-
- /**
- * Thread to access information about available Maemo SDK virtual images on
- * website.
- *
- * @author raulherbster
- *
- */
- protected class MaemoVMInstallScriptFetcherThread extends Thread {
- protected Object newInput;
-
- /**
- * Construtor.
- *
- * @param newInput
- */
- public MaemoVMInstallScriptFetcherThread(Object newInput) {
- this.newInput = newInput;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Thread#run()
- */
- public void run() {
- doFetchScripts();
-
- contents.remove(LOADING_LABEL);
- doFireContentChanged();
- }
-
- /**
- * Implement by querying the input and/or calling fetchScriptsFromUrl()
- * and adding them to contents.
- */
- protected void doFetchScripts() {
- List<MaemoSDKVMDescription> virtualImagesNames = fetchVMNamesFromUrl("http://tablets-dev.nokia.com/maemo-dev-env-downloads.php");
- for (MaemoSDKVMDescription maemoSDKVM : virtualImagesNames) {
- MaemoSDKVMInfo downloadFile = new MaemoSDKVMInfo();
- downloadFile.setDescriptor(maemoSDKVM);
- if (!contents.contains(downloadFile))
- contents.add(downloadFile);
- else {
- int indexOfExistingDownloadFile = contents
- .indexOf(downloadFile);
- ((MaemoSDKVMInfo) contents.get(indexOfExistingDownloadFile))
- .setHasMoreParts(true);
- }
- }
- }
-
- /**
- * Get available Maemo SDK virtual image from given URL.
- *
- * @param urlString
- * the url of website that contains information about
- * available Maemo SDK virtual images.
- * @return a list with the names of available Maemo SDK virtual images.
- */
- protected List<MaemoSDKVMDescription> fetchVMNamesFromUrl(String urlString) {
- URL url;
- try {
- url = new URL(urlString);
- } catch (MalformedURLException e) {
- Activator.getErrorLogger().logAndShowError(
- "Invalid URL: " + urlString, e);
- return Collections.emptyList();
- }
-
- List<MaemoSDKVMDescription> virtualImagesDescriptors = new ArrayList<MaemoSDKVMDescription>();
- try {
-
- URLConnection connection = url.openConnection();
- connection.setConnectTimeout(1000 * 10);
- connection.connect();
-
- // apparently this fetches the HTML...
- String content = new String(FileUtils.readInputStreamContents(
- connection.getInputStream(), "UTF-8"));
-
- /*
- * The names of virtual images are on
- * http://tablets-dev.nokia.com/maemo-dev-env-downloads.php
- * (front-page). Basically, they list have the following format:
- * Maemo ANY_WORD Virtual ANY_WORD Image ANY_WORD Also, we
- * filter duplicated entries, for example, files split into two
- * parts.
- */
- String license = getLicense(content);
-
- Pattern maemoVMPattern = Pattern
- .compile("Maemo(\\s)+SDK(\\s)+Virtual(\\s)+Image(\\s)+with(\\s)+Ubuntu(\\s)+(\\w)+(\\s)+([\\d]*\\.[\\d]*)(\\s)+(Server|Desktop)(\\s\\-(Part)\\s\\d)?");
- Matcher matcher = maemoVMPattern.matcher(content);
- while (matcher.find()) {
- String virtualImageName = matcher.group(0);
- String version = matcher.group(9);
- virtualImageName = processVirtualImageName(virtualImageName);
- boolean isServer = virtualImageName.toLowerCase().contains("server");
- String virtualImageDescription = isServer ? MaemoSDKVMDescription.SERVER_IMAGE_DESCRIPTION : MaemoSDKVMDescription.DESKTOP_IMAGE_DESCRIPTION;
- virtualImagesDescriptors.add(new MaemoSDKVMDescription(isServer,virtualImageName,version,virtualImageDescription,license));
- }
- } catch (Exception e) {
- if (e instanceof InterruptedException)
- return virtualImagesDescriptors;
-
- if (!isInterrupted())
- Activator.getErrorLogger().logAndShowError(
- "Could not fetch listing from " + url, e);
- }
-
- return virtualImagesDescriptors;
- }
-
- /**
- * Process the description of Maemo SDK virtual image and only returns
- * the main description.
- *
- * @param virtualImageName
- * the complete description of a certain Maemo SDK virtual
- * image.
- * @return the main description of a certain Maemo SDK virtual image.
- */
- private String processVirtualImageName(String virtualImageName) {
- int indexOfPar = virtualImageName.indexOf("(");
- if (indexOfPar < 0)
- return virtualImageName;
- return virtualImageName.substring(0, indexOfPar).trim();
- }
-
- /**
- * Get license from virtual images website.
- * @param content
- * @return
- */
- private String getLicense(String content) {
- final String LICENSE_PATTERN = "IMPORTANT:\\s*READ\\s*CAREFULLY\\s*BEFORE\\s*INSTALLING,\\s*DOWNLOADING,\\s*OR\\s*USING\\s*THE\\s*SOFTWARE(.*?)PLEASE\\s*SUBMIT\\s*ANY\\s*ACCOMPANYING\\s*REGISTRATION\\s*FORMS\\s*TO\\s*RECEIVE\\s*REGISTRATION\\s*BENEFITS\\s*WHERE\\s*APPLICABLE";
- Pattern licensePattern = Pattern.compile(LICENSE_PATTERN,Pattern.DOTALL | Pattern.UNIX_LINES);
- Matcher matcher = licensePattern.matcher(content);
- String license = "";
- while (matcher.find()) {
- license = matcher.group(0);
- }
- return license;
- }
- }
-
- private Image vmImage;
-
- /**
- * Construtor.
- */
- public MaemoSDKVMInstallerContentLabelProvider() {
- super();
- vmImage = Activator.MAEMO_VM_DESCRIPTOR.createImage();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.maemo.mica.common.ui.common.LazyLoadingThreadTableContentProvider
- * #createContentFetchThread(java.lang.Object)
- */
- @Override
- protected Thread createContentFetchThread(Object newInput) {
- return new MaemoVMInstallScriptFetcherThread(newInput);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.
- * Object)
- */
- public Object[] getChildren(Object parentElement) {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object
- * )
- */
- public Object getParent(Object element) {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.
- * Object)
- */
- public boolean hasChildren(Object element) {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
- */
- public String getColumnText(Object element, int column) {
- if (element == LOADING_LABEL)
- return super.getColumnText(element, column);
-
- if (element instanceof MaemoSDKVMInfo) {
- MaemoSDKVMInfo data = (MaemoSDKVMInfo) element;
- if (column == 0)
- return data.getDescriptor().getName();
- }
- return "";
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
- */
- public Image getColumnImage(Object element, int column) {
- if (element instanceof MaemoSDKVMInfo) {
- if (column == 0)
- return vmImage;
- }
- return null;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.swt.graphics.Image;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMDescription;
+import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInfo;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
+
+import com.nokia.cpp.internal.api.utils.core.FileUtils;
+
+/**
+ * Content and label provider for table that shows available Maemo SDK virtual
+ * images.
+ *
+ * @author raulherbster
+ *
+ */
+public class MaemoSDKVMInstallerContentLabelProvider extends
+ LazyLoadingThreadTableContentProvider {
+
+ /**
+ * Thread to access information about available Maemo SDK virtual images on
+ * website.
+ *
+ * @author raulherbster
+ *
+ */
+ protected class MaemoVMInstallScriptFetcherThread extends Thread {
+ protected Object newInput;
+
+ /**
+ * Construtor.
+ *
+ * @param newInput
+ */
+ public MaemoVMInstallScriptFetcherThread(Object newInput) {
+ this.newInput = newInput;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Thread#run()
+ */
+ public void run() {
+ doFetchScripts();
+
+ contents.remove(LOADING_LABEL);
+ doFireContentChanged();
+ }
+
+ /**
+ * Implement by querying the input and/or calling fetchScriptsFromUrl()
+ * and adding them to contents.
+ */
+ protected void doFetchScripts() {
+ List<MaemoSDKVMDescription> virtualImagesNames = fetchVMNamesFromUrl(MaemoSDKVMInfo.DOWNLOAD_PAGE);
+ for (MaemoSDKVMDescription maemoSDKVM : virtualImagesNames) {
+ MaemoSDKVMInfo downloadFile = new MaemoSDKVMInfo();
+ downloadFile.setDescriptor(maemoSDKVM);
+ if (!contents.contains(downloadFile))
+ contents.add(downloadFile);
+ else {
+ int indexOfExistingDownloadFile = contents
+ .indexOf(downloadFile);
+ MaemoSDKVMInfo info = ((MaemoSDKVMInfo) contents.get(indexOfExistingDownloadFile));
+ info.setNumberOfParts(info.getNumParts() +1);
+ }
+ }
+ }
+
+ /**
+ * Get available Maemo SDK virtual image from given URL.
+ *
+ * @param urlString
+ * the url of website that contains information about
+ * available Maemo SDK virtual images.
+ * @return a list with the names of available Maemo SDK virtual images.
+ */
+ protected List<MaemoSDKVMDescription> fetchVMNamesFromUrl(String urlString) {
+ URL url;
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e) {
+ Activator.getErrorLogger().logAndShowError(
+ "Invalid URL: " + urlString, e);
+ return Collections.emptyList();
+ }
+
+ List<MaemoSDKVMDescription> virtualImagesDescriptors = new ArrayList<MaemoSDKVMDescription>();
+ try {
+
+ URLConnection connection = url.openConnection();
+ connection.setConnectTimeout(1000 * 10);
+ connection.connect();
+
+ // apparently this fetches the HTML...
+ String content = new String(FileUtils.readInputStreamContents(
+ connection.getInputStream(), "UTF-8"));
+
+ /*
+ * The names of virtual images are on
+ * http://tablets-dev.nokia.com/maemo-dev-env-downloads.php
+ * (front-page). Basically, they list have the following format:
+ * Maemo ANY_WORD Virtual ANY_WORD Image ANY_WORD Also, we
+ * filter duplicated entries, for example, files split into two
+ * parts.
+ */
+ String license = getLicense(content);
+
+ Pattern maemoVMPattern = Pattern
+ .compile("Maemo(\\s)+SDK(\\s)+Virtual(\\s)+Image(\\s)+with(\\s)+Ubuntu(\\s)+(\\w)+(\\s)+([\\d]*\\.[\\d]*)(\\s)+(Server|Desktop)(\\s\\-(Part)\\s\\d)?");
+ Matcher matcher = maemoVMPattern.matcher(content);
+ while (matcher.find()) {
+ String virtualImageName = matcher.group(0);
+ String version = matcher.group(9);
+ virtualImageName = processVirtualImageName(virtualImageName);
+ boolean isServer = virtualImageName.toLowerCase().contains("server");
+ String virtualImageDescription = isServer ? MaemoSDKVMDescription.SERVER_IMAGE_DESCRIPTION : MaemoSDKVMDescription.DESKTOP_IMAGE_DESCRIPTION;
+ virtualImagesDescriptors.add(new MaemoSDKVMDescription(isServer,virtualImageName,version,virtualImageDescription,license));
+ }
+ } catch (Exception e) {
+ if (e instanceof InterruptedException)
+ return virtualImagesDescriptors;
+
+ if (!isInterrupted())
+ Activator.getErrorLogger().logAndShowError(
+ "Could not fetch listing from " + url, e);
+ }
+
+ return virtualImagesDescriptors;
+ }
+
+ /**
+ * Process the description of Maemo SDK virtual image and only returns
+ * the main description.
+ *
+ * @param virtualImageName
+ * the complete description of a certain Maemo SDK virtual
+ * image.
+ * @return the main description of a certain Maemo SDK virtual image.
+ */
+ private String processVirtualImageName(String virtualImageName) {
+ int indexOfPar = virtualImageName.indexOf("(");
+ if (indexOfPar < 0)
+ return virtualImageName;
+ return virtualImageName.substring(0, indexOfPar).trim();
+ }
+
+ /**
+ * Get license from virtual images website.
+ * @param content
+ * @return
+ */
+ private String getLicense(String content) {
+ final String LICENSE_PATTERN = "IMPORTANT:\\s*READ\\s*CAREFULLY\\s*BEFORE\\s*INSTALLING,\\s*DOWNLOADING,\\s*OR\\s*USING\\s*THE\\s*SOFTWARE(.*?)PLEASE\\s*SUBMIT\\s*ANY\\s*ACCOMPANYING\\s*REGISTRATION\\s*FORMS\\s*TO\\s*RECEIVE\\s*REGISTRATION\\s*BENEFITS\\s*WHERE\\s*APPLICABLE";
+ Pattern licensePattern = Pattern.compile(LICENSE_PATTERN,Pattern.DOTALL | Pattern.UNIX_LINES);
+ Matcher matcher = licensePattern.matcher(content);
+ String license = "";
+ while (matcher.find()) {
+ license = matcher.group(0);
+ }
+ return license;
+ }
+ }
+
+ private Image vmImage;
+
+ /**
+ * Construtor.
+ */
+ public MaemoSDKVMInstallerContentLabelProvider() {
+ super();
+ vmImage = Activator.MAEMO_VM_DESCRIPTOR.createImage();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.maemo.mica.common.ui.common.LazyLoadingThreadTableContentProvider
+ * #createContentFetchThread(java.lang.Object)
+ */
+ @Override
+ protected Thread createContentFetchThread(Object newInput) {
+ return new MaemoVMInstallScriptFetcherThread(newInput);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.
+ * Object)
+ */
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object
+ * )
+ */
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.
+ * Object)
+ */
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ public String getColumnText(Object element, int column) {
+ if (element == LOADING_LABEL)
+ return super.getColumnText(element, column);
+
+ if (element instanceof MaemoSDKVMInfo) {
+ MaemoSDKVMInfo data = (MaemoSDKVMInfo) element;
+ if (column == 0)
+ return data.getDescriptor().getName();
+ }
+ return "";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
+ */
+ public Image getColumnImage(Object element, int column) {
+ if (element instanceof MaemoSDKVMInfo) {
+ if (column == 0)
+ return vmImage;
+ }
+ return null;
+ }
+
+}
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMSelectionWizardPage.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -46,6 +46,7 @@
import org.maemo.mica.common.core.machine.MachineRegistry;
import org.maemo.mica.common.ui.NetworkSettingsUI;
import org.maemo.mica.common.ui.dialogs.DialogUtils;
+import org.maemo.mica.common.ui.dialogs.DirectoryDialogHelper;
import org.maemo.mica.internal.api.common.ui.LazyLoadingThreadTableContentProvider;
/**
@@ -258,6 +259,8 @@
public void widgetSelected(SelectionEvent evt) {
DirectoryDialog dialog = new DirectoryDialog(DialogUtils.getShell(), SWT.OPEN);
+ DirectoryDialogHelper.setFilterPathToExistingDirectory(dialog,
+ destinationTextField.getText());
dialog.setText("Select the directory to save the Maemo SDK virtual image");
String pathDirectory = dialog.open();
if (pathDirectory != null) {
@@ -530,6 +533,8 @@
private MaemoSDKVMInfo getLatestVMInstallData(LabelProviderChangedEvent event) {
LazyLoadingThreadTableContentProvider provider = (LazyLoadingThreadTableContentProvider)event.getSource();
Object[] elements = provider.getElements(new Object[0]);
+ if (elements.length == 0)
+ return null;
Arrays.sort(elements);
return (MaemoSDKVMInfo) elements[0];
}
Copied: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java (from rev 2129, trunk/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java)
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java (rev 0)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2009 INdT, (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (INdT) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.vm.vmware.ui.wizards;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.maemo.esbox.internal.vm.vmware.Activator;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.machine.MachineUtils;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
+
+/**
+ * This page displays information about Maemo SDK virtual machine configuration.
+ *
+ * @author raulherbster
+ *
+ */
+public class MaemoSDKVMUncompressInfoWizardPage extends WizardPage {
+
+ // options for uncompress tool
+ private Text uncompressToolTextField;
+
+ /**
+ * Constructor.
+ *
+ * @param wizard
+ * parent wizard.
+ */
+ protected MaemoSDKVMUncompressInfoWizardPage(NewMaemoSDKVMWizard wizard) {
+ super("maemovm_uncompresstool", "Uncompress tool specification",
+ Activator.MAEMO_VM_WIZBAN_DESCRIPTOR);
+ setDescription("Specify the tool used to uncompress Maemo SDK Virtual Image.");
+ setWizard(wizard);
+ setPageComplete(false);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
+ setControl(composite);
+
+ Label mainMessage = new Label(composite, SWT.WRAP);
+ mainMessage.setText("Maemo SDK Virtual Image wizard also uncompress the virtual machine for you. " +
+ "However, since Maemo SDK Virtual Images are considerable large, most of existing tools cannot uncompress them.\n" +
+ "This wizard uses 7zip tool for uncompression, please specify a valid path for 7zip tool bellow.");
+
+ GridData labelData = new GridData();
+ labelData.horizontalSpan = 4;
+ labelData.horizontalAlignment = SWT.FILL;
+ Rectangle rect = getShell().getMonitor().getClientArea();
+ labelData.widthHint = rect.width / 4;
+ mainMessage.setLayoutData(labelData);
+
+ Label separator = new Label(composite, SWT.NONE);
+ GridDataFactory.swtDefaults().span(4, 1).align(SWT.LEFT, SWT.CENTER)
+ .applyTo(separator);
+
+
+ Label uncompressToollabel = new Label(composite, SWT.NONE);
+ uncompressToollabel.setText("Uncompress tool path:");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
+ .applyTo(uncompressToollabel);
+
+ uncompressToolTextField = new Text(composite, SWT.BORDER);
+ uncompressToolTextField.setText(getDefault7zPath());
+ uncompressToolTextField.setToolTipText("Specify the path of tool to uncompress Maemo SDK Virtual Image.");
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(
+ uncompressToolTextField);
+
+ Listener textFieldValidator = new Listener() {
+ public void handleEvent(Event event) {
+ validatePage();
+ }
+ };
+
+ uncompressToolTextField.addListener(SWT.SELECTED, textFieldValidator);
+ uncompressToolTextField.addListener(SWT.KeyDown, textFieldValidator);
+ uncompressToolTextField.addListener(SWT.KeyUp, textFieldValidator);
+
+ Button browserButton = new Button(composite, SWT.PUSH);
+ browserButton.setText("Browse...");
+ GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(
+ browserButton);
+ browserButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent evt) {
+ FileDialog dialog = new FileDialog(DialogUtils.getShell(),
+ SWT.OPEN);
+
+ String currentFile = uncompressToolTextField.getText();
+ if (currentFile.length() > 0) {
+ File current = new File(currentFile);
+ dialog.setFilterPath(current.getParent());
+ dialog.setFileName(current.getName());
+ }
+ dialog.setText("Select the path of uncompress tool");
+ String pathDirectory = dialog.open();
+ if (pathDirectory != null) {
+ uncompressToolTextField.setText(pathDirectory);
+ validatePage();
+ }
+ }
+ });
+
+ validatePage();
+ }
+
+ /**
+ * Validate the wizard page.
+ */
+ public void validatePage() {
+ String errorMessage = null;
+
+ String uncompressToolPath = uncompressToolTextField.getText().trim();
+ if (uncompressToolPath.equals("")){
+ errorMessage = "You must specify the path of tool to uncompress the Maemo SDK Virtual Image.";
+ } else {
+ File file = new File(uncompressToolPath);
+ if (!file.exists() || file.isDirectory()){
+ errorMessage = "Invalid path for uncompress tool. Please, select a valid directory.";
+ } else {
+ ((NewMaemoSDKVMWizard) getWizard()).getInstallData().setUncompressToolPath(uncompressToolPath);
+ }
+ }
+
+ setErrorMessage(errorMessage);
+ setPageComplete(errorMessage == null);
+ }
+
+
+ public static String getDefault7zPath(){
+ String path = "/usr/bin/7z";
+
+ IMachine machine = MachineRegistry.getInstance().getLocalMachine();
+ IPath defaultPath = MachineUtils.findProgramOnPath(machine, "7z");
+
+ if(defaultPath !=null)
+ return defaultPath.toOSString();
+
+ if (machine.getOS().equals(Platform.OS_WIN32))
+ return "C:/Program Files/7-Zip/7z.exe";
+
+ if (machine.getOS().equals(Platform.OS_LINUX)) {
+ return "/usr/bin/7z";
+ }
+ if (machine.getOS().equals(Platform.OS_MACOSX)) {
+ return "/usr/bin/7z";
+ }
+ return path;
+
+ }
+}
Property changes on: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/MaemoSDKVMUncompressInfoWizardPage.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java
===================================================================
--- branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java 2009-09-09 22:29:39 UTC (rev 2136)
+++ branches/2.0.0-prefinal/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/ui/wizards/NewMaemoSDKVMWizard.java 2009-09-09 22:54:44 UTC (rev 2137)
@@ -10,21 +10,22 @@
*******************************************************************************/
package org.maemo.esbox.internal.vm.vmware.ui.wizards;
-import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.maemo.esbox.internal.api.vm.vmware.MaemoSDKVMInstaller;
import org.maemo.esbox.internal.vm.vmware.Activator;
-import org.maemo.mica.common.core.Policy;
-import org.maemo.mica.common.core.ui.IProgressReporter;
+import org.maemo.mica.common.ui.dialogs.DialogUtils;
import org.maemo.mica.internal.api.common.ui.wizards.WizardWorkProgressPageBase;
/**
@@ -40,8 +41,10 @@
private MaemoSDKVMSelectionWizardPage targetPage;
private MaemoSDKVMInstallationWorkPage downloadUncompressWorkPage;
private MaemoSDKVMConfigurationWizardPage configurationPage;
+ private MaemoSDKVMUncompressInfoWizardPage uncompressToolPage;
private MaemoSDKVMLicenseWizardPage licensePage;
private MaemoSDKVMInstallData installData;
+ private int httpTimeout;
/**
* Constructor
@@ -70,6 +73,8 @@
public void addPages() {
targetPage = new MaemoSDKVMSelectionWizardPage(this);
addPage(targetPage);
+ uncompressToolPage = new MaemoSDKVMUncompressInfoWizardPage(this);
+ addPage(uncompressToolPage);
configurationPage = new MaemoSDKVMConfigurationWizardPage(this);
addPage(configurationPage);
licensePage = new MaemoSDKVMLicenseWizardPage(this);
@@ -98,66 +103,56 @@
return downloadUncompressWorkPage;
}
+
+ protected IStatus doWork() {
+
+ final IStatus statuses[] = { Status.CANCEL_STATUS };
+
+ final MaemoSDKVMInstaller installer = new MaemoSDKVMInstaller(
+ installData);
+
+ try {
+ statuses[0] = installer.installVirtualImage(
+ httpTimeout,
+ null,
+ new NullProgressMonitor());
+
+ return statuses[0];
+ } catch (Exception e) {
+ return Activator.createErrorStatus("Unexpected exception running installer", e);
+ }
+ }
+
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
public boolean performFinish() {
- final IStatus status = doWork();
+ httpTimeout = ((MaemoSDKVMInstallationWorkPage)getWorkPage()).getTimeout();
+
+ // invoke the work after the wizard has gone away
+ getContainer().getShell().addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ final IStatus status = doWork();
- final boolean success = (status.isOK() || status.matches(IStatus.INFO));
+ final boolean success = (status.isOK() || status.matches(IStatus.INFO));
+
+ if (success)
+ DialogUtils.showMessageDialog(null, "Installation Complete", "All the steps of the VM installation are complete.");
+ else
+ Activator.getErrorLogger().logAndShowError("Installation did not complete successfully.\n \nIf the virtual machine was downloaded and configured, you can finish the installation manually with wizards under 'File > New > Other > Maemo Installers'.",
+ new CoreException(status));
+ }
+ });
+ }
+ });
- String message = success ? "Installation succeeded"
- : "Installation encountered some errors";
-
- boolean goOn = getWorkPage().reportOperationStatus(
- "Maemo SDK Virtual Image installation results", message,
- status, true)
- && !status.matches(IStatus.CANCEL);
-
- return goOn;
+ return true;
}
- protected IStatus doWork() {
-
- getWorkPage().showAndClearLog();
-
- final IStatus[] statuses = { Policy.getCancelStatus(Activator
- .getDefault()) };
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
-
- IStatus status = null;
-
- IProgressReporter reporter = getWorkPage().getProgressReporter();
-
- MaemoSDKVMInstaller vmInstaller = new MaemoSDKVMInstaller(installData, reporter);
-
- status = vmInstaller.installVirtualImage(((MaemoSDKVMInstallationWorkPage)getWorkPage()).getTimeout(), getShell(), monitor);
-
- if (status.matches(IStatus.CANCEL))
- status = Activator.createErrorStatus("The Maemo SDK virtual image installation was canceled.", null);
-
- if (status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR))
- reporter.appendStreamText(status.getMessage(), true);
-
- statuses[0] = status;
- }
-
- });
- } catch (Exception e) {
- Activator.getErrorLogger().logAndShowError(e.getMessage(),
- e.getCause());
- statuses[0] = Activator.createErrorStatus("Maemo SDK virtual image installation failed unexpectedly",
- e);
- }
- return statuses[0];
- }
-
/**
* Get the installation data that contains information to install Maemo SDK
* virtual image.
More information about the Esbox-commits
mailing list