diff options
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk')
32 files changed, 4323 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/ProjectSpecificContributionItem.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/ProjectSpecificContributionItem.java new file mode 100644 index 0000000..c29d278 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/ProjectSpecificContributionItem.java | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | |||
| 12 | package org.yocto.sdk.ide; | ||
| 13 | |||
| 14 | import java.util.ArrayList; | ||
| 15 | |||
| 16 | import org.eclipse.core.resources.IProject; | ||
| 17 | import org.eclipse.jface.action.IContributionItem; | ||
| 18 | import org.eclipse.ui.menus.CommandContributionItem; | ||
| 19 | import org.eclipse.ui.menus.CommandContributionItemParameter; | ||
| 20 | import org.eclipse.ui.services.IServiceLocator; | ||
| 21 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
| 22 | import org.yocto.sdk.ide.actions.ProfileSwitchHandler; | ||
| 23 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 24 | |||
| 25 | public class ProjectSpecificContributionItem extends TargetProfileContributionItem { | ||
| 26 | private static final String PROJECT_SPECIFIC_PROFILE = | ||
| 27 | "Preferences.Profile.ProjectSpecific.Profile.Label"; //$NON-NLS-N$ | ||
| 28 | private static final String DISABLED_COMMAND_ID = "org.yocto.sdk.ide.command.disabled"; //$NON-NLS-N$ | ||
| 29 | |||
| 30 | private IServiceLocator serviceLocator; | ||
| 31 | |||
| 32 | public ProjectSpecificContributionItem() {} | ||
| 33 | |||
| 34 | public ProjectSpecificContributionItem(String id) { | ||
| 35 | super(id); | ||
| 36 | } | ||
| 37 | |||
| 38 | @Override | ||
| 39 | protected IContributionItem[] getContributionItems() { | ||
| 40 | ArrayList<IContributionItem> items = new ArrayList<IContributionItem>(); | ||
| 41 | |||
| 42 | IProject project = getSelectedProject(serviceLocator); | ||
| 43 | YoctoUIElement yoctoUIElement = ProjectPreferenceUtils.getElem(project); | ||
| 44 | SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(yoctoUIElement); | ||
| 45 | |||
| 46 | if ((result != SDKCheckResults.SDK_PASS)) { | ||
| 47 | CommandContributionItemParameter parameter = new CommandContributionItemParameter(serviceLocator, | ||
| 48 | null, | ||
| 49 | DISABLED_COMMAND_ID, | ||
| 50 | CommandContributionItem.STYLE_PUSH); | ||
| 51 | |||
| 52 | parameter.label = YoctoSDKMessages.getString(PROJECT_SPECIFIC_PROFILE); | ||
| 53 | |||
| 54 | items.add(new CommandContributionItem(parameter)); | ||
| 55 | } else { | ||
| 56 | items.add(super.createProfileItem(serviceLocator, ProfileSwitchHandler.PROJECT_SPECIFIC_PARAMETER, | ||
| 57 | YoctoSDKMessages.getString(PROJECT_SPECIFIC_PROFILE))); | ||
| 58 | } | ||
| 59 | |||
| 60 | updateSelection(serviceLocator); | ||
| 61 | |||
| 62 | return items.toArray(new IContributionItem[items.size()]); | ||
| 63 | } | ||
| 64 | |||
| 65 | @Override | ||
| 66 | public void initialize(IServiceLocator serviceLocator) { | ||
| 67 | this.serviceLocator = serviceLocator; | ||
| 68 | } | ||
| 69 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/TargetProfileContributionItem.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/TargetProfileContributionItem.java new file mode 100644 index 0000000..95d8229 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/TargetProfileContributionItem.java | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import java.util.ArrayList; | ||
| 14 | import java.util.HashMap; | ||
| 15 | import java.util.TreeSet; | ||
| 16 | |||
| 17 | import org.eclipse.cdt.core.model.ICElement; | ||
| 18 | import org.eclipse.cdt.core.model.ICProject; | ||
| 19 | import org.eclipse.core.commands.Command; | ||
| 20 | import org.eclipse.core.commands.ExecutionException; | ||
| 21 | import org.eclipse.core.resources.IProject; | ||
| 22 | import org.eclipse.core.resources.IResource; | ||
| 23 | import org.eclipse.core.runtime.IAdaptable; | ||
| 24 | import org.eclipse.jface.action.IContributionItem; | ||
| 25 | import org.eclipse.jface.viewers.ISelection; | ||
| 26 | import org.eclipse.jface.viewers.ITreeSelection; | ||
| 27 | import org.eclipse.ui.ISelectionService; | ||
| 28 | import org.eclipse.ui.actions.CompoundContributionItem; | ||
| 29 | import org.eclipse.ui.commands.ICommandService; | ||
| 30 | import org.eclipse.ui.handlers.HandlerUtil; | ||
| 31 | import org.eclipse.ui.handlers.RadioState; | ||
| 32 | import org.eclipse.ui.menus.CommandContributionItem; | ||
| 33 | import org.eclipse.ui.menus.CommandContributionItemParameter; | ||
| 34 | import org.eclipse.ui.menus.IWorkbenchContribution; | ||
| 35 | import org.eclipse.ui.services.IServiceLocator; | ||
| 36 | import org.yocto.sdk.ide.actions.ProfileSwitchHandler; | ||
| 37 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 38 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 39 | |||
| 40 | public class TargetProfileContributionItem extends CompoundContributionItem implements IWorkbenchContribution { | ||
| 41 | private IServiceLocator serviceLocator; | ||
| 42 | |||
| 43 | public TargetProfileContributionItem() {} | ||
| 44 | |||
| 45 | public TargetProfileContributionItem(String id) { | ||
| 46 | super(id); | ||
| 47 | } | ||
| 48 | |||
| 49 | protected CommandContributionItem createProfileItem(IServiceLocator serviceLocator, | ||
| 50 | String parameter, String label) { | ||
| 51 | CommandContributionItemParameter itemParameter; | ||
| 52 | itemParameter = new CommandContributionItemParameter(serviceLocator, | ||
| 53 | null, | ||
| 54 | ProfileSwitchHandler.PROFILE_SWITCH_COMMAND, | ||
| 55 | CommandContributionItem.STYLE_RADIO); | ||
| 56 | |||
| 57 | HashMap<String, String> params = new HashMap<String, String>(); | ||
| 58 | params.put(RadioState.PARAMETER_ID, parameter); | ||
| 59 | |||
| 60 | itemParameter.label = label; | ||
| 61 | itemParameter.parameters = params; | ||
| 62 | |||
| 63 | return new CommandContributionItem(itemParameter); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Override | ||
| 67 | protected IContributionItem[] getContributionItems() { | ||
| 68 | TreeSet<String> profiles = YoctoSDKUtils.getProfilesFromDefaultStore().getProfiles(); | ||
| 69 | ArrayList<IContributionItem> items = new ArrayList<IContributionItem>(); | ||
| 70 | |||
| 71 | for (String profile : profiles) { | ||
| 72 | items.add(createProfileItem(serviceLocator, profile, profile)); | ||
| 73 | } | ||
| 74 | |||
| 75 | updateSelection(serviceLocator); | ||
| 76 | |||
| 77 | return items.toArray(new IContributionItem[profiles.size()]); | ||
| 78 | } | ||
| 79 | |||
| 80 | public IProject getSelectedProject(IServiceLocator serviceLocator) { | ||
| 81 | ISelectionService selectionService = (ISelectionService) serviceLocator.getService(ISelectionService.class); | ||
| 82 | ISelection selection = selectionService.getSelection(); | ||
| 83 | |||
| 84 | if (selection instanceof ITreeSelection) { | ||
| 85 | Object selectedItem = ((ITreeSelection) selection).getFirstElement(); | ||
| 86 | if (selectedItem instanceof IResource) { | ||
| 87 | return ((IResource) selectedItem).getProject(); | ||
| 88 | } else if (selectedItem instanceof ICElement) { | ||
| 89 | ICProject cProject = ((ICElement) selectedItem).getCProject(); | ||
| 90 | if (cProject != null) { | ||
| 91 | return cProject.getProject(); | ||
| 92 | } | ||
| 93 | } else if (selectedItem instanceof IAdaptable) { | ||
| 94 | Object projectObject = ((IAdaptable) selectedItem).getAdapter(IProject.class); | ||
| 95 | if (projectObject != null && projectObject instanceof IProject) { | ||
| 96 | return ((IProject) projectObject); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | return null; | ||
| 102 | } | ||
| 103 | |||
| 104 | @Override | ||
| 105 | public void initialize(IServiceLocator serviceLocator) { | ||
| 106 | this.serviceLocator = serviceLocator; | ||
| 107 | } | ||
| 108 | |||
| 109 | protected void updateSelection(IServiceLocator serviceLocator) { | ||
| 110 | ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); | ||
| 111 | Command command = commandService.getCommand(ProfileSwitchHandler.PROFILE_SWITCH_COMMAND); | ||
| 112 | IProject project = getSelectedProject(serviceLocator); | ||
| 113 | |||
| 114 | try { | ||
| 115 | if (ProjectPreferenceUtils.getUseProjectSpecificOption(project)) { | ||
| 116 | HandlerUtil.updateRadioState(command, ProfileSwitchHandler.PROJECT_SPECIFIC_PARAMETER); | ||
| 117 | return; | ||
| 118 | } | ||
| 119 | |||
| 120 | String selectedProfile = ProjectPreferenceUtils.getProfiles(project).getSelectedProfile(); | ||
| 121 | HandlerUtil.updateRadioState(command, selectedProfile); | ||
| 122 | } catch (ExecutionException e) { | ||
| 123 | // ignore | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoGeneralException.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoGeneralException.java new file mode 100644 index 0000000..971425c --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoGeneralException.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | /* All specific exceptions raised from yocto project should use | ||
| 14 | * this specific exception class. | ||
| 15 | * Currently we only use it for message printing | ||
| 16 | */ | ||
| 17 | |||
| 18 | public class YoctoGeneralException extends Exception { | ||
| 19 | |||
| 20 | /** | ||
| 21 | * | ||
| 22 | */ | ||
| 23 | private static final long serialVersionUID = 6600798490815526253L; | ||
| 24 | /** | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | |||
| 28 | public YoctoGeneralException(String message) | ||
| 29 | { | ||
| 30 | super(message); | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java new file mode 100644 index 0000000..02626ad --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileElement.java | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import java.util.Comparator; | ||
| 14 | import java.util.StringTokenizer; | ||
| 15 | import java.util.TreeSet; | ||
| 16 | |||
| 17 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
| 18 | |||
| 19 | public class YoctoProfileElement { | ||
| 20 | private TreeSet<String> profiles = new TreeSet<String>(new Comparator<String>() { | ||
| 21 | |||
| 22 | @Override | ||
| 23 | public int compare(String o1, String o2) { | ||
| 24 | int strcompare = o1.compareTo(o2); | ||
| 25 | |||
| 26 | if (strcompare == 0) { | ||
| 27 | return strcompare; | ||
| 28 | } | ||
| 29 | |||
| 30 | // Standard profile always less than anything else | ||
| 31 | if (o1.equals(PreferenceConstants.STANDARD_PROFILE_NAME)) { | ||
| 32 | return -1; | ||
| 33 | } | ||
| 34 | |||
| 35 | if (o2.equals(PreferenceConstants.STANDARD_PROFILE_NAME)) { | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | return strcompare; | ||
| 40 | } | ||
| 41 | }); | ||
| 42 | |||
| 43 | private String selectedProfile; | ||
| 44 | |||
| 45 | public YoctoProfileElement(String profilesString, String selectedProfile) { | ||
| 46 | setProfilesFromString(profilesString); | ||
| 47 | this.selectedProfile = selectedProfile; | ||
| 48 | } | ||
| 49 | |||
| 50 | public void addProfile(String profile) { | ||
| 51 | this.profiles.add(profile); | ||
| 52 | } | ||
| 53 | |||
| 54 | public boolean contains(String newText) { | ||
| 55 | return profiles.contains(newText); | ||
| 56 | } | ||
| 57 | |||
| 58 | public TreeSet<String> getProfiles() { | ||
| 59 | return profiles; | ||
| 60 | } | ||
| 61 | |||
| 62 | public String getProfilesAsString() { | ||
| 63 | String profileString = ""; | ||
| 64 | |||
| 65 | for (String profile : profiles) { | ||
| 66 | profileString += "\"" + profile + "\","; | ||
| 67 | } | ||
| 68 | return profileString.substring(0, profileString.length() - 1); | ||
| 69 | } | ||
| 70 | |||
| 71 | public String getSelectedProfile() { | ||
| 72 | return selectedProfile; | ||
| 73 | } | ||
| 74 | |||
| 75 | public void remove(String profile) { | ||
| 76 | this.profiles.remove(profile); | ||
| 77 | } | ||
| 78 | |||
| 79 | public void rename(String oldProfileName, String newProfileName) { | ||
| 80 | this.remove(oldProfileName); | ||
| 81 | this.addProfile(newProfileName); | ||
| 82 | |||
| 83 | if (selectedProfile.equals(oldProfileName)) { | ||
| 84 | selectedProfile = newProfileName; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | public void setProfiles(TreeSet<String> profiles) { | ||
| 89 | this.profiles = profiles; | ||
| 90 | } | ||
| 91 | |||
| 92 | public void setProfilesFromString(String profilesString) { | ||
| 93 | StringTokenizer tokenizer = new StringTokenizer(profilesString, ","); | ||
| 94 | |||
| 95 | while (tokenizer.hasMoreElements()) { | ||
| 96 | String config = (String) tokenizer.nextElement(); | ||
| 97 | profiles.add(config.replace("\"", "")); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | public void setSelectedProfile(String selectedProfile) { | ||
| 102 | this.selectedProfile = selectedProfile; | ||
| 103 | } | ||
| 104 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileSetting.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileSetting.java new file mode 100644 index 0000000..f56fea4 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileSetting.java | |||
| @@ -0,0 +1,245 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
| 14 | import org.eclipse.jface.dialogs.InputDialog; | ||
| 15 | import org.eclipse.jface.dialogs.MessageDialog; | ||
| 16 | import org.eclipse.jface.preference.PreferencePage; | ||
| 17 | import org.eclipse.swt.SWT; | ||
| 18 | import org.eclipse.swt.events.MouseAdapter; | ||
| 19 | import org.eclipse.swt.events.MouseEvent; | ||
| 20 | import org.eclipse.swt.layout.GridData; | ||
| 21 | import org.eclipse.swt.layout.GridLayout; | ||
| 22 | import org.eclipse.swt.widgets.Button; | ||
| 23 | import org.eclipse.swt.widgets.Combo; | ||
| 24 | import org.eclipse.swt.widgets.Composite; | ||
| 25 | import org.eclipse.swt.widgets.Event; | ||
| 26 | import org.eclipse.swt.widgets.Group; | ||
| 27 | import org.eclipse.swt.widgets.Listener; | ||
| 28 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
| 29 | import org.yocto.sdk.ide.preferences.ProfileNameInputValidator; | ||
| 30 | import org.yocto.sdk.ide.preferences.YoctoSDKPreferencePage; | ||
| 31 | import org.yocto.sdk.ide.preferences.YoctoSDKProjectPropertyPage; | ||
| 32 | |||
| 33 | public class YoctoProfileSetting { | ||
| 34 | private static final String PROFILES_TITLE = "Preferences.Profiles.Title"; | ||
| 35 | private static final String NEW_PROFILE_TITLE = "Preferences.Profile.New.Title"; | ||
| 36 | private static final String RENAME_PROFILE_TITLE = "Preferences.Profile.Rename.Title"; | ||
| 37 | private static final String RENAME_DIALOG_TITLE = "Preferences.Profile.Rename.Dialog.Title"; | ||
| 38 | private static final String RENAME_DIALOG_MESSAGE = "Preferences.Profile.Rename.Dialog.Message"; | ||
| 39 | private static final String REMOVE_PROFILE_TITLE = "Preferences.Profile.Remove.Title"; | ||
| 40 | private static final String REMOVE_DIALOG_TITLE = "Preferences.Profile.Remove.Dialog.Title"; | ||
| 41 | private static final String REMOVE_DIALOG_MESSAGE = "Preferences.Profile.Remove.Dialog.Message"; | ||
| 42 | private static final String MODIFY_STANDARD_TITLE = "Preferences.Profile.Standard.Modification.Title"; | ||
| 43 | private static final String MODIFY_STANDARD_MESSAGE = "Preferences.Profile.Standard.Modification.Message"; | ||
| 44 | |||
| 45 | private Combo sdkConfigsCombo; | ||
| 46 | private Button btnConfigRename; | ||
| 47 | private Button btnConfigRemove; | ||
| 48 | private Button btnConfigSaveAs; | ||
| 49 | |||
| 50 | private YoctoProfileElement profileElement; | ||
| 51 | private PreferencePage preferencePage; | ||
| 52 | private final boolean editable; | ||
| 53 | |||
| 54 | public YoctoProfileSetting(YoctoProfileElement profileElement, PreferencePage preferencePage, final boolean editable) { | ||
| 55 | this.profileElement = profileElement; | ||
| 56 | this.preferencePage = preferencePage; | ||
| 57 | this.editable = editable; | ||
| 58 | } | ||
| 59 | |||
| 60 | public void createComposite(Composite composite) { | ||
| 61 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
| 62 | GridLayout layout = new GridLayout(2, false); | ||
| 63 | |||
| 64 | Group storeYoctoConfigurationsGroup = new Group (composite, SWT.NONE); | ||
| 65 | layout = new GridLayout(1, false); | ||
| 66 | if (isEditable()) { | ||
| 67 | layout.numColumns = 3; | ||
| 68 | } | ||
| 69 | |||
| 70 | storeYoctoConfigurationsGroup.setLayout(layout); | ||
| 71 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
| 72 | gd.horizontalSpan = 2; | ||
| 73 | storeYoctoConfigurationsGroup.setLayoutData(gd); | ||
| 74 | storeYoctoConfigurationsGroup.setText(YoctoSDKMessages.getString(PROFILES_TITLE)); | ||
| 75 | |||
| 76 | sdkConfigsCombo = new Combo(storeYoctoConfigurationsGroup, SWT.READ_ONLY); | ||
| 77 | addConfigs(sdkConfigsCombo); | ||
| 78 | sdkConfigsCombo.select(sdkConfigsCombo.indexOf(profileElement.getSelectedProfile())); | ||
| 79 | sdkConfigsCombo.setLayout(new GridLayout(2, false)); | ||
| 80 | sdkConfigsCombo.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false)); | ||
| 81 | |||
| 82 | Listener selectionListener = new Listener() { | ||
| 83 | @Override | ||
| 84 | public void handleEvent(Event event) { | ||
| 85 | Object source = event.widget; | ||
| 86 | if (!(source instanceof Combo)) { | ||
| 87 | return; | ||
| 88 | } | ||
| 89 | |||
| 90 | Combo sdkCombo = (Combo) source; | ||
| 91 | if (sdkCombo.getSelectionIndex() < 0) { | ||
| 92 | return; | ||
| 93 | } | ||
| 94 | |||
| 95 | String selectedItem = sdkCombo.getItem(sdkCombo.getSelectionIndex()); | ||
| 96 | profileElement.setSelectedProfile(selectedItem); | ||
| 97 | |||
| 98 | if (preferencePage instanceof YoctoSDKPreferencePage) { | ||
| 99 | ((YoctoSDKPreferencePage) preferencePage).switchProfile(selectedItem); | ||
| 100 | } else if (preferencePage instanceof YoctoSDKProjectPropertyPage) { | ||
| 101 | ((YoctoSDKProjectPropertyPage) preferencePage).switchProfile(selectedItem); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | }; | ||
| 105 | |||
| 106 | sdkConfigsCombo.addListener(SWT.Selection, selectionListener); | ||
| 107 | sdkConfigsCombo.addListener(SWT.Modify, selectionListener); | ||
| 108 | |||
| 109 | if (isEditable()) { | ||
| 110 | createSaveAsProfileButton(storeYoctoConfigurationsGroup); | ||
| 111 | createRenameButton(storeYoctoConfigurationsGroup); | ||
| 112 | createRemoveButton(storeYoctoConfigurationsGroup); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | private void createSaveAsProfileButton(Group storeYoctoConfigurationsGroup) { | ||
| 117 | btnConfigSaveAs = new Button(storeYoctoConfigurationsGroup, SWT.PUSH | SWT.LEAD); | ||
| 118 | btnConfigSaveAs.setText(YoctoSDKMessages.getString(NEW_PROFILE_TITLE)); | ||
| 119 | btnConfigSaveAs.addMouseListener(new MouseAdapter() { | ||
| 120 | @Override | ||
| 121 | public void mouseDown(MouseEvent e) { | ||
| 122 | if (preferencePage instanceof YoctoSDKPreferencePage) { | ||
| 123 | ((YoctoSDKPreferencePage) preferencePage).performSaveAs(); | ||
| 124 | } | ||
| 125 | } | ||
| 126 | }); | ||
| 127 | } | ||
| 128 | |||
| 129 | private void createRemoveButton(Group storeYoctoConfigurationsGroup) { | ||
| 130 | btnConfigRemove = new Button(storeYoctoConfigurationsGroup, SWT.PUSH | SWT.LEAD); | ||
| 131 | btnConfigRemove.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false, 3, 1)); | ||
| 132 | btnConfigRemove.setText(YoctoSDKMessages.getString(REMOVE_PROFILE_TITLE)); | ||
| 133 | btnConfigRemove.addMouseListener(new MouseAdapter() { | ||
| 134 | @Override | ||
| 135 | public void mouseDown(MouseEvent e) { | ||
| 136 | saveChangesOnCurrentProfile(); | ||
| 137 | int selectionIndex = sdkConfigsCombo.getSelectionIndex(); | ||
| 138 | String selectedItem = sdkConfigsCombo.getItem(selectionIndex); | ||
| 139 | |||
| 140 | if (selectedItem.equals(PreferenceConstants.STANDARD_PROFILE_NAME)) { | ||
| 141 | MessageDialog.openInformation(null, | ||
| 142 | YoctoSDKMessages.getString(MODIFY_STANDARD_TITLE), | ||
| 143 | YoctoSDKMessages.getString(MODIFY_STANDARD_MESSAGE)); | ||
| 144 | return; | ||
| 145 | } | ||
| 146 | |||
| 147 | boolean deleteConfirmed = | ||
| 148 | MessageDialog.openConfirm(null, | ||
| 149 | YoctoSDKMessages.getString(REMOVE_DIALOG_TITLE), | ||
| 150 | YoctoSDKMessages.getFormattedString(REMOVE_DIALOG_MESSAGE, selectedItem)); | ||
| 151 | |||
| 152 | if (!deleteConfirmed) { | ||
| 153 | return; | ||
| 154 | } | ||
| 155 | |||
| 156 | sdkConfigsCombo.select(0); | ||
| 157 | sdkConfigsCombo.remove(selectionIndex); | ||
| 158 | profileElement.remove(selectedItem); | ||
| 159 | |||
| 160 | if (preferencePage instanceof YoctoSDKPreferencePage) { | ||
| 161 | ((YoctoSDKPreferencePage) preferencePage).deleteProfile(selectedItem); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | }); | ||
| 165 | } | ||
| 166 | |||
| 167 | private void createRenameButton(Group storeYoctoConfigurationsGroup) { | ||
| 168 | btnConfigRename = new Button(storeYoctoConfigurationsGroup, SWT.PUSH | SWT.LEAD); | ||
| 169 | btnConfigRename.setText(YoctoSDKMessages.getString(RENAME_PROFILE_TITLE)); | ||
| 170 | btnConfigRename.addMouseListener(new MouseAdapter() { | ||
| 171 | @Override | ||
| 172 | public void mouseDown(MouseEvent e) { | ||
| 173 | saveChangesOnCurrentProfile(); | ||
| 174 | int selectedIndex = sdkConfigsCombo.getSelectionIndex(); | ||
| 175 | final String selectedItem = sdkConfigsCombo.getItem(selectedIndex); | ||
| 176 | |||
| 177 | if (selectedItem.equals(PreferenceConstants.STANDARD_PROFILE_NAME)) { | ||
| 178 | MessageDialog.openInformation(null, | ||
| 179 | YoctoSDKMessages.getString(MODIFY_STANDARD_TITLE), | ||
| 180 | YoctoSDKMessages.getString(MODIFY_STANDARD_MESSAGE)); | ||
| 181 | return; | ||
| 182 | } | ||
| 183 | |||
| 184 | InputDialog profileNameDialog = | ||
| 185 | new InputDialog(null, | ||
| 186 | YoctoSDKMessages.getString(RENAME_DIALOG_TITLE), | ||
| 187 | YoctoSDKMessages.getString(RENAME_DIALOG_MESSAGE), | ||
| 188 | null, | ||
| 189 | new ProfileNameInputValidator(profileElement, selectedItem)); | ||
| 190 | |||
| 191 | int returnCode = profileNameDialog.open(); | ||
| 192 | if (returnCode == IDialogConstants.CANCEL_ID) { | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | |||
| 196 | String newProfileName = profileNameDialog.getValue(); | ||
| 197 | profileElement.rename(selectedItem, profileNameDialog.getValue()); | ||
| 198 | |||
| 199 | if (preferencePage instanceof YoctoSDKPreferencePage) { | ||
| 200 | ((YoctoSDKPreferencePage) preferencePage).renameProfile(selectedItem, newProfileName); | ||
| 201 | } | ||
| 202 | |||
| 203 | sdkConfigsCombo.setItem(selectedIndex, newProfileName); | ||
| 204 | sdkConfigsCombo.select(selectedIndex); | ||
| 205 | } | ||
| 206 | }); | ||
| 207 | } | ||
| 208 | |||
| 209 | private void saveChangesOnCurrentProfile() { | ||
| 210 | preferencePage.performOk(); | ||
| 211 | } | ||
| 212 | |||
| 213 | private void addConfigs(Combo combo) { | ||
| 214 | for (String profile : profileElement.getProfiles()) { | ||
| 215 | combo.add(profile); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | public void addProfile(String profileName) { | ||
| 220 | int index = sdkConfigsCombo.getItemCount(); | ||
| 221 | sdkConfigsCombo.add(profileName, index); | ||
| 222 | sdkConfigsCombo.select(index); | ||
| 223 | } | ||
| 224 | |||
| 225 | public void setUIFormEnabledState(boolean isEnabled) { | ||
| 226 | setButtonsEnabledState(isEnabled); | ||
| 227 | sdkConfigsCombo.setEnabled(isEnabled); | ||
| 228 | } | ||
| 229 | |||
| 230 | public YoctoProfileElement getCurrentInput() { | ||
| 231 | return profileElement; | ||
| 232 | } | ||
| 233 | |||
| 234 | public void setButtonsEnabledState(boolean isEnabled) { | ||
| 235 | if (isEditable()) { | ||
| 236 | btnConfigRename.setEnabled(isEnabled); | ||
| 237 | btnConfigRemove.setEnabled(isEnabled); | ||
| 238 | btnConfigSaveAs.setEnabled(isEnabled); | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | private boolean isEditable() { | ||
| 243 | return editable; | ||
| 244 | } | ||
| 245 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProjectSpecificSetting.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProjectSpecificSetting.java new file mode 100644 index 0000000..2a55a64 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProjectSpecificSetting.java | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import org.eclipse.jface.preference.PreferencePage; | ||
| 14 | import org.eclipse.swt.SWT; | ||
| 15 | import org.eclipse.swt.events.SelectionEvent; | ||
| 16 | import org.eclipse.swt.events.SelectionListener; | ||
| 17 | import org.eclipse.swt.layout.GridData; | ||
| 18 | import org.eclipse.swt.layout.GridLayout; | ||
| 19 | import org.eclipse.swt.widgets.Button; | ||
| 20 | import org.eclipse.swt.widgets.Composite; | ||
| 21 | import org.eclipse.swt.widgets.Group; | ||
| 22 | import org.yocto.sdk.ide.preferences.YoctoSDKProjectPropertyPage; | ||
| 23 | |||
| 24 | public class YoctoProjectSpecificSetting { | ||
| 25 | private static final String PROJECT_SPECIFIC_TITLE = "Preferences.Profile.ProjectSpecific.Title"; | ||
| 26 | private static final String PROJECT_SPECIFIC_GROUP_TITLE = "Preferences.Profile.ProjectSpecific.Group.Title"; | ||
| 27 | |||
| 28 | private YoctoProfileSetting yoctoConfigurationsSetting; | ||
| 29 | private YoctoUISetting yoctoUISetting; | ||
| 30 | |||
| 31 | private Button btnUseProjectSpecificSettingsCheckbox; | ||
| 32 | private PreferencePage preferencePage; | ||
| 33 | |||
| 34 | public YoctoProjectSpecificSetting(YoctoProfileSetting yoctoConfigurationsSetting, | ||
| 35 | YoctoUISetting yoctoUISetting, PreferencePage preferencePage) { | ||
| 36 | this.yoctoConfigurationsSetting = yoctoConfigurationsSetting; | ||
| 37 | this.yoctoUISetting = yoctoUISetting; | ||
| 38 | this.preferencePage = preferencePage; | ||
| 39 | } | ||
| 40 | |||
| 41 | public void createComposite(Composite composite) { | ||
| 42 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
| 43 | GridLayout layout = new GridLayout(2, false); | ||
| 44 | |||
| 45 | Group storeYoctoConfigurationsGroup = new Group (composite, SWT.NONE); | ||
| 46 | layout = new GridLayout(2, false); | ||
| 47 | storeYoctoConfigurationsGroup.setLayout(layout); | ||
| 48 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
| 49 | gd.horizontalSpan = 2; | ||
| 50 | storeYoctoConfigurationsGroup.setLayoutData(gd); | ||
| 51 | storeYoctoConfigurationsGroup.setText(YoctoSDKMessages.getString(PROJECT_SPECIFIC_GROUP_TITLE)); | ||
| 52 | |||
| 53 | btnUseProjectSpecificSettingsCheckbox = new Button(storeYoctoConfigurationsGroup, SWT.CHECK); | ||
| 54 | btnUseProjectSpecificSettingsCheckbox.setText(YoctoSDKMessages.getString(PROJECT_SPECIFIC_TITLE)); | ||
| 55 | btnUseProjectSpecificSettingsCheckbox.addSelectionListener(new SelectionListener() { | ||
| 56 | @Override | ||
| 57 | public void widgetSelected(SelectionEvent e) { | ||
| 58 | if (btnUseProjectSpecificSettingsCheckbox.getSelection()){ | ||
| 59 | yoctoConfigurationsSetting.setUIFormEnabledState(false); | ||
| 60 | yoctoUISetting.setUIFormEnabledState(true); | ||
| 61 | |||
| 62 | if (preferencePage instanceof YoctoSDKProjectPropertyPage) { | ||
| 63 | ((YoctoSDKProjectPropertyPage) preferencePage).switchToProjectSpecificProfile(); | ||
| 64 | } | ||
| 65 | } else { | ||
| 66 | yoctoConfigurationsSetting.setUIFormEnabledState(true); | ||
| 67 | yoctoConfigurationsSetting.setButtonsEnabledState(false); | ||
| 68 | yoctoUISetting.setUIFormEnabledState(false); | ||
| 69 | |||
| 70 | if (preferencePage instanceof YoctoSDKProjectPropertyPage) { | ||
| 71 | ((YoctoSDKProjectPropertyPage) preferencePage).switchToSelectedProfile(); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | @Override | ||
| 77 | public void widgetDefaultSelected(SelectionEvent e) {} | ||
| 78 | }); | ||
| 79 | } | ||
| 80 | |||
| 81 | public void setUseProjectSpecificSettings(boolean isUsingProjectSpecificSettings) { | ||
| 82 | btnUseProjectSpecificSettingsCheckbox.setSelection(isUsingProjectSpecificSettings); | ||
| 83 | } | ||
| 84 | |||
| 85 | public boolean isUsingProjectSpecificSettings() { | ||
| 86 | return btnUseProjectSpecificSettingsCheckbox.getSelection(); | ||
| 87 | } | ||
| 88 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKChecker.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKChecker.java new file mode 100644 index 0000000..714470b --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKChecker.java | |||
| @@ -0,0 +1,291 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
| 4 | * | ||
| 5 | * All rights reserved. This program and the accompanying materials | ||
| 6 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 7 | * which accompanies this distribution, and is available at | ||
| 8 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 9 | * | ||
| 10 | * Contributors: | ||
| 11 | * Intel - initial API and implementation | ||
| 12 | * BMW Car IT - include error and advice messages with check results | ||
| 13 | *******************************************************************************/ | ||
| 14 | package org.yocto.sdk.ide; | ||
| 15 | |||
| 16 | import java.io.BufferedReader; | ||
| 17 | import java.io.File; | ||
| 18 | import java.io.FileReader; | ||
| 19 | import java.io.FilenameFilter; | ||
| 20 | import java.io.IOException; | ||
| 21 | import java.io.InputStream; | ||
| 22 | import java.io.InputStreamReader; | ||
| 23 | |||
| 24 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 25 | import org.yocto.sdk.ide.natures.YoctoSDKProjectNature; | ||
| 26 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 27 | import org.yocto.sdk.ide.utils.YoctoSDKUtilsConstants; | ||
| 28 | |||
| 29 | public class YoctoSDKChecker { | ||
| 30 | private static final String[] saInvalidVer = {"1.0", "0.9", "0.9+"}; | ||
| 31 | private static final String SYSROOTS_DIR = "sysroots"; | ||
| 32 | private static final String SDK_VERSION = "OECORE_SDK_VERSION"; | ||
| 33 | |||
| 34 | public static enum SDKCheckResults { | ||
| 35 | SDK_PASS("", false), | ||
| 36 | TOOLCHAIN_LOCATION_EMPTY( | ||
| 37 | "Poky.SDK.Location.Empty", true), | ||
| 38 | TOOLCHAIN_LOCATION_NONEXIST( | ||
| 39 | "Poky.SDK.Location.Nonexist", true), | ||
| 40 | SDK_TARGET_EMPTY( | ||
| 41 | "Poky.SDK.Target.Empty", true), | ||
| 42 | SDK_NO_TARGET_SELECTED( | ||
| 43 | "Poky.SDK.No.Target.Selected", false), | ||
| 44 | SYSROOT_EMPTY( | ||
| 45 | "Poky.Sysroot.Empty", true), | ||
| 46 | SYSROOT_NONEXIST( | ||
| 47 | "Poky.Sysroot.Nonexist", true), | ||
| 48 | QEMU_KERNEL_EMPTY( | ||
| 49 | "Poky.Qemu.Kernel.Empty", true), | ||
| 50 | QEMU_KERNEL_NONEXIST( | ||
| 51 | "Poky.Qemu.Kernel.Nonexist", true), | ||
| 52 | WRONG_ADT_VERSION( | ||
| 53 | "Poky.ADT.Sysroot.Wrongversion", false), | ||
| 54 | ENV_SETUP_SCRIPT_NONEXIST( | ||
| 55 | "Poky.Env.Script.Nonexist", false), | ||
| 56 | TOOLCHAIN_NO_SYSROOT( | ||
| 57 | "Poky.Toolchain.No.Sysroot", false), | ||
| 58 | TOOLCHAIN_HOST_MISMATCH( | ||
| 59 | "Poky.Toolchain.Host.Mismatch", false); | ||
| 60 | |||
| 61 | private static final String DEFAULT_ADVICE = "Default.Advice"; | ||
| 62 | private static final String ADVICE_SUFFIX = ".Advice"; | ||
| 63 | |||
| 64 | private final String messageID; | ||
| 65 | private final boolean addDefaultAdvice; | ||
| 66 | |||
| 67 | private SDKCheckResults(final String messageID, final boolean addDefaultAdvice) { | ||
| 68 | this.messageID = messageID; | ||
| 69 | this.addDefaultAdvice = addDefaultAdvice; | ||
| 70 | } | ||
| 71 | |||
| 72 | public String getMessage() { | ||
| 73 | return YoctoSDKMessages.getString(messageID); | ||
| 74 | } | ||
| 75 | |||
| 76 | public String getAdvice() { | ||
| 77 | String advice = YoctoSDKMessages.getString(messageID + ADVICE_SUFFIX); | ||
| 78 | |||
| 79 | if (addDefaultAdvice) { | ||
| 80 | advice += YoctoSDKMessages.getString(DEFAULT_ADVICE); | ||
| 81 | } | ||
| 82 | |||
| 83 | return advice; | ||
| 84 | } | ||
| 85 | }; | ||
| 86 | |||
| 87 | public static enum SDKCheckRequestFrom { | ||
| 88 | Wizard("Poky.SDK.Error.Origin.Wizard"), | ||
| 89 | Menu("Poky.SDK.Error.Origin.Menu"), | ||
| 90 | Preferences("Poky.SDK.Error.Origin.Preferences"), | ||
| 91 | Other("Poky.SDK.Error.Origin.Other"); | ||
| 92 | |||
| 93 | private final String errorMessageID; | ||
| 94 | |||
| 95 | private SDKCheckRequestFrom(final String errorMessageID) { | ||
| 96 | this.errorMessageID = errorMessageID; | ||
| 97 | } | ||
| 98 | |||
| 99 | public String getErrorMessage() { | ||
| 100 | return YoctoSDKMessages.getString(errorMessageID); | ||
| 101 | } | ||
| 102 | }; | ||
| 103 | |||
| 104 | public static void checkIfGloballySelectedYoctoProfileIsValid() throws YoctoGeneralException { | ||
| 105 | YoctoProfileElement profileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 106 | IPreferenceStore selectedProfileStore = YoctoSDKPlugin.getProfilePreferenceStore(profileElement.getSelectedProfile()); | ||
| 107 | YoctoUIElement elem = YoctoSDKUtils.getElemFromStore(selectedProfileStore); | ||
| 108 | |||
| 109 | SDKCheckResults result = checkYoctoSDK(elem); | ||
| 110 | if (result != SDKCheckResults.SDK_PASS){ | ||
| 111 | String strErrorMsg = getErrorMessage(result, SDKCheckRequestFrom.Wizard); | ||
| 112 | throw new YoctoGeneralException(strErrorMsg); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | public static SDKCheckResults checkYoctoSDK(YoctoUIElement elem) { | ||
| 117 | if (elem.getStrToolChainRoot().isEmpty()) | ||
| 118 | return SDKCheckResults.TOOLCHAIN_LOCATION_EMPTY; | ||
| 119 | else { | ||
| 120 | File fToolChain = new File(elem.getStrToolChainRoot()); | ||
| 121 | if (!fToolChain.exists()) | ||
| 122 | return SDKCheckResults.TOOLCHAIN_LOCATION_NONEXIST; | ||
| 123 | } | ||
| 124 | |||
| 125 | if (elem.getStrSysrootLoc().isEmpty()) { | ||
| 126 | return SDKCheckResults.SYSROOT_EMPTY; | ||
| 127 | } else { | ||
| 128 | File fSysroot = new File(elem.getStrSysrootLoc()); | ||
| 129 | if (!fSysroot.exists()) | ||
| 130 | return SDKCheckResults.SYSROOT_NONEXIST; | ||
| 131 | } | ||
| 132 | |||
| 133 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
| 134 | //Check for SDK compatible with the host arch | ||
| 135 | String platform = getPlatformArch(); | ||
| 136 | String sysroot_dir_str = elem.getStrToolChainRoot() + "/" + SYSROOTS_DIR; | ||
| 137 | File sysroot_dir = new File(sysroot_dir_str); | ||
| 138 | if (!sysroot_dir.exists()) | ||
| 139 | return SDKCheckResults.TOOLCHAIN_NO_SYSROOT; | ||
| 140 | |||
| 141 | String toolchain_host_arch = null; | ||
| 142 | |||
| 143 | try { | ||
| 144 | toolchain_host_arch = findHostArch(sysroot_dir); | ||
| 145 | } catch(NullPointerException e) { | ||
| 146 | return SDKCheckResults.TOOLCHAIN_NO_SYSROOT; | ||
| 147 | } | ||
| 148 | |||
| 149 | if (!toolchain_host_arch.equalsIgnoreCase(platform)) { | ||
| 150 | if (!platform.matches("i\\d86") || !toolchain_host_arch.matches("i\\d86")) | ||
| 151 | return SDKCheckResults.TOOLCHAIN_HOST_MISMATCH; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | if (elem.getStrTarget().isEmpty() && elem.getStrTargetsArray().length > 0) { | ||
| 156 | return SDKCheckResults.SDK_NO_TARGET_SELECTED; | ||
| 157 | } | ||
| 158 | |||
| 159 | if (elem.getIntTargetIndex() < 0 || elem.getStrTarget().isEmpty()) { | ||
| 160 | //if this is poky tree mode, prompt user whether bitbake meta-ide-support is executed? | ||
| 161 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_TREE_MODE) | ||
| 162 | return SDKCheckResults.ENV_SETUP_SCRIPT_NONEXIST; | ||
| 163 | else | ||
| 164 | return SDKCheckResults.SDK_TARGET_EMPTY; | ||
| 165 | } else { | ||
| 166 | String sFileName; | ||
| 167 | |||
| 168 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
| 169 | sFileName = elem.getStrToolChainRoot()+"/" + YoctoSDKUtilsConstants.DEFAULT_ENV_FILE_PREFIX + elem.getStrTarget(); | ||
| 170 | } else { | ||
| 171 | //POKY TREE Mode | ||
| 172 | sFileName = elem.getStrToolChainRoot() + YoctoSDKUtilsConstants.DEFAULT_TMP_PREFIX + | ||
| 173 | YoctoSDKUtilsConstants.DEFAULT_ENV_FILE_PREFIX + elem.getStrTarget(); | ||
| 174 | } | ||
| 175 | |||
| 176 | try { | ||
| 177 | File file = new File(sFileName); | ||
| 178 | boolean bVersion = false; | ||
| 179 | |||
| 180 | if (file.exists()) { | ||
| 181 | BufferedReader input = new BufferedReader(new FileReader(file)); | ||
| 182 | |||
| 183 | try { | ||
| 184 | String line = null; | ||
| 185 | |||
| 186 | while ((line = input.readLine()) != null) { | ||
| 187 | if (line.startsWith("export "+ SDK_VERSION)) { | ||
| 188 | int beginIndex = 2; | ||
| 189 | String sVersion = ""; | ||
| 190 | for (;;) { | ||
| 191 | char cValue = line.charAt(line.indexOf('=') + beginIndex++); | ||
| 192 | |||
| 193 | if ((cValue != '.') && (!Character.isDigit(cValue)) && (cValue != '+')) | ||
| 194 | break; | ||
| 195 | else | ||
| 196 | sVersion += String.valueOf(cValue); | ||
| 197 | } | ||
| 198 | |||
| 199 | for (int i = 0; i < saInvalidVer.length; i++) { | ||
| 200 | if (!sVersion.equals(saInvalidVer[i])) { | ||
| 201 | bVersion = true; | ||
| 202 | break; | ||
| 203 | } | ||
| 204 | } | ||
| 205 | |||
| 206 | break; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | } finally { | ||
| 210 | input.close(); | ||
| 211 | } | ||
| 212 | |||
| 213 | if (!bVersion) | ||
| 214 | return SDKCheckResults.WRONG_ADT_VERSION; | ||
| 215 | } | ||
| 216 | } catch (IOException e) { | ||
| 217 | e.printStackTrace(); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | if (elem.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) { | ||
| 222 | if (elem.getStrQemuKernelLoc().isEmpty()) { | ||
| 223 | return SDKCheckResults.QEMU_KERNEL_EMPTY; | ||
| 224 | } else { | ||
| 225 | File fQemuKernel = new File(elem.getStrQemuKernelLoc()); | ||
| 226 | if (!fQemuKernel.exists()) | ||
| 227 | return SDKCheckResults.QEMU_KERNEL_NONEXIST; | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | return SDKCheckResults.SDK_PASS; | ||
| 232 | } | ||
| 233 | |||
| 234 | public static String getErrorMessage(SDKCheckResults result, SDKCheckRequestFrom from) { | ||
| 235 | String strErrorMsg; | ||
| 236 | strErrorMsg = from.getErrorMessage(); | ||
| 237 | strErrorMsg += "\n" + result.getMessage(); | ||
| 238 | strErrorMsg += "\n" + result.getAdvice(); | ||
| 239 | |||
| 240 | return strErrorMsg; | ||
| 241 | } | ||
| 242 | |||
| 243 | private static String getPlatformArch() { | ||
| 244 | String value = null; | ||
| 245 | try | ||
| 246 | { | ||
| 247 | Runtime rt = Runtime.getRuntime(); | ||
| 248 | Process proc = rt.exec("uname -m"); | ||
| 249 | InputStream stdin = proc.getInputStream(); | ||
| 250 | InputStreamReader isr = new InputStreamReader(stdin); | ||
| 251 | BufferedReader br = new BufferedReader(isr); | ||
| 252 | String line = null; | ||
| 253 | |||
| 254 | while ( (line = br.readLine()) != null) { | ||
| 255 | value = line; | ||
| 256 | } | ||
| 257 | proc.waitFor(); | ||
| 258 | |||
| 259 | } catch (Throwable t) { | ||
| 260 | t.printStackTrace(); | ||
| 261 | } | ||
| 262 | return value; | ||
| 263 | } | ||
| 264 | |||
| 265 | private static String findHostArch(File sysroot_dir) { | ||
| 266 | FilenameFilter nativeFilter = new FilenameFilter() { | ||
| 267 | public boolean accept(File dir, String name) { | ||
| 268 | if (name.endsWith("sdk-linux")) { | ||
| 269 | return true; | ||
| 270 | } else { | ||
| 271 | return false; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | }; | ||
| 275 | |||
| 276 | File[] files = sysroot_dir.listFiles(nativeFilter); | ||
| 277 | String arch = null; | ||
| 278 | |||
| 279 | for (File file : files) { | ||
| 280 | if (file.isDirectory()) { | ||
| 281 | String path = file.getName(); | ||
| 282 | String[] subPath = path.split("-"); | ||
| 283 | arch = subPath[0]; | ||
| 284 | } else { | ||
| 285 | continue; | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
| 289 | return arch; | ||
| 290 | } | ||
| 291 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.java new file mode 100644 index 0000000..8fe40d3 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.java | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import java.text.MessageFormat; | ||
| 14 | import java.util.MissingResourceException; | ||
| 15 | import java.util.ResourceBundle; | ||
| 16 | |||
| 17 | public class YoctoSDKMessages { | ||
| 18 | private static final String RESOURCE_BUNDLE= YoctoSDKMessages.class.getName(); | ||
| 19 | private static ResourceBundle fgResourceBundle; | ||
| 20 | static { | ||
| 21 | try { | ||
| 22 | fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE); | ||
| 23 | } catch (MissingResourceException x) { | ||
| 24 | fgResourceBundle = null; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | private YoctoSDKMessages() { | ||
| 29 | } | ||
| 30 | |||
| 31 | public static String getString(String key) { | ||
| 32 | try { | ||
| 33 | return fgResourceBundle.getString(key); | ||
| 34 | } catch (MissingResourceException e) { | ||
| 35 | return '!' + key + '!'; | ||
| 36 | } catch (NullPointerException e) { | ||
| 37 | return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$ | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Gets a string from the resource bundle and formats it with the argument | ||
| 43 | * | ||
| 44 | * @param key the string used to get the bundle value, must not be null | ||
| 45 | */ | ||
| 46 | public static String getFormattedString(String key, Object arg) { | ||
| 47 | return MessageFormat.format(getString(key), new Object[] { arg }); | ||
| 48 | } | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Gets a string from the resource bundle and formats it with arguments | ||
| 52 | */ | ||
| 53 | public static String getFormattedString(String key, Object[] args) { | ||
| 54 | return MessageFormat.format(getString(key), args); | ||
| 55 | } | ||
| 56 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties new file mode 100644 index 0000000..e3f3308 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | * BMW Car IT - added keys for target profiles | ||
| 11 | *******************************************************************************/ | ||
| 12 | Wizard.SDK.Warning.Title = Invalid Yocto Project ADT Location | ||
| 13 | Wizard.SDK.Error.ProjectName = Project name "{0}" is invalid! \nNone of these characters are accepted inside project names: whitespaces, {1} | ||
| 14 | |||
| 15 | Poky.SDK.Location.Empty = Specified Toolchain Root Location is empty. | ||
| 16 | Poky.SDK.Location.Empty.Advice = You need specify Toolchain Root Location before building any project. | ||
| 17 | Poky.SDK.Location.Nonexist = Specified SDK toolchain directory does not exist. | ||
| 18 | Poky.SDK.Location.Nonexist.Advice = Please specify a valid toolchain directory. | ||
| 19 | Poky.SDK.Target.Empty = Specified location does not contain environment script file. | ||
| 20 | Poky.SDK.Target.Empty.Advice = You need specify Target Architecture before building any project. | ||
| 21 | Poky.SDK.No.Target.Selected = Target Architecture is not defined. | ||
| 22 | Poky.SDK.No.Target.Selected.Advice = Please choose a Target Architecture. | ||
| 23 | Poky.Sysroot.Empty = Specified Sysroot Location is empty. | ||
| 24 | Poky.Sysroot.Empty.Advice = You need specify Sysroot Location before building any project. | ||
| 25 | Poky.Sysroot.Nonexist = Specified Sysroot Location does not exist. | ||
| 26 | Poky.Sysroot.Nonexist.Advice = You need specify a valid Sysroot Location before building any project. | ||
| 27 | Poky.Qemu.Kernel.Empty = Specified QEMU kernel location is emtpy. | ||
| 28 | Poky.Qemu.Kernel.Empty.Advice = You need specify QEMU kernel image file Location before building any project. | ||
| 29 | Poky.Qemu.Kernel.Nonexist = Specified QEMU kernel image file does not exist. | ||
| 30 | Poky.Qemu.Kernel.Empty.Advice = You need specify a valid QEMU kernel image file before building any project. | ||
| 31 | Poky.ADT.Sysroot.Wrongversion = The ADT version you're using is too old. | ||
| 32 | Poky.ADT.Sysroot.Wrongversion.Advice = OECORE related items are not found in environment setup files.\nPlease upgrade to our latest ADT Version! | ||
| 33 | Poky.Env.Script.Nonexist = Specified toolchain directory does not contain a toolchain generated with "bitbake meta-ide-support". | ||
| 34 | Poky.Env.Script.Nonexist.Advice = Please run "bitbake meta-ide-support" to build the toolchain. | ||
| 35 | Poky.Toolchain.No.Sysroot = Specified Toolchain Root Location does not contain a sysroot directory. | ||
| 36 | Poky.Toolchain.No.Sysroot.Advice = Please install a valid toolchain sysroot. | ||
| 37 | Poky.Toolchain.Host.Mismatch = Toolchain and host arch mismatch. | ||
| 38 | Poky.Toolchain.Host.Mismatch.Advice = Make sure you use 32bit toolchain for 32bit host and same for 64bit machines! | ||
| 39 | |||
| 40 | Default.Advice = \nDo IDE-wide settings from Window > Preferences > Yocto Project ADT\nOr do Project-wide settings from Project > Change Yocto Project Settings. | ||
| 41 | Poky.SDK.Revalidation.Message = Please apply the changes to revalidate. | ||
| 42 | |||
| 43 | Poky.SDK.Error.Origin.Wizard = Yocto Wizard Configuration Error: | ||
| 44 | Poky.SDK.Error.Origin.Menu = Yocto Menu Configuration Error: | ||
| 45 | Poky.SDK.Error.Origin.Preferences = Yocto Preferences Configuration Error: | ||
| 46 | Poky.SDK.Error.Origin.Other = Yocto Configuration Error: | ||
| 47 | |||
| 48 | Menu.SDK.Console.Configure.Message = The Yocto Project ADT has been successfully set up for this project.\nTo see the environment variables created during setup,\ngo to Project > Properties > C/C++ Build > Environment. | ||
| 49 | Menu.SDK.Console.Deploy.Action.Message = \nDeploying {0} to {1} ...\n | ||
| 50 | Menu.SDK.Console.Deploy.Extract.Message = \nExtracting {0} into {1} ...\n | ||
| 51 | Menu.SDK.Console.Deploy.Success.Message = \nThe project {0} has been successfully deployed to {1}\n | ||
| 52 | Menu.SDK.Console.Deploy.Fail.Message = \nDeploying the project {0} to {1} failed!\n | ||
| 53 | Menu.SDK.Console.Undeploy.Success.Message = \nThe project {0} has been successfully undeployed from {1}\n | ||
| 54 | Menu.SDK.Console.Undeploy.Fail.Message = \nUndeploying the project {0} from {1} failed!\n | ||
| 55 | |||
| 56 | |||
| 57 | Menu.Deploy.Title = Deploy {0} to ... | ||
| 58 | Menu.Deploy.Message = Please specify a directory: | ||
| 59 | |||
| 60 | Menu.Undeploy.Title = Undeploy {0} from ... | ||
| 61 | Menu.Undeploy.Message = Please specify a directory: | ||
| 62 | |||
| 63 | |||
| 64 | Preferences.Yocto.Config.Name = Preferences: | ||
| 65 | Preferences.SDK.Target.name = Target Preferences: | ||
| 66 | Preferences.SDK.Informing.Title = Yocto Project ADT has been successfully set up. | ||
| 67 | Preferences.SDK.Informing.Message = You might need to reconfigure your existing Yocto Project Autotools Projects to use the Yocto Project ADT. Do this from Project > Reconfigure Project! | ||
| 68 | |||
| 69 | Preferences.Profile.Validator.InvalidName.Comma = Warning: The profile name cannot contain a comma (,). | ||
| 70 | Preferences.Profile.Validator.InvalidName.Quote = Warning: The profile name cannot contain a double quote (\"). | ||
| 71 | Preferences.Profile.Validator.InvalidName.Empty = Please provide a new profile name. | ||
| 72 | Preferences.Profile.Validator.InvalidName.Exists = Warning: The profile already exists. | ||
| 73 | |||
| 74 | Preferences.Profiles.Title = Cross development profiles: | ||
| 75 | Preferences.Profile.New.Title = Save as ... | ||
| 76 | Preferences.Profile.New.Dialog.Title = Save as new cross development profile | ||
| 77 | Preferences.Profile.New.Dialog.Message = Please input a profile name. | ||
| 78 | Preferences.Profile.Rename.Title = Rename | ||
| 79 | Preferences.Profile.Rename.Dialog.Title = Rename cross development profile | ||
| 80 | Preferences.Profile.Rename.Dialog.Message = Please input a new profile name. | ||
| 81 | Preferences.Profile.Remove.Title = Remove | ||
| 82 | Preferences.Profile.Remove.Dialog.Title = Remove cross development profile | ||
| 83 | Preferences.Profile.Remove.Dialog.Message = Do you really want to the remove the cross development profile "{0}"?\nProjects using this cross development profile will be reconfigured to use the standard profile. | ||
| 84 | Preferences.Profile.Update.Dialog.Title = Update cross development profile | ||
| 85 | Preferences.Profile.Update.Dialog.Message = Do you really want to the update the cross development profile "{0}"?\nProjects using this cross development profile will be reconfigured. | ||
| 86 | Preferences.Profile.Standard.Modification.Title = Modify standard cross development profile | ||
| 87 | Preferences.Profile.Standard.Modification.Message = Standard cross development profile cannot be removed or renamed. | ||
| 88 | |||
| 89 | Preferences.Profile.ProjectSpecific.Title = Use project specific settings | ||
| 90 | Preferences.Profile.ProjectSpecific.Group.Title = Project specific settings: | ||
| 91 | Preferences.Profile.ProjectSpecific.Profile.Label = Project specific profile | ||
| 92 | |||
| 93 | Preferences.Profile.ProjectSpecific.Error.Title = Could not change to project specific target profile | ||
| 94 | Preferences.Profile.ProjectSpecific.Error.Message = The project specific target profile is not defined for the project "{0}".\nYou can define it in the project's property page. | ||
| 95 | |||
| 96 | Console.SDK.Name = Yocto Project Console | ||
| 97 | |||
| 98 | LaunchConfig.Type.Name = org.eclipse.ui.externaltools.ProgramLaunchConfigurationType | ||
| 99 | LaunchConfig.LaunchGroup.Value = org.eclipse.ui.externaltools.launchGroup | ||
| 100 | LaunchConfig.LaunchGroup.Attr = org.eclipse.debug.ui.favoriteGroups | ||
| 101 | LaunchConfig.BuildScope.Attr = org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE | ||
| 102 | LaunchConfig.BuildScope.Value = ${projects:} | ||
| 103 | LaunchConfig.Location.Attr = org.eclipse.ui.externaltools.ATTR_LOCATION | ||
| 104 | LaunchConfig.Arguments.Attr = org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS; | ||
| 105 | |||
| 106 | AutotoolsProjectPostProcess.WrongProjectNature = {0} is not an Autotools project | ||
| 107 | AutotoolsProjectPostProcess.ChmodFailure = Failed to make autogen.sh executable for project: {0} | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKPlugin.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKPlugin.java new file mode 100644 index 0000000..9777396 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKPlugin.java | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import java.lang.reflect.InvocationTargetException; | ||
| 14 | |||
| 15 | import org.eclipse.core.resources.ResourcesPlugin; | ||
| 16 | import org.eclipse.core.runtime.CoreException; | ||
| 17 | import org.eclipse.core.runtime.IStatus; | ||
| 18 | import org.eclipse.core.runtime.Status; | ||
| 19 | import org.eclipse.core.runtime.preferences.InstanceScope; | ||
| 20 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 21 | import org.eclipse.swt.widgets.Shell; | ||
| 22 | import org.eclipse.ui.IWorkbenchWindow; | ||
| 23 | import org.eclipse.ui.plugin.AbstractUIPlugin; | ||
| 24 | import org.eclipse.ui.preferences.ScopedPreferenceStore; | ||
| 25 | import org.osgi.framework.BundleContext; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * The activator class controls the plug-in life cycle | ||
| 29 | */ | ||
| 30 | public class YoctoSDKPlugin extends AbstractUIPlugin { | ||
| 31 | |||
| 32 | // The plug-in ID | ||
| 33 | public static final String PLUGIN_ID = "org.yocto.sdk.ide"; | ||
| 34 | |||
| 35 | // The shared instance | ||
| 36 | private static YoctoSDKPlugin plugin; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * The constructor | ||
| 40 | */ | ||
| 41 | public YoctoSDKPlugin() { | ||
| 42 | } | ||
| 43 | |||
| 44 | /* | ||
| 45 | * (non-Javadoc) | ||
| 46 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) | ||
| 47 | */ | ||
| 48 | public void start(BundleContext context) throws Exception { | ||
| 49 | super.start(context); | ||
| 50 | plugin = this; | ||
| 51 | } | ||
| 52 | |||
| 53 | /* | ||
| 54 | * (non-Javadoc) | ||
| 55 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) | ||
| 56 | */ | ||
| 57 | public void stop(BundleContext context) throws Exception { | ||
| 58 | plugin = null; | ||
| 59 | super.stop(context); | ||
| 60 | } | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Returns the shared instance | ||
| 64 | * | ||
| 65 | * @return the shared instance | ||
| 66 | */ | ||
| 67 | public static YoctoSDKPlugin getDefault() { | ||
| 68 | return plugin; | ||
| 69 | } | ||
| 70 | |||
| 71 | public static IPreferenceStore getProfilePreferenceStore(String profileName) { | ||
| 72 | int profileIdentifier = profileName.hashCode(); | ||
| 73 | |||
| 74 | return new ScopedPreferenceStore(InstanceScope.INSTANCE,getUniqueIdentifier() + "." + profileIdentifier); | ||
| 75 | } | ||
| 76 | |||
| 77 | public static void log(IStatus status) { | ||
| 78 | ResourcesPlugin.getPlugin().getLog().log(status); | ||
| 79 | } | ||
| 80 | |||
| 81 | public static void log(Throwable e) { | ||
| 82 | if (e instanceof InvocationTargetException) | ||
| 83 | e = ((InvocationTargetException) e).getTargetException(); | ||
| 84 | IStatus status = null; | ||
| 85 | if (e instanceof CoreException) | ||
| 86 | status = ((CoreException) e).getStatus(); | ||
| 87 | else | ||
| 88 | status = new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.OK, e.getMessage(), e); | ||
| 89 | log(status); | ||
| 90 | } | ||
| 91 | |||
| 92 | public static void logErrorMessage(String message) { | ||
| 93 | log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null)); | ||
| 94 | } | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Returns active shell. | ||
| 98 | */ | ||
| 99 | public static Shell getActiveWorkbenchShell() { | ||
| 100 | IWorkbenchWindow window = getDefault().getWorkbench().getActiveWorkbenchWindow(); | ||
| 101 | if (window != null) { | ||
| 102 | return window.getShell(); | ||
| 103 | } | ||
| 104 | return null; | ||
| 105 | } | ||
| 106 | |||
| 107 | public static String getUniqueIdentifier() { | ||
| 108 | if (getDefault() == null) { | ||
| 109 | // If the default instance is not yet initialized, | ||
| 110 | // return a static identifier. This identifier must | ||
| 111 | // match the plugin id defined in plugin.xml | ||
| 112 | return PLUGIN_ID; | ||
| 113 | } | ||
| 114 | return getDefault().getBundle().getSymbolicName(); | ||
| 115 | } | ||
| 116 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoUIElement.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoUIElement.java new file mode 100644 index 0000000..de3e905 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoUIElement.java | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | public class YoctoUIElement { | ||
| 14 | public enum PokyMode | ||
| 15 | { | ||
| 16 | POKY_SDK_MODE, | ||
| 17 | POKY_TREE_MODE | ||
| 18 | }; | ||
| 19 | public enum DeviceMode | ||
| 20 | { | ||
| 21 | QEMU_MODE, | ||
| 22 | DEVICE_MODE | ||
| 23 | }; | ||
| 24 | |||
| 25 | private String strTarget; | ||
| 26 | private String[] strTargetsArray; | ||
| 27 | private DeviceMode enumDeviceMode; | ||
| 28 | private String strQemuKernelLoc; | ||
| 29 | private String strQemuOption; | ||
| 30 | private String strSysrootLoc; | ||
| 31 | private PokyMode enumPokyMode; | ||
| 32 | private String strToolChainRoot; | ||
| 33 | private int intTargetIndex; | ||
| 34 | |||
| 35 | public YoctoUIElement() | ||
| 36 | { | ||
| 37 | this.enumDeviceMode = DeviceMode.QEMU_MODE; | ||
| 38 | this.enumPokyMode = PokyMode.POKY_SDK_MODE; | ||
| 39 | this.strToolChainRoot = ""; | ||
| 40 | this.strQemuKernelLoc = ""; | ||
| 41 | this.strQemuOption = ""; | ||
| 42 | this.strSysrootLoc = ""; | ||
| 43 | this.intTargetIndex = -1; | ||
| 44 | this.strTarget = ""; | ||
| 45 | } | ||
| 46 | |||
| 47 | public PokyMode getEnumPokyMode() { | ||
| 48 | return enumPokyMode; | ||
| 49 | } | ||
| 50 | public void setEnumPokyMode(PokyMode enumPokyMode) { | ||
| 51 | this.enumPokyMode = enumPokyMode; | ||
| 52 | } | ||
| 53 | public String getStrToolChainRoot() { | ||
| 54 | return strToolChainRoot; | ||
| 55 | } | ||
| 56 | public void setStrToolChainRoot(String strToolChainRoot) { | ||
| 57 | this.strToolChainRoot = strToolChainRoot; | ||
| 58 | } | ||
| 59 | public int getIntTargetIndex() { | ||
| 60 | if ((this.strTargetsArray != null) && (this.strTargetsArray.length == 1)) | ||
| 61 | return 0; | ||
| 62 | return intTargetIndex; | ||
| 63 | } | ||
| 64 | public void setIntTargetIndex(int intTargetIndex) { | ||
| 65 | this.intTargetIndex = intTargetIndex; | ||
| 66 | } | ||
| 67 | public String getStrTarget() { | ||
| 68 | return strTarget; | ||
| 69 | } | ||
| 70 | public void setStrTarget(String strTarget) { | ||
| 71 | this.strTarget = strTarget; | ||
| 72 | } | ||
| 73 | public String[] getStrTargetsArray() { | ||
| 74 | return strTargetsArray; | ||
| 75 | } | ||
| 76 | public void setStrTargetsArray(String[] strTargetsArray) { | ||
| 77 | this.strTargetsArray = strTargetsArray; | ||
| 78 | } | ||
| 79 | public DeviceMode getEnumDeviceMode() { | ||
| 80 | return enumDeviceMode; | ||
| 81 | } | ||
| 82 | public void setEnumDeviceMode(DeviceMode enumDeviceMode) { | ||
| 83 | this.enumDeviceMode = enumDeviceMode; | ||
| 84 | } | ||
| 85 | public String getStrQemuKernelLoc() { | ||
| 86 | return strQemuKernelLoc; | ||
| 87 | } | ||
| 88 | public void setStrQemuKernelLoc(String strQemuKernelLoc) { | ||
| 89 | this.strQemuKernelLoc = strQemuKernelLoc; | ||
| 90 | } | ||
| 91 | public String getStrQemuOption() { | ||
| 92 | return strQemuOption; | ||
| 93 | } | ||
| 94 | public void setStrQemuOption(String strQemuOption) { | ||
| 95 | this.strQemuOption = strQemuOption; | ||
| 96 | } | ||
| 97 | public String getStrSysrootLoc() { | ||
| 98 | return strSysrootLoc; | ||
| 99 | } | ||
| 100 | public void setStrSysrootLoc(String strSysrootLoc) { | ||
| 101 | this.strSysrootLoc = strSysrootLoc; | ||
| 102 | } | ||
| 103 | |||
| 104 | @Override | ||
| 105 | public int hashCode() { | ||
| 106 | final int prime = 31; | ||
| 107 | int result = 1; | ||
| 108 | result = prime * result + ((enumDeviceMode == null) ? 0 : enumDeviceMode.hashCode()); | ||
| 109 | result = prime * result + ((enumPokyMode == null) ? 0 : enumPokyMode.hashCode()); | ||
| 110 | result = prime * result + intTargetIndex; | ||
| 111 | result = prime * result + ((strQemuKernelLoc == null) ? 0 : strQemuKernelLoc.hashCode()); | ||
| 112 | result = prime * result + ((strQemuOption == null) ? 0 : strQemuOption.hashCode()); | ||
| 113 | result = prime * result + ((strSysrootLoc == null) ? 0 : strSysrootLoc.hashCode()); | ||
| 114 | result = prime * result + ((strTarget == null) ? 0 : strTarget.hashCode()); | ||
| 115 | result = prime * result + ((strToolChainRoot == null) ? 0 : strToolChainRoot.hashCode()); | ||
| 116 | return result; | ||
| 117 | } | ||
| 118 | |||
| 119 | @Override | ||
| 120 | public boolean equals(Object obj) { | ||
| 121 | if (this == obj) | ||
| 122 | return true; | ||
| 123 | if (obj == null) | ||
| 124 | return false; | ||
| 125 | if (getClass() != obj.getClass()) | ||
| 126 | return false; | ||
| 127 | YoctoUIElement other = (YoctoUIElement) obj; | ||
| 128 | if (enumDeviceMode != other.enumDeviceMode) | ||
| 129 | return false; | ||
| 130 | if (enumPokyMode != other.enumPokyMode) | ||
| 131 | return false; | ||
| 132 | if (intTargetIndex != other.intTargetIndex) | ||
| 133 | return false; | ||
| 134 | if (strQemuKernelLoc == null) { | ||
| 135 | if (other.strQemuKernelLoc != null) | ||
| 136 | return false; | ||
| 137 | } else if (!strQemuKernelLoc.equals(other.strQemuKernelLoc)) | ||
| 138 | return false; | ||
| 139 | if (strQemuOption == null) { | ||
| 140 | if (other.strQemuOption != null) | ||
| 141 | return false; | ||
| 142 | } else if (!strQemuOption.equals(other.strQemuOption)) | ||
| 143 | return false; | ||
| 144 | if (strSysrootLoc == null) { | ||
| 145 | if (other.strSysrootLoc != null) | ||
| 146 | return false; | ||
| 147 | } else if (!strSysrootLoc.equals(other.strSysrootLoc)) | ||
| 148 | return false; | ||
| 149 | if (strTarget == null) { | ||
| 150 | if (other.strTarget != null) | ||
| 151 | return false; | ||
| 152 | } else if (!strTarget.equals(other.strTarget)) | ||
| 153 | return false; | ||
| 154 | if (strToolChainRoot == null) { | ||
| 155 | if (other.strToolChainRoot != null) | ||
| 156 | return false; | ||
| 157 | } else if (!strToolChainRoot.equals(other.strToolChainRoot)) | ||
| 158 | return false; | ||
| 159 | return true; | ||
| 160 | } | ||
| 161 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoUISetting.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoUISetting.java new file mode 100644 index 0000000..d192538 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoUISetting.java | |||
| @@ -0,0 +1,555 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide; | ||
| 12 | |||
| 13 | import java.io.File; | ||
| 14 | import java.util.ArrayList; | ||
| 15 | |||
| 16 | import org.eclipse.cdt.ui.templateengine.uitree.InputUIElement; | ||
| 17 | import org.eclipse.core.runtime.Status; | ||
| 18 | import org.eclipse.jface.dialogs.ErrorDialog; | ||
| 19 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 20 | import org.eclipse.swt.SWT; | ||
| 21 | import org.eclipse.swt.events.ModifyEvent; | ||
| 22 | import org.eclipse.swt.events.ModifyListener; | ||
| 23 | import org.eclipse.swt.events.SelectionAdapter; | ||
| 24 | import org.eclipse.swt.events.SelectionEvent; | ||
| 25 | import org.eclipse.swt.events.SelectionListener; | ||
| 26 | import org.eclipse.swt.layout.GridData; | ||
| 27 | import org.eclipse.swt.layout.GridLayout; | ||
| 28 | import org.eclipse.swt.widgets.Button; | ||
| 29 | import org.eclipse.swt.widgets.Combo; | ||
| 30 | import org.eclipse.swt.widgets.Composite; | ||
| 31 | import org.eclipse.swt.widgets.Control; | ||
| 32 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
| 33 | import org.eclipse.swt.widgets.Display; | ||
| 34 | import org.eclipse.swt.widgets.Event; | ||
| 35 | import org.eclipse.swt.widgets.FileDialog; | ||
| 36 | import org.eclipse.swt.widgets.Group; | ||
| 37 | import org.eclipse.swt.widgets.Label; | ||
| 38 | import org.eclipse.swt.widgets.Text; | ||
| 39 | import org.eclipse.swt.widgets.Widget; | ||
| 40 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckRequestFrom; | ||
| 41 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
| 42 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
| 43 | |||
| 44 | public class YoctoUISetting { | ||
| 45 | private static final String ENV_SCRIPT_FILE_PREFIX = "environment-setup-"; | ||
| 46 | |||
| 47 | private SelectionListener fSelectionListener; | ||
| 48 | private ModifyListener fModifyListener; | ||
| 49 | private YoctoUIElement yoctoUIElement; | ||
| 50 | |||
| 51 | private Group crossCompilerGroup; | ||
| 52 | |||
| 53 | private Button btnSDKRoot; | ||
| 54 | private Button btnQemu; | ||
| 55 | private Button btnPokyRoot; | ||
| 56 | private Button btnDevice; | ||
| 57 | |||
| 58 | private Button btnKernelLoc; | ||
| 59 | private Button btnSysrootLoc; | ||
| 60 | private Button btnToolChainLoc; | ||
| 61 | |||
| 62 | private Text textKernelLoc; | ||
| 63 | private Text textQemuOption; | ||
| 64 | private Text textSysrootLoc; | ||
| 65 | private Text textRootLoc; | ||
| 66 | private Combo targetArchCombo; | ||
| 67 | |||
| 68 | private Label root_label; | ||
| 69 | private Label sysroot_label; | ||
| 70 | private Label targetArchLabel; | ||
| 71 | private Label kernel_label; | ||
| 72 | private Label option_label; | ||
| 73 | |||
| 74 | public YoctoUISetting(YoctoUIElement elem) | ||
| 75 | { | ||
| 76 | yoctoUIElement = elem; | ||
| 77 | elem.setStrTargetsArray(getTargetArray(elem)); | ||
| 78 | |||
| 79 | fSelectionListener= new SelectionListener() { | ||
| 80 | public void widgetDefaultSelected(SelectionEvent e) {} | ||
| 81 | |||
| 82 | public void widgetSelected(SelectionEvent e) { | ||
| 83 | controlChanged(e.widget); | ||
| 84 | relayEvent(e); | ||
| 85 | } | ||
| 86 | |||
| 87 | private void relayEvent(SelectionEvent e) { | ||
| 88 | Event event = new Event(); | ||
| 89 | event.data = e.data; | ||
| 90 | event.detail = e.detail; | ||
| 91 | event.display = e.display; | ||
| 92 | event.doit = e.doit; | ||
| 93 | event.height = e.height; | ||
| 94 | event.item = e.item; | ||
| 95 | event.stateMask = e.stateMask; | ||
| 96 | event.text = e.text; | ||
| 97 | event.time = e.time; | ||
| 98 | event.widget = e.widget; | ||
| 99 | event.width = e.width; | ||
| 100 | event.x = e.x; | ||
| 101 | event.y = e.y; | ||
| 102 | crossCompilerGroup.getParent().notifyListeners(SWT.Selection, event); | ||
| 103 | } | ||
| 104 | }; | ||
| 105 | |||
| 106 | fModifyListener= new ModifyListener() { | ||
| 107 | public void modifyText(ModifyEvent e) { | ||
| 108 | controlModified(e.widget); | ||
| 109 | relayEvent(e); | ||
| 110 | } | ||
| 111 | |||
| 112 | private void relayEvent(ModifyEvent e) { | ||
| 113 | Event event = new Event(); | ||
| 114 | event.data = e.data; | ||
| 115 | event.display = e.display; | ||
| 116 | event.time = e.time; | ||
| 117 | event.widget = e.widget; | ||
| 118 | crossCompilerGroup.getParent().notifyListeners(SWT.Modify, event); | ||
| 119 | } | ||
| 120 | }; | ||
| 121 | } | ||
| 122 | |||
| 123 | private Control addControls(Control fControl, final String sKey, String sValue) | ||
| 124 | { | ||
| 125 | fControl.setData(new String[]{sKey,sValue}); | ||
| 126 | return fControl; | ||
| 127 | } | ||
| 128 | |||
| 129 | private Control addRadioButton(Composite parent, String label, String key, boolean bSelected) { | ||
| 130 | GridData gd= new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
| 131 | String sValue; | ||
| 132 | Button button= new Button(parent, SWT.RADIO); | ||
| 133 | |||
| 134 | gd.horizontalSpan= 2; | ||
| 135 | button.setText(label); | ||
| 136 | button.setLayoutData(gd); | ||
| 137 | button.setSelection(bSelected); | ||
| 138 | |||
| 139 | if (bSelected) | ||
| 140 | sValue = IPreferenceStore.TRUE; | ||
| 141 | else | ||
| 142 | sValue = IPreferenceStore.FALSE; | ||
| 143 | return addControls((Control)button, key, sValue); | ||
| 144 | |||
| 145 | } | ||
| 146 | |||
| 147 | private Control addTextControl(final Composite parent, String key, String value) { | ||
| 148 | final Text text; | ||
| 149 | |||
| 150 | text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER); | ||
| 151 | text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
| 152 | text.setText(value); | ||
| 153 | text.setSize(10, 150); | ||
| 154 | |||
| 155 | return addControls((Control)text, key, value); | ||
| 156 | } | ||
| 157 | |||
| 158 | private Button addFileSelectButton(final Composite parent, final Text text, final String key) { | ||
| 159 | Button button = new Button(parent, SWT.PUSH | SWT.LEAD); | ||
| 160 | button.setText(InputUIElement.BROWSELABEL); | ||
| 161 | button.addSelectionListener(new SelectionAdapter() { | ||
| 162 | @Override | ||
| 163 | public void widgetSelected(SelectionEvent event) { | ||
| 164 | String dirName; | ||
| 165 | if (key.equals(PreferenceConstants.TOOLCHAIN_ROOT)|| key.equals(PreferenceConstants.SYSROOT)) | ||
| 166 | dirName = new DirectoryDialog(parent.getShell()).open(); | ||
| 167 | else | ||
| 168 | dirName = new FileDialog(parent.getShell()).open(); | ||
| 169 | if (dirName != null) { | ||
| 170 | text.setText(dirName); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | }); | ||
| 174 | return button; | ||
| 175 | } | ||
| 176 | |||
| 177 | private void createQemuSetup(final Group targetGroup) | ||
| 178 | { | ||
| 179 | //QEMU Setup | ||
| 180 | kernel_label= new Label(targetGroup, SWT.NONE); | ||
| 181 | kernel_label.setText("Kernel: "); | ||
| 182 | kernel_label.setAlignment(SWT.RIGHT); | ||
| 183 | |||
| 184 | Composite textContainer = new Composite(targetGroup, SWT.NONE); | ||
| 185 | textContainer.setLayout(new GridLayout(2, false)); | ||
| 186 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false)); | ||
| 187 | textKernelLoc= (Text)addTextControl(textContainer, PreferenceConstants.QEMU_KERNEL, yoctoUIElement.getStrQemuKernelLoc()); | ||
| 188 | btnKernelLoc = addFileSelectButton(textContainer, textKernelLoc, PreferenceConstants.QEMU_KERNEL); | ||
| 189 | |||
| 190 | |||
| 191 | option_label = new Label(targetGroup, SWT.NONE); | ||
| 192 | option_label.setText("Custom Option: "); | ||
| 193 | option_label.setAlignment(SWT.RIGHT); | ||
| 194 | |||
| 195 | textContainer = new Composite(targetGroup, SWT.NONE); | ||
| 196 | textContainer.setLayout(new GridLayout(2, false)); | ||
| 197 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false)); | ||
| 198 | textQemuOption = (Text)addTextControl(textContainer, PreferenceConstants.QEMU_OPTION, yoctoUIElement.getStrQemuOption()); | ||
| 199 | |||
| 200 | /* | ||
| 201 | rootfs_label= new Label(targetGroup, SWT.NONE); | ||
| 202 | rootfs_label.setText("Root Filesystem: "); | ||
| 203 | rootfs_label.setAlignment(SWT.RIGHT); | ||
| 204 | |||
| 205 | textContainer = new Composite(targetGroup, SWT.NONE); | ||
| 206 | textContainer.setLayout(new GridLayout(2, false)); | ||
| 207 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false)); | ||
| 208 | textRootFSLoc= (Text)addTextControl(textContainer, PreferenceConstants.QEMU_ROOTFS, yoctoUIElement.getStrQemuRootFSLoc()); | ||
| 209 | btnRootFSLoc = addFileSelectButton(textContainer, textRootFSLoc, PreferenceConstants.QEMU_ROOTFS); | ||
| 210 | */ | ||
| 211 | |||
| 212 | } | ||
| 213 | public void createComposite(Composite composite) | ||
| 214 | { | ||
| 215 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
| 216 | GridLayout layout = new GridLayout(2, false); | ||
| 217 | |||
| 218 | crossCompilerGroup = new Group(composite, SWT.NONE); | ||
| 219 | layout= new GridLayout(2, false); | ||
| 220 | crossCompilerGroup.setLayout(layout); | ||
| 221 | gd= new GridData(SWT.FILL, SWT.CENTER, true, false); | ||
| 222 | gd.horizontalSpan= 2; | ||
| 223 | crossCompilerGroup.setLayoutData(gd); | ||
| 224 | crossCompilerGroup.setText("Cross Compiler Options:"); | ||
| 225 | |||
| 226 | if (yoctoUIElement.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
| 227 | |||
| 228 | btnSDKRoot = (Button)addRadioButton(crossCompilerGroup, "Standalone pre-built toolchain", PreferenceConstants.SDK_MODE + "_1", true); | ||
| 229 | btnPokyRoot = (Button)addRadioButton(crossCompilerGroup, "Build system derived toolchain", PreferenceConstants.SDK_MODE + "_2", false); | ||
| 230 | } | ||
| 231 | else { | ||
| 232 | btnSDKRoot = (Button)addRadioButton(crossCompilerGroup, "Standalone pre-built toolchain", PreferenceConstants.SDK_MODE + "_1", false); | ||
| 233 | btnPokyRoot = (Button)addRadioButton(crossCompilerGroup, "Build system derived toolchain", PreferenceConstants.SDK_MODE + "_2", true); | ||
| 234 | } | ||
| 235 | |||
| 236 | root_label = new Label(crossCompilerGroup, SWT.NONE); | ||
| 237 | root_label.setText("Toolchain Root Location: "); | ||
| 238 | Composite textContainer = new Composite(crossCompilerGroup, SWT.NONE); | ||
| 239 | textContainer.setLayout(new GridLayout(2, false)); | ||
| 240 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
| 241 | textRootLoc = (Text)addTextControl(textContainer, | ||
| 242 | PreferenceConstants.TOOLCHAIN_ROOT, yoctoUIElement.getStrToolChainRoot()); | ||
| 243 | btnToolChainLoc = addFileSelectButton(textContainer, textRootLoc, PreferenceConstants.TOOLCHAIN_ROOT); | ||
| 244 | |||
| 245 | sysroot_label= new Label(crossCompilerGroup, SWT.NONE); | ||
| 246 | sysroot_label.setText("Sysroot Location: "); | ||
| 247 | sysroot_label.setAlignment(SWT.RIGHT); | ||
| 248 | |||
| 249 | textContainer = new Composite(crossCompilerGroup, SWT.NONE); | ||
| 250 | textContainer.setLayout(new GridLayout(2, false)); | ||
| 251 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false)); | ||
| 252 | textSysrootLoc= (Text)addTextControl(textContainer, PreferenceConstants.SYSROOT, yoctoUIElement.getStrSysrootLoc()); | ||
| 253 | btnSysrootLoc = addFileSelectButton(textContainer, textSysrootLoc, PreferenceConstants.SYSROOT); | ||
| 254 | |||
| 255 | updateSDKControlState(); | ||
| 256 | targetArchLabel = new Label(crossCompilerGroup, SWT.NONE); | ||
| 257 | targetArchLabel.setText("Target Architecture: "); | ||
| 258 | |||
| 259 | targetArchCombo= new Combo(crossCompilerGroup, SWT.READ_ONLY); | ||
| 260 | if (yoctoUIElement.getStrTargetsArray() != null) | ||
| 261 | { | ||
| 262 | targetArchCombo.setItems(yoctoUIElement.getStrTargetsArray()); | ||
| 263 | targetArchCombo.select(yoctoUIElement.getIntTargetIndex()); | ||
| 264 | } | ||
| 265 | targetArchCombo.setLayout(new GridLayout(2, false)); | ||
| 266 | targetArchCombo.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false)); | ||
| 267 | this.addControls((Control)targetArchCombo, | ||
| 268 | PreferenceConstants.TOOLCHAIN_TRIPLET, String.valueOf(yoctoUIElement.getIntTargetIndex())); | ||
| 269 | |||
| 270 | |||
| 271 | //Target Options | ||
| 272 | GridData gd2= new GridData(SWT.FILL, SWT.LEFT, true, false); | ||
| 273 | gd2.horizontalSpan= 2; | ||
| 274 | Group targetGroup= new Group(composite, SWT.NONE); | ||
| 275 | layout= new GridLayout(); | ||
| 276 | layout.numColumns= 2; | ||
| 277 | targetGroup.setLayout(layout); | ||
| 278 | targetGroup.setLayoutData(gd2); | ||
| 279 | targetGroup.setText("Target Options:"); | ||
| 280 | |||
| 281 | if (yoctoUIElement.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) { | ||
| 282 | btnQemu = (Button)addRadioButton(targetGroup, "QEMU", PreferenceConstants.TARGET_MODE + "_1", true); | ||
| 283 | createQemuSetup(targetGroup); | ||
| 284 | |||
| 285 | btnDevice = (Button)addRadioButton(targetGroup, "External HW", PreferenceConstants.TARGET_MODE + "_2", false); | ||
| 286 | } | ||
| 287 | else { | ||
| 288 | btnQemu = (Button)addRadioButton(targetGroup, "QEMU", PreferenceConstants.TARGET_MODE + "_1", false); | ||
| 289 | createQemuSetup(targetGroup); | ||
| 290 | |||
| 291 | btnDevice = (Button)addRadioButton(targetGroup, "External HW", PreferenceConstants.TARGET_MODE + "_2", true); | ||
| 292 | } | ||
| 293 | |||
| 294 | updateQemuControlState(); | ||
| 295 | |||
| 296 | //we add the listener at the end for avoiding the useless event trigger when control | ||
| 297 | //changed or modified. | ||
| 298 | btnSDKRoot.addSelectionListener(fSelectionListener); | ||
| 299 | btnPokyRoot.addSelectionListener(fSelectionListener); | ||
| 300 | btnQemu.addSelectionListener(fSelectionListener); | ||
| 301 | btnDevice.addSelectionListener(fSelectionListener); | ||
| 302 | targetArchCombo.addSelectionListener(fSelectionListener); | ||
| 303 | textRootLoc.addModifyListener(fModifyListener); | ||
| 304 | textKernelLoc.addModifyListener(fModifyListener); | ||
| 305 | textQemuOption.addModifyListener(fModifyListener); | ||
| 306 | textSysrootLoc.addModifyListener(fModifyListener); | ||
| 307 | } | ||
| 308 | |||
| 309 | //Load all Control values into the YoctoUIElement | ||
| 310 | public YoctoUIElement getCurrentInput() | ||
| 311 | { | ||
| 312 | YoctoUIElement elem = new YoctoUIElement(); | ||
| 313 | if (btnSDKRoot.getSelection()) | ||
| 314 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_SDK_MODE); | ||
| 315 | else | ||
| 316 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_TREE_MODE); | ||
| 317 | |||
| 318 | if (btnQemu.getSelection()) | ||
| 319 | { | ||
| 320 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.QEMU_MODE); | ||
| 321 | } | ||
| 322 | else { | ||
| 323 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.DEVICE_MODE); | ||
| 324 | } | ||
| 325 | elem.setStrToolChainRoot(textRootLoc.getText()); | ||
| 326 | elem.setIntTargetIndex(targetArchCombo.getSelectionIndex()); | ||
| 327 | elem.setStrTargetsArray(targetArchCombo.getItems()); | ||
| 328 | elem.setStrTarget(targetArchCombo.getText()); | ||
| 329 | elem.setStrQemuKernelLoc(textKernelLoc.getText()); | ||
| 330 | elem.setStrQemuOption(textQemuOption.getText()); | ||
| 331 | elem.setStrSysrootLoc(textSysrootLoc.getText()); | ||
| 332 | return elem; | ||
| 333 | } | ||
| 334 | |||
| 335 | public void setCurrentInput(YoctoUIElement elem){ | ||
| 336 | elem.setStrTargetsArray(getTargetArray(elem)); | ||
| 337 | |||
| 338 | btnSDKRoot.setSelection(false); | ||
| 339 | btnPokyRoot.setSelection(false); | ||
| 340 | if(elem.getEnumPokyMode().equals(YoctoUIElement.PokyMode.POKY_SDK_MODE)){ | ||
| 341 | btnSDKRoot.setSelection(true); | ||
| 342 | } | ||
| 343 | else if(elem.getEnumPokyMode().equals(YoctoUIElement.PokyMode.POKY_TREE_MODE)){ | ||
| 344 | btnPokyRoot.setSelection(true); | ||
| 345 | } | ||
| 346 | |||
| 347 | btnQemu.setSelection(false); | ||
| 348 | btnDevice.setSelection(false); | ||
| 349 | if(elem.getEnumDeviceMode().equals(YoctoUIElement.DeviceMode.QEMU_MODE)){ | ||
| 350 | btnQemu.setSelection(true); | ||
| 351 | } | ||
| 352 | else if(elem.getEnumDeviceMode().equals(YoctoUIElement.DeviceMode.DEVICE_MODE)){ | ||
| 353 | btnDevice.setSelection(true); | ||
| 354 | } | ||
| 355 | |||
| 356 | textRootLoc.setText(elem.getStrToolChainRoot()); | ||
| 357 | targetArchCombo.select(elem.getIntTargetIndex()); | ||
| 358 | if(elem.getStrTargetsArray() == null){ | ||
| 359 | targetArchCombo.setItems(new String[]{}); | ||
| 360 | } | ||
| 361 | else { | ||
| 362 | targetArchCombo.setItems(elem.getStrTargetsArray()); | ||
| 363 | } | ||
| 364 | targetArchCombo.setText(elem.getStrTarget()); | ||
| 365 | textKernelLoc.setText(elem.getStrQemuKernelLoc()); | ||
| 366 | textQemuOption.setText(elem.getStrQemuOption()); | ||
| 367 | textSysrootLoc.setText(elem.getStrSysrootLoc()); | ||
| 368 | } | ||
| 369 | |||
| 370 | public SDKCheckResults validateInput(SDKCheckRequestFrom from, boolean showErrorDialog) { | ||
| 371 | SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(getCurrentInput()); | ||
| 372 | |||
| 373 | //Show Error Message on the Label to help users. | ||
| 374 | if ((result != SDKCheckResults.SDK_PASS) && showErrorDialog) { | ||
| 375 | Display display = Display.getCurrent(); | ||
| 376 | ErrorDialog.openError(display.getActiveShell(), | ||
| 377 | YoctoSDKChecker.SDKCheckRequestFrom.Other.getErrorMessage(), | ||
| 378 | YoctoSDKChecker.getErrorMessage(result, from), | ||
| 379 | new Status(Status.ERROR, YoctoSDKPlugin.PLUGIN_ID, result.getMessage())); | ||
| 380 | |||
| 381 | } | ||
| 382 | |||
| 383 | return result; | ||
| 384 | } | ||
| 385 | |||
| 386 | public void setUIFormEnabledState(boolean isEnabled) { | ||
| 387 | btnSDKRoot.setEnabled(isEnabled); | ||
| 388 | btnPokyRoot.setEnabled(isEnabled); | ||
| 389 | |||
| 390 | root_label.setEnabled(isEnabled); | ||
| 391 | textRootLoc.setEnabled(isEnabled); | ||
| 392 | btnToolChainLoc.setEnabled(isEnabled); | ||
| 393 | |||
| 394 | sysroot_label.setEnabled(isEnabled); | ||
| 395 | textSysrootLoc.setEnabled(isEnabled); | ||
| 396 | btnSysrootLoc.setEnabled(isEnabled); | ||
| 397 | |||
| 398 | targetArchLabel.setEnabled(isEnabled); | ||
| 399 | targetArchCombo.setEnabled(isEnabled); | ||
| 400 | |||
| 401 | btnQemu.setEnabled(isEnabled); | ||
| 402 | |||
| 403 | if(isEnabled) { | ||
| 404 | /* enabling widgets regarding | ||
| 405 | * Kernel and Custom Options | ||
| 406 | * depends on the state of the QEMU button */ | ||
| 407 | kernel_label.setEnabled(isEnabled); | ||
| 408 | option_label.setEnabled(isEnabled); | ||
| 409 | |||
| 410 | if(btnQemu.getSelection()) { | ||
| 411 | textKernelLoc.setEnabled(isEnabled); | ||
| 412 | btnKernelLoc.setEnabled(isEnabled); | ||
| 413 | |||
| 414 | textQemuOption.setEnabled(isEnabled); | ||
| 415 | } | ||
| 416 | } else { | ||
| 417 | /* disable all widgets regarding | ||
| 418 | * Kernel and Custom Options */ | ||
| 419 | kernel_label.setEnabled(isEnabled); | ||
| 420 | textKernelLoc.setEnabled(isEnabled); | ||
| 421 | btnKernelLoc.setEnabled(isEnabled); | ||
| 422 | |||
| 423 | option_label.setEnabled(isEnabled); | ||
| 424 | textQemuOption.setEnabled(isEnabled); | ||
| 425 | } | ||
| 426 | |||
| 427 | btnDevice.setEnabled(isEnabled); | ||
| 428 | } | ||
| 429 | |||
| 430 | private void updateQemuControlState() | ||
| 431 | { | ||
| 432 | boolean bQemuMode = btnQemu.getSelection(); | ||
| 433 | |||
| 434 | textKernelLoc.setEnabled(bQemuMode); | ||
| 435 | //textRootFSLoc.setEnabled(bQemuMode); | ||
| 436 | btnKernelLoc.setEnabled(bQemuMode); | ||
| 437 | //btnRootFSLoc.setEnabled(bQemuMode); | ||
| 438 | textQemuOption.setEnabled(bQemuMode); | ||
| 439 | } | ||
| 440 | |||
| 441 | private void updateSDKControlState() | ||
| 442 | { | ||
| 443 | if (btnSDKRoot.getSelection()) | ||
| 444 | { | ||
| 445 | } | ||
| 446 | else { | ||
| 447 | if (!yoctoUIElement.getStrToolChainRoot().startsWith("/opt/poky")) | ||
| 448 | { | ||
| 449 | textRootLoc.setText(yoctoUIElement.getStrToolChainRoot()); | ||
| 450 | } | ||
| 451 | textRootLoc.setEnabled(true); | ||
| 452 | btnToolChainLoc.setEnabled(true); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | private void controlChanged(Widget widget) { | ||
| 457 | |||
| 458 | if (widget == btnSDKRoot || widget == btnPokyRoot) | ||
| 459 | { | ||
| 460 | |||
| 461 | setTargetCombo(targetArchCombo); | ||
| 462 | updateSDKControlState(); | ||
| 463 | } | ||
| 464 | |||
| 465 | if (widget == btnDevice || widget == btnQemu) | ||
| 466 | updateQemuControlState(); | ||
| 467 | } | ||
| 468 | |||
| 469 | private void controlModified(Widget widget) { | ||
| 470 | if (widget == textRootLoc) | ||
| 471 | { | ||
| 472 | setTargetCombo(targetArchCombo); | ||
| 473 | } | ||
| 474 | } | ||
| 475 | |||
| 476 | /* Search current supported Target triplet from the toolchain root | ||
| 477 | * by parsing ENV script file name | ||
| 478 | */ | ||
| 479 | private static ArrayList<String> getTargetTripletList(String strFileName) | ||
| 480 | { | ||
| 481 | File fFile = new File(strFileName); | ||
| 482 | if (!fFile.exists()) | ||
| 483 | return null; | ||
| 484 | |||
| 485 | ArrayList<String> arrTarget = new ArrayList<String>(); | ||
| 486 | String[] strFileArray = fFile.list(); | ||
| 487 | for (int i = 0; i < strFileArray.length; i++) | ||
| 488 | { | ||
| 489 | if (strFileArray[i].startsWith(ENV_SCRIPT_FILE_PREFIX)) { | ||
| 490 | arrTarget.add(strFileArray[i].substring(ENV_SCRIPT_FILE_PREFIX.length())); | ||
| 491 | } | ||
| 492 | } | ||
| 493 | return arrTarget; | ||
| 494 | |||
| 495 | } | ||
| 496 | |||
| 497 | private static String[] getTargetArray(YoctoUIElement elem) | ||
| 498 | { | ||
| 499 | ArrayList<String> arrTarget; | ||
| 500 | String sEnvFilePath = elem.getStrToolChainRoot(); | ||
| 501 | |||
| 502 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) | ||
| 503 | { | ||
| 504 | arrTarget = getTargetTripletList(sEnvFilePath); | ||
| 505 | } | ||
| 506 | else | ||
| 507 | { | ||
| 508 | arrTarget = getTargetTripletList(sEnvFilePath + "/tmp"); | ||
| 509 | } | ||
| 510 | if (arrTarget == null || arrTarget.size() <= 0) | ||
| 511 | return null; | ||
| 512 | |||
| 513 | String [] strTargetArray = new String[arrTarget.size()]; | ||
| 514 | for (int i = 0; i < arrTarget.size(); i++) | ||
| 515 | strTargetArray[i] = arrTarget.get(i); | ||
| 516 | |||
| 517 | return strTargetArray; | ||
| 518 | |||
| 519 | } | ||
| 520 | |||
| 521 | private void setTargetCombo(Combo targetCombo) | ||
| 522 | { | ||
| 523 | YoctoUIElement elem = getCurrentInput(); | ||
| 524 | //re-get Combo box items according to latest input! | ||
| 525 | elem.setStrTargetsArray(getTargetArray(elem)); | ||
| 526 | targetCombo.removeAll(); | ||
| 527 | if (elem.getStrTargetsArray() != null) | ||
| 528 | { | ||
| 529 | targetCombo.setItems(elem.getStrTargetsArray()); | ||
| 530 | for (int i = 0; i < targetCombo.getItemCount(); i++) | ||
| 531 | { | ||
| 532 | if(elem.getStrTarget().equalsIgnoreCase(targetCombo.getItem(i))) | ||
| 533 | { | ||
| 534 | targetCombo.select(i); | ||
| 535 | return; | ||
| 536 | } | ||
| 537 | if (elem.getStrTargetsArray().length == 1) | ||
| 538 | targetCombo.select(0); | ||
| 539 | targetCombo.select(-1); | ||
| 540 | } | ||
| 541 | } | ||
| 542 | //prompt user,if he use tree mode, maybe he hasn't bitbake meta-ide-support yet. | ||
| 543 | else if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_TREE_MODE) | ||
| 544 | { | ||
| 545 | if (elem.getStrToolChainRoot().isEmpty()) | ||
| 546 | return; | ||
| 547 | else { | ||
| 548 | File fToolChain = new File(elem.getStrToolChainRoot()); | ||
| 549 | if (!fToolChain.exists()) | ||
| 550 | return; | ||
| 551 | } | ||
| 552 | } | ||
| 553 | |||
| 554 | } | ||
| 555 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java new file mode 100644 index 0000000..f39d5fd --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/InvokeSyncAction.java | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.actions; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.io.OutputStream; | ||
| 15 | import java.util.ArrayList; | ||
| 16 | |||
| 17 | import org.eclipse.cdt.core.CommandLauncher; | ||
| 18 | import org.eclipse.cdt.core.ConsoleOutputStream; | ||
| 19 | import org.eclipse.cdt.core.envvar.IEnvironmentVariable; | ||
| 20 | import org.eclipse.cdt.core.resources.IConsole; | ||
| 21 | import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
| 22 | import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; | ||
| 23 | import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; | ||
| 24 | import org.eclipse.core.resources.IProject; | ||
| 25 | import org.eclipse.core.runtime.CoreException; | ||
| 26 | import org.eclipse.core.runtime.IPath; | ||
| 27 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
| 28 | import org.eclipse.core.runtime.Path; | ||
| 29 | import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator; | ||
| 30 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; | ||
| 31 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeMessages; | ||
| 32 | |||
| 33 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 34 | |||
| 35 | @SuppressWarnings("restriction") | ||
| 36 | public class InvokeSyncAction extends InvokeAction { | ||
| 37 | protected void executeLocalConsoleCommand(final IConsole console, final String actionName, final String command, | ||
| 38 | final String[] argumentList, final IPath execDir, final String password) throws CoreException, IOException { | ||
| 39 | |||
| 40 | String errMsg = null; | ||
| 41 | IProject project = getSelectedContainer().getProject(); | ||
| 42 | // Get a build console for the project | ||
| 43 | ConsoleOutputStream consoleOutStream = console.getOutputStream(); | ||
| 44 | // FIXME: we want to remove need for ManagedBuilderManager, but how do we | ||
| 45 | // get environment variables. | ||
| 46 | IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); | ||
| 47 | IConfiguration cfg = info.getDefaultConfiguration(); | ||
| 48 | |||
| 49 | StringBuffer buf = new StringBuffer(); | ||
| 50 | String[] consoleHeader = new String[3]; | ||
| 51 | |||
| 52 | consoleHeader[0] = actionName; | ||
| 53 | consoleHeader[1] = cfg.getName(); | ||
| 54 | consoleHeader[2] = project.getName(); | ||
| 55 | buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ | ||
| 56 | String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$ | ||
| 57 | new String[]{actionName, execDir.toString()}); //$NON-NLS-1$ | ||
| 58 | buf.append(invokeMsg); | ||
| 59 | buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ | ||
| 60 | buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ | ||
| 61 | consoleOutStream.write(buf.toString().getBytes()); | ||
| 62 | consoleOutStream.flush(); | ||
| 63 | |||
| 64 | ArrayList<String> additionalEnvs = new ArrayList<String>(); | ||
| 65 | String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs); | ||
| 66 | // Get a launcher for the config command | ||
| 67 | CommandLauncher launcher = new CommandLauncher(); | ||
| 68 | // Set the environment | ||
| 69 | IEnvironmentVariable variables[] = ManagedBuildManager | ||
| 70 | .getEnvironmentVariableProvider().getVariables(cfg, true); | ||
| 71 | String[] env = null; | ||
| 72 | ArrayList<String> envList = new ArrayList<String>(); | ||
| 73 | if (variables != null) { | ||
| 74 | for (int i = 0; i < variables.length; i++) { | ||
| 75 | envList.add(variables[i].getName() | ||
| 76 | + "=" + variables[i].getValue()); //$NON-NLS-1$ | ||
| 77 | } | ||
| 78 | // add any additional environment variables specified ahead of script | ||
| 79 | if (additionalEnvs.size() > 0) | ||
| 80 | envList.addAll(additionalEnvs); | ||
| 81 | env = (String[]) envList.toArray(new String[envList.size()]); | ||
| 82 | } | ||
| 83 | OutputStream stdout = consoleOutStream; | ||
| 84 | OutputStream stderr = consoleOutStream; | ||
| 85 | |||
| 86 | launcher.showCommand(true); | ||
| 87 | // Run the shell script via shell command. | ||
| 88 | Process proc = launcher.execute(new Path(strippedCommand), argumentList, env, | ||
| 89 | execDir, new NullProgressMonitor()); | ||
| 90 | |||
| 91 | if (proc != null) { | ||
| 92 | // Close the input of the process since we will never write to it | ||
| 93 | OutputStream out = proc.getOutputStream(); | ||
| 94 | if (!password.isEmpty()) { | ||
| 95 | out.write(password.getBytes()); | ||
| 96 | out.write("\n".getBytes()); | ||
| 97 | } | ||
| 98 | out.close(); | ||
| 99 | |||
| 100 | if (launcher.waitAndRead(stdout, stderr) != CommandLauncher.OK) { | ||
| 101 | errMsg = launcher.getErrorMessage(); | ||
| 102 | } | ||
| 103 | } else { | ||
| 104 | errMsg = launcher.getErrorMessage(); | ||
| 105 | } | ||
| 106 | |||
| 107 | if (errMsg != null) | ||
| 108 | YoctoSDKPlugin.logErrorMessage(errMsg); | ||
| 109 | } | ||
| 110 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ProfileSwitchHandler.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ProfileSwitchHandler.java new file mode 100644 index 0000000..e3e7e60 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ProfileSwitchHandler.java | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.actions; | ||
| 12 | |||
| 13 | import java.util.Map; | ||
| 14 | |||
| 15 | import org.eclipse.cdt.core.model.ICElement; | ||
| 16 | import org.eclipse.cdt.core.model.ICProject; | ||
| 17 | import org.eclipse.core.commands.AbstractHandler; | ||
| 18 | import org.eclipse.core.commands.Command; | ||
| 19 | import org.eclipse.core.commands.ExecutionEvent; | ||
| 20 | import org.eclipse.core.commands.ExecutionException; | ||
| 21 | import org.eclipse.core.commands.State; | ||
| 22 | import org.eclipse.core.resources.IProject; | ||
| 23 | import org.eclipse.core.resources.IResource; | ||
| 24 | import org.eclipse.core.runtime.IAdaptable; | ||
| 25 | import org.eclipse.core.runtime.Status; | ||
| 26 | import org.eclipse.jface.dialogs.ErrorDialog; | ||
| 27 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 28 | import org.eclipse.jface.viewers.ISelection; | ||
| 29 | import org.eclipse.jface.viewers.ITreeSelection; | ||
| 30 | import org.eclipse.swt.widgets.Display; | ||
| 31 | import org.eclipse.ui.commands.ICommandService; | ||
| 32 | import org.eclipse.ui.commands.IElementUpdater; | ||
| 33 | import org.eclipse.ui.handlers.HandlerUtil; | ||
| 34 | import org.eclipse.ui.handlers.RadioState; | ||
| 35 | import org.eclipse.ui.menus.UIElement; | ||
| 36 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 37 | import org.yocto.sdk.ide.YoctoSDKChecker; | ||
| 38 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
| 39 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 40 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 41 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 42 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 43 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 44 | |||
| 45 | public class ProfileSwitchHandler extends AbstractHandler implements IElementUpdater { | ||
| 46 | private static final String PROJECT_SPECIFIC_ERROR = "Preferences.Profile.ProjectSpecific.Error.Title"; | ||
| 47 | private static final String PROJECT_SPECIFIC_ERROR_MESSAGE = "Preferences.Profile.ProjectSpecific.Error.Message"; | ||
| 48 | |||
| 49 | public static final String PROFILE_SWITCH_COMMAND = "org.yocto.sdk.ide.targetProfile.switch"; //$NON-NLS-N$ | ||
| 50 | public static final String PROJECT_SPECIFIC_PARAMETER = "##PROJECT_SPECIFIC_PROFILE##"; //$NON-NLS-N$ | ||
| 51 | |||
| 52 | @Override | ||
| 53 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
| 54 | if(HandlerUtil.matchesRadioState(event)) { | ||
| 55 | return null; | ||
| 56 | } | ||
| 57 | |||
| 58 | String currentState = event.getParameter(RadioState.PARAMETER_ID); | ||
| 59 | HandlerUtil.updateRadioState(event.getCommand(), currentState); | ||
| 60 | |||
| 61 | switchProfile(getSelectedProject(event), currentState); | ||
| 62 | |||
| 63 | return null; | ||
| 64 | } | ||
| 65 | |||
| 66 | public IProject getSelectedProject(ExecutionEvent event) { | ||
| 67 | ISelection selection = HandlerUtil.getCurrentSelection(event); | ||
| 68 | |||
| 69 | if (selection instanceof ITreeSelection) { | ||
| 70 | Object selectedItem = ((ITreeSelection) selection).getFirstElement(); | ||
| 71 | if (selectedItem instanceof IResource) { | ||
| 72 | return ((IResource) selectedItem).getProject(); | ||
| 73 | } else if (selectedItem instanceof ICElement) { | ||
| 74 | ICProject cProject = ((ICElement) selectedItem).getCProject(); | ||
| 75 | if (cProject != null) { | ||
| 76 | return cProject.getProject(); | ||
| 77 | } | ||
| 78 | } else if (selectedItem instanceof IAdaptable) { | ||
| 79 | Object projectObject = ((IAdaptable) selectedItem).getAdapter(IProject.class); | ||
| 80 | if (projectObject != null && projectObject instanceof IProject) { | ||
| 81 | return ((IProject) projectObject); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | return null; | ||
| 87 | } | ||
| 88 | |||
| 89 | private void switchProfile(IProject project, String selectedProfile) { | ||
| 90 | if (PROJECT_SPECIFIC_PARAMETER.equals(selectedProfile)) { | ||
| 91 | YoctoUIElement yoctoUIElement = ProjectPreferenceUtils.getElem(project); | ||
| 92 | SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(yoctoUIElement); | ||
| 93 | |||
| 94 | if ((result != SDKCheckResults.SDK_PASS)) { | ||
| 95 | Display display = Display.getCurrent(); | ||
| 96 | ErrorDialog.openError(display.getActiveShell(), | ||
| 97 | YoctoSDKMessages.getString(PROJECT_SPECIFIC_ERROR), | ||
| 98 | YoctoSDKMessages.getFormattedString(PROJECT_SPECIFIC_ERROR_MESSAGE, | ||
| 99 | project.getName()), | ||
| 100 | new Status(Status.ERROR, YoctoSDKPlugin.PLUGIN_ID, result.getMessage())); | ||
| 101 | return; | ||
| 102 | } | ||
| 103 | |||
| 104 | ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUIElement, project); | ||
| 105 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, true); | ||
| 106 | } else { | ||
| 107 | IPreferenceStore store = YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile); | ||
| 108 | YoctoUIElement yoctoUIElement = YoctoSDKUtils.getElemFromStore(store); | ||
| 109 | ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUIElement, project); | ||
| 110 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, false); | ||
| 111 | |||
| 112 | YoctoProfileElement profileSettings = ProjectPreferenceUtils.getProfiles(project); | ||
| 113 | profileSettings.setSelectedProfile(selectedProfile); | ||
| 114 | ProjectPreferenceUtils.saveProfiles(profileSettings, project); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | /* | ||
| 119 | * Workaround for BUG 398647 to allow checking radio items | ||
| 120 | * in a dynamic contribution | ||
| 121 | * | ||
| 122 | * https://bugs.eclipse.org/bugs/show_bug.cgi?id=398647 | ||
| 123 | */ | ||
| 124 | @Override | ||
| 125 | public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) { | ||
| 126 | ICommandService service = (ICommandService) element.getServiceLocator().getService(ICommandService.class); | ||
| 127 | String state = (String) parameters.get(RadioState.PARAMETER_ID); | ||
| 128 | Command command = service.getCommand(PROFILE_SWITCH_COMMAND); | ||
| 129 | State commandState = command.getState(RadioState.STATE_ID); | ||
| 130 | if (commandState.getValue().equals(state)) { | ||
| 131 | element.setChecked(true); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoAction.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoAction.java new file mode 100644 index 0000000..e255fd1 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoAction.java | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.actions; | ||
| 12 | |||
| 13 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; | ||
| 14 | import org.eclipse.core.resources.IContainer; | ||
| 15 | import org.eclipse.core.resources.IProject; | ||
| 16 | import org.eclipse.jface.action.IAction; | ||
| 17 | import org.eclipse.jface.preference.PreferenceDialog; | ||
| 18 | import org.eclipse.ui.dialogs.PreferencesUtil; | ||
| 19 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 20 | |||
| 21 | |||
| 22 | @SuppressWarnings("restriction") | ||
| 23 | public class ReconfigYoctoAction extends InvokeAction { | ||
| 24 | |||
| 25 | public void run(IAction action) { | ||
| 26 | IContainer container = getSelectedContainer(); | ||
| 27 | if (container == null) | ||
| 28 | return; | ||
| 29 | |||
| 30 | IProject project = container.getProject(); | ||
| 31 | |||
| 32 | PreferenceDialog dialog = | ||
| 33 | PreferencesUtil.createPropertyDialogOn(YoctoSDKPlugin.getActiveWorkbenchShell(), | ||
| 34 | project, | ||
| 35 | "org.yocto.sdk.ide.page", | ||
| 36 | null, | ||
| 37 | null); | ||
| 38 | dialog.open(); | ||
| 39 | } | ||
| 40 | |||
| 41 | public void dispose() { | ||
| 42 | |||
| 43 | } | ||
| 44 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoHandler.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoHandler.java new file mode 100644 index 0000000..6d508d3 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/ReconfigYoctoHandler.java | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.actions; | ||
| 12 | |||
| 13 | import java.lang.reflect.Method; | ||
| 14 | |||
| 15 | import org.eclipse.core.commands.ExecutionEvent; | ||
| 16 | import org.eclipse.core.commands.ExecutionException; | ||
| 17 | import org.eclipse.core.expressions.IEvaluationContext; | ||
| 18 | import org.eclipse.core.resources.IContainer; | ||
| 19 | import org.eclipse.core.runtime.IStatus; | ||
| 20 | import org.eclipse.core.runtime.Status; | ||
| 21 | import org.eclipse.jface.dialogs.ErrorDialog; | ||
| 22 | import org.eclipse.cdt.internal.autotools.ui.actions.AbstractAutotoolsHandler; | ||
| 23 | import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction; | ||
| 24 | import org.eclipse.swt.widgets.Display; | ||
| 25 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 26 | |||
| 27 | |||
| 28 | @SuppressWarnings("restriction") | ||
| 29 | public class ReconfigYoctoHandler extends AbstractAutotoolsHandler { | ||
| 30 | |||
| 31 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
| 32 | ReconfigYoctoAction action = new ReconfigYoctoAction(); | ||
| 33 | Method method = null; | ||
| 34 | |||
| 35 | try { | ||
| 36 | /* | ||
| 37 | * This is hack to workaround upstream eclipse bug #370288 | ||
| 38 | */ | ||
| 39 | Class [] params = {ExecutionEvent.class, InvokeAction.class}; | ||
| 40 | method = AbstractAutotoolsHandler.class.getDeclaredMethod("execute",params ); | ||
| 41 | } catch (NoSuchMethodException e) { | ||
| 42 | //no such method, old version of plugin org.eclipse.linuxtools.autotools.ui | ||
| 43 | method = null; | ||
| 44 | } catch (Exception e) { | ||
| 45 | throw new ExecutionException(e.getMessage(), e); | ||
| 46 | } | ||
| 47 | |||
| 48 | if (method != null) { | ||
| 49 | //new version | ||
| 50 | Object [] params = {event, action}; | ||
| 51 | try { | ||
| 52 | return method.invoke(this, params); | ||
| 53 | }catch (Exception e) { | ||
| 54 | throw new ExecutionException(e.getMessage(), e); | ||
| 55 | } | ||
| 56 | } else { | ||
| 57 | //old version | ||
| 58 | //display a dialog to warn the user | ||
| 59 | Display.getDefault().syncExec(new Runnable() { | ||
| 60 | public void run() { | ||
| 61 | ErrorDialog.openError(null, "Change Yocto Project Settings", "Please update the plugin of \"Autotools support for CDT\"!", | ||
| 62 | new Status(IStatus.WARNING,YoctoSDKPlugin.PLUGIN_ID,"old version of plugin \"Autotools support for CDT\" detected.")); | ||
| 63 | } | ||
| 64 | }); | ||
| 65 | //try to display the dialog in the old way | ||
| 66 | Object o = event.getApplicationContext(); | ||
| 67 | if (o instanceof IEvaluationContext) { | ||
| 68 | IContainer container = getContainer((IEvaluationContext)o); | ||
| 69 | if (container != null) { | ||
| 70 | action.setSelectedContainer(container); | ||
| 71 | action.run(null); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | return null; | ||
| 77 | } | ||
| 78 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/YoctoConsole.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/YoctoConsole.java new file mode 100644 index 0000000..4b25d94 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/actions/YoctoConsole.java | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.actions; | ||
| 12 | |||
| 13 | import org.eclipse.cdt.internal.autotools.ui.Console; | ||
| 14 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 15 | |||
| 16 | @SuppressWarnings("restriction") | ||
| 17 | public class YoctoConsole extends Console { | ||
| 18 | private static final String CONTEXT_MENU_ID = "YoctoConsole"; | ||
| 19 | private static final String CONSOLE_NAME = YoctoSDKMessages.getString("Console.SDK.Name"); | ||
| 20 | |||
| 21 | public YoctoConsole() { | ||
| 22 | super(CONSOLE_NAME, CONTEXT_MENU_ID); | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKAutotoolsProjectNature.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKAutotoolsProjectNature.java new file mode 100644 index 0000000..ce80d77 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKAutotoolsProjectNature.java | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.natures; | ||
| 12 | |||
| 13 | import org.eclipse.cdt.internal.autotools.core.configure.AutotoolsConfigurationManager; | ||
| 14 | import org.eclipse.cdt.internal.autotools.core.configure.IAConfiguration; | ||
| 15 | import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
| 16 | import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; | ||
| 17 | import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; | ||
| 18 | import org.eclipse.core.resources.IProject; | ||
| 19 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 20 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 21 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 22 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 23 | |||
| 24 | public class YoctoSDKAutotoolsProjectNature extends YoctoSDKProjectNature { | ||
| 25 | public static final String YoctoSDK_AUTOTOOLS_NATURE_ID = YoctoSDKPlugin.getUniqueIdentifier() + ".YoctoSDKAutotoolsNature"; | ||
| 26 | |||
| 27 | private static final String DEFAULT_HOST_STR = "host"; | ||
| 28 | private static final String DEFAULT_TARGET_STR = "target"; | ||
| 29 | private static final String DEFAULT_BUILD_STR = "build"; | ||
| 30 | private static final String DEFAULT_AUTOGEN_OPT_STR = "autogenOpts"; | ||
| 31 | |||
| 32 | private static final String DEFAULT_CONFIGURE_STR = "configure"; | ||
| 33 | private static final String DEFAULT_AUTOGEN_STR = "autogen"; | ||
| 34 | private static final String DEFAULT_LIBTOOL_SYSROOT_PREFIX = " --with-libtool-sysroot="; | ||
| 35 | |||
| 36 | public static void configureAutotoolsOptions(IProject project) { | ||
| 37 | IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); | ||
| 38 | IConfiguration icfg = info.getDefaultConfiguration(); | ||
| 39 | YoctoUIElement elem = ProjectPreferenceUtils.getElemFromProjectEnv(project); | ||
| 40 | String sysroot_str = elem.getStrSysrootLoc(); | ||
| 41 | String id = icfg.getId(); | ||
| 42 | String CFLAGS_str = YoctoSDKUtils.getEnvValue(project, "CFLAGS"); | ||
| 43 | String CXXFLAGS_str = YoctoSDKUtils.getEnvValue(project, "CXXFLAGS"); | ||
| 44 | String CPPFLAGS_str = YoctoSDKUtils.getEnvValue(project, "CPPFLAGS"); | ||
| 45 | String LDFLAGS_str = YoctoSDKUtils.getEnvValue(project, "LDFLAGS"); | ||
| 46 | |||
| 47 | String command_prefix = "CFLAGS=\" -g -O0 " + CFLAGS_str + "\" CXXFLAGS=\" -g -O0 " | ||
| 48 | + CXXFLAGS_str + "\" LDFLAGS=\"" + LDFLAGS_str + "\" CPPFLAGS=\"" + CPPFLAGS_str + "\""; | ||
| 49 | String autogen_setting = command_prefix+" autogen.sh" + DEFAULT_LIBTOOL_SYSROOT_PREFIX + sysroot_str; | ||
| 50 | String configure_setting = command_prefix + " configure" + DEFAULT_LIBTOOL_SYSROOT_PREFIX + sysroot_str; | ||
| 51 | IAConfiguration cfg = AutotoolsConfigurationManager.getInstance().getConfiguration(project, id); | ||
| 52 | String strConfigure = YoctoSDKUtils.getEnvValue(project, "CONFIGURE_FLAGS"); | ||
| 53 | |||
| 54 | cfg.setOption(DEFAULT_CONFIGURE_STR, configure_setting); | ||
| 55 | cfg.setOption(DEFAULT_BUILD_STR, splitString(strConfigure, "--build=")); | ||
| 56 | cfg.setOption(DEFAULT_HOST_STR, splitString(strConfigure, "--host=")); | ||
| 57 | cfg.setOption(DEFAULT_TARGET_STR, splitString(strConfigure, "--target=")); | ||
| 58 | cfg.setOption(DEFAULT_AUTOGEN_STR, autogen_setting); | ||
| 59 | cfg.setOption(DEFAULT_AUTOGEN_OPT_STR, strConfigure); | ||
| 60 | |||
| 61 | AutotoolsConfigurationManager.getInstance().addConfiguration(project, cfg); | ||
| 62 | AutotoolsConfigurationManager.getInstance().saveConfigs(project); | ||
| 63 | } | ||
| 64 | |||
| 65 | private static String splitString(String strValue, String strDelim) { | ||
| 66 | int iBeginIndex = strValue.indexOf(strDelim); | ||
| 67 | |||
| 68 | if (iBeginIndex < 0) { | ||
| 69 | return ""; | ||
| 70 | } | ||
| 71 | int iEndIndex = strValue.indexOf(' ', iBeginIndex + 1); | ||
| 72 | |||
| 73 | if (iEndIndex < 0) { | ||
| 74 | return strValue.substring(iBeginIndex + strDelim.length()); | ||
| 75 | } else { | ||
| 76 | return strValue.substring(iBeginIndex + strDelim.length(), iEndIndex); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java new file mode 100644 index 0000000..b3d0f2c --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKCMakeProjectNature.java | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.natures; | ||
| 12 | |||
| 13 | import org.eclipse.cdt.core.CCorePlugin; | ||
| 14 | import org.eclipse.cdt.core.envvar.IContributedEnvironment; | ||
| 15 | import org.eclipse.cdt.core.envvar.IEnvironmentVariable; | ||
| 16 | import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; | ||
| 17 | import org.eclipse.cdt.core.model.CoreModel; | ||
| 18 | import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; | ||
| 19 | import org.eclipse.cdt.core.settings.model.ICProjectDescription; | ||
| 20 | import org.eclipse.core.resources.IProject; | ||
| 21 | import org.eclipse.core.runtime.CoreException; | ||
| 22 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 23 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 24 | |||
| 25 | public class YoctoSDKCMakeProjectNature extends YoctoSDKProjectNature { | ||
| 26 | public static final String YoctoSDK_CMAKE_NATURE_ID = YoctoSDKPlugin.getUniqueIdentifier() + ".YoctoSDKCMakeNature"; | ||
| 27 | |||
| 28 | // Considered poky's cmake.bbclass for this method | ||
| 29 | public static void extendProjectEnvironmentForCMake(IProject project) { | ||
| 30 | ICProjectDescription cpdesc = CoreModel.getDefault().getProjectDescription(project, true); | ||
| 31 | ICConfigurationDescription ccdesc = cpdesc.getActiveConfiguration(); | ||
| 32 | IEnvironmentVariableManager manager = CCorePlugin.getDefault().getBuildEnvironmentManager(); | ||
| 33 | IContributedEnvironment env = manager.getContributedEnvironment(); | ||
| 34 | String delimiter = manager.getDefaultDelimiter(); | ||
| 35 | |||
| 36 | env.addVariable("CCACHE", "", IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 37 | |||
| 38 | env.addVariable("OECMAKE_SOURCEPATH", "..", | ||
| 39 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 40 | |||
| 41 | String oecmakeBuildPathString = ""; | ||
| 42 | env.addVariable("OECMAKE_BUILDPATH", oecmakeBuildPathString, | ||
| 43 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 44 | env.addVariable("EXTRA_OEMAKE", "-C " + oecmakeBuildPathString, | ||
| 45 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 46 | |||
| 47 | String ccString = YoctoSDKUtils.getEnvValue(project, "CC"); | ||
| 48 | |||
| 49 | if (!ccString.equals("") && !ccString.equals(" ")) { | ||
| 50 | ccString.trim(); | ||
| 51 | ccString = ccString.split(" ")[0]; | ||
| 52 | } | ||
| 53 | |||
| 54 | env.addVariable("OECMAKE_C_COMPILER", ccString, | ||
| 55 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 56 | String cxxString = YoctoSDKUtils.getEnvValue(project, "CXX"); | ||
| 57 | |||
| 58 | if (!cxxString.equals("") && !cxxString.equals(" ")) { | ||
| 59 | cxxString.trim(); | ||
| 60 | cxxString = cxxString.split(" ")[0]; | ||
| 61 | } | ||
| 62 | |||
| 63 | env.addVariable("OECMAKE_CXX_COMPILER", cxxString, | ||
| 64 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 65 | |||
| 66 | String hostCCArchString = YoctoSDKUtils.getEnvValue(project, "HOST_CC_ARCH"); | ||
| 67 | String toolchainOptionsString = YoctoSDKUtils.getEnvValue(project, "TOOLCHAIN_OPTIONS"); | ||
| 68 | String cppFlagsString = YoctoSDKUtils.getEnvValue(project, "CPPFLAGS"); | ||
| 69 | String cxxFlagsString = YoctoSDKUtils.getEnvValue(project, "CXXFLAGS"); | ||
| 70 | String selectedOptimizationString = YoctoSDKUtils.getEnvValue(project, "SELECTED_OPTIMIZATION"); | ||
| 71 | env.addVariable("OECMAKE_C_FLAGS", hostCCArchString + " " + toolchainOptionsString + " " + cppFlagsString, | ||
| 72 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 73 | env.addVariable("OECMAKE_CXX_FLAGS", hostCCArchString + " " + toolchainOptionsString + " " + cxxFlagsString | ||
| 74 | + " -fpermissive", | ||
| 75 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 76 | env.addVariable("OECMAKE_C_FLAGS_RELEASE", selectedOptimizationString + " " + cppFlagsString + " -DNDEBUG", | ||
| 77 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 78 | env.addVariable("OECMAKE_CXX_FLAGS_RELEASE", selectedOptimizationString + " " + cxxFlagsString + " -DNDEBUG", | ||
| 79 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 80 | |||
| 81 | env.addVariable("OECMAKE_RPATH", "", | ||
| 82 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 83 | env.addVariable("OECMAKE_PERLNATIVE_DIR", "", | ||
| 84 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 85 | |||
| 86 | try { | ||
| 87 | CoreModel.getDefault().setProjectDescription(project, cpdesc); | ||
| 88 | } catch (CoreException e) { | ||
| 89 | e.printStackTrace(); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKEmptyProjectNature.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKEmptyProjectNature.java new file mode 100644 index 0000000..e1b847a --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKEmptyProjectNature.java | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | package org.yocto.sdk.ide.natures; | ||
| 2 | |||
| 3 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 4 | |||
| 5 | public class YoctoSDKEmptyProjectNature extends YoctoSDKProjectNature { | ||
| 6 | |||
| 7 | public static final String YoctoSDK_EMPTY_NATURE_ID = YoctoSDKPlugin.getUniqueIdentifier() + ".YoctoSDKEmptyNature"; | ||
| 8 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKNatureUtils.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKNatureUtils.java new file mode 100644 index 0000000..5a2a6b1 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKNatureUtils.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | * BMW Car IT - extracted in an own class | ||
| 11 | *******************************************************************************/ | ||
| 12 | package org.yocto.sdk.ide.natures; | ||
| 13 | |||
| 14 | import org.eclipse.core.resources.IProject; | ||
| 15 | import org.eclipse.core.resources.IProjectDescription; | ||
| 16 | import org.eclipse.core.runtime.CoreException; | ||
| 17 | import org.eclipse.core.runtime.IProgressMonitor; | ||
| 18 | |||
| 19 | public class YoctoSDKNatureUtils { | ||
| 20 | |||
| 21 | public static void addNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException | ||
| 22 | { | ||
| 23 | IProjectDescription description = project.getDescription(); | ||
| 24 | String[] natures = description.getNatureIds(); | ||
| 25 | |||
| 26 | for (int i = 0; i < natures.length; ++i) { | ||
| 27 | if (natureId.equals(natures[i])) | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | String[] newNatures = new String[natures.length + 1]; | ||
| 32 | System.arraycopy(natures, 0, newNatures, 0, natures.length); | ||
| 33 | newNatures[natures.length] = natureId; | ||
| 34 | description.setNatureIds(newNatures); | ||
| 35 | project.setDescription(description, monitor); | ||
| 36 | |||
| 37 | } | ||
| 38 | |||
| 39 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKProjectNature.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKProjectNature.java new file mode 100644 index 0000000..e3f6a35 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/natures/YoctoSDKProjectNature.java | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.natures; | ||
| 12 | |||
| 13 | import org.eclipse.core.resources.IProject; | ||
| 14 | import org.eclipse.core.resources.IProjectNature; | ||
| 15 | import org.eclipse.core.runtime.CoreException; | ||
| 16 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 17 | |||
| 18 | public class YoctoSDKProjectNature implements IProjectNature { | ||
| 19 | public static final String YoctoSDK_NATURE_ID = YoctoSDKPlugin.getUniqueIdentifier() + ".YoctoSDKNature"; | ||
| 20 | |||
| 21 | private IProject proj; | ||
| 22 | |||
| 23 | public void configure() throws CoreException { | ||
| 24 | } | ||
| 25 | |||
| 26 | public void deconfigure() throws CoreException { | ||
| 27 | } | ||
| 28 | |||
| 29 | public IProject getProject() { | ||
| 30 | return proj; | ||
| 31 | } | ||
| 32 | |||
| 33 | public void setProject(IProject project) { | ||
| 34 | this.proj = project; | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceConstants.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceConstants.java new file mode 100644 index 0000000..0ebbe99 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceConstants.java | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Constant definitions for plug-in preferences | ||
| 15 | */ | ||
| 16 | public class PreferenceConstants { | ||
| 17 | |||
| 18 | public static final String TOOLCHAIN_ROOT = "toolChainRoot"; | ||
| 19 | |||
| 20 | public static final String TARGET_MODE = "TargetMode"; | ||
| 21 | |||
| 22 | public static final String SDK_MODE = "SDKMode"; | ||
| 23 | |||
| 24 | public static final String TARGET_ARCH_INDEX = "targeArchIndex"; | ||
| 25 | |||
| 26 | public static final String TOOLCHAIN_TRIPLET = "toolchainTriplet"; | ||
| 27 | |||
| 28 | public static final String QEMU_KERNEL = "QemuKernel"; | ||
| 29 | |||
| 30 | public static final String QEMU_OPTION = "QemuOption"; | ||
| 31 | |||
| 32 | public static final String SYSROOT = "Sysroot"; | ||
| 33 | |||
| 34 | public static final String IP_ADDR = "IPAddr"; | ||
| 35 | |||
| 36 | public static final String STANDARD_PROFILE_NAME = "Standard Profile"; | ||
| 37 | |||
| 38 | public static final String PROFILES = "profiles"; | ||
| 39 | |||
| 40 | public static final String SELECTED_PROFILE = "selectedProfile"; | ||
| 41 | |||
| 42 | public static final String PROJECT_SPECIFIC_PROFILE = "##PROJECT_SPECIFIC_PROFILE##"; | ||
| 43 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceInitializer.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceInitializer.java new file mode 100644 index 0000000..40f37d0 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceInitializer.java | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; | ||
| 14 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 15 | |||
| 16 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 17 | |||
| 18 | import static org.yocto.sdk.ide.preferences.PreferenceConstants.*; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Class used to initialize default preference values. | ||
| 22 | */ | ||
| 23 | public class PreferenceInitializer extends AbstractPreferenceInitializer { | ||
| 24 | /* | ||
| 25 | * (non-Javadoc) | ||
| 26 | * | ||
| 27 | * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() | ||
| 28 | */ | ||
| 29 | public void initializeDefaultPreferences() { | ||
| 30 | IPreferenceStore store = YoctoSDKPlugin.getDefault().getPreferenceStore(); | ||
| 31 | store.setDefault(TOOLCHAIN_ROOT, ""); | ||
| 32 | store.setDefault(SDK_MODE, true); | ||
| 33 | store.setDefault(TARGET_MODE, false); | ||
| 34 | store.setDefault(TARGET_ARCH_INDEX, -1); | ||
| 35 | store.setDefault(IP_ADDR, ""); | ||
| 36 | store.setDefault(QEMU_KERNEL, ""); | ||
| 37 | store.setDefault(QEMU_OPTION, ""); | ||
| 38 | store.setDefault(SYSROOT, ""); | ||
| 39 | store.setDefault(TOOLCHAIN_TRIPLET, ""); | ||
| 40 | store.setDefault(PROFILES, "\"" + STANDARD_PROFILE_NAME + "\""); | ||
| 41 | store.setDefault(SELECTED_PROFILE, STANDARD_PROFILE_NAME); | ||
| 42 | } | ||
| 43 | |||
| 44 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java new file mode 100644 index 0000000..38e38b1 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | import org.eclipse.jface.dialogs.IInputValidator; | ||
| 14 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 15 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 16 | |||
| 17 | public class ProfileNameInputValidator implements IInputValidator { | ||
| 18 | private static final String WARNING_CONTAINS_COMMA = "Preferences.Profile.Validator.InvalidName.Comma"; | ||
| 19 | private static final String WARNING_CONTAINS_DOUBLEQUOTE = "Preferences.Profile.Validator.InvalidName.Quote"; | ||
| 20 | private static final String PROFILE_NAME_IS_EMPTY = "Preferences.Profile.Validator.InvalidName.Empty"; | ||
| 21 | private static final String WARNING_ALREADY_EXISTS = "Preferences.Profile.Validator.InvalidName.Exists"; | ||
| 22 | |||
| 23 | private final String selectedItem; | ||
| 24 | private final YoctoProfileElement profileSetting; | ||
| 25 | |||
| 26 | public ProfileNameInputValidator(YoctoProfileElement profileSetting) { | ||
| 27 | this(profileSetting, ""); | ||
| 28 | } | ||
| 29 | |||
| 30 | public ProfileNameInputValidator(YoctoProfileElement profileSetting, String selectedItem) { | ||
| 31 | this.selectedItem = selectedItem; | ||
| 32 | this.profileSetting = profileSetting; | ||
| 33 | } | ||
| 34 | |||
| 35 | @Override | ||
| 36 | public String isValid(String newText) { | ||
| 37 | if (newText.contains(",")) { | ||
| 38 | return YoctoSDKMessages.getString(WARNING_CONTAINS_COMMA); | ||
| 39 | } | ||
| 40 | |||
| 41 | if (newText.contains("\"")) { | ||
| 42 | return YoctoSDKMessages.getString(WARNING_CONTAINS_DOUBLEQUOTE); | ||
| 43 | } | ||
| 44 | |||
| 45 | if (newText.isEmpty()) { | ||
| 46 | return YoctoSDKMessages.getString(PROFILE_NAME_IS_EMPTY); | ||
| 47 | } | ||
| 48 | |||
| 49 | if (selectedItemEquals(newText)) { | ||
| 50 | return null; | ||
| 51 | } | ||
| 52 | |||
| 53 | if (profileSetting.contains(newText)) { | ||
| 54 | return YoctoSDKMessages.getString(WARNING_ALREADY_EXISTS); | ||
| 55 | } | ||
| 56 | |||
| 57 | return null; | ||
| 58 | } | ||
| 59 | |||
| 60 | private boolean selectedItemEquals(String newText) { | ||
| 61 | return !selectedItem.isEmpty() && newText.equals(selectedItem); | ||
| 62 | } | ||
| 63 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java new file mode 100644 index 0000000..4e6ca2a --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | import java.util.HashSet; | ||
| 14 | |||
| 15 | import org.eclipse.core.resources.IProject; | ||
| 16 | import org.eclipse.core.resources.ResourcesPlugin; | ||
| 17 | import org.eclipse.core.runtime.CoreException; | ||
| 18 | import org.eclipse.jface.dialogs.Dialog; | ||
| 19 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
| 20 | import org.eclipse.jface.dialogs.InputDialog; | ||
| 21 | import org.eclipse.jface.dialogs.MessageDialog; | ||
| 22 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 23 | import org.eclipse.jface.preference.PreferencePage; | ||
| 24 | import org.eclipse.swt.SWT; | ||
| 25 | import org.eclipse.swt.layout.GridLayout; | ||
| 26 | import org.eclipse.swt.widgets.Composite; | ||
| 27 | import org.eclipse.swt.widgets.Control; | ||
| 28 | import org.eclipse.swt.widgets.Event; | ||
| 29 | import org.eclipse.swt.widgets.Listener; | ||
| 30 | import org.eclipse.ui.IWorkbench; | ||
| 31 | import org.eclipse.ui.IWorkbenchPreferencePage; | ||
| 32 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 33 | import org.yocto.sdk.ide.YoctoProfileSetting; | ||
| 34 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckRequestFrom; | ||
| 35 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
| 36 | import org.yocto.sdk.ide.natures.YoctoSDKProjectNature; | ||
| 37 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 38 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 39 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 40 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 41 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 42 | import org.yocto.sdk.ide.YoctoUISetting; | ||
| 43 | |||
| 44 | public class YoctoSDKPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { | ||
| 45 | |||
| 46 | private static final String NEW_DIALOG_TITLE = "Preferences.Profile.New.Dialog.Title"; | ||
| 47 | private static final String NEW_DIALOG_MESSAGE = "Preferences.Profile.New.Dialog.Message"; | ||
| 48 | private static final String UPDATE_DIALOG_TITLE = "Preferences.Profile.Update.Dialog.Title"; | ||
| 49 | private static final String UPDATE_DIALOG_MESSAGE = "Preferences.Profile.Update.Dialog.Message"; | ||
| 50 | private static final String REVALIDATION_MESSAGE = "Poky.SDK.Revalidation.Message"; | ||
| 51 | |||
| 52 | private YoctoProfileSetting yoctoProfileSetting; | ||
| 53 | private YoctoUISetting yoctoUISetting; | ||
| 54 | |||
| 55 | private Listener changeListener; | ||
| 56 | |||
| 57 | public YoctoSDKPreferencePage() { | ||
| 58 | //super(GRID); | ||
| 59 | IPreferenceStore defaultStore = YoctoSDKPlugin.getDefault().getPreferenceStore(); | ||
| 60 | String profiles = defaultStore.getString(PreferenceConstants.PROFILES); | ||
| 61 | String selectedProfile = defaultStore.getString(PreferenceConstants.SELECTED_PROFILE); | ||
| 62 | |||
| 63 | if (profiles.isEmpty()) { | ||
| 64 | profiles = defaultStore.getDefaultString(PreferenceConstants.PROFILES); | ||
| 65 | selectedProfile = defaultStore.getDefaultString(PreferenceConstants.SELECTED_PROFILE); | ||
| 66 | } | ||
| 67 | |||
| 68 | setPreferenceStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile)); | ||
| 69 | //setDescription(YoctoSDKMessages.getString(PREFERENCES_Yocto_CONFIG)); | ||
| 70 | YoctoUIElement elem = YoctoSDKUtils.getElemFromStore(getPreferenceStore()); | ||
| 71 | this.yoctoUISetting = new YoctoUISetting(elem); | ||
| 72 | |||
| 73 | YoctoProfileElement profileElement = new YoctoProfileElement(profiles, selectedProfile); | ||
| 74 | this.yoctoProfileSetting = new YoctoProfileSetting(profileElement, this, true); | ||
| 75 | |||
| 76 | changeListener = new Listener() { | ||
| 77 | @Override | ||
| 78 | public void handleEvent(Event event) { | ||
| 79 | setErrorMessage(null); | ||
| 80 | setMessage(YoctoSDKMessages.getString(REVALIDATION_MESSAGE), INFORMATION); | ||
| 81 | } | ||
| 82 | }; | ||
| 83 | } | ||
| 84 | |||
| 85 | /* | ||
| 86 | * @see IWorkbenchPreferencePage#init(IWorkbench) | ||
| 87 | */ | ||
| 88 | public void init(IWorkbench workbench) { | ||
| 89 | } | ||
| 90 | |||
| 91 | protected Control createContents(Composite parent) { | ||
| 92 | initializeDialogUnits(parent); | ||
| 93 | final Composite composite= new Composite(parent, SWT.NONE); | ||
| 94 | composite.setLayout(new GridLayout(2, false)); | ||
| 95 | |||
| 96 | yoctoProfileSetting.createComposite(composite); | ||
| 97 | yoctoUISetting.createComposite(composite); | ||
| 98 | |||
| 99 | composite.addListener(SWT.Modify, changeListener); | ||
| 100 | composite.addListener(SWT.Selection, changeListener); | ||
| 101 | |||
| 102 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 103 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 104 | } | ||
| 105 | |||
| 106 | Dialog.applyDialogFont(composite); | ||
| 107 | return composite; | ||
| 108 | } | ||
| 109 | |||
| 110 | /* | ||
| 111 | * @see IPreferencePage#performOk() | ||
| 112 | */ | ||
| 113 | public boolean performOk() { | ||
| 114 | clearMessages(); | ||
| 115 | |||
| 116 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 117 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 118 | setErrorMessage(result.getMessage()); | ||
| 119 | return false; | ||
| 120 | } | ||
| 121 | |||
| 122 | YoctoUIElement savedElement = YoctoSDKUtils.getElemFromStore(getPreferenceStore()); | ||
| 123 | YoctoUIElement modifiedElement = yoctoUISetting.getCurrentInput(); | ||
| 124 | |||
| 125 | YoctoProfileElement savedProfileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 126 | YoctoProfileElement profileElement = yoctoProfileSetting.getCurrentInput(); | ||
| 127 | |||
| 128 | if (savedElement.equals(modifiedElement) && | ||
| 129 | profileElement.getSelectedProfile().equals(savedProfileElement.getSelectedProfile())) { | ||
| 130 | return true; | ||
| 131 | } | ||
| 132 | |||
| 133 | HashSet<IProject> yoctoProjects = getAffectedProjects(profileElement.getSelectedProfile()); | ||
| 134 | |||
| 135 | if (!yoctoProjects.isEmpty()) { | ||
| 136 | boolean deleteConfirmed = | ||
| 137 | MessageDialog.openConfirm(null, YoctoSDKMessages.getString(UPDATE_DIALOG_TITLE), | ||
| 138 | YoctoSDKMessages.getFormattedString(UPDATE_DIALOG_MESSAGE, profileElement.getSelectedProfile())); | ||
| 139 | |||
| 140 | if (!deleteConfirmed) { | ||
| 141 | return false; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | saveElemToStore(modifiedElement, getPreferenceStore()); | ||
| 146 | YoctoSDKUtils.saveProfilesToDefaultStore(profileElement); | ||
| 147 | |||
| 148 | updateProjects(yoctoProjects, modifiedElement); | ||
| 149 | |||
| 150 | return super.performOk(); | ||
| 151 | } | ||
| 152 | |||
| 153 | private void clearMessages() { | ||
| 154 | setErrorMessage(null); | ||
| 155 | setMessage(null); | ||
| 156 | setTitle(getTitle()); | ||
| 157 | } | ||
| 158 | |||
| 159 | /* | ||
| 160 | * @see PreferencePage#performDefaults() | ||
| 161 | */ | ||
| 162 | protected void performDefaults() { | ||
| 163 | YoctoUIElement defaultElement = YoctoSDKUtils.getDefaultElemFromDefaultStore(); | ||
| 164 | yoctoUISetting.setCurrentInput(defaultElement); | ||
| 165 | super.performDefaults(); | ||
| 166 | } | ||
| 167 | |||
| 168 | public void performSaveAs() { | ||
| 169 | YoctoProfileElement profileElement = yoctoProfileSetting.getCurrentInput(); | ||
| 170 | YoctoUIElement uiElement = yoctoUISetting.getCurrentInput(); | ||
| 171 | |||
| 172 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, true); | ||
| 173 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 174 | setErrorMessage(result.getMessage()); | ||
| 175 | return; | ||
| 176 | } | ||
| 177 | |||
| 178 | InputDialog profileNameDialog = | ||
| 179 | new InputDialog(null, | ||
| 180 | YoctoSDKMessages.getString(NEW_DIALOG_TITLE), | ||
| 181 | YoctoSDKMessages.getString(NEW_DIALOG_MESSAGE), | ||
| 182 | null, | ||
| 183 | new ProfileNameInputValidator(profileElement)); | ||
| 184 | |||
| 185 | int returnCode = profileNameDialog.open(); | ||
| 186 | if (returnCode == IDialogConstants.CANCEL_ID) { | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | |||
| 190 | profileElement.addProfile(profileNameDialog.getValue()); | ||
| 191 | yoctoProfileSetting.addProfile(profileNameDialog.getValue()); | ||
| 192 | |||
| 193 | yoctoUISetting.setCurrentInput(uiElement); | ||
| 194 | performOk(); | ||
| 195 | } | ||
| 196 | |||
| 197 | public void switchProfile(String selectedProfile) { | ||
| 198 | setPreferenceStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile)); | ||
| 199 | YoctoUIElement profileElement = YoctoSDKUtils.getElemFromStore(getPreferenceStore()); | ||
| 200 | yoctoUISetting.setCurrentInput(profileElement); | ||
| 201 | } | ||
| 202 | |||
| 203 | public void renameProfile(String oldProfileName, String newProfileName) { | ||
| 204 | YoctoUIElement oldProfileElement = YoctoSDKUtils.getElemFromStore(YoctoSDKPlugin.getProfilePreferenceStore(oldProfileName)); | ||
| 205 | saveElemToStore(oldProfileElement, YoctoSDKPlugin.getProfilePreferenceStore(newProfileName)); | ||
| 206 | |||
| 207 | renameProfileInAffectedProjects(oldProfileName, newProfileName); | ||
| 208 | } | ||
| 209 | |||
| 210 | public void deleteProfile(String selectedProfile) | ||
| 211 | { | ||
| 212 | resetProfileInAffectedProjects(selectedProfile); | ||
| 213 | } | ||
| 214 | |||
| 215 | /* Save IDE wide POKY Preference settings to a specific preference store */ | ||
| 216 | private void saveElemToStore(YoctoUIElement elem, IPreferenceStore store) { | ||
| 217 | store.setValue(PreferenceConstants.TARGET_ARCH_INDEX, elem.getIntTargetIndex()); | ||
| 218 | |||
| 219 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
| 220 | store.setValue(PreferenceConstants.SDK_MODE, IPreferenceStore.TRUE); | ||
| 221 | } else { | ||
| 222 | store.setValue(PreferenceConstants.SDK_MODE, IPreferenceStore.FALSE); | ||
| 223 | } | ||
| 224 | store.setValue(PreferenceConstants.QEMU_KERNEL, elem.getStrQemuKernelLoc()); | ||
| 225 | store.setValue(PreferenceConstants.QEMU_OPTION, elem.getStrQemuOption()); | ||
| 226 | store.setValue(PreferenceConstants.SYSROOT, elem.getStrSysrootLoc()); | ||
| 227 | if (elem.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) { | ||
| 228 | store.setValue(PreferenceConstants.TARGET_MODE, IPreferenceStore.TRUE); | ||
| 229 | } else { | ||
| 230 | store.setValue(PreferenceConstants.TARGET_MODE, IPreferenceStore.FALSE); | ||
| 231 | } | ||
| 232 | store.setValue(PreferenceConstants.TOOLCHAIN_ROOT, elem.getStrToolChainRoot()); | ||
| 233 | store.setValue(PreferenceConstants.TOOLCHAIN_TRIPLET, elem.getStrTarget()); | ||
| 234 | } | ||
| 235 | |||
| 236 | private void resetProfileInAffectedProjects(String usedProfile) | ||
| 237 | { | ||
| 238 | HashSet<IProject> yoctoProjects = getAffectedProjects(usedProfile); | ||
| 239 | YoctoProfileElement profileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 240 | profileElement.setSelectedProfile(PreferenceConstants.STANDARD_PROFILE_NAME); | ||
| 241 | |||
| 242 | for (IProject project : yoctoProjects) | ||
| 243 | { | ||
| 244 | ProjectPreferenceUtils.saveProfiles(profileElement, project); | ||
| 245 | YoctoUIElement elem = YoctoSDKUtils.getElemFromStore( | ||
| 246 | YoctoSDKPlugin.getProfilePreferenceStore(PreferenceConstants.STANDARD_PROFILE_NAME)); | ||
| 247 | ProjectPreferenceUtils.saveElemToProjectEnv(elem, project); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | |||
| 251 | private void renameProfileInAffectedProjects(String oldProfileName, String newProfileName) { | ||
| 252 | HashSet<IProject> yoctoProjects = getAffectedProjects(oldProfileName); | ||
| 253 | YoctoProfileElement profileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 254 | profileElement.setSelectedProfile(newProfileName); | ||
| 255 | |||
| 256 | for (IProject project : yoctoProjects) | ||
| 257 | { | ||
| 258 | ProjectPreferenceUtils.saveProfiles(profileElement, project); | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | private void updateProjects(HashSet<IProject> yoctoProjects, YoctoUIElement elem) { | ||
| 263 | for (IProject project : yoctoProjects) | ||
| 264 | { | ||
| 265 | ProjectPreferenceUtils.saveElemToProjectEnv(elem, project); | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | private HashSet<IProject> getAffectedProjects(String usedProfile) | ||
| 270 | { | ||
| 271 | HashSet<IProject> yoctoProjects = new HashSet<IProject>(); | ||
| 272 | |||
| 273 | IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); | ||
| 274 | |||
| 275 | for (IProject project : projects) | ||
| 276 | { | ||
| 277 | try | ||
| 278 | { | ||
| 279 | if (!project.hasNature(YoctoSDKProjectNature.YoctoSDK_NATURE_ID)) { | ||
| 280 | continue; | ||
| 281 | } | ||
| 282 | } catch (CoreException e) | ||
| 283 | { | ||
| 284 | // project is closed or does not exist so don't update | ||
| 285 | continue; | ||
| 286 | } | ||
| 287 | |||
| 288 | if (!projectUsesProfile(project, usedProfile)) { | ||
| 289 | continue; | ||
| 290 | } | ||
| 291 | |||
| 292 | yoctoProjects.add(project); | ||
| 293 | } | ||
| 294 | return yoctoProjects; | ||
| 295 | } | ||
| 296 | |||
| 297 | private boolean projectUsesProfile(IProject project, String profile) | ||
| 298 | { | ||
| 299 | YoctoProfileElement profileElement = ProjectPreferenceUtils.getProfiles(project); | ||
| 300 | |||
| 301 | if (!profileElement.getSelectedProfile().equals(profile)) { | ||
| 302 | return false; | ||
| 303 | } | ||
| 304 | |||
| 305 | return true; | ||
| 306 | } | ||
| 307 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKProjectPropertyPage.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKProjectPropertyPage.java new file mode 100644 index 0000000..a85cbd9 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKProjectPropertyPage.java | |||
| @@ -0,0 +1,202 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * Copyright (c) 2010 Intel. | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * BMW Car IT GmbH - initial implementation | ||
| 11 | * Intel - initial API implementation (copied from YoctoSDKPreferencePage) | ||
| 12 | *******************************************************************************/ | ||
| 13 | package org.yocto.sdk.ide.preferences; | ||
| 14 | |||
| 15 | import org.eclipse.core.resources.IProject; | ||
| 16 | import org.eclipse.core.runtime.IAdaptable; | ||
| 17 | import org.eclipse.jface.dialogs.Dialog; | ||
| 18 | import org.eclipse.swt.SWT; | ||
| 19 | import org.eclipse.swt.layout.GridLayout; | ||
| 20 | import org.eclipse.swt.widgets.Composite; | ||
| 21 | import org.eclipse.swt.widgets.Control; | ||
| 22 | import org.eclipse.swt.widgets.Event; | ||
| 23 | import org.eclipse.swt.widgets.Listener; | ||
| 24 | import org.eclipse.ui.IWorkbenchPropertyPage; | ||
| 25 | import org.eclipse.ui.dialogs.PropertyPage; | ||
| 26 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 27 | import org.yocto.sdk.ide.YoctoProfileSetting; | ||
| 28 | import org.yocto.sdk.ide.YoctoProjectSpecificSetting; | ||
| 29 | import org.yocto.sdk.ide.YoctoSDKChecker; | ||
| 30 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckRequestFrom; | ||
| 31 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
| 32 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 33 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 34 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 35 | import org.yocto.sdk.ide.YoctoUISetting; | ||
| 36 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 37 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 38 | |||
| 39 | public class YoctoSDKProjectPropertyPage extends PropertyPage implements | ||
| 40 | IWorkbenchPropertyPage { | ||
| 41 | |||
| 42 | private static final String REVALIDATION_MESSAGE = "Poky.SDK.Revalidation.Message"; | ||
| 43 | |||
| 44 | private YoctoProfileSetting yoctoProfileSetting; | ||
| 45 | private YoctoProjectSpecificSetting yoctoProjectSpecificSetting; | ||
| 46 | private YoctoUISetting yoctoUISetting; | ||
| 47 | private IProject project = null; | ||
| 48 | |||
| 49 | private Listener changeListener; | ||
| 50 | |||
| 51 | public YoctoSDKProjectPropertyPage() { | ||
| 52 | changeListener = new Listener() { | ||
| 53 | @Override | ||
| 54 | public void handleEvent(Event event) { | ||
| 55 | if (getErrorMessage() != null) { | ||
| 56 | setErrorMessage(null); | ||
| 57 | setMessage(YoctoSDKMessages.getString(REVALIDATION_MESSAGE), INFORMATION); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | }; | ||
| 61 | } | ||
| 62 | |||
| 63 | @Override | ||
| 64 | protected Control createContents(Composite parent) { | ||
| 65 | IProject project = getProject(); | ||
| 66 | |||
| 67 | YoctoProfileElement globalProfileElement= YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 68 | YoctoProfileElement profileElement = ProjectPreferenceUtils.getProfiles(project); | ||
| 69 | |||
| 70 | String selectedProfile = profileElement.getSelectedProfile(); | ||
| 71 | if (!globalProfileElement.contains(selectedProfile)) { | ||
| 72 | selectedProfile = globalProfileElement.getSelectedProfile(); | ||
| 73 | } | ||
| 74 | |||
| 75 | yoctoProfileSetting = new YoctoProfileSetting( | ||
| 76 | new YoctoProfileElement(globalProfileElement.getProfilesAsString(), selectedProfile), this, false); | ||
| 77 | boolean useProjectSpecificSetting = ProjectPreferenceUtils.getUseProjectSpecificOption(project); | ||
| 78 | |||
| 79 | if (useProjectSpecificSetting) { | ||
| 80 | yoctoUISetting = new YoctoUISetting(ProjectPreferenceUtils.getElem(project)); | ||
| 81 | } else { | ||
| 82 | yoctoUISetting = new YoctoUISetting(YoctoSDKUtils.getElemFromStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile))); | ||
| 83 | } | ||
| 84 | |||
| 85 | yoctoProjectSpecificSetting = new YoctoProjectSpecificSetting(yoctoProfileSetting, yoctoUISetting, this); | ||
| 86 | |||
| 87 | initializeDialogUnits(parent); | ||
| 88 | final Composite composite = new Composite(parent, SWT.NONE); | ||
| 89 | composite.setLayout(new GridLayout(2, false)); | ||
| 90 | |||
| 91 | yoctoProfileSetting.createComposite(composite); | ||
| 92 | yoctoProjectSpecificSetting.createComposite(composite); | ||
| 93 | yoctoUISetting.createComposite(composite); | ||
| 94 | |||
| 95 | if (useProjectSpecificSetting) { | ||
| 96 | yoctoProfileSetting.setUIFormEnabledState(false); | ||
| 97 | yoctoProjectSpecificSetting.setUseProjectSpecificSettings(true); | ||
| 98 | yoctoUISetting.setUIFormEnabledState(true); | ||
| 99 | |||
| 100 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 101 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 102 | setErrorMessage(result.getMessage()); | ||
| 103 | } | ||
| 104 | } else { | ||
| 105 | yoctoProfileSetting.setUIFormEnabledState(true); | ||
| 106 | yoctoProjectSpecificSetting.setUseProjectSpecificSettings(false); | ||
| 107 | yoctoUISetting.setUIFormEnabledState(false); | ||
| 108 | } | ||
| 109 | |||
| 110 | composite.addListener(SWT.Modify, changeListener); | ||
| 111 | composite.addListener(SWT.Selection, changeListener); | ||
| 112 | |||
| 113 | Dialog.applyDialogFont(composite); | ||
| 114 | return composite; | ||
| 115 | } | ||
| 116 | |||
| 117 | private IProject getProject() { | ||
| 118 | if (project != null) { | ||
| 119 | return project; | ||
| 120 | } | ||
| 121 | |||
| 122 | IAdaptable adaptable = getElement(); | ||
| 123 | if (adaptable == null) { | ||
| 124 | throw new IllegalStateException("Project can only be retrieved after properties page has been set up."); | ||
| 125 | } | ||
| 126 | |||
| 127 | project = (IProject) adaptable.getAdapter(IProject.class); | ||
| 128 | return project; | ||
| 129 | } | ||
| 130 | |||
| 131 | /* | ||
| 132 | * @see PreferencePage#performDefaults() | ||
| 133 | */ | ||
| 134 | @Override | ||
| 135 | protected void performDefaults() { | ||
| 136 | YoctoUIElement defaultElement = YoctoSDKUtils.getDefaultElemFromDefaultStore(); | ||
| 137 | yoctoUISetting.setCurrentInput(defaultElement); | ||
| 138 | yoctoProjectSpecificSetting.setUseProjectSpecificSettings(true); | ||
| 139 | super.performDefaults(); | ||
| 140 | } | ||
| 141 | |||
| 142 | /* | ||
| 143 | * @see IPreferencePage#performOk() | ||
| 144 | */ | ||
| 145 | @Override | ||
| 146 | public boolean performOk() { | ||
| 147 | clearMessages(); | ||
| 148 | |||
| 149 | IProject project = getProject(); | ||
| 150 | |||
| 151 | if (yoctoProjectSpecificSetting.isUsingProjectSpecificSettings()) { | ||
| 152 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 153 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 154 | setErrorMessage(result.getMessage()); | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 158 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, true); | ||
| 159 | ProjectPreferenceUtils.saveProfiles(yoctoProfileSetting.getCurrentInput(), project); | ||
| 160 | ProjectPreferenceUtils.saveElem(yoctoUISetting.getCurrentInput(), project); | ||
| 161 | } else { | ||
| 162 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, false); | ||
| 163 | ProjectPreferenceUtils.saveProfiles(yoctoProfileSetting.getCurrentInput(), project); | ||
| 164 | } | ||
| 165 | |||
| 166 | ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUISetting.getCurrentInput(), getProject()); | ||
| 167 | |||
| 168 | return super.performOk(); | ||
| 169 | } | ||
| 170 | |||
| 171 | private void clearMessages() { | ||
| 172 | setErrorMessage(null); | ||
| 173 | setMessage(null); | ||
| 174 | setTitle(getTitle()); | ||
| 175 | } | ||
| 176 | |||
| 177 | public void switchProfile(String selectedProfile) | ||
| 178 | { | ||
| 179 | YoctoUIElement profileElement = YoctoSDKUtils.getElemFromStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile)); | ||
| 180 | yoctoUISetting.setCurrentInput(profileElement); | ||
| 181 | } | ||
| 182 | |||
| 183 | public void switchToProjectSpecificProfile() | ||
| 184 | { | ||
| 185 | YoctoUIElement profileElement = ProjectPreferenceUtils.getElem(getProject()); | ||
| 186 | SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(profileElement); | ||
| 187 | |||
| 188 | if ((result != SDKCheckResults.SDK_PASS)) { | ||
| 189 | /* Project specific profile has not yet been defined, | ||
| 190 | * leave settings from previously selected profile | ||
| 191 | */ | ||
| 192 | return; | ||
| 193 | } | ||
| 194 | |||
| 195 | yoctoUISetting.setCurrentInput(profileElement); | ||
| 196 | } | ||
| 197 | |||
| 198 | public void switchToSelectedProfile() | ||
| 199 | { | ||
| 200 | switchProfile(yoctoProfileSetting.getCurrentInput().getSelectedProfile()); | ||
| 201 | } | ||
| 202 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java new file mode 100644 index 0000000..a06a03c --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/ProjectPreferenceUtils.java | |||
| @@ -0,0 +1,240 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
| 3 | * Copyright (c) 2010 Intel Corporation. | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * Intel - initial implementation | ||
| 11 | * BMW Car IT - initial implementation and refactoring | ||
| 12 | *******************************************************************************/ | ||
| 13 | package org.yocto.sdk.ide.utils; | ||
| 14 | |||
| 15 | import java.io.IOException; | ||
| 16 | |||
| 17 | import org.eclipse.cdt.core.CCorePlugin; | ||
| 18 | import org.eclipse.cdt.core.ConsoleOutputStream; | ||
| 19 | import org.eclipse.cdt.core.resources.IConsole; | ||
| 20 | import org.eclipse.core.resources.IProject; | ||
| 21 | import org.eclipse.core.resources.ProjectScope; | ||
| 22 | import org.eclipse.core.runtime.CoreException; | ||
| 23 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; | ||
| 24 | import org.eclipse.core.runtime.preferences.IScopeContext; | ||
| 25 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 26 | import org.osgi.service.prefs.BackingStoreException; | ||
| 27 | import org.yocto.sdk.ide.YoctoGeneralException; | ||
| 28 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 29 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 30 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 31 | import org.yocto.sdk.ide.natures.YoctoSDKAutotoolsProjectNature; | ||
| 32 | import org.yocto.sdk.ide.natures.YoctoSDKCMakeProjectNature; | ||
| 33 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
| 34 | |||
| 35 | public class ProjectPreferenceUtils { | ||
| 36 | private static final String CONSOLE_MESSAGE = "Menu.SDK.Console.Configure.Message"; | ||
| 37 | |||
| 38 | /* Get POKY Preference settings from project's preference store */ | ||
| 39 | public static YoctoUIElement getElem(IProject project) { | ||
| 40 | IScopeContext projectScope = new ProjectScope(project); | ||
| 41 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
| 42 | if (projectNode == null) { | ||
| 43 | return getElemFromProjectEnv(project); | ||
| 44 | } | ||
| 45 | |||
| 46 | YoctoUIElement elem = new YoctoUIElement(); | ||
| 47 | elem.setStrToolChainRoot(projectNode.get(PreferenceConstants.TOOLCHAIN_ROOT,"")); | ||
| 48 | elem.setStrTarget(projectNode.get(PreferenceConstants.TOOLCHAIN_TRIPLET,"")); | ||
| 49 | elem.setStrQemuKernelLoc(projectNode.get(PreferenceConstants.QEMU_KERNEL,"")); | ||
| 50 | elem.setStrSysrootLoc(projectNode.get(PreferenceConstants.SYSROOT,"")); | ||
| 51 | elem.setStrQemuOption(projectNode.get(PreferenceConstants.QEMU_OPTION,"")); | ||
| 52 | String sTemp = projectNode.get(PreferenceConstants.TARGET_ARCH_INDEX,""); | ||
| 53 | if (!sTemp.isEmpty()) { | ||
| 54 | elem.setIntTargetIndex(Integer.valueOf(sTemp).intValue()); | ||
| 55 | } | ||
| 56 | |||
| 57 | if (projectNode.get(PreferenceConstants.SDK_MODE,"").equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
| 58 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_SDK_MODE); | ||
| 59 | } else { | ||
| 60 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_TREE_MODE); | ||
| 61 | } | ||
| 62 | |||
| 63 | if(projectNode.get(PreferenceConstants.TARGET_MODE,"").equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
| 64 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.QEMU_MODE); | ||
| 65 | } else { | ||
| 66 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.DEVICE_MODE); | ||
| 67 | } | ||
| 68 | return elem; | ||
| 69 | } | ||
| 70 | |||
| 71 | /* Get POKY Preference settings from project's environment */ | ||
| 72 | public static YoctoUIElement getElemFromProjectEnv(IProject project) { | ||
| 73 | YoctoUIElement elem = new YoctoUIElement(); | ||
| 74 | elem.setStrToolChainRoot(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TOOLCHAIN_ROOT)); | ||
| 75 | elem.setStrTarget(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TOOLCHAIN_TRIPLET)); | ||
| 76 | elem.setStrQemuKernelLoc(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.QEMU_KERNEL)); | ||
| 77 | elem.setStrSysrootLoc(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.SYSROOT)); | ||
| 78 | elem.setStrQemuOption(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.QEMU_OPTION)); | ||
| 79 | String sTemp = YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TARGET_ARCH_INDEX); | ||
| 80 | |||
| 81 | if (!sTemp.isEmpty()) { | ||
| 82 | elem.setIntTargetIndex(Integer.valueOf(sTemp).intValue()); | ||
| 83 | } | ||
| 84 | |||
| 85 | if (YoctoSDKUtils.getEnvValue(project, PreferenceConstants.SDK_MODE).equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
| 86 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_SDK_MODE); | ||
| 87 | } else { | ||
| 88 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_TREE_MODE); | ||
| 89 | } | ||
| 90 | |||
| 91 | if(YoctoSDKUtils.getEnvValue(project, PreferenceConstants.TARGET_MODE).equalsIgnoreCase(IPreferenceStore.TRUE)) { | ||
| 92 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.QEMU_MODE); | ||
| 93 | } else { | ||
| 94 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.DEVICE_MODE); | ||
| 95 | } | ||
| 96 | |||
| 97 | return elem; | ||
| 98 | } | ||
| 99 | |||
| 100 | /* Get profiles and selected profile from the project's preference store */ | ||
| 101 | public static YoctoProfileElement getProfiles(IProject project) { | ||
| 102 | IScopeContext projectScope = new ProjectScope(project); | ||
| 103 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
| 104 | |||
| 105 | if (projectNode == null) { | ||
| 106 | return YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 107 | } | ||
| 108 | |||
| 109 | String profiles = projectNode.get(PreferenceConstants.PROFILES, ""); | ||
| 110 | String selectedProfile = projectNode.get(PreferenceConstants.SELECTED_PROFILE, ""); | ||
| 111 | |||
| 112 | return new YoctoProfileElement(profiles, selectedProfile); | ||
| 113 | } | ||
| 114 | |||
| 115 | public static boolean getUseProjectSpecificOption(IProject project) { | ||
| 116 | IScopeContext projectScope = new ProjectScope(project); | ||
| 117 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
| 118 | if (projectNode == null) { | ||
| 119 | return false; | ||
| 120 | } | ||
| 121 | |||
| 122 | String useProjectSpecificSettingString = projectNode.get(PreferenceConstants.PROJECT_SPECIFIC_PROFILE, | ||
| 123 | IPreferenceStore.FALSE); | ||
| 124 | |||
| 125 | if (useProjectSpecificSettingString.equals(IPreferenceStore.FALSE)) { | ||
| 126 | return false; | ||
| 127 | } | ||
| 128 | |||
| 129 | return true; | ||
| 130 | } | ||
| 131 | |||
| 132 | /* Save POKY Preference settings to project's preference store */ | ||
| 133 | public static void saveElem(YoctoUIElement elem, IProject project) { | ||
| 134 | IScopeContext projectScope = new ProjectScope(project); | ||
| 135 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
| 136 | if (projectNode == null) { | ||
| 137 | return; | ||
| 138 | } | ||
| 139 | |||
| 140 | projectNode.putInt(PreferenceConstants.TARGET_ARCH_INDEX, elem.getIntTargetIndex()); | ||
| 141 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
| 142 | projectNode.put(PreferenceConstants.SDK_MODE, IPreferenceStore.TRUE); | ||
| 143 | } else { | ||
| 144 | projectNode.put(PreferenceConstants.SDK_MODE, IPreferenceStore.FALSE); | ||
| 145 | } | ||
| 146 | projectNode.put(PreferenceConstants.QEMU_KERNEL, elem.getStrQemuKernelLoc()); | ||
| 147 | projectNode.put(PreferenceConstants.QEMU_OPTION, elem.getStrQemuOption()); | ||
| 148 | projectNode.put(PreferenceConstants.SYSROOT, elem.getStrSysrootLoc()); | ||
| 149 | if (elem.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) { | ||
| 150 | projectNode.put(PreferenceConstants.TARGET_MODE, IPreferenceStore.TRUE); | ||
| 151 | } else { | ||
| 152 | projectNode.put(PreferenceConstants.TARGET_MODE, IPreferenceStore.FALSE); | ||
| 153 | } | ||
| 154 | projectNode.put(PreferenceConstants.TOOLCHAIN_ROOT, elem.getStrToolChainRoot()); | ||
| 155 | projectNode.put(PreferenceConstants.TOOLCHAIN_TRIPLET, elem.getStrTarget()); | ||
| 156 | |||
| 157 | try { | ||
| 158 | projectNode.flush(); | ||
| 159 | } catch (BackingStoreException e) { | ||
| 160 | e.printStackTrace(); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | /* Save POKY Preference settings to project's environment */ | ||
| 165 | public static void saveElemToProjectEnv(YoctoUIElement elem, IProject project) { | ||
| 166 | ConsoleOutputStream consoleOutStream = null; | ||
| 167 | |||
| 168 | try { | ||
| 169 | YoctoSDKUtils.setEnvironmentVariables(project, elem); | ||
| 170 | YoctoSDKUtils.createRemoteDebugAndQemuLaunchers(project, elem); | ||
| 171 | |||
| 172 | if (project.hasNature(YoctoSDKAutotoolsProjectNature.YoctoSDK_AUTOTOOLS_NATURE_ID)) { | ||
| 173 | YoctoSDKAutotoolsProjectNature.configureAutotoolsOptions(project); | ||
| 174 | } else if (project.hasNature(YoctoSDKCMakeProjectNature.YoctoSDK_CMAKE_NATURE_ID)) { | ||
| 175 | YoctoSDKCMakeProjectNature.extendProjectEnvironmentForCMake(project); | ||
| 176 | } | ||
| 177 | |||
| 178 | IConsole console = CCorePlugin.getDefault().getConsole("org.yocto.sdk.ide.YoctoConsole"); | ||
| 179 | console.start(project); | ||
| 180 | consoleOutStream = console.getOutputStream(); | ||
| 181 | String messages = YoctoSDKMessages.getString(CONSOLE_MESSAGE); | ||
| 182 | consoleOutStream.write(messages.getBytes()); | ||
| 183 | } catch (CoreException e) { | ||
| 184 | System.out.println(e.getMessage()); | ||
| 185 | } catch (IOException e) { | ||
| 186 | System.out.println(e.getMessage()); | ||
| 187 | } catch (YoctoGeneralException e) { | ||
| 188 | System.out.println(e.getMessage()); | ||
| 189 | } finally { | ||
| 190 | if (consoleOutStream != null) { | ||
| 191 | try { | ||
| 192 | consoleOutStream.flush(); | ||
| 193 | consoleOutStream.close(); | ||
| 194 | } catch (IOException e) { | ||
| 195 | // ignore | ||
| 196 | } | ||
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | /* Save profiles and selected profile to the project's preference store */ | ||
| 202 | public static void saveProfiles(YoctoProfileElement profileElement, IProject project) { | ||
| 203 | IScopeContext projectScope = new ProjectScope(project); | ||
| 204 | IEclipsePreferences projectPreferences = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
| 205 | |||
| 206 | if (projectPreferences == null) { | ||
| 207 | return; | ||
| 208 | } | ||
| 209 | |||
| 210 | projectPreferences.put(PreferenceConstants.PROFILES, profileElement.getProfilesAsString()); | ||
| 211 | projectPreferences.put(PreferenceConstants.SELECTED_PROFILE, profileElement.getSelectedProfile()); | ||
| 212 | |||
| 213 | try { | ||
| 214 | projectPreferences.flush(); | ||
| 215 | } catch (BackingStoreException e) { | ||
| 216 | // TODO Auto-generated catch block | ||
| 217 | e.printStackTrace(); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | public static void saveUseProjectSpecificOption(IProject project, boolean useProjectSpecificSetting) { | ||
| 222 | IScopeContext projectScope = new ProjectScope(project); | ||
| 223 | IEclipsePreferences projectNode = projectScope.getNode(YoctoSDKUtilsConstants.PROJECT_SCOPE); | ||
| 224 | if (projectNode == null) { | ||
| 225 | return; | ||
| 226 | } | ||
| 227 | |||
| 228 | if (useProjectSpecificSetting) { | ||
| 229 | projectNode.put(PreferenceConstants.PROJECT_SPECIFIC_PROFILE, IPreferenceStore.TRUE); | ||
| 230 | } else { | ||
| 231 | projectNode.put(PreferenceConstants.PROJECT_SPECIFIC_PROFILE, IPreferenceStore.FALSE); | ||
| 232 | } | ||
| 233 | |||
| 234 | try { | ||
| 235 | projectNode.flush(); | ||
| 236 | } catch (BackingStoreException e) { | ||
| 237 | e.printStackTrace(); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/YoctoSDKUtils.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/YoctoSDKUtils.java new file mode 100644 index 0000000..2ac48f8 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/YoctoSDKUtils.java | |||
| @@ -0,0 +1,461 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | * BMW Car IT - add methods to use different preference stores | ||
| 11 | * Atanas Gegov (BMW Car IT) - add method to get the project environment | ||
| 12 | *******************************************************************************/ | ||
| 13 | package org.yocto.sdk.ide.utils; | ||
| 14 | |||
| 15 | import java.io.BufferedReader; | ||
| 16 | import java.io.File; | ||
| 17 | import java.io.FileReader; | ||
| 18 | import java.io.FileWriter; | ||
| 19 | import java.io.IOException; | ||
| 20 | import java.util.ArrayList; | ||
| 21 | import java.util.HashMap; | ||
| 22 | import java.util.HashSet; | ||
| 23 | import java.util.Iterator; | ||
| 24 | import java.util.Set; | ||
| 25 | import java.util.StringTokenizer; | ||
| 26 | |||
| 27 | import org.eclipse.cdt.core.CCorePlugin; | ||
| 28 | import org.eclipse.cdt.core.envvar.IContributedEnvironment; | ||
| 29 | import org.eclipse.cdt.core.envvar.IEnvironmentVariable; | ||
| 30 | import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; | ||
| 31 | import org.eclipse.cdt.core.model.CoreModel; | ||
| 32 | import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; | ||
| 33 | import org.eclipse.cdt.core.settings.model.ICProjectDescription; | ||
| 34 | import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; | ||
| 35 | import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants; | ||
| 36 | import org.eclipse.core.resources.IProject; | ||
| 37 | import org.eclipse.core.runtime.CoreException; | ||
| 38 | import org.eclipse.debug.core.DebugPlugin; | ||
| 39 | import org.eclipse.debug.core.ILaunchConfiguration; | ||
| 40 | import org.eclipse.debug.core.ILaunchConfigurationType; | ||
| 41 | import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; | ||
| 42 | import org.eclipse.debug.core.ILaunchManager; | ||
| 43 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 44 | import org.yocto.sdk.ide.YoctoGeneralException; | ||
| 45 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 46 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 47 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 48 | import org.yocto.sdk.ide.natures.YoctoSDKCMakeProjectNature; | ||
| 49 | import org.yocto.sdk.ide.natures.YoctoSDKEmptyProjectNature; | ||
| 50 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
| 51 | |||
| 52 | public class YoctoSDKUtils { | ||
| 53 | |||
| 54 | private static final String DEFAULT_SYSROOT_PREFIX = "--sysroot="; | ||
| 55 | private static final String LIBTOOL_SYSROOT_PREFIX = "--with-libtool-sysroot="; | ||
| 56 | |||
| 57 | private static final String DEFAULT_USR_BIN = "/usr/bin/"; | ||
| 58 | private static final String NATIVE_SYSROOT = "OECORE_NATIVE_SYSROOT"; | ||
| 59 | |||
| 60 | public static String getEnvValue(IProject project, String strKey) | ||
| 61 | { | ||
| 62 | ICProjectDescription cpdesc = CoreModel.getDefault().getProjectDescription(project, true); | ||
| 63 | ICConfigurationDescription ccdesc = cpdesc.getActiveConfiguration(); | ||
| 64 | IEnvironmentVariableManager manager = CCorePlugin.getDefault().getBuildEnvironmentManager(); | ||
| 65 | IContributedEnvironment env = manager.getContributedEnvironment(); | ||
| 66 | IEnvironmentVariable var = env.getVariable(strKey, ccdesc); | ||
| 67 | |||
| 68 | if (var == null) | ||
| 69 | { | ||
| 70 | System.out.printf("ENV key %s is NULL\n", strKey); | ||
| 71 | return ""; | ||
| 72 | } | ||
| 73 | |||
| 74 | else | ||
| 75 | return var.getValue(); | ||
| 76 | } | ||
| 77 | |||
| 78 | /* Save project wide settings into ENV VARs including POKY preference settings | ||
| 79 | * and Environment Script File export VARs | ||
| 80 | */ | ||
| 81 | private static void setEnvVars(ICProjectDescription cpdesc, | ||
| 82 | YoctoUIElement elem, HashMap<String, String> envMap) { | ||
| 83 | ICConfigurationDescription ccdesc = cpdesc.getActiveConfiguration(); | ||
| 84 | IEnvironmentVariableManager manager = CCorePlugin.getDefault().getBuildEnvironmentManager(); | ||
| 85 | IContributedEnvironment env = manager.getContributedEnvironment(); | ||
| 86 | String delimiter = manager.getDefaultDelimiter(); | ||
| 87 | |||
| 88 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) | ||
| 89 | env.addVariable(PreferenceConstants.SDK_MODE, IPreferenceStore.TRUE, | ||
| 90 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 91 | else | ||
| 92 | env.addVariable(PreferenceConstants.SDK_MODE, IPreferenceStore.FALSE, | ||
| 93 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 94 | |||
| 95 | env.addVariable(PreferenceConstants.TOOLCHAIN_ROOT, elem.getStrToolChainRoot(), | ||
| 96 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 97 | env.addVariable(PreferenceConstants.TOOLCHAIN_TRIPLET, elem.getStrTarget(), | ||
| 98 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 99 | env.addVariable(PreferenceConstants.TARGET_ARCH_INDEX, String.valueOf(elem.getIntTargetIndex()), | ||
| 100 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 101 | |||
| 102 | if (elem.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) | ||
| 103 | env.addVariable(PreferenceConstants.TARGET_MODE, IPreferenceStore.TRUE, | ||
| 104 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 105 | else | ||
| 106 | env.addVariable(PreferenceConstants.TARGET_MODE, IPreferenceStore.FALSE, | ||
| 107 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 108 | |||
| 109 | env.addVariable(PreferenceConstants.QEMU_KERNEL, elem.getStrQemuKernelLoc(), | ||
| 110 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 111 | env.addVariable(PreferenceConstants.QEMU_OPTION, elem.getStrQemuOption(), | ||
| 112 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 113 | env.addVariable(PreferenceConstants.SYSROOT, elem.getStrSysrootLoc(), | ||
| 114 | IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 115 | |||
| 116 | if (envMap == null) | ||
| 117 | { | ||
| 118 | System.out.println("ENV var hasmap is NULL, Please check ENV script File!"); | ||
| 119 | return; | ||
| 120 | } | ||
| 121 | Iterator<String> iter = envMap.keySet().iterator(); | ||
| 122 | while (iter.hasNext()) | ||
| 123 | { | ||
| 124 | String sKey = (String)iter.next(); | ||
| 125 | String sValue = (String)envMap.get(sKey); | ||
| 126 | String targetFilePath; | ||
| 127 | File targetFile; | ||
| 128 | //replace --sysroot | ||
| 129 | if (sKey.matches("CFLAGS") || sKey.matches("CXXFLAGS") || sKey.matches("CXXFLAGS") || sKey.matches("LDFLAGS") || | ||
| 130 | sKey.matches("CPPFLAGS")) { | ||
| 131 | |||
| 132 | int SYSROOT_idx = sValue.lastIndexOf(DEFAULT_SYSROOT_PREFIX); | ||
| 133 | if (SYSROOT_idx >=0 ) | ||
| 134 | sValue = sValue.substring(0, SYSROOT_idx) + DEFAULT_SYSROOT_PREFIX + elem.getStrSysrootLoc(); | ||
| 135 | else | ||
| 136 | sValue = " " + DEFAULT_SYSROOT_PREFIX + elem.getStrSysrootLoc(); | ||
| 137 | targetFilePath = elem.getStrSysrootLoc() + "/" + elem.getStrTarget(); | ||
| 138 | targetFile = new File(targetFilePath); | ||
| 139 | if (targetFile.exists()) | ||
| 140 | sValue = sValue + "/" + elem.getStrTarget(); | ||
| 141 | } else if (sKey.matches("CONFIGURE_FLAGS")) { | ||
| 142 | int LIBTOOL_idx = sValue.lastIndexOf(LIBTOOL_SYSROOT_PREFIX); | ||
| 143 | if (LIBTOOL_idx >= 0) | ||
| 144 | sValue = sValue.substring(0, LIBTOOL_idx) + LIBTOOL_SYSROOT_PREFIX + elem.getStrSysrootLoc(); | ||
| 145 | else | ||
| 146 | sValue = " " + LIBTOOL_SYSROOT_PREFIX + elem.getStrSysrootLoc(); | ||
| 147 | targetFilePath = elem.getStrSysrootLoc() + "/" + elem.getStrTarget(); | ||
| 148 | targetFile = new File(targetFilePath); | ||
| 149 | if (targetFile.exists()) | ||
| 150 | sValue = sValue + "/" + elem.getStrTarget(); | ||
| 151 | } else if(sKey.matches("PKG_CONFIG_SYSROOT_DIR") || sKey.matches("OECORE_TARGET_SYSROOT")) { | ||
| 152 | sValue = elem.getStrSysrootLoc(); | ||
| 153 | targetFilePath = elem.getStrSysrootLoc() + "/" + elem.getStrTarget(); | ||
| 154 | targetFile = new File(targetFilePath); | ||
| 155 | if (targetFile.exists()) | ||
| 156 | sValue = sValue + "/" + elem.getStrTarget(); | ||
| 157 | } else if (sKey.matches("PKG_CONFIG_PATH")) { | ||
| 158 | sValue = elem.getStrSysrootLoc(); | ||
| 159 | targetFilePath = elem.getStrSysrootLoc() + "/" + elem.getStrTarget(); | ||
| 160 | targetFile = new File(targetFilePath); | ||
| 161 | if (targetFile.exists()) | ||
| 162 | sValue = sValue + "/" + elem.getStrTarget(); | ||
| 163 | sValue = sValue + "/usr/lib/pkgconfig"; | ||
| 164 | } | ||
| 165 | // env.addVariable(sKey, elem.getStrSysrootLoc(), IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 166 | /* | ||
| 167 | else if (sKey.matches("PKG_CONFIG_PATH")) | ||
| 168 | env.addVariable(sKey, elem.getStrSysrootLoc()+"/"+elem.getStrTarget()+"/usr/lib/pkgconfig", IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 169 | //env.addVariable(sKey, sValue, IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 170 | else if (sKey.matches("PKG_CONFIG_SYSROOT_DIR")) | ||
| 171 | env.addVariable(sKey, elem.getStrSysrootLoc()+"/"+elem.getStrTarget(), IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 172 | */ | ||
| 173 | env.addVariable(sKey, sValue, IEnvironmentVariable.ENVVAR_REPLACE, delimiter, ccdesc); | ||
| 174 | } | ||
| 175 | //add ACLOCAL OPTS for libtool 2.4 support | ||
| 176 | env.addVariable("OECORE_ACLOCAL_OPTS", | ||
| 177 | "-I " + env.getVariable(NATIVE_SYSROOT, ccdesc).getValue() + "/usr/share/aclocal", | ||
| 178 | IEnvironmentVariable.ENVVAR_REPLACE, | ||
| 179 | delimiter, | ||
| 180 | ccdesc); | ||
| 181 | return; | ||
| 182 | |||
| 183 | } | ||
| 184 | |||
| 185 | private static String getEnvironmentSetupFileFullPath(YoctoUIElement elem) { | ||
| 186 | String envSetupFile = ""; | ||
| 187 | |||
| 188 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
| 189 | envSetupFile = elem.getStrToolChainRoot() + "/"; | ||
| 190 | } else { | ||
| 191 | //POKY TREE Mode | ||
| 192 | envSetupFile = elem.getStrToolChainRoot() + YoctoSDKUtilsConstants.DEFAULT_TMP_PREFIX; | ||
| 193 | } | ||
| 194 | envSetupFile += YoctoSDKUtilsConstants.DEFAULT_ENV_FILE_PREFIX + elem.getStrTarget(); | ||
| 195 | return envSetupFile; | ||
| 196 | } | ||
| 197 | |||
| 198 | private static HashMap<String, String> parseEnvScript(String sFileName) { | ||
| 199 | try { | ||
| 200 | HashMap<String, String> envMap = new HashMap<String, String>(); | ||
| 201 | File file = new File(sFileName); | ||
| 202 | |||
| 203 | if (file.exists()) { | ||
| 204 | BufferedReader input = new BufferedReader(new FileReader(file)); | ||
| 205 | |||
| 206 | try { | ||
| 207 | String line = null; | ||
| 208 | |||
| 209 | while ((line = input.readLine()) != null) { | ||
| 210 | if (!line.startsWith("export")) { | ||
| 211 | continue; | ||
| 212 | } | ||
| 213 | String sKey = line.substring("export".length() + 1, line.indexOf('=')); | ||
| 214 | String sValue = line.substring(line.indexOf('=') + 1); | ||
| 215 | if (sValue.startsWith("\"") && sValue.endsWith("\"")) | ||
| 216 | sValue = sValue.substring(sValue.indexOf('"') + 1, sValue.lastIndexOf('"')); | ||
| 217 | /* If PATH ending with $PATH, we need to join with current system path */ | ||
| 218 | if (sKey.equalsIgnoreCase("PATH")) { | ||
| 219 | if (sValue.lastIndexOf("$PATH") >= 0) | ||
| 220 | sValue = sValue.substring(0, sValue.lastIndexOf("$PATH")) + System.getenv("PATH"); | ||
| 221 | } | ||
| 222 | envMap.put(sKey, sValue); | ||
| 223 | System.out.printf("get env key %s value %s\n", sKey, sValue); | ||
| 224 | } | ||
| 225 | } finally { | ||
| 226 | input.close(); | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | return envMap; | ||
| 231 | |||
| 232 | } catch (IOException e) { | ||
| 233 | e.printStackTrace(); | ||
| 234 | return null; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | public static void setEnvironmentVariables(IProject project, YoctoUIElement elem) { | ||
| 239 | ICProjectDescription cpdesc = CoreModel.getDefault().getProjectDescription(project, true); | ||
| 240 | |||
| 241 | String sFileName = getEnvironmentSetupFileFullPath(elem); | ||
| 242 | HashMap<String, String> envMap = parseEnvScript(sFileName); | ||
| 243 | |||
| 244 | setEnvVars(cpdesc, elem, envMap); | ||
| 245 | try { | ||
| 246 | CoreModel.getDefault().setProjectDescription(project,cpdesc); | ||
| 247 | } catch (CoreException e) { | ||
| 248 | e.printStackTrace(); | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | public static void createRemoteDebugAndQemuLaunchers(IProject project, YoctoUIElement elem) throws YoctoGeneralException { | ||
| 253 | ILaunchManager lManager = DebugPlugin.getDefault().getLaunchManager(); | ||
| 254 | ILaunchConfigurationType configType = | ||
| 255 | lManager.getLaunchConfigurationType("org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"); | ||
| 256 | ILaunchConfigurationType debug_configType = | ||
| 257 | lManager.getLaunchConfigurationType("org.eclipse.cdt.launch.remoteApplicationLaunchType"); | ||
| 258 | |||
| 259 | String sPath = getEnvValue(project, "PATH"); | ||
| 260 | String sDebugName = getEnvValue(project, "GDB"); | ||
| 261 | String sysroot_str = elem.getStrSysrootLoc(); | ||
| 262 | |||
| 263 | if (configType == null || debug_configType == null) { | ||
| 264 | throw new YoctoGeneralException("Failed to get program or remote debug launcher!"); | ||
| 265 | } | ||
| 266 | createRemoteDebugLauncher(project, lManager, debug_configType, elem.getStrTarget(), sPath, sDebugName, sysroot_str); | ||
| 267 | |||
| 268 | ArrayList<String> listValue = new ArrayList<String>(); | ||
| 269 | listValue.add(new String("org.eclipse.ui.externaltools.launchGroup")); | ||
| 270 | |||
| 271 | if (elem.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) { | ||
| 272 | String sFileName = getEnvironmentSetupFileFullPath(elem); | ||
| 273 | createQemuLauncher(project, configType, listValue, sFileName, elem); | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | protected static void createRemoteDebugLauncher(IProject project, | ||
| 278 | ILaunchManager lManager, ILaunchConfigurationType configType, | ||
| 279 | String sTargetTriplet, String strPath, String sDebugName, String sSysroot) { | ||
| 280 | try { | ||
| 281 | |||
| 282 | String sDebugSubDir = DEFAULT_USR_BIN + sTargetTriplet; | ||
| 283 | StringTokenizer token = new StringTokenizer(strPath, ":"); | ||
| 284 | String strDebugger = ""; | ||
| 285 | while (token.hasMoreTokens()) | ||
| 286 | { | ||
| 287 | String sTemp = token.nextToken(); | ||
| 288 | if (sTemp.endsWith(sDebugSubDir)) { | ||
| 289 | strDebugger = sTemp + "/" + sDebugName; | ||
| 290 | break; | ||
| 291 | } | ||
| 292 | } | ||
| 293 | if (strDebugger.isEmpty()) | ||
| 294 | return; | ||
| 295 | //If get default Debugger successfully, go ahead! | ||
| 296 | |||
| 297 | //create the gdbinit file | ||
| 298 | String sDebugInitFile = project.getLocation().toString() + "/.gdbinit"; | ||
| 299 | FileWriter out = new FileWriter(new File(sDebugInitFile)); | ||
| 300 | out.write("set sysroot " + sSysroot); | ||
| 301 | out.flush(); | ||
| 302 | out.close(); | ||
| 303 | |||
| 304 | //set the launch configuration | ||
| 305 | String projectName = project.getName(); | ||
| 306 | String configName = projectName+"_gdb_"+sTargetTriplet; | ||
| 307 | int i; | ||
| 308 | ILaunchConfiguration[] configs=lManager.getLaunchConfigurations(configType); | ||
| 309 | for(i=0; i<configs.length; i++) | ||
| 310 | { //delete the old configuration | ||
| 311 | ILaunchConfiguration config=configs[i]; | ||
| 312 | if(config.getName().equals(configName)) { | ||
| 313 | config.delete(); | ||
| 314 | break; | ||
| 315 | } | ||
| 316 | } | ||
| 317 | ILaunchConfigurationWorkingCopy w_copy = configType.newInstance(project, configName); | ||
| 318 | Set<String> modes=new HashSet<String>(); | ||
| 319 | modes.add("debug"); | ||
| 320 | w_copy.setPreferredLaunchDelegate(modes, "org.eclipse.rse.remotecdt.launch"); | ||
| 321 | w_copy.setAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, sDebugInitFile); | ||
| 322 | w_copy.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_AUTO_SOLIB, false); | ||
| 323 | w_copy.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, strDebugger); | ||
| 324 | w_copy.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); | ||
| 325 | //TWEAK avoid loading default values in org.eclipse.cdt.launch.remote.tabs.RemoteCDebuggerTab | ||
| 326 | w_copy.setAttribute("org.eclipse.cdt.launch.remote.RemoteCDSFDebuggerTab.DEFAULTS_SET",true); | ||
| 327 | w_copy.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName); | ||
| 328 | if (!project.hasNature(YoctoSDKEmptyProjectNature.YoctoSDK_EMPTY_NATURE_ID)) { | ||
| 329 | String pathToCompiledBinary = ""; | ||
| 330 | if (project.hasNature(YoctoSDKCMakeProjectNature.YoctoSDK_CMAKE_NATURE_ID)) { | ||
| 331 | pathToCompiledBinary = "Debug/"; | ||
| 332 | } else { | ||
| 333 | pathToCompiledBinary = "src/"; | ||
| 334 | } | ||
| 335 | pathToCompiledBinary += projectName; | ||
| 336 | w_copy.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, pathToCompiledBinary); | ||
| 337 | } | ||
| 338 | |||
| 339 | w_copy.doSave(); | ||
| 340 | } | ||
| 341 | catch (CoreException e) | ||
| 342 | { | ||
| 343 | System.out.println(e.getMessage()); | ||
| 344 | } | ||
| 345 | catch (IOException e) | ||
| 346 | { | ||
| 347 | System.out.println("Failed to generate debug init file!"); | ||
| 348 | System.out.println(e.getMessage()); | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | protected static void createQemuLauncher(IProject project, | ||
| 353 | ILaunchConfigurationType configType, | ||
| 354 | ArrayList<String> listValue, String sScriptFile, | ||
| 355 | YoctoUIElement elem) { | ||
| 356 | try { | ||
| 357 | |||
| 358 | ILaunchConfigurationWorkingCopy w_copy = configType.newInstance(null, "qemu_"+elem.getStrTarget()); | ||
| 359 | |||
| 360 | w_copy.setAttribute("org.eclipse.debug.ui.favoriteGroups", listValue); | ||
| 361 | w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", "/usr/bin/xterm"); | ||
| 362 | |||
| 363 | String argument = "-e \"source " + sScriptFile + ";runqemu " + qemuTargetTranslate(elem.getStrTarget()) + " " + | ||
| 364 | elem.getStrQemuKernelLoc() + " " + elem.getStrSysrootLoc() + " " + elem.getStrQemuOption() + ";bash\""; | ||
| 365 | |||
| 366 | w_copy.setAttribute("org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS", argument); | ||
| 367 | w_copy.doSave(); | ||
| 368 | } catch (CoreException e) { | ||
| 369 | } | ||
| 370 | |||
| 371 | } | ||
| 372 | |||
| 373 | private static String qemuTargetTranslate(String strTargetArch) { | ||
| 374 | String qemu_target = ""; | ||
| 375 | if (strTargetArch.indexOf("i586") != -1) { | ||
| 376 | qemu_target = "qemux86"; | ||
| 377 | } else if (strTargetArch.indexOf("x86_64") != -1) { | ||
| 378 | qemu_target = "qemux86-64"; | ||
| 379 | } else if (strTargetArch.indexOf("arm") != -1) { | ||
| 380 | qemu_target = "qemuarm"; | ||
| 381 | } else if (strTargetArch.indexOf("mips") != -1) { | ||
| 382 | qemu_target = "qemumips"; | ||
| 383 | } else if (strTargetArch.indexOf("ppc") != -1) { | ||
| 384 | qemu_target = "qemuppc"; | ||
| 385 | } | ||
| 386 | return qemu_target; | ||
| 387 | } | ||
| 388 | |||
| 389 | /* Get IDE wide POKY Preference settings from a specific preference store */ | ||
| 390 | public static YoctoUIElement getElemFromStore(IPreferenceStore store) { | ||
| 391 | YoctoUIElement elem = new YoctoUIElement(); | ||
| 392 | if (store.getString(PreferenceConstants.SDK_MODE).equals(IPreferenceStore.TRUE)) | ||
| 393 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_SDK_MODE); | ||
| 394 | else | ||
| 395 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_TREE_MODE); | ||
| 396 | |||
| 397 | elem.setStrToolChainRoot(store.getString(PreferenceConstants.TOOLCHAIN_ROOT)); | ||
| 398 | elem.setStrTarget(store.getString(PreferenceConstants.TOOLCHAIN_TRIPLET)); | ||
| 399 | elem.setIntTargetIndex(store.getInt(PreferenceConstants.TARGET_ARCH_INDEX)); | ||
| 400 | elem.setStrQemuKernelLoc(store.getString(PreferenceConstants.QEMU_KERNEL)); | ||
| 401 | elem.setStrQemuOption(store.getString(PreferenceConstants.QEMU_OPTION)); | ||
| 402 | elem.setStrSysrootLoc(store.getString(PreferenceConstants.SYSROOT)); | ||
| 403 | |||
| 404 | if (store.getString(PreferenceConstants.TARGET_MODE).equals(IPreferenceStore.TRUE)) | ||
| 405 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.QEMU_MODE); | ||
| 406 | else | ||
| 407 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.DEVICE_MODE); | ||
| 408 | |||
| 409 | return elem; | ||
| 410 | } | ||
| 411 | |||
| 412 | /* Get default POKY Preference settings from the default preference store */ | ||
| 413 | public static YoctoUIElement getDefaultElemFromDefaultStore() | ||
| 414 | { | ||
| 415 | IPreferenceStore store = YoctoSDKPlugin.getDefault().getPreferenceStore(); | ||
| 416 | YoctoUIElement elem = new YoctoUIElement(); | ||
| 417 | if (store.getDefaultString(PreferenceConstants.SDK_MODE).equals(IPreferenceStore.TRUE)) | ||
| 418 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_SDK_MODE); | ||
| 419 | else | ||
| 420 | elem.setEnumPokyMode(YoctoUIElement.PokyMode.POKY_TREE_MODE); | ||
| 421 | |||
| 422 | elem.setStrToolChainRoot(store.getDefaultString(PreferenceConstants.TOOLCHAIN_ROOT)); | ||
| 423 | elem.setStrTarget(store.getDefaultString(PreferenceConstants.TOOLCHAIN_TRIPLET)); | ||
| 424 | elem.setIntTargetIndex(store.getDefaultInt(PreferenceConstants.TARGET_ARCH_INDEX)); | ||
| 425 | elem.setStrQemuKernelLoc(store.getDefaultString(PreferenceConstants.QEMU_KERNEL)); | ||
| 426 | elem.setStrQemuOption(store.getDefaultString(PreferenceConstants.QEMU_OPTION)); | ||
| 427 | elem.setStrSysrootLoc(store.getDefaultString(PreferenceConstants.SYSROOT)); | ||
| 428 | |||
| 429 | if (store.getDefaultString(PreferenceConstants.TARGET_MODE).equals(IPreferenceStore.TRUE)) | ||
| 430 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.QEMU_MODE); | ||
| 431 | else | ||
| 432 | elem.setEnumDeviceMode(YoctoUIElement.DeviceMode.DEVICE_MODE); | ||
| 433 | |||
| 434 | return elem; | ||
| 435 | } | ||
| 436 | |||
| 437 | /* Save profiles and selected profile to the default preference store */ | ||
| 438 | public static void saveProfilesToDefaultStore(YoctoProfileElement profileElement) { | ||
| 439 | saveProfilesToStore(profileElement, YoctoSDKPlugin.getDefault().getPreferenceStore()); | ||
| 440 | } | ||
| 441 | |||
| 442 | /* Save profiles and selected profile to a specific preference store */ | ||
| 443 | private static void saveProfilesToStore(YoctoProfileElement profileElement, IPreferenceStore store) { | ||
| 444 | store.setValue(PreferenceConstants.PROFILES, profileElement.getProfilesAsString()); | ||
| 445 | store.setValue(PreferenceConstants.SELECTED_PROFILE, profileElement.getSelectedProfile()); | ||
| 446 | } | ||
| 447 | |||
| 448 | /* Get profiles and selected profile from the default preference store */ | ||
| 449 | public static YoctoProfileElement getProfilesFromDefaultStore() | ||
| 450 | { | ||
| 451 | return getProfilesFromStore(YoctoSDKPlugin.getDefault().getPreferenceStore()); | ||
| 452 | } | ||
| 453 | |||
| 454 | /* Get profiles and selected profile from a specific preference store */ | ||
| 455 | private static YoctoProfileElement getProfilesFromStore(IPreferenceStore store) { | ||
| 456 | String profiles = store.getString(PreferenceConstants.PROFILES); | ||
| 457 | String selectedProfile = store.getString(PreferenceConstants.SELECTED_PROFILE); | ||
| 458 | |||
| 459 | return new YoctoProfileElement(profiles, selectedProfile); | ||
| 460 | } | ||
| 461 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/YoctoSDKUtilsConstants.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/YoctoSDKUtilsConstants.java new file mode 100644 index 0000000..65dfce8 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/utils/YoctoSDKUtilsConstants.java | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2013 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.utils; | ||
| 12 | |||
| 13 | public class YoctoSDKUtilsConstants { | ||
| 14 | |||
| 15 | public static final String DEFAULT_ENV_FILE_PREFIX = "environment-setup-"; | ||
| 16 | public static final String DEFAULT_TMP_PREFIX = "/tmp/"; | ||
| 17 | public static final String PROJECT_SCOPE = "org.yocto.sdk.ide"; | ||
| 18 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java new file mode 100644 index 0000000..f467dac --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoAutotoolsProjectPostProcess.java | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.wizard; | ||
| 12 | |||
| 13 | import java.io.BufferedReader; | ||
| 14 | import java.io.File; | ||
| 15 | import java.io.InputStream; | ||
| 16 | import java.io.InputStreamReader; | ||
| 17 | |||
| 18 | import org.eclipse.cdt.core.templateengine.TemplateCore; | ||
| 19 | import org.eclipse.cdt.core.templateengine.process.ProcessArgument; | ||
| 20 | import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; | ||
| 21 | import org.eclipse.cdt.core.templateengine.process.ProcessRunner; | ||
| 22 | import org.eclipse.cdt.core.templateengine.process.processes.Messages; | ||
| 23 | import org.eclipse.core.resources.IProject; | ||
| 24 | import org.eclipse.core.resources.ResourcesPlugin; | ||
| 25 | import org.eclipse.core.runtime.IPath; | ||
| 26 | import org.eclipse.core.runtime.IProgressMonitor; | ||
| 27 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 28 | import org.yocto.sdk.ide.natures.YoctoSDKAutotoolsProjectNature; | ||
| 29 | |||
| 30 | public class NewYoctoAutotoolsProjectPostProcess extends ProcessRunner { | ||
| 31 | |||
| 32 | public static final String CHMOD_COMMAND = "chmod +x "; //$NON-NLS-1$ | ||
| 33 | public static final String AUTOGEN_SCRIPT_NAME = "autogen.sh"; //$NON-NLS-1$ | ||
| 34 | |||
| 35 | public NewYoctoAutotoolsProjectPostProcess() {} | ||
| 36 | |||
| 37 | public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException { | ||
| 38 | |||
| 39 | String projectName = args[0].getSimpleValue(); | ||
| 40 | |||
| 41 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); | ||
| 42 | try { | ||
| 43 | if (!project.exists()) { | ||
| 44 | throw new ProcessFailureException(Messages.getString("NewManagedProject.4") + projectName); //$NON-NLS-1$ | ||
| 45 | } else if (!project.hasNature(YoctoSDKAutotoolsProjectNature.YoctoSDK_AUTOTOOLS_NATURE_ID)) { | ||
| 46 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + //$NON-NLS-1$ | ||
| 47 | YoctoSDKMessages.getFormattedString("AutotoolsProjectPostProcess.WrongProjectNature", //$NON-NLS-1$ | ||
| 48 | projectName)); | ||
| 49 | } else { | ||
| 50 | IPath path = project.getLocation(); | ||
| 51 | String path_str = path.toString(); | ||
| 52 | String autogen_cmd = CHMOD_COMMAND + path_str + File.separator + AUTOGEN_SCRIPT_NAME; | ||
| 53 | try { | ||
| 54 | Runtime rt = Runtime.getRuntime(); | ||
| 55 | Process proc = rt.exec(autogen_cmd); | ||
| 56 | InputStream stdin = proc.getInputStream(); | ||
| 57 | InputStreamReader isr = new InputStreamReader(stdin); | ||
| 58 | BufferedReader br = new BufferedReader(isr); | ||
| 59 | String line = null; | ||
| 60 | String error_message = ""; //$NON-NLS-1$ | ||
| 61 | |||
| 62 | while ( (line = br.readLine()) != null) { | ||
| 63 | error_message = error_message + line; | ||
| 64 | } | ||
| 65 | |||
| 66 | int exitVal = proc.waitFor(); | ||
| 67 | if (exitVal != 0) { | ||
| 68 | throw new ProcessFailureException( | ||
| 69 | YoctoSDKMessages.getFormattedString("AutotoolsProjectPostProcess.ChmodFailure", //$NON-NLS-1$ | ||
| 70 | projectName)); | ||
| 71 | } | ||
| 72 | } catch (Throwable t) { | ||
| 73 | t.printStackTrace(); | ||
| 74 | |||
| 75 | } | ||
| 76 | } | ||
| 77 | } catch (Exception e) { | ||
| 78 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage(), e); //$NON-NLS-1$ | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoProjectTemplateProcess.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoProjectTemplateProcess.java new file mode 100644 index 0000000..d8c1232 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/wizard/NewYoctoProjectTemplateProcess.java | |||
| @@ -0,0 +1,270 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.wizard; | ||
| 12 | |||
| 13 | import java.util.Arrays; | ||
| 14 | import java.util.LinkedHashMap; | ||
| 15 | import java.util.List; | ||
| 16 | import java.util.regex.Matcher; | ||
| 17 | import java.util.regex.Pattern; | ||
| 18 | |||
| 19 | import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature; | ||
| 20 | import org.eclipse.cdt.core.CCorePlugin; | ||
| 21 | import org.eclipse.cdt.core.templateengine.TemplateCore; | ||
| 22 | import org.eclipse.cdt.core.templateengine.process.ProcessArgument; | ||
| 23 | import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; | ||
| 24 | import org.eclipse.cdt.core.templateengine.process.ProcessRunner; | ||
| 25 | import org.eclipse.cdt.core.templateengine.process.processes.Messages; | ||
| 26 | import org.eclipse.cdt.internal.autotools.core.configure.AutotoolsConfigurationManager; | ||
| 27 | import org.eclipse.cdt.make.core.MakeCorePlugin; | ||
| 28 | import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager; | ||
| 29 | import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; | ||
| 30 | import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerProjectDiscoveredPathInfo; | ||
| 31 | import org.eclipse.cdt.make.internal.core.scannerconfig.util.SymbolEntry; | ||
| 32 | import org.eclipse.cdt.managedbuilder.core.BuildException; | ||
| 33 | import org.eclipse.cdt.managedbuilder.core.IConfiguration; | ||
| 34 | import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; | ||
| 35 | import org.eclipse.cdt.managedbuilder.core.IOption; | ||
| 36 | import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; | ||
| 37 | import org.eclipse.cdt.managedbuilder.templateengine.ProjectCreatedActions; | ||
| 38 | import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager; | ||
| 39 | import org.eclipse.jface.wizard.IWizardPage; | ||
| 40 | import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; | ||
| 41 | import org.eclipse.cdt.internal.ui.wizards.ICDTCommonProjectWizard; | ||
| 42 | import org.eclipse.core.resources.IProject; | ||
| 43 | import org.eclipse.core.resources.IWorkspace; | ||
| 44 | import org.eclipse.core.resources.IWorkspaceDescription; | ||
| 45 | import org.eclipse.core.resources.ResourcesPlugin; | ||
| 46 | import org.eclipse.core.runtime.CoreException; | ||
| 47 | import org.eclipse.core.runtime.IPath; | ||
| 48 | import org.eclipse.core.runtime.IProgressMonitor; | ||
| 49 | import org.eclipse.core.runtime.OperationCanceledException; | ||
| 50 | import org.eclipse.core.runtime.Path; | ||
| 51 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 52 | import org.yocto.sdk.ide.YoctoGeneralException; | ||
| 53 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 54 | import org.yocto.sdk.ide.YoctoSDKChecker; | ||
| 55 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 56 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 57 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 58 | import org.yocto.sdk.ide.natures.YoctoSDKAutotoolsProjectNature; | ||
| 59 | import org.yocto.sdk.ide.natures.YoctoSDKCMakeProjectNature; | ||
| 60 | import org.yocto.sdk.ide.natures.YoctoSDKEmptyProjectNature; | ||
| 61 | import org.yocto.sdk.ide.natures.YoctoSDKNatureUtils; | ||
| 62 | import org.yocto.sdk.ide.natures.YoctoSDKProjectNature; | ||
| 63 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 64 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 65 | |||
| 66 | @SuppressWarnings("restriction") | ||
| 67 | public class NewYoctoProjectTemplateProcess extends ProcessRunner { | ||
| 68 | protected boolean savedAutoBuildingValue; | ||
| 69 | protected ProjectCreatedActions pca; | ||
| 70 | protected IManagedBuildInfo info; | ||
| 71 | protected List<Character> illegalChars = Arrays.asList('$', '"','#','%','&','\'','(',')','*', '+', ',','.','/',':',';','<','=','>','?','@','[','\\',']','^','`','{','|','}','~'); | ||
| 72 | private static final String PROJECT_NAME_ERROR = "Wizard.SDK.Error.ProjectName"; | ||
| 73 | |||
| 74 | private boolean isCProject; | ||
| 75 | private boolean isEmptyProject; | ||
| 76 | private boolean isAutotoolsProject; | ||
| 77 | private boolean isCMakeProject; | ||
| 78 | |||
| 79 | public NewYoctoProjectTemplateProcess() { | ||
| 80 | pca = new ProjectCreatedActions(); | ||
| 81 | |||
| 82 | isCProject = false; | ||
| 83 | isEmptyProject = false; | ||
| 84 | isAutotoolsProject = false; | ||
| 85 | isCMakeProject = false; | ||
| 86 | } | ||
| 87 | |||
| 88 | private String printIllegalChars(){ | ||
| 89 | String print = ""; | ||
| 90 | for (Character ch : illegalChars) | ||
| 91 | print += ch + ", "; | ||
| 92 | print = print.substring(0, print.length() - 2); | ||
| 93 | return print; | ||
| 94 | } | ||
| 95 | |||
| 96 | public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException { | ||
| 97 | |||
| 98 | String projectName = args[0].getSimpleValue(); | ||
| 99 | String location = args[1].getSimpleValue(); | ||
| 100 | String artifactExtension = args[2].getSimpleValue(); | ||
| 101 | String isCProjectValue = args[3].getSimpleValue(); | ||
| 102 | String isEmptyProjetValue = args[4].getSimpleValue(); | ||
| 103 | String isAutotoolsProjectValue = args[5].getSimpleValue(); | ||
| 104 | String isCMakeProjectValue = args[6].getSimpleValue(); | ||
| 105 | |||
| 106 | isCProject = Boolean.valueOf(isCProjectValue).booleanValue(); | ||
| 107 | isEmptyProject = Boolean.valueOf(isEmptyProjetValue).booleanValue(); | ||
| 108 | isAutotoolsProject = Boolean.valueOf(isAutotoolsProjectValue).booleanValue(); | ||
| 109 | isCMakeProject = Boolean.valueOf(isCMakeProjectValue).booleanValue(); | ||
| 110 | |||
| 111 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); | ||
| 112 | try { | ||
| 113 | if (!isValidProjectName(projectName)) { | ||
| 114 | |||
| 115 | IWizardPage[] pages = MBSCustomPageManager.getPages(); | ||
| 116 | if(pages != null && pages.length > 0) { | ||
| 117 | CDTMainWizardPage cdtMainPage = (CDTMainWizardPage)pages[0]; | ||
| 118 | cdtMainPage.setPageComplete(false); | ||
| 119 | ICDTCommonProjectWizard wizard = (ICDTCommonProjectWizard) pages[0].getWizard(); | ||
| 120 | wizard.performCancel(); | ||
| 121 | |||
| 122 | project.delete(true, null); | ||
| 123 | } | ||
| 124 | throw new ProcessFailureException(YoctoSDKMessages.getFormattedString(PROJECT_NAME_ERROR, new Object[]{projectName, printIllegalChars()})); | ||
| 125 | } | ||
| 126 | |||
| 127 | if (!project.exists()) { | ||
| 128 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
| 129 | turnOffAutoBuild(workspace); | ||
| 130 | |||
| 131 | IPath locationPath = null; | ||
| 132 | if (location != null && !location.trim().equals("")) { //$NON-NLS-1$ | ||
| 133 | locationPath = Path.fromPortableString(location); | ||
| 134 | } | ||
| 135 | |||
| 136 | List<?> configs = template.getTemplateInfo().getConfigurations(); | ||
| 137 | |||
| 138 | if (configs == null || configs.size() == 0) { | ||
| 139 | throw new ProcessFailureException(Messages.getString("NewManagedProject.4") + projectName); //$NON-NLS-1$ | ||
| 140 | } | ||
| 141 | |||
| 142 | pca.setProject(project); | ||
| 143 | pca.setProjectLocation(locationPath); | ||
| 144 | pca.setConfigs((IConfiguration[]) configs.toArray(new IConfiguration[configs.size()])); | ||
| 145 | pca.setArtifactExtension(artifactExtension); | ||
| 146 | info = pca.createProject(monitor, CCorePlugin.DEFAULT_INDEXER, isCProject); | ||
| 147 | |||
| 148 | addNatures(project, false, monitor); | ||
| 149 | |||
| 150 | info.setValid(true); | ||
| 151 | ManagedBuildManager.saveBuildInfo(project, true); | ||
| 152 | |||
| 153 | restoreAutoBuild(workspace); | ||
| 154 | } else { | ||
| 155 | |||
| 156 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
| 157 | turnOffAutoBuild(workspace); | ||
| 158 | |||
| 159 | YoctoSDKChecker.checkIfGloballySelectedYoctoProfileIsValid(); | ||
| 160 | |||
| 161 | addNatures(project, true, monitor); | ||
| 162 | |||
| 163 | //restoreAutoBuild(workspace); | ||
| 164 | IDiscoveredPathManager manager = MakeCorePlugin.getDefault().getDiscoveryManager(); | ||
| 165 | IDiscoveredPathInfo pathInfo = manager.getDiscoveredInfo(project); | ||
| 166 | |||
| 167 | if (pathInfo instanceof IPerProjectDiscoveredPathInfo) { | ||
| 168 | IPerProjectDiscoveredPathInfo projectPathInfo = | ||
| 169 | (IPerProjectDiscoveredPathInfo) pathInfo; | ||
| 170 | projectPathInfo.setIncludeMap(new LinkedHashMap<String, Boolean>()); | ||
| 171 | projectPathInfo.setSymbolMap(new LinkedHashMap<String, SymbolEntry>()); | ||
| 172 | manager.removeDiscoveredInfo(project); | ||
| 173 | } | ||
| 174 | } | ||
| 175 | } | ||
| 176 | catch (CoreException e) | ||
| 177 | { | ||
| 178 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage(), e); //$NON-NLS-1$ | ||
| 179 | } | ||
| 180 | catch (BuildException e) | ||
| 181 | { | ||
| 182 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage()); //$NON-NLS-1$ | ||
| 183 | } | ||
| 184 | catch (YoctoGeneralException e) | ||
| 185 | { | ||
| 186 | try { | ||
| 187 | project.delete(true, monitor); | ||
| 188 | } catch (CoreException err) { | ||
| 189 | throw new ProcessFailureException(Messages.getString("NewManagedProject.3") + e.getMessage() //$NON-NLS-1$ | ||
| 190 | + " " + err.getMessage()); //$NON-NLS-1$ | ||
| 191 | } | ||
| 192 | throw new OperationCanceledException(Messages.getString("NewManagedProject.3") + e.getMessage()); //$NON-NLS-1$ | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | private boolean isValidProjectName(String projectName) { | ||
| 197 | Pattern pattern = Pattern.compile("^[a-zA-Z][a-zA-Z0-9_\\-]*$"); //$NON-NLS-1$ | ||
| 198 | Matcher matcher = pattern.matcher(projectName); | ||
| 199 | return matcher.find(); | ||
| 200 | } | ||
| 201 | |||
| 202 | private void addNatures(IProject project, boolean projectExists, IProgressMonitor monitor) | ||
| 203 | throws CoreException, YoctoGeneralException { | ||
| 204 | YoctoSDKNatureUtils.addNature(project, YoctoSDKProjectNature.YoctoSDK_NATURE_ID, monitor); | ||
| 205 | |||
| 206 | YoctoSDKChecker.checkIfGloballySelectedYoctoProfileIsValid(); | ||
| 207 | |||
| 208 | YoctoProfileElement profileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 209 | ProjectPreferenceUtils.saveProfiles(profileElement, project); | ||
| 210 | |||
| 211 | IPreferenceStore selecteProfileStore = YoctoSDKPlugin.getProfilePreferenceStore(profileElement.getSelectedProfile()); | ||
| 212 | YoctoUIElement elem = YoctoSDKUtils.getElemFromStore(selecteProfileStore); | ||
| 213 | YoctoSDKUtils.setEnvironmentVariables(project, elem); | ||
| 214 | |||
| 215 | if (isEmptyProject) { | ||
| 216 | YoctoSDKNatureUtils.addNature(project, YoctoSDKEmptyProjectNature.YoctoSDK_EMPTY_NATURE_ID, monitor); | ||
| 217 | } | ||
| 218 | |||
| 219 | if (isAutotoolsProject) { | ||
| 220 | AutotoolsNewProjectNature.addAutotoolsNature(project, monitor); | ||
| 221 | |||
| 222 | if (!projectExists) { | ||
| 223 | // For each IConfiguration, create a corresponding Autotools Configuration | ||
| 224 | for (IConfiguration cfg : pca.getConfigs()) { | ||
| 225 | AutotoolsConfigurationManager.getInstance().getConfiguration(project, cfg.getName(), true); | ||
| 226 | } | ||
| 227 | AutotoolsConfigurationManager.getInstance().saveConfigs(project); | ||
| 228 | } | ||
| 229 | |||
| 230 | YoctoSDKNatureUtils.addNature(project, YoctoSDKAutotoolsProjectNature.YoctoSDK_AUTOTOOLS_NATURE_ID, monitor); | ||
| 231 | YoctoSDKAutotoolsProjectNature.configureAutotoolsOptions(project); | ||
| 232 | } else if (isCMakeProject) { | ||
| 233 | YoctoSDKNatureUtils.addNature(project, YoctoSDKCMakeProjectNature.YoctoSDK_CMAKE_NATURE_ID, monitor); | ||
| 234 | YoctoSDKCMakeProjectNature.extendProjectEnvironmentForCMake(project); | ||
| 235 | } | ||
| 236 | |||
| 237 | YoctoSDKUtils.createRemoteDebugAndQemuLaunchers(project, elem); | ||
| 238 | } | ||
| 239 | |||
| 240 | protected final void turnOffAutoBuild(IWorkspace workspace) throws CoreException { | ||
| 241 | IWorkspaceDescription workspaceDesc = workspace.getDescription(); | ||
| 242 | savedAutoBuildingValue = workspaceDesc.isAutoBuilding(); | ||
| 243 | workspaceDesc.setAutoBuilding(false); | ||
| 244 | workspace.setDescription(workspaceDesc); | ||
| 245 | } | ||
| 246 | |||
| 247 | protected final void restoreAutoBuild(IWorkspace workspace) throws CoreException { | ||
| 248 | IWorkspaceDescription workspaceDesc = workspace.getDescription(); | ||
| 249 | workspaceDesc.setAutoBuilding(savedAutoBuildingValue); | ||
| 250 | workspace.setDescription(workspaceDesc); | ||
| 251 | } | ||
| 252 | |||
| 253 | /** | ||
| 254 | * setOptionValue | ||
| 255 | * @param config | ||
| 256 | * @param option | ||
| 257 | * @param val | ||
| 258 | * @throws BuildException | ||
| 259 | */ | ||
| 260 | protected void setOptionValue(IConfiguration config, IOption option, String val) throws BuildException { | ||
| 261 | if (val != null) { | ||
| 262 | if (!option.isExtensionElement()) { | ||
| 263 | option.setValue(val); | ||
| 264 | } else { | ||
| 265 | IOption newOption = config.getToolChain().createOption(option, option.getId() + "." + ManagedBuildManager.getRandomNumber(), option.getName(), false); //$NON-NLS-1$ | ||
| 266 | newOption.setValue(val); | ||
| 267 | } | ||
| 268 | } | ||
| 269 | } | ||
| 270 | } | ||
