diff options
author | Henrik Rentz-Reichert | 2016-04-11 15:07:18 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2016-04-11 15:07:18 +0000 |
commit | d4ca6ae5f62de526394f5cf66fd3713640557058 (patch) | |
tree | 846c17aa7f7020d5a3b12eb926a943c94561167c /plugins/org.eclipse.etrice.generator.ui | |
parent | 01960481541062204fcc0d286b9e9dcd4b2e0973 (diff) | |
download | org.eclipse.etrice-d4ca6ae5f62de526394f5cf66fd3713640557058.tar.gz org.eclipse.etrice-d4ca6ae5f62de526394f5cf66fd3713640557058.tar.xz org.eclipse.etrice-d4ca6ae5f62de526394f5cf66fd3713640557058.zip |
Bug 491444 - Add possibility that the wizard copies the C runtime
sources into the project
https://bugs.eclipse.org/bugs/show_bug.cgi?id=491444
Change-Id: Iaee8f26d5052ff31f1535b9e4bb3e5f615f84865
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.ui')
8 files changed, 377 insertions, 44 deletions
diff --git a/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF index 26b09bc24..1345a2154 100644 --- a/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.generator.ui/META-INF/MANIFEST.MF @@ -28,4 +28,5 @@ Require-Bundle: org.eclipse.etrice.core.etmap;bundle-version="0.5.0", Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.etrice.generator.ui.Activator Export-Package: org.eclipse.etrice.generator.ui.configurator, - org.eclipse.etrice.generator.ui.preferences + org.eclipse.etrice.generator.ui.preferences, + org.eclipse.etrice.generator.ui.wizard diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java index c61e0f873..8b8a6948c 100644 --- a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java +++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/IProjectConfigurator.java @@ -27,6 +27,9 @@ public interface IProjectConfigurator { /** * @param project the project to be configured + * @param progressMonitor the progress monitor + * @param copyRuntime <code>true</code> if runtime should be copied into the project + * @param platform the name of the chosen platform (others will be excluded from the build) */ - void configure(IProject project, IProgressMonitor progressMonitor); + void configure(IProject project, IProgressMonitor progressMonitor, boolean copyRuntime, String platform); } diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java index a2c67781a..9b47e2e87 100644 --- a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java +++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/configurator/ProjectConfigurationDelegator.java @@ -90,12 +90,12 @@ public class ProjectConfigurationDelegator implements IProjectConfigurator { * @see org.eclipse.etrice.generator.ui.configurator.IProjectConfigurator#configure(org.eclipse.core.resources.IProject) */ @Override - public void configure(IProject project, IProgressMonitor progressMonitor) { + public void configure(IProject project, IProgressMonitor progressMonitor, boolean copyRuntime, String platform) { for (Entry<String, ArrayList<IProjectConfigurator>> entry : nature2configurators.entrySet()) { try { if (project.hasNature(entry.getKey())) { for (IProjectConfigurator configurator : entry.getValue()) { - configurator.configure(project, progressMonitor); + configurator.configure(project, progressMonitor, copyRuntime, platform); } } } catch (CoreException e) { diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java index d55c49330..9f1dae7bc 100644 --- a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java +++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/NewSetOfModelsWizard.java @@ -24,6 +24,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.URI; import org.eclipse.etrice.generator.ui.configurator.ProjectConfigurationDelegator; import org.eclipse.etrice.generator.ui.wizard.deprecated.ModelCreationPage; +import org.eclipse.etrice.generator.ui.wizard.internal.COptionsPage; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; @@ -51,7 +52,8 @@ public class NewSetOfModelsWizard extends Wizard implements INewWizard { private IWorkbench workbench; private IStructuredSelection selection; - private ModelCreationPage page; + private ModelCreationPage modelPage; + private COptionsPage optionsPage; private URI modelURI = null; /* (non-Javadoc) @@ -71,9 +73,13 @@ public class NewSetOfModelsWizard extends Wizard implements INewWizard { */ @Override public void addPages() { - page = new ModelCreationPage("Create new set of models", selection); - page.setTitle("Create a new set of eTrice models"); - addPage(page); + modelPage = new ModelCreationPage("Create new set of models", selection); + modelPage.setTitle("Create a new set of eTrice models"); + addPage(modelPage); + + optionsPage = new COptionsPage("Options", modelPage); + optionsPage.setTitle("Options"); + addPage(optionsPage); } /* (non-Javadoc) @@ -86,28 +92,32 @@ public class NewSetOfModelsWizard extends Wizard implements INewWizard { @Override protected void execute(IProgressMonitor progressMonitor) { try { - String baseName = page.getBaseName(); - IPath file = page.getPath().append(baseName).addFileExtension("room"); + String baseName = modelPage.getBaseName(); + IPath file = modelPage.getPath().append(baseName).addFileExtension("room"); modelURI = URI.createPlatformResourceURI(file.toString(), true); ProjectCreator.createModel(modelURI, baseName); - file = page.getPath().append(baseName).addFileExtension("etphys"); + file = modelPage.getPath().append(baseName).addFileExtension("etphys"); URI physModelURI = URI.createPlatformResourceURI(file.toString(), true); ProjectCreator.createPhysicalModel(physModelURI, baseName); - file = page.getPath().append(baseName).addFileExtension("etmap"); + file = modelPage.getPath().append(baseName).addFileExtension("etmap"); URI mapModelURI = URI.createPlatformResourceURI(file.toString(), true); ProjectCreator.createMappingModel(mapModelURI, baseName); IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IProject project = (page.getPath().segmentCount()==1)? - workspace.getRoot().getProject(page.getPath().lastSegment()) - : workspace.getRoot().getFolder(page.getPath()).getProject(); + IProject project = (modelPage.getPath().segmentCount()==1)? + workspace.getRoot().getProject(modelPage.getPath().lastSegment()) + : workspace.getRoot().getFolder(modelPage.getPath()).getProject(); - ProjectCreator.createRunAndLaunchConfigurations(baseName, project, page.getPath().toString(), additionalLaunchConfigLines); + ProjectCreator.createRunAndLaunchConfigurations(baseName, project, modelPage.getPath().toString(), additionalLaunchConfigLines); ProjectCreator.addXtextNature(project, progressMonitor); - ProjectConfigurationDelegator.getInstance().configure(project, progressMonitor); + ProjectConfigurationDelegator.getInstance().configure( + project, + progressMonitor, + optionsPage.getCopyRuntime(), + optionsPage.getPlatform()); } catch (Exception e) { Logger.getLogger(getClass()).error(e.getMessage(), e); diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/WizardHelpers.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/WizardHelpers.java new file mode 100644 index 000000000..fa3e2c649 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/WizardHelpers.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2016 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * hrentz (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.generator.ui.wizard; + +import java.io.File; +import java.io.IOException; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.CommonPlugin; +import org.eclipse.emf.common.ui.CommonUIPlugin; +import org.eclipse.emf.common.util.URI; + +/** + * @author hrentz + * + */ +public class WizardHelpers { + + public static ZipFile getRuntimeZip() { + ZipFile zipFile = null; + + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint(CommonUIPlugin.INSTANCE.getSymbolicName(), + "examples"); + IConfigurationElement[] exampleElements = extensionPoint.getConfigurationElements(); + for (int i = 0; i < exampleElements.length; i++) { + IConfigurationElement exampleElement = exampleElements[i]; + IConfigurationElement[] projectDescriptorElements = exampleElement + .getChildren("projectDescriptor"); + for (int j = 0; j < projectDescriptorElements.length; j++) { + IConfigurationElement projectDescriptorElement = projectDescriptorElements[j]; + String projectName = projectDescriptorElement + .getAttribute("name"); + if (projectName != null + && projectName.equals("org.eclipse.etrice.runtime.c")) { + String contentURI = projectDescriptorElement + .getAttribute("contentURI"); + if (contentURI != null) { + URI uri = URI.createURI(contentURI); + if (uri.isRelative()) { + uri = URI + .createPlatformPluginURI( + projectDescriptorElement + .getContributor().getName() + + "/" + contentURI, true); + } + if (uri.isPlatform()) { + uri = CommonPlugin.asLocalURI(uri); + } + + String location = uri.toFileString(); + if (location != null) { + File file = new File(location); + if (file.isFile() && file.canRead()) { + zipFile = createZipFile(file); + } + } + } + } + if (zipFile != null) + break; + } + if (zipFile != null) + break; + } + + return zipFile; + } + + private static ZipFile createZipFile(File file) { + try { + return new ZipFile(file); + } catch (ZipException e) { + // Ignore + } catch (IOException e) { + // Ignore + } + return null; + } + +} diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/deprecated/ModelCreationPage.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/deprecated/ModelCreationPage.java index fce89907e..96f4c81fa 100644 --- a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/deprecated/ModelCreationPage.java +++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/deprecated/ModelCreationPage.java @@ -20,6 +20,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.etrice.generator.ui.wizard.internal.IProjectPathProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -35,7 +36,7 @@ import org.eclipse.ui.internal.ide.misc.ResourceAndContainerGroup; * */ @SuppressWarnings("restriction") -public class ModelCreationPage extends WizardPage implements Listener { +public class ModelCreationPage extends WizardPage implements Listener, IProjectPathProvider { private static final int SIZING_CONTAINER_GROUP_HEIGHT = 250; protected RoomValidationHelper roomValidator; @@ -124,34 +125,37 @@ public class ModelCreationPage extends WizardPage implements Listener { valid = false; } - String resourceName = resourceGroup.getResource(); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IStatus result = workspace.validateName(resourceName, IResource.FILE); - if (!result.isOK()) { - setErrorMessage(result.getMessage()); - return false; + if (valid) { + String resourceName = resourceGroup.getResource(); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IStatus result = workspace.validateName(resourceName, IResource.FILE); + if (!result.isOK()) { + setErrorMessage(result.getMessage()); + return false; + } + + IPath folder = resourceGroup.getContainerFullPath(); + IPath file = folder.append(resourceName).addFileExtension("etmap"); + if (workspace.getRoot().exists(file)) { + setErrorMessage("file '"+file+"' already exists in the workspace"); + return false; + } + file = folder.append(resourceName).addFileExtension("etphys"); + if (workspace.getRoot().exists(file)) { + setErrorMessage("file '"+file+"' already exists in the workspace"); + return false; + } + file = folder.append(resourceName).addFileExtension("room"); + if (workspace.getRoot().exists(file)) { + setErrorMessage("file '"+file+"' already exists in the workspace"); + return false; + } + if(!roomValidator.isValidFQN(getBaseName())){ + setErrorMessage("Invalid roomModel name ("+roomValidator.getMessage()+")"); + return false; + } } - IPath folder = resourceGroup.getContainerFullPath(); - IPath file = folder.append(resourceName).addFileExtension("etmap"); - if (workspace.getRoot().exists(file)) { - setErrorMessage("file '"+file+"' already exists in the workspace"); - return false; - } - file = folder.append(resourceName).addFileExtension("etphys"); - if (workspace.getRoot().exists(file)) { - setErrorMessage("file '"+file+"' already exists in the workspace"); - return false; - } - file = folder.append(resourceName).addFileExtension("room"); - if (workspace.getRoot().exists(file)) { - setErrorMessage("file '"+file+"' already exists in the workspace"); - return false; - } - if(!roomValidator.isValidFQN(getBaseName())){ - setErrorMessage("Invalid roomModel name ("+roomValidator.getMessage()+")"); - return false; - } if (valid) { setErrorMessage(null); setMessage(null); diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/internal/COptionsPage.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/internal/COptionsPage.java new file mode 100644 index 000000000..01a93a957 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/internal/COptionsPage.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2016 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * hrentz (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.generator.ui.wizard.internal; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.etrice.generator.ui.wizard.WizardHelpers; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; + +/** + * @author hrentz + * + */ +public class COptionsPage extends WizardPage { + + private IProjectPathProvider projectPathProvider; + private Button copyRuntimeButton = null; + private Combo platformCombo = null; + + public COptionsPage(String title, IProjectPathProvider projectPathProvider) { + super(title); + this.projectPathProvider = projectPathProvider; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControl(Composite parent) { + Composite buttonComposite = new Composite(parent, SWT.NONE); + + GridData gd = new GridData( + GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END); + buttonComposite.setLayoutData(gd); + buttonComposite.setLayout(new GridLayout(2, false)); + + copyRuntimeButton = new Button(buttonComposite, SWT.CHECK); + copyRuntimeButton.setText("Copy C-Runtime into project"); + copyRuntimeButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + } + }); + gd = new GridData(); + gd.horizontalSpan = 2; + copyRuntimeButton.setLayoutData(gd); + + Label l = new Label(buttonComposite, SWT.NONE); + l.setText("Select active platform:"); + l.setLayoutData(new GridData(SWT.NONE)); + + platformCombo = new Combo(buttonComposite, SWT.READ_ONLY); + gd = new GridData(SWT.HORIZONTAL); + gd.widthHint = 200; + platformCombo.setLayoutData(gd); + platformCombo.setVisibleItemCount(10); + + setErrorMessage(null); + setMessage(null); + setControl(buttonComposite); + } + + @Override + public void setVisible(boolean visible) + { + super.setVisible(visible); + + if (visible) { + refresh(); + } + } + + private void refresh() { + copyRuntimeButton.setEnabled(false); + platformCombo.setEnabled(false); + platformCombo.removeAll(); + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IPath chosenPath = projectPathProvider.getPath(); + IProject project = (chosenPath.segmentCount()==1)? + workspace.getRoot().getProject(chosenPath.lastSegment()) + : workspace.getRoot().getFolder(chosenPath).getProject(); + + try { + if (project.hasNature("org.eclipse.cdt.core.cnature")) { + copyRuntimeButton.setEnabled(true); + platformCombo.setEnabled(true); + + List<String> platformNames = getPlatformNames(); + for (String name : platformNames) { + platformCombo.add(name); + } + + platformCombo.select(0); + } + } catch (CoreException e) { + e.printStackTrace(); + } + } + + private List<String> getPlatformNames() { + List<String> result = new ArrayList<String>(); + + ZipFile zipFile = WizardHelpers.getRuntimeZip(); + if (zipFile != null) { + ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(zipFile); + List<?> children = structureProvider.getChildren(structureProvider.getRoot()); + ZipEntry current = null; + for (Object child : children) { + if (child instanceof ZipEntry) { + if (((ZipEntry) child).getName().equals("src/")) { + current = (ZipEntry) child; + break; + } + } + } + if (current!=null) { + children = structureProvider.getChildren(current); + current = null; + for (Object child : children) { + if (child instanceof ZipEntry) { + if (((ZipEntry) child).getName().equals("src/platforms/")) { + current = (ZipEntry) child; + break; + } + } + } + } + if (current!=null) { + children = structureProvider.getChildren(current); + for (Object child : children) { + if (child instanceof ZipEntry) { + String name = ((ZipEntry) child).getName(); + if (name.endsWith("/")) { + String[] split = name.split("/"); + result.add(split[split.length-1]); + } + } + } + } + try { + zipFile.close(); + } catch (IOException e) { + // Ignore. + } + } + + return result; + } + + public boolean getCopyRuntime() { + if (copyRuntimeButton!=null && !copyRuntimeButton.isDisposed()) { + return copyRuntimeButton.getSelection(); + } + return false; + } + + public String getPlatform() { + if (platformCombo!=null && !platformCombo.isDisposed()) { + if (platformCombo.getSelectionIndex()>=0) { + return platformCombo.getText(); + } + } + + return ""; + } +} diff --git a/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/internal/IProjectPathProvider.java b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/internal/IProjectPathProvider.java new file mode 100644 index 000000000..186936dbc --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.ui/src/org/eclipse/etrice/generator/ui/wizard/internal/IProjectPathProvider.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2016 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * hrentz (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.generator.ui.wizard.internal; + +import org.eclipse.core.runtime.IPath; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface IProjectPathProvider { + + public IPath getPath(); +} |