[Esbox-commits] r1565 - in trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard: . nokiabin
fabricioepa at garage.maemo.org
fabricioepa at garage.maemo.org
Sat May 9 02:13:41 EEST 2009
Author: fabricioepa
Date: 2009-05-09 02:13:40 +0300 (Sat, 09 May 2009)
New Revision: 1565
Modified:
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerData.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerEngine.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerSelectionWizardPage.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/NokiaBinariesInstallWizard.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/SDKTargetSelectionPage.java
Log:
Fixing BUG #4003 and #4054
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java 2009-05-08 21:38:21 UTC (rev 1564)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/NewScratchbox1TargetWizard.java 2009-05-08 23:13:40 UTC (rev 1565)
@@ -161,6 +161,7 @@
public void run() {
//get installed targets
Scratchbox1TargetInstallerData data = targetPage.getTargetInstallerData();
+ data.getScratchbox1SDK().refresh();
ISDKTarget[] targets = data.getScratchbox1SDK().getSDKTargets();
List<ISDKTarget> installed = new ArrayList<ISDKTarget>();
for(ISDKTarget t: targets){
@@ -169,7 +170,7 @@
installed.add(t);
}
//call wizard with targets pre selected
- NokiaBinariesInstallWizard.startWizard(installed.toArray(new ISDKTarget[2]));
+ NokiaBinariesInstallWizard.startWizard(installed.toArray(new ISDKTarget[installed.size()]));
}
});
}
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerData.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerData.java 2009-05-08 21:38:21 UTC (rev 1564)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerData.java 2009-05-08 23:13:40 UTC (rev 1565)
@@ -7,6 +7,7 @@
*
* Contributors:
* Ed Swartz (Nokia) - initial API and implementation
+ * Fabrício S Epaminondas (UFCG)
*******************************************************************************/
package org.maemo.esbox.internal.scratchbox.sb1.ui.wizard;
@@ -36,6 +37,9 @@
private String qemu;
private IScratchbox1SDK sdk;
private boolean forceRemove;
+ private boolean installRequiredDevkits = false;
+ private boolean installRequiredCompilers = false;
+ private boolean useCache;
/**
*
@@ -208,6 +212,48 @@
}
/**
+ * @return the installRequiredDevkits
+ */
+ public boolean isInstallRequiredDevkits() {
+ return installRequiredDevkits;
+ }
+
+ /**
+ * @param installRequiredDevkits the installRequiredDevkits to set
+ */
+ public void setInstallRequiredDevkits(boolean installRequiredDevkits) {
+ this.installRequiredDevkits = installRequiredDevkits;
+ }
+
+ /**
+ * @return the installRequiredCompilers
+ */
+ public boolean isInstallRequiredCompilers() {
+ return installRequiredCompilers;
+ }
+
+ /**
+ * @param installRequiredCompilers the installRequiredCompilers to set
+ */
+ public void setInstallRequiredCompilers(boolean installRequiredCompilers) {
+ this.installRequiredCompilers = installRequiredCompilers;
+ }
+
+ /**
+ * @return the useCache
+ */
+ public boolean isUseCache() {
+ return useCache;
+ }
+
+ /**
+ * @param useCache the useCache to set
+ */
+ public void setUseCache(boolean useCache) {
+ this.useCache = useCache;
+ }
+
+ /**
* Get the name of the X86 target, given the default basename
*/
public String getX86TargetName() {
@@ -251,6 +297,9 @@
cmdLine.add("-y");
}
+ if(isUseCache()){
+ cmdLine.add("-c");
+ }
return cmdLine;
}
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerEngine.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerEngine.java 2009-05-08 21:38:21 UTC (rev 1564)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerEngine.java 2009-05-08 23:13:40 UTC (rev 1565)
@@ -11,9 +11,13 @@
package org.maemo.esbox.internal.scratchbox.sb1.ui.wizard;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.regex.Pattern;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -23,6 +27,7 @@
import org.eclipse.swt.widgets.Shell;
import org.maemo.esbox.internal.scratchbox.sb1.Activator;
import org.maemo.esbox.internal.scratchbox.sb1.core.Scratchbox1SDK;
+import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDK;
import org.maemo.mica.common.core.IProgressReporter;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
@@ -32,6 +37,10 @@
import org.maemo.mica.common.core.process.ProcessLauncherCreator;
import org.maemo.mica.common.core.process.ProcessLauncherUtils;
import org.maemo.mica.common.core.sdk.SDKFactory;
+import org.maemo.mica.linux.packages.core.IPackageManager;
+import org.maemo.mica.linux.packages.core.ISystemPackage;
+import org.maemo.mica.linux.packages.core.PackageManagerProvider;
+import org.maemo.mica.linux.packages.ui.MachinePackageInstaller;
/**
* This engine runs the SDK installer script in non-interactive mode,
@@ -103,6 +112,11 @@
IStatus status;
monitor.beginTask("", IProgressMonitor.UNKNOWN);
+ checkRequiredDevkitsAndCompilers(multiStatus, new SubProgressMonitor(monitor, 1));
+
+ if (!multiStatus.isOK())
+ return multiStatus;
+
reporter.logInfo("Installing " + installerData.getName());
IPath installScript = fetchInstallScript(multiStatus, monitor, installerData.getInstallerURL());
@@ -176,6 +190,171 @@
return multiStatus;
}
+ /**
+ * Check if required devkits and compilers are installed. If not, it tries to install.
+ * @param multiStatus
+ * @param monitor
+ */
+ private void checkRequiredDevkitsAndCompilers(MultiStatus multiStatus, IProgressMonitor monitor) {
+ IStatus status;
+ if(!installerData.isInstallRequiredCompilers() || !installerData.isInstallRequiredDevkits())
+ return;
+
+ monitor.beginTask("", 3);
+ monitor.subTask("Looking for required scratchbox compilers and devkits...");
+ reporter.logInfo("Looking for required scratchbox compilers and devkits");
+
+ IScratchbox1SDK sdk = installerData.getScratchbox1SDK();
+
+ List<String> missingDevkits = new ArrayList<String>(Arrays.asList(installerData.getRequiredDevkits()));
+ List<String> missingCompilers = new ArrayList<String>(Arrays.asList(installerData.getRequiredCompilers()));
+ try {
+ missingDevkits.removeAll(sdk.getDevkits());
+ missingCompilers.removeAll(sdk.getCompilers());
+ } catch (MicaException e) {
+ status = Activator.createErrorStatus(
+ "The Scratchbox 1 installation at " + sdk
+ + " has problems; please fix or reinstall it:\n"
+ + e.getMessage(), e);
+ reporter.log(status);
+ multiStatus.add(status);
+ return;
+ }
+
+
+ monitor.worked(1);
+
+ IPackageManager manager = PackageManagerProvider.getInstance().getPackageManagerFor(
+ machine);
+
+ if (manager == null){
+ status = Activator.createStatus(IStatus.ERROR,
+ "Could not found package manager.");
+ reporter.log(status);
+ multiStatus.add(status);
+ return;
+ }
+
+ ISystemPackage[] sboxPackages = null;
+ try {
+ sboxPackages = manager.searchSystemPackages(
+ Pattern.compile("scratchbox-(core|libs|devkit-.*|toolchain-.*)"),
+ new SubProgressMonitor(monitor, 1));
+
+ if (sboxPackages.length == 0) {
+ reporter.logInfo("No Scratchbox 1 packages detected.");
+ status = Activator.createStatus(IStatus.ERROR, "No Scratchbox 1 packages detected.");
+ reporter.log(status);
+ multiStatus.add(status);
+ return;
+ }
+ } catch (MicaException e) {
+ status = Activator.createErrorStatus("Failed to scan Scratchbox compilers and devkits", e);
+ reporter.log(status);
+ multiStatus.add(status);
+ return;
+ }
+
+
+ try {
+ if(installerData.isInstallRequiredDevkits()){
+ reporter.logInfo("Checking required devkits for " + installerData.getName());
+ List<ISystemPackage> toInstall = new ArrayList<ISystemPackage>();
+ List<String> uninstallable = new ArrayList<String>();
+ for(String devkit : missingDevkits){
+ boolean unknown = true;//unknown package?
+ String name = inferPkgNameFromDevkit(devkit);
+ for(ISystemPackage pkg : sboxPackages){
+ if(pkg.getName().matches(name)){
+ unknown = false;
+ toInstall.add(pkg);
+ }
+ }
+ if(unknown)
+ uninstallable.add(devkit);
+ }
+
+
+ if (uninstallable.size() > 0) {
+ status = Activator.createStatus(IStatus.ERROR,
+ "Could not find required packages for devkits: " + uninstallable
+ + " you should add the repository to sources list before use this installer, or manually install them.");
+ reporter.log(status);
+ multiStatus.add(status);
+ return;
+ }
+
+ MachinePackageInstaller.installPackages(toInstall, shell, reporter, monitor);
+ }
+
+ monitor.worked(2);
+
+ if(installerData.isInstallRequiredCompilers()){
+ reporter.logInfo("Checking required compilers for " + installerData.getName());
+ List<ISystemPackage> toInstall = new ArrayList<ISystemPackage>();
+ List<String> uninstallable = new ArrayList<String>();
+ for(String compiler : missingCompilers){
+ boolean unknown = true;//unknown package?
+ String name = inferPkgNameFromCompiler(compiler);
+ for(ISystemPackage pkg : sboxPackages){
+ if(pkg.getName().matches(name)){
+ unknown = false;
+ toInstall.add(pkg);
+ }
+ }
+ if(unknown)
+ uninstallable.add(compiler);
+ }
+
+
+ if (uninstallable.size() > 0) {
+ status = Activator.createStatus(IStatus.ERROR,
+ "Could not find required packages for compilers: " + uninstallable
+ + " you should add the repository to sources list before use this installer, or manually install them.");
+ reporter.log(status);
+ multiStatus.add(status);
+ return;
+ }
+
+ MachinePackageInstaller.installPackages(toInstall, shell, reporter, monitor);
+ }
+ monitor.worked(3);
+
+ } catch (CoreException e) {
+ multiStatus.add(e.getStatus());
+ }
+ }
+
+ /**
+ * It can infer the packages names from devkit name
+ * @param devkit
+ * @return
+ */
+ private String inferPkgNameFromDevkit(String devkit) {
+ String prefix = "scratchbox-devkit-";
+ //XXX HACK: to infer package names from devkit name
+ if(devkit.matches("debian-*")){
+ return prefix + "debian";
+ }
+
+ if(devkit.matches("maemo3-tools")){
+ return prefix + "maemo3";
+ }
+
+ return prefix + devkit;
+ }
+
+ /**
+ * It can infer the packages names from compiler name
+ * @param devkit
+ * @return
+ */
+ private String inferPkgNameFromCompiler(String compiler) {
+ //XXX HACK: to infer package names from compiler name
+ String prefix = "scratchbox-toolchain-";
+ return prefix + compiler;
+ }
+
@Override
protected String doRewriteInstallScript(String text) {
text = super.doRewriteInstallScript(text);
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerSelectionWizardPage.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerSelectionWizardPage.java 2009-05-08 21:38:21 UTC (rev 1564)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/Scratchbox1TargetInstallerSelectionWizardPage.java 2009-05-08 23:13:40 UTC (rev 1565)
@@ -500,6 +500,9 @@
private boolean validateScratchbox(IProgressMonitor monitor, IScratchbox1SDK sdk) {
monitor.beginTask("Validating Scratchbox installation", IProgressMonitor.UNKNOWN);
+ targetInstallerData.setInstallRequiredCompilers(false);
+ targetInstallerData.setInstallRequiredDevkits(false);
+
StringBuilder errors = new StringBuilder();
try {
List<String> devkits = sdk.getDevkits();
@@ -513,7 +516,8 @@
}
}
if (!matched) {
- errors.append("no devkit '" + reqdDevkit + "'; ");
+ errors.append(" devkit '" + reqdDevkit + "'; ");
+ targetInstallerData.setInstallRequiredDevkits(true);
}
}
@@ -526,13 +530,14 @@
}
}
if (!matched) {
- errors.append("no compiler '" + reqdToolchain + "'; ");
+ errors.append(" compiler '" + reqdToolchain + "'; ");
+ targetInstallerData.setInstallRequiredCompilers(true);
}
}
if (errors.length() != 0) {
- setErrorMessage("This Scratchbox 1 installation is not suitable: " + errors + "please upgrade it or install a new one.");
- return false;
+ setMessage("This Scratchbox 1 installation is not suitable, it will require to install support to: " + errors + " ", WARNING);
+ return true;
}
// check existing targets
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/NokiaBinariesInstallWizard.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/NokiaBinariesInstallWizard.java 2009-05-08 21:38:21 UTC (rev 1564)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/NokiaBinariesInstallWizard.java 2009-05-08 23:13:40 UTC (rev 1565)
@@ -113,7 +113,6 @@
addPage(new BadInstallationPage());
return;
}
-
addPage(targetPage);
}
@@ -194,11 +193,11 @@
// action has been disposed
return;
}
-
+
NokiaBinariesInstallWizard wizard = new NokiaBinariesInstallWizard();
- wizard.setDefaultTargets(defaultTargets);
wizard.init(activeWorkbenchWindow.getWorkbench(),
StructuredSelection.EMPTY);
+ wizard.setDefaultTargets(defaultTargets);
Shell parent = activeWorkbenchWindow.getShell();
WizardDialog dialog = new WizardDialog(parent, wizard);
dialog.create();
@@ -207,4 +206,5 @@
SIZING_WIZARD_HEIGHT);
dialog.open();
}
+
}
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/SDKTargetSelectionPage.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/SDKTargetSelectionPage.java 2009-05-08 21:38:21 UTC (rev 1564)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/ui/wizard/nokiabin/SDKTargetSelectionPage.java 2009-05-08 23:13:40 UTC (rev 1565)
@@ -11,12 +11,16 @@
*******************************************************************************/
package org.maemo.esbox.internal.scratchbox.sb1.ui.wizard.nokiabin;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
@@ -34,8 +38,10 @@
import org.eclipse.swt.widgets.Label;
import org.maemo.esbox.internal.scratchbox.sb1.Activator;
import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDK;
+import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDKTarget;
import org.maemo.mica.common.core.sdk.ISDK;
import org.maemo.mica.common.core.sdk.ISDKTarget;
+import org.maemo.mica.common.core.sdk.SDKFactory;
import org.maemo.mica.common.project.core.IBuildTargetFilter;
import org.maemo.mica.common.ui.BuildTargetUI;
@@ -101,17 +107,13 @@
GridDataFactory.fillDefaults().grab(true, true).applyTo(container);
setControl(container);
-
Label comboLb = new Label(container, SWT.NONE);
comboLb.setText("Select Platform:");
GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(comboLb);
-
fmaemoSDKCombo = new Combo(container, SWT.READ_ONLY | SWT.DROP_DOWN);
fmaemoSDKCombo.setItems(SDK_NAMES);
-
-
fmaemoSDKCombo.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
updateUI();
@@ -130,6 +132,7 @@
clabel.setText(label);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2,1).applyTo(clabel);
+ detectTargetsPlatform();
targetTree = BuildTargetUI.createConfiguredBuildTargetCheckboxViewer(
container, BuildTargetUI.DEFAULT_STYLE, targetFilter);
@@ -152,10 +155,28 @@
}
});
-
targetTree.setInput(new Object());
+ }
-
+ private void detectTargetsPlatform() {
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
+ try {
+ dialog.run(true, false, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException,
+ InterruptedException {
+ monitor.beginTask("Establishing platforms of sdk targets", 2);
+ for (ISDKTarget t : SDKFactory.getInstance().getAllSDKTargets()) {
+ if(IScratchbox1SDKTarget.class.isAssignableFrom(t.getClass()))
+ SDKFactory.getInstance().establishPlatform(t,monitor);
+ }
+ }
+
+ });
+ } catch (Exception e) {
+ Activator.getErrorLogger().logAndShowError(
+ "Failed to establish platforms of sdk targets", e);
+ }
}
@@ -165,20 +186,35 @@
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
-
+
selectDefaults();
}
private void selectDefaults() {
- //Select default platform
- ISDKTarget[] targets = getDefaultTargets();
+
+ //Select default platform
+ //FIXME: Main contains a target that references an unknown platform
+ ISDKTarget[] defaults = getDefaultTargets();
+
+ if(defaults ==null)
+ return;
+
+ //HACK: Get refreshed targets with detected platform
+ for(int i = 0; i < defaults.length; i++){
+ ISDKTarget t = defaults[i];
+ for(ISDKTarget refreshed : SDKFactory.getInstance().getAllSDKTargets()){
+ if(t != null && t.compareTo(refreshed) == 0)
+ defaults[i] = refreshed;
+ }
+ }
+
ISDKTarget target = null;
- if(targets !=null && targets.length != 0 && (target = targets[0]) !=null){
+ if(defaults.length != 0 && (target = defaults[0]) !=null){
int index = Arrays.asList(SDK_NAMES).indexOf(target.getPlatform().getName().toUpperCase());
if(index != -1){
fmaemoSDKCombo.select(index);
updateUI();
targetTree.expandToLevel(target, TreeViewer.ALL_LEVELS);
- targetTree.setCheckedElements(targets);
+ targetTree.setCheckedElements(defaults);
}
setPageComplete(validatePage());
}
More information about the Esbox-commits
mailing list