[Esbox-commits] r1036 - in branches/work_Petr: org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk
baranov at garage.maemo.org
baranov at garage.maemo.org
Thu Dec 4 16:04:16 EET 2008
Author: baranov
Date: 2008-12-04 16:04:16 +0200 (Thu, 04 Dec 2008)
New Revision: 1036
Added:
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java
Modified:
branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java
branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java
branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/MaemoRootstrap.java
Log:
reverting sb2 install target property page
Modified: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -29,7 +29,7 @@
maemoRootstrapCommand.remove(TARGET_DOESNT_EXIST);
fail("Invalid number of param");
} catch (MicaException e) {
- // TODO: handle exception
+
}
param.add(TARGET_DOESNT_EXIST);
@@ -55,6 +55,7 @@
List<String> targets = new ArrayList<String>();
try {
+ CacheUtils.getInstance().clearCachedData();
targets = sb2Sdk.getTargets();
} catch (MicaException e) {
// again, ignore error
Modified: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -16,6 +16,7 @@
import org.maemo.esbox.internal.api.scratchbox.core.sdk.IScratchboxSDKPlatformArchitectureProvider;
import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
+import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
import org.maemo.mica.common.core.sdk.ISDKPlatform;
public class TestScratchbox2SDK extends BaseSb2Test {
@@ -47,7 +48,7 @@
}
public void testAvailableMaemoRootstraps() throws Exception {
- List<String> rootstraps = sb2Sdk.getAvailableMaemoRootstraps(null);
+ List<MaemoRootstrap> rootstraps = sb2Sdk.getAvailableMaemoRootstraps(sb2Sdk.getMachine());
assertTrue("Available rootstrap list is not same as predefined possible rootstraps list.",
rootstraps.containsAll(possibleRootstraps) && rootstraps.size()==possibleRootstraps.size());
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -1,4 +1,4 @@
- /*******************************************************************************
+/*******************************************************************************
* Copyright (c) 2008 Nokia Corporation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,35 +10,21 @@
*******************************************************************************/
package org.maemo.esbox.internal.scratchbox.sb2.command;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-import java.security.InvalidParameterException;
-import java.util.Arrays;
-import java.util.List;
-
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.ui.console.MessageConsole;
import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.internal.scratchbox.sb2.Activator;
import org.maemo.esbox.scratchbox.core.command.AbstractSDKCommand;
-import org.maemo.mica.common.core.CoreConsoleManager;
import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.Policy;
-import org.maemo.mica.common.core.process.IProcessLauncher;
-import org.maemo.mica.common.core.process.IProcessLauncherFactory;
-import org.maemo.mica.common.core.process.ProcessLauncherUtils;
+import org.maemo.mica.common.core.process.*;
import org.maemo.mica.common.core.process.ProcessLauncherUtils.Results;
import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+import java.security.InvalidParameterException;
+import java.util.Arrays;
+import java.util.List;
+
public abstract class AbstractSb2Command extends AbstractSDKCommand {
+
private final IProcessLauncherFactory processLauncherFactory;
- private static final String lineSeparator = System.getProperty("line.separator");
public AbstractSb2Command(ICommandAbstractor commandAbstractor, IProcessLauncherFactory launcherFactory) {
super(commandAbstractor);
@@ -65,7 +51,16 @@
return replaceScratchboxCommand(sboxCommand, action, options);
}
-
+ protected Results runProcess(String...args) throws MicaException{
+ return runProcess(this.processLauncherFactory,args);
+ }
+
+ protected Results runProcess( IProgressMonitor monitor,String...args) throws MicaException{
+ List<String> cli = Arrays.asList(args);
+ IProcessLauncher launcher = processLauncherFactory.createProcessLauncher(null, cli,null);
+ return ProcessLauncherUtils.launchAndReadStandardStreams(launcher, monitor);
+ }
+
/**
* run process in host environment
* @param processLauncherFactory
@@ -77,114 +72,4 @@
return ProcessLauncherUtils.launchAndReadStandardStreams(processLauncherFactory, Arrays.asList(args));
}
- protected Results runProcess(String...args) throws MicaException{
- Results results = runProcess(this.processLauncherFactory,args);
- return results;
- }
-
- protected Results runProcess( IProgressMonitor monitor,String...args) throws MicaException{
- final List<String> cli = Arrays.asList(args);
- final String cliStr = toCli(args);
-
- final IProcessLauncher launcher = processLauncherFactory.createProcessLauncher(null, cli,null);
- final MessageConsole console = getConsole();
- final Process process = launcher.createProcess();
-
- Job job = createJob(monitor, cliStr, process);
-
- String inputStr = toString(process.getInputStream());
- String errStr = toString(process.getErrorStream());
- int exitCode = process.exitValue();
-
- printToConsole(cliStr, console, inputStr, errStr);
- if(job.getResult()!=null&&job.getResult().getSeverity()==IStatus.OK){
- return new Results(exitCode,inputStr,errStr);
- }
- return null;
- }
-
- //--private
- private Job createJob(IProgressMonitor monitor, final String cliStr,
- final Process process) {
- Job job = new Job(cliStr){
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(cliStr, 100);
- monitor.subTask(cliStr);
- try{
- try{
- process.waitFor();
- monitor.worked(100);
- }catch(InterruptedException e){
- return Status.CANCEL_STATUS;
- }
- }finally{
- monitor.done();
- }
- return Status.OK_STATUS;
- }
-
- @Override
- protected void canceling() {
- super.canceling();
-
- }
-
- };
- job.schedule();
- try{
- while(job.getResult()==null){
- Thread.sleep(500);
- if(monitor.isCanceled()){
- process.destroy();
- job.cancel();
- }
- }
- }catch (InterruptedException e){
- // write to console
- }
- return job;
- }
-
- private void printToConsole(final String cliStr,
- final MessageConsole console, String inputStr, String errStr) {
- PrintStream stream = new PrintStream(console.newMessageStream());
- stream.println("running:"+cliStr);
- stream.println(inputStr);
- if(errStr.length()!=0){
- stream.println("Errors:");
- stream.println(errStr);
- }
- }
-
- private String toCli(String[] args) {
- String result = "";
- for (int i = 0; i < args.length; i++) {
- result += " "+args[i];
- }
- return result;
- }
-
- private String toString(InputStream stream) {
- BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
- String result="";
- String line=null;
- try{
- while ((line = reader.readLine()) != null) {
- result += line+lineSeparator;
- }
- }catch(IOException e){
- Activator.getErrorLogger().log(IStatus.WARNING, "Problem while reading result", e);
- }
- return result;
- }
-
- private MessageConsole getConsole() {
- if(console==null){
- console=CoreConsoleManager.getInstance().getConsole(true, null, "SB2 command console");
- }
- return console;
- }
-
-
}
Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java (from rev 1035, trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java)
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Ed Swartz (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
+import org.maemo.mica.common.core.CoreConsoleManager;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils;
+import org.maemo.mica.common.core.sdk.ISDK;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Creates a new rootstrap for a target, if it does not exist. This command
+ * wraps the callback to service:
+ * <p>
+ * maemo-rootstrap [--force] install <target>
+ *
+ */
+public class CreateMaemoRootstrapSb2Command extends MaemoRootstrapSb2Command {
+
+ private ISDK sdk;
+ private IProgressMonitor monitor;
+
+ public CreateMaemoRootstrapSb2Command(ISDK sdk,
+ ICommandAbstractor commandAbstractor, IProgressMonitor monitor) {
+ super(commandAbstractor);
+ this.sdk = sdk;
+ this.monitor = monitor;
+ }
+
+ protected boolean checkParameters(List<String> param) {
+ return param.size() == 3;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
+ * .lang.Object)
+ */
+ public Boolean performCommand(List<String> param)
+ throws ScratchboxException, MicaException {
+ if (!this.checkParameters(param))
+ throw new ScratchboxInvalidParameterException(
+ "Invalid number of parameters");
+
+ String targetName = param.get(0);
+ String useHostToolsFlag = param.get(1);
+ String forceFlag = param.get(2);
+
+ List<String> params = new ArrayList<String>();
+ if (forceFlag.equals(Boolean.TRUE.toString())) {
+ params
+ .add(commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_FORCE_OPT));
+ }
+ params
+ .add(commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_INSTALL_ACT));
+ params.add(targetName);
+
+ IEnvironmentModifierBlock envBlock = commandAbstractor
+ .getProcessLauncherFactory().defaultEnvironmentModifierBlock();
+ ProcessLauncherUtils.defineProxyVariables(envBlock);
+
+ setMonitorAndConsole(monitor, CoreConsoleManager.getInstance().getConsole(true,
+ null, "Installing rootstrap " + targetName));
+ doPerformCommand(params, envBlock, 0);
+
+ sdk.refresh();
+
+ return true;
+ }
+
+ public int getParametersSize() {
+ return 1;
+ }
+
+}
Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java (from rev 1035, trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java)
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Ed Swartz (Nokia) - initial API and implementation
+ * Petr Baranov (Nokia)
+ *******************************************************************************/
+
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
+import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author eswartz
+ *
+ */
+public class GetMaemoRootstrapLocationCommand extends MaemoRootstrapSb2Command {
+
+ private IScratchboxSDKTarget sdkTarget;
+
+ public GetMaemoRootstrapLocationCommand(
+ ICommandAbstractor commandAbstractor, IScratchboxSDKTarget sdkTarget) {
+ super(commandAbstractor);
+ this.sdkTarget = sdkTarget;
+ }
+
+ @Override
+ public int getParametersSize() {
+ return 0;
+ }
+
+ @Override
+ protected boolean checkParameters(List<String> param) {
+ return param.size() == 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.maemo.mica.internal.common.core.command.ICommand#performCommand(java.util
+ * .List)
+ */
+ public Object performCommand(List<String> params)
+ throws ScratchboxException, MicaException {
+ if (!this.checkParameters(params))
+ throw new ScratchboxInvalidParameterException(
+ "Invalid number of parameters");
+
+ List<String> rsCommands = new ArrayList<String>(2);
+
+ String pathAction = commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_PATH_ACT);
+
+ rsCommands.add(pathAction);
+ rsCommands.add(sdkTarget.getName());
+
+ List<String> results = doPerformCommand(rsCommands, null, 0);
+ if (results.size() == 0)
+ throw new ScratchboxException(
+ "Could not detect rootstrap location for " + sdkTarget
+ + "\ngot:\n" + catenateLines(results));
+
+ // ignore bogus report of deleted rootstrap
+ IPath root = new Path(results.get(0).trim());
+ IFileStore store = sdkTarget.getMachineFileSystemAccess().getFileStore(
+ root);
+ if (store.fetchInfo().exists())
+ return root;
+ else
+ throw new ScratchboxException("Rootstrap location for " + sdkTarget
+ + " does not exist: " + store);
+ }
+
+}
Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java (from rev 1035, trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java)
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Ed Swartz (Nokia) - initial API and implementation
+ * Petr Baranov (Nokia)
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.internal.scratchbox.sb2.core.Scratchbox2SDK;
+import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
+import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.*;
+import java.util.regex.Matcher;
+
+/**
+ * List the maemo rootstraps available for installation.
+ */
+public class ListAvailableMaemoRootstrapsSb2Command extends
+ MaemoRootstrapSb2Command {
+
+ private static final int LIST_TIMEOUT = 10000;
+
+ public ListAvailableMaemoRootstrapsSb2Command(
+ ICommandAbstractor commandAbstractor) {
+ super(commandAbstractor);
+ }
+
+ @Override
+ protected boolean checkParameters(List<String> param) {
+ return param.size() == 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
+ * .lang.Object)
+ */
+ public List<MaemoRootstrap> performCommand(List<String> param)
+ throws ScratchboxException, MicaException {
+ if (!this.checkParameters(param))
+ throw new ScratchboxInvalidParameterException(
+ "Invalid number of parameters");
+
+ String availableAction = commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_AVAILABLE_ACT);
+
+ // ensure the proxy is established
+ IEnvironmentModifierBlock proxyEnvBlock = commandAbstractor
+ .getProcessLauncherFactory().defaultEnvironmentModifierBlock();
+ ProcessLauncherUtils.defineProxyVariables(proxyEnvBlock);
+
+ List<String> available = doPerformCommand(Collections
+ .singletonList(availableAction), proxyEnvBlock, LIST_TIMEOUT);
+
+ // this output has a few header lines
+ List<MaemoRootstrap> targetsAvailable = new ArrayList<MaemoRootstrap>();
+
+ for (String line : available) {
+ Matcher matcher = Scratchbox2SDK.TARGET_PLATFORM_VERSION_ARCHITECTURE_PATTERN.matcher(line);
+ if(!matcher.matches()){
+ continue;
+ }
+ if (line.trim().length() == 0) {
+ continue;
+ }
+
+ String[] tokens = line.split("_");
+ if (tokens.length == 2) {
+ targetsAvailable.add(new MaemoRootstrap(tokens[0], tokens[1],
+ ""));
+ }
+
+ }
+ return targetsAvailable;
+ }
+
+ @Override
+ public int getParametersSize() {
+ return 0;
+ }
+
+}
Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java (from rev 1035, trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java)
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Ed Swartz (Nokia) - initial API and implementation
+ * Petr Baranov (Nokia)
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * List the maemo rootstraps installed
+ */
+public class ListInstalledMaemoRootstrapsSb2Command extends
+ MaemoRootstrapSb2Command {
+
+ public ListInstalledMaemoRootstrapsSb2Command(
+ ICommandAbstractor commandAbstractor) {
+ super(commandAbstractor);
+ }
+
+ @Override
+ protected boolean checkParameters(List<String> param) {
+ return param.size() == 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
+ * .lang.Object)
+ */
+ public List<String> performCommand(List<String> param)
+ throws ScratchboxException, MicaException {
+ if (!this.checkParameters(param))
+ throw new ScratchboxInvalidParameterException(
+ "Invalid number of parameters");
+
+ String availableAction = commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_LIST_ACT);
+
+ List<String> installed = doPerformCommand(Collections
+ .singletonList(availableAction), null, 0);
+
+ return installed;
+ }
+
+ @Override
+ public int getParametersSize() {
+ return 0;
+ }
+
+}
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -94,7 +94,9 @@
* @throws MicaException
*/
public void remove(String name) throws MicaException{
- runProcess(MAEMO_ROOTSTRAP,OPTION_FORCE,COMMAND_REMOVE,name);
+ Results results = runProcess(MAEMO_ROOTSTRAP,OPTION_FORCE,COMMAND_REMOVE,name);
+ if(results.exitCode!=0)
+ throw new MicaException(results.stdout);
}
/**
Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java (from rev 1035, trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java)
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Ed Swartz (Nokia) - initial API and implementation
+ * Petr Baranov (Nokia)
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
+import org.maemo.mica.common.core.process.CommandLineArguments;
+import org.maemo.mica.common.core.process.ShellTemplateSubstitutor;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Base class for maemo rootstrap command.
+ */
+public abstract class MaemoRootstrapSb2Command extends AbstractSb2Command {
+
+ public MaemoRootstrapSb2Command(ICommandAbstractor commandAbstractor) {
+ super(commandAbstractor);
+ }
+
+ @Override
+ protected boolean checkParameters(List<String> param) {
+ return true;
+ }
+
+ /**
+ * Override if stderr output is allowed.
+ *
+ * @return false
+ */
+ protected boolean allowErrors() {
+ return false;
+
+ }
+
+ /**
+ * Perform the command with the given params as command line arguments, with
+ * an optional timeout (triggering ScratchboxException if reached)
+ *
+ * @param params
+ * command line parameters to maemo-rootstrap
+ * @param envBlock
+ * any environment needed or <code>null</code>
+ * @param timeout
+ * if not 0, timeout in milliseconds
+ * @return lines from stdout
+ * @throws ScratchboxException
+ * if command execution fails or if timeout reached
+ */
+ @SuppressWarnings("unchecked")
+ protected List<String> doPerformCommand(List<String> params,
+ IEnvironmentModifierBlock envBlock, long timeout)
+ throws MicaException {
+ String rootstrapCommand = commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_COMMAND);
+
+ String options = CommandLineArguments.toCommandLine(params);
+
+ ShellTemplateSubstitutor substitutor = new ShellTemplateSubstitutor();
+ substitutor.define("OPTIONS", options);
+
+ rootstrapCommand = substitutor.substitute(rootstrapCommand);
+
+ if (console == null) {
+ Process process = createProcess(rootstrapCommand, envBlock);
+ List<String> results = getLineInputFromProcessAndWait(process,
+ allowErrors(), timeout);
+ return results;
+ } else {
+ runAndWaitForProcess("Running " + rootstrapCommand,
+ rootstrapCommand, envBlock, timeout);
+ return Collections.EMPTY_LIST;
+ }
+ }
+
+ @Override
+ public int getParametersSize() {
+ return 0;
+ }
+
+}
Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java (from rev 1035, trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java)
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Ed Swartz (Nokia) - initial API and implementation
+ * Petr Baranov (Nokia)
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
+import org.maemo.mica.common.core.CoreConsoleManager;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Remove a maemo rootstrap. Parameters are target name and force boolean flag.
+ */
+public class RemoveMaemoRootstrapSb2Command extends MaemoRootstrapSb2Command {
+
+ private final IProgressMonitor monitor;
+
+ public RemoveMaemoRootstrapSb2Command(ICommandAbstractor commandAbstractor,
+ IProgressMonitor monitor) {
+ super(commandAbstractor);
+ this.monitor = monitor;
+ }
+
+ @Override
+ protected boolean checkParameters(List<String> param) {
+ return param.size() == 2;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
+ * .lang.Object)
+ */
+ public Boolean performCommand(List<String> param)
+ throws ScratchboxException, MicaException {
+ if (!this.checkParameters(param))
+ throw new ScratchboxInvalidParameterException(
+ "Invalid number of parameters");
+
+ String targetName = param.get(0);
+ String forceFlag = param.get(1);
+
+ String action = commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_REMOVE_ACT);
+
+ List<String> commands = new ArrayList<String>();
+
+ if (forceFlag.equals(Boolean.TRUE.toString())) {
+ String force = commandAbstractor
+ .getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_FORCE_OPT);
+ commands.add(force);
+ }
+ commands.add(action);
+ commands.add(targetName);
+
+ IEnvironmentModifierBlock envBlock = commandAbstractor
+ .getProcessLauncherFactory().defaultEnvironmentModifierBlock();
+ ProcessLauncherUtils.defineProxyVariables(envBlock);
+
+ setMonitorAndConsole(monitor, CoreConsoleManager.getInstance().getConsole(true,
+ null, "Removing rootstrap " + targetName));
+
+ doPerformCommand(commands, envBlock, 0);
+
+ return Boolean.TRUE;
+ }
+
+ @Override
+ public int getParametersSize() {
+ return 0;
+ }
+
+}
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -20,13 +20,17 @@
import org.maemo.esbox.internal.api.scratchbox.core.sdk.AbstractScratchboxSDK;
import org.maemo.esbox.internal.api.scratchbox.core.sdk.CacheUtils;
import org.maemo.esbox.internal.scratchbox.sb2.Activator;
+import org.maemo.esbox.internal.scratchbox.sb2.command.CreateMaemoRootstrapSb2Command;
import org.maemo.esbox.internal.scratchbox.sb2.command.GetVersionScratchboxCommand;
+import org.maemo.esbox.internal.scratchbox.sb2.command.ListAvailableMaemoRootstrapsSb2Command;
import org.maemo.esbox.internal.scratchbox.sb2.command.ListCputranspSb2Command;
+import org.maemo.esbox.internal.scratchbox.sb2.command.ListInstalledMaemoRootstrapsSb2Command;
import org.maemo.esbox.internal.scratchbox.sb2.command.MaemoRootstrapCommand;
import org.maemo.esbox.internal.scratchbox.sb2.command.MaemoSdkCommand;
import org.maemo.esbox.internal.scratchbox.sb2.command.ShowPathMappingSb2Command;
import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
+import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.machine.IMachine;
import org.maemo.mica.common.core.machine.MachineUtils;
@@ -45,8 +49,8 @@
IScratchbox2SDK {
private static final IPath ROOT_PATH = new Path("/");
- private static Pattern TARGET_PLATFORM_VERSION_ARCHITECTURE_PATTERN = Pattern
- .compile("([a-zA-Z_]+)(\\d+)_([a-zA-Z\\d]+)");
+ public static Pattern TARGET_PLATFORM_VERSION_ARCHITECTURE_PATTERN = Pattern
+ .compile("([a-zA-Z_]+)([\\d.]+)_([a-zA-Z\\d]+)");
private static final String SB2_MACHINE = "sb2_machine";
private static final String SB2_VERSION = "sb2_version";
@@ -110,7 +114,7 @@
IPath rootstrapLocation = null;
try{
rootstrapLocation = new Path(maemoRootstrapCommand.showLocation(target));
-
+
Scratchbox2SDKTarget sdkTarget = new Scratchbox2SDKTarget(this,
getPlatform(target), getArchitecture(target), target,
rootstrapLocation);
@@ -140,14 +144,15 @@
public List<String> getTargets() throws MicaException {
// check cached value
CacheUtils.getInstance().ensureCurrentMachine(SB2_MACHINE, this.getMachine());
-
String[] targetsArray = (String[]) CacheUtils.getInstance()
.getCachedValue(SB_TARGETS);
if (targetsArray != null)
return Arrays.asList(targetsArray);
- // do the hard work
- List<String> targets = maemoRootstrapCommand.list(MaemoRootstrapCommand.INSTALLED_TARGETS,null);
+ ListInstalledMaemoRootstrapsSb2Command listTargetsCommand = new ListInstalledMaemoRootstrapsSb2Command(
+ getCommandAbstractor());
+ List<String> targets = listTargetsCommand
+ .performCommand(new ArrayList<String>());
CacheUtils.getInstance().setCachedValue(SB_TARGETS,
(String[]) targets.toArray(new String[targets.size()]));
@@ -233,19 +238,17 @@
* @see org.maemo.esbox.internal.api.scratchbox.core.sdk.IScratchboxSDKPlatformArchitectureProvider#getArchitecture(java.lang.String)
*/
public String getArchitecture(String target) {
- String arch;
- try{
- arch = maemoRootstrapCommand.showArchitecture(target);
- if (arch.equalsIgnoreCase("I386"))
- arch = IScratchboxSDKTarget.ARCHITECTURE_X86;
- else if (arch.equalsIgnoreCase("armel"))
- arch = IScratchboxSDKTarget.ARCHITECTURE_ARMEL;
- }catch(MicaException e){
- return IScratchboxSDKTarget.ARCHITECTURE_UNKNOWN;
+ String[] tokens = target.split("_");
+ if(tokens.length==2){
+ if(tokens[1].equalsIgnoreCase("I386")
+ ||tokens[1].equalsIgnoreCase("armel"))
+ return tokens[1];
}
- return arch.toUpperCase();
+ Activator.getErrorLogger().logError("Invalid scratchbox 2 target, ignoring: " + target,null);
+ return IScratchboxSDKTarget.ARCHITECTURE_UNKNOWN;
}
+
public ISDKPlatform getPlatform(String target) {
// convention says this is the part of the target before the underscore,
// minus a version.
@@ -278,7 +281,9 @@
*/
public synchronized List<String> getInstalledMaemoRootstraps()
throws MicaException {
- return maemoRootstrapCommand.list(MaemoRootstrapCommand.INSTALLED_TARGETS,null);
+ ListInstalledMaemoRootstrapsSb2Command command = new ListInstalledMaemoRootstrapsSb2Command(
+ MachineUtils.getHostCommandAbstractor(this.getMachine()));
+ return command.performCommand(EMPTY_ARGS);
}
/*
@@ -289,9 +294,11 @@
* (org.maemo.mica.common.core.machine.IMachine)
*/
- public List<String> getAvailableMaemoRootstraps(IProgressMonitor monitor)
+ public List<MaemoRootstrap> getAvailableMaemoRootstraps(IMachine machine)
throws MicaException {
- return maemoRootstrapCommand.list(MaemoRootstrapCommand.AVAILABLE_TARGETS,monitor);
+ ListAvailableMaemoRootstrapsSb2Command command = new ListAvailableMaemoRootstrapsSb2Command(
+ MachineUtils.getHostCommandAbstractor(this.getMachine()));
+ return command.performCommand(EMPTY_ARGS);
}
/*
@@ -305,7 +312,17 @@
public boolean createRootstrapTarget(String targetName,
boolean useHostTools, boolean force, IProgressMonitor monitor)
throws MicaException {
- return maemoRootstrapCommand.newRootstrap(targetName);
+ List<String> params = new ArrayList<String>();
+ params.add(targetName);
+ params.add(Boolean.toString(useHostTools));
+ params.add(Boolean.toString(force));
+
+ CreateMaemoRootstrapSb2Command createTargetCommand = new CreateMaemoRootstrapSb2Command(
+ this, getCommandAbstractor(), monitor);
+
+ CacheUtils.getInstance().setCachedValue(SB_TARGETS, null);
+
+ return createTargetCommand.performCommand(params);
}
/*
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -108,16 +108,17 @@
return targetRoot;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.maemo.mica.internal.api.common.core.sdk.BaseSDKTarget#getArchitecture()
- */
- public String getArchitecture() {
- // sb2 doesn't YET ship an x86 emulator
- return IScratchboxSDKTarget.ARCHITECTURE_ARMEL;
- }
+
+
+// /*
+// * (non-Javadoc)
+// *
+// * @see
+// * org.maemo.mica.internal.api.common.core.sdk.BaseSDKTarget#getArchitecture()
+// */
+// public String getArchitecture() {
+// return super.getName().split("_")[1];
+// }
/**
* Get the command template for launching qemu under gdb with this target
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -20,6 +20,7 @@
import org.maemo.esbox.internal.scratchbox.sb2.Activator;
import org.maemo.esbox.internal.scratchbox.sb2.ui.wizard.NewScratchbox2TargetWizard;
import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
+import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.Policy;
import org.maemo.mica.common.core.adapters.ISDKManageTargetAdapter;
@@ -97,13 +98,14 @@
try {
// see if a rootstrap -- possibly disconnected from the target --
// exists
- List<String> rootstraps = sdk.getAvailableMaemoRootstraps(null);
- for (String rootstrap : rootstraps) {
- if (rootstrap.equals(selectedTarget.getName())) {
+ List<MaemoRootstrap> rootstraps = sdk
+ .getAvailableMaemoRootstraps(selectedTarget.getMachine());
+ for (MaemoRootstrap rootstrap : rootstraps) {
+ if (rootstrap.getName().equals(selectedTarget.getName())) {
rootstrapUsed_ = true;
break;
- }
}
+ }
} catch (MicaException e1) {
Activator.getErrorLogger().logError(
"Failure scanning maemo rootstraps", e1);
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -12,28 +12,19 @@
package org.maemo.esbox.internal.scratchbox.sb2.ui.wizard;
-import java.lang.reflect.InvocationTargetException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.Display;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
+import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
+import org.maemo.mica.common.core.MicaException;
+
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.IColorProvider;
-import org.eclipse.jface.viewers.IFontProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.IWizardContainer;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.maemo.esbox.internal.scratchbox.sb2.Activator;
-import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
-import org.maemo.mica.common.core.ErrorLogger;
-import org.maemo.mica.common.core.MicaException;
-
/**
* This class provides installable rootstraps, descriptions, etc. from the
* result of 'maemo-rootstrap'.
@@ -48,40 +39,62 @@
static final int COLUMN_ARCHITECTURE = 1;
static final int COLUMN_DESCRIPTION = 2;
+ public static Object LOADING_LABEL = new Object();
private boolean rootstrapsFetched;
- private List<String> rootstraps;
+ // either MaemoRootstrap or NO_ROOTSTRAP
+ private List<Object> rootstraps;
+ private Thread rootstrapThread;
private final IScratchbox2SDK sdk;
- private final IWizardContainer wizardContainer;
- public MaemoRootstrapContentLabelProvider(IScratchbox2SDK sdk,IWizardContainer wizardContainer) {
+ public MaemoRootstrapContentLabelProvider(IScratchbox2SDK sdk) {
this.sdk = sdk;
- this.wizardContainer = wizardContainer;
}
public Object[] getElements(Object inputElement) {
if (!rootstrapsFetched) {
- rootstraps = new ArrayList<String>();
- try {
- wizardContainer.run(true, true,new IRunnableWithProgress(){
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- monitor.beginTask("Loading...",
- IProgressMonitor.UNKNOWN);
+ rootstraps = new ArrayList<Object>();
+ rootstraps.add(LOADING_LABEL);
+
+ if (rootstrapThread == null) {
+ rootstrapThread = new Thread(new Runnable() {
+
+ public void run() {
try {
- rootstraps =
- sdk.getAvailableMaemoRootstraps(new SubProgressMonitor(monitor, 1));
- }catch(MicaException e) {
- throw new InvocationTargetException(e);
+ List<MaemoRootstrap> realRootstraps = sdk
+ .getAvailableMaemoRootstraps(sdk
+ .getMachine());
+ synchronized (rootstraps) {
+ rootstraps.remove(LOADING_LABEL);
+ rootstraps.addAll(realRootstraps);
+ }
+ } catch (final MicaException e) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog.openError(null,
+ "Rootstrap lookup failed",
+ "Error fetching rootstraps: check proxy settings?\n\n"
+ + e.getMessage());
+ }
+
+ });
}
- monitor.done();
+ rootstrapsFetched = true;
+ rootstrapThread = null;
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ fireLabelProviderChanged(new LabelProviderChangedEvent(
+ MaemoRootstrapContentLabelProvider.this));
+ }
+
+ });
}
+
});
- }catch(Exception e){
- ErrorLogger errorLogger = Activator.getErrorLogger();
- errorLogger.logAndShowError("Cannot get available rootstraps.", e);
+ rootstrapThread.start();
}
- rootstrapsFetched=true;
}
synchronized (rootstraps) {
return rootstraps.toArray();
@@ -115,13 +128,25 @@
public String getColumnText(Object element, int columnIndex) {
switch (columnIndex) {
case COLUMN_NAME:
- return (String) element;
+ if (element == LOADING_LABEL) {
+ return "Loading...";
+ } else {
+ return ((MaemoRootstrap) element).getName();
+ }
case COLUMN_ARCHITECTURE:
- return sdk.getArchitecture((String)element);
+ if (element == LOADING_LABEL) {
+ return null;
+ } else {
+ return ((MaemoRootstrap) element).getArchitecture();
+ }
case COLUMN_DESCRIPTION:
- return "";
+ if (element == LOADING_LABEL) {
+ return null;
+ } else {
+ return ((MaemoRootstrap) element).getDescription();
+ }
}
return null;
}
@@ -131,11 +156,18 @@
}
public Color getForeground(Object element) {
- return null;
+ if (element == LOADING_LABEL)
+ return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
+ else
+ return null;
}
public Font getFont(Object element) {
- return null;
+ if (element == LOADING_LABEL)
+ return JFaceResources.getFontRegistry().getItalic(
+ JFaceResources.DIALOG_FONT);
+ else
+ return null;
}
}
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -14,10 +14,13 @@
package org.maemo.esbox.internal.scratchbox.sb2.ui.wizard;
import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -28,7 +31,9 @@
import org.eclipse.ui.IWorkbenchWizard;
import org.maemo.esbox.internal.api.scratchbox.ui.wizards.TargetWizardPageFactory;
import org.maemo.esbox.internal.scratchbox.sb2.Activator;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
+import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
import org.maemo.mica.common.core.ErrorLogger;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.sdk.ISDKTarget;
@@ -92,16 +97,70 @@
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
public boolean performFinish() {
- final String rootstrap = getRootstrap();
+ if (getRootstrap() != null) {
+ if (!setupTargetFromRootstrap())
+ return false;
+ }
+ return true;
+ }
+
+ private boolean setupTargetFromRootstrap() {
+ String targetName;
+ // in this mode, make a predefined target from a maemo rootstrap
+ targetName = getRootstrap().getTarget();
+ boolean create = true;
+
+ if (true) {
+ // see if the rootstrap (not necessarily the target) already exists,
+ // and ask user, in case this will overwrite their customizations
+ try {
+ List<String> installedRootstraps = sdk
+ .getInstalledMaemoRootstraps();
+ if (installedRootstraps.contains(targetName)) {
+ create = MessageDialog
+ .openConfirm(
+ getShell(),
+ "Reinstall rootstrap?",
+ MessageFormat
+ .format(
+ "The rootstrap ''{0}'' appears to be already installed, though it may be disconnected from scratchbox.\n\n"
+ + "At this time, we can't recreate a target for this rootstrap, but "
+ + "you could do it manually with 'sb2-init'.\n\n"
+ + "Do you want to overwrite the rootstrap?",
+ targetName));
+ }
+ } catch (MicaException e) {
+ ErrorLogger errorLogger = Activator.getErrorLogger();
+ errorLogger.logError("Cannot detect installed rootstraps", e);
+ }
+ }
+
+ if (create) {
+ try {
+ createRootstrap(targetName, true);
+ } catch (MicaException e) {
+ ErrorLogger errorLogger = Activator.getErrorLogger();
+ errorLogger.logAndShowError(
+ "Cannot get create rootstrap target " + targetName, e);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void createRootstrap(final String targetName,
+ final boolean useHostTools) throws ScratchboxException {
try {
getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
- monitor.beginTask("Installing rootstrap...",
+ monitor.beginTask("Creating rootstrap",
IProgressMonitor.UNKNOWN);
try {
- sdk.installRootstrap(rootstrap,new SubProgressMonitor(monitor, 1));
+ sdk.createRootstrapTarget(targetName, useHostTools,
+ false, new SubProgressMonitor(monitor, 1));
+ createdTarget = sdk.findSDKTarget(targetName);
} catch (MicaException e) {
throw new InvocationTargetException(e);
}
@@ -109,20 +168,21 @@
}
});
- } catch (Exception e) {
- ErrorLogger errorLogger = Activator.getErrorLogger();
- errorLogger.logAndShowError("Cannot install rootstrap "
- + rootstrap, e);
+ } catch (InvocationTargetException e) {
+ if (e.getCause() instanceof ScratchboxException)
+ throw (ScratchboxException) e.getCause();
+ else
+ throw new ScratchboxException(e);
+ } catch (InterruptedException e) {
+ throw new ScratchboxException(e);
}
- return true;
}
- private String getRootstrap() {
+ private MaemoRootstrap getRootstrap() {
return ((TargetWizardRootstrapSb2Page) maemoRootstrapPage)
.getRootstrap();
}
-
/**
* We will accept the selection in the workbench to see if we can initialize
* from it.
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -85,7 +85,7 @@
.setToolTipText("If checked, rootstraps with names matching existing targets will be shown. This is the only way to reinstall a target.");
- provider = new MaemoRootstrapContentLabelProvider(sdk,this.getContainer());
+ provider = new MaemoRootstrapContentLabelProvider(sdk);
rootstrapTargetViewer.setContentProvider(provider);
rootstrapTargetViewer.setLabelProvider(provider);
@@ -152,9 +152,9 @@
@Override
public boolean select(Viewer viewer,
Object parentElement, Object element) {
- if (element instanceof String) {
- String rootstrap = (String) element;
- if (sdk.findSDKTarget(rootstrap) != null)
+ if (element instanceof MaemoRootstrap) {
+ MaemoRootstrap rootstrap = (MaemoRootstrap) element;
+ if (sdk.findSDKTarget(rootstrap.getTarget()) != null)
return false;
}
return true;
@@ -185,7 +185,7 @@
return selection instanceof MaemoRootstrap;
}
- public String getRootstrap() {
- return (String) selection;
+ public MaemoRootstrap getRootstrap() {
+ return (MaemoRootstrap) selection;
}
}
\ No newline at end of file
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -13,6 +13,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDK;
import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.machine.IMachine;
import java.util.List;
@@ -88,7 +89,7 @@
* @return List, never null
* @throws MicaException
*/
- public List<String> getAvailableMaemoRootstraps(IProgressMonitor mnitor)
+ public List<MaemoRootstrap> getAvailableMaemoRootstraps(IMachine machine)
throws MicaException;
/**
Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/MaemoRootstrap.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/MaemoRootstrap.java 2008-12-04 06:09:36 UTC (rev 1035)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/MaemoRootstrap.java 2008-12-04 14:04:16 UTC (rev 1036)
@@ -41,6 +41,9 @@
return description;
}
+ public String getTarget(){
+ return name+"_"+architecture;
+ }
@Override
public int hashCode() {
final int prime = 31;
More information about the Esbox-commits
mailing list