mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
New Import Existing Code Wizard.
This commit is contained in:
parent
2ff6a31767
commit
0c26d91b94
6 changed files with 395 additions and 3 deletions
|
@ -63,6 +63,9 @@ MBS.create.configuration=Create New Configuration
|
|||
WizardConvertMakeProject.name=Convert to a C/C++ Project
|
||||
WizardConvertMakeProject.description=Convert to a C/C++ Project
|
||||
|
||||
WizardMakeProjFromExisting.name=Existing Code
|
||||
WizardMakeProjFromExisting.description=Creates a new Makefile project in a directory containing existing code
|
||||
|
||||
Tool.settings=Tool Settings
|
||||
Build.steps=Build Steps
|
||||
Build.artifact=Build Artifact
|
||||
|
|
|
@ -685,8 +685,19 @@
|
|||
id="org.eclipse.cdt.managedbuilder.core.managedBuildNature">
|
||||
</projectNature>
|
||||
</projectConfigurationFactory>
|
||||
</extension>
|
||||
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.importWizards">
|
||||
<wizard
|
||||
category="org.eclipse.cdt.ui.importWizardCategory"
|
||||
class="org.eclipse.cdt.managedbuilder.ui.wizards.NewMakeProjFromExisting"
|
||||
icon="icons/obj16/convert-normal.gif"
|
||||
id="org.eclipse.cdt.ui.wizards.MakeProjFromExisting"
|
||||
name="%WizardMakeProjFromExisting.name">
|
||||
<description>
|
||||
%WizardMakeProjFromExisting.description
|
||||
</description>
|
||||
</wizard>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package org.eclipse.cdt.managedbuilder.ui.wizards;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @since 7.0
|
||||
*/
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.managedbuilder.ui.wizards.messages"; //$NON-NLS-1$
|
||||
public static String NewMakeProjFromExisting_0;
|
||||
public static String NewMakeProjFromExisting_1;
|
||||
public static String NewMakeProjFromExistingPage_0;
|
||||
public static String NewMakeProjFromExistingPage_1;
|
||||
public static String NewMakeProjFromExistingPage_10;
|
||||
public static String NewMakeProjFromExistingPage_11;
|
||||
public static String NewMakeProjFromExistingPage_2;
|
||||
public static String NewMakeProjFromExistingPage_3;
|
||||
public static String NewMakeProjFromExistingPage_4;
|
||||
public static String NewMakeProjFromExistingPage_5;
|
||||
public static String NewMakeProjFromExistingPage_6;
|
||||
public static String NewMakeProjFromExistingPage_7;
|
||||
public static String NewMakeProjFromExistingPage_8;
|
||||
public static String NewMakeProjFromExistingPage_9;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Wind River Systems and others.
|
||||
* 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:
|
||||
* Doug Schaefer (WRS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.ui.wizards;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
||||
import org.eclipse.cdt.managedbuilder.core.IBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
import org.eclipse.ui.IImportWizard;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
||||
|
||||
/**
|
||||
* Wizard to create a new CDT project that wraps existing code.
|
||||
* @since 7.0
|
||||
*/
|
||||
public class NewMakeProjFromExisting extends Wizard implements IImportWizard {
|
||||
|
||||
NewMakeProjFromExistingPage page;
|
||||
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
||||
setWindowTitle(Messages.NewMakeProjFromExisting_0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages() {
|
||||
page = new NewMakeProjFromExistingPage();
|
||||
addPage(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish() {
|
||||
final String projectName = page.getProjectName();
|
||||
final String location = page.getLocation();
|
||||
final boolean isCPP = page.isCPP();
|
||||
final IToolChain toolChain = page.getToolChain();
|
||||
|
||||
IRunnableWithProgress op = new WorkspaceModifyOperation() {
|
||||
@Override
|
||||
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
|
||||
InterruptedException {
|
||||
monitor.beginTask(Messages.NewMakeProjFromExisting_1, 10);
|
||||
|
||||
// Create Project
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IProject project = workspace.getRoot().getProject(projectName);
|
||||
|
||||
// TODO handle the case where a .project file was already there
|
||||
IProjectDescription description = workspace.newProjectDescription(project.getName());
|
||||
description.setLocation(new Path(location));
|
||||
|
||||
CCorePlugin.getDefault().createCDTProject(description, project, monitor);
|
||||
|
||||
// Optionally C++ natures
|
||||
if (isCPP)
|
||||
CCProjectNature.addCCNature(project, new SubProgressMonitor(monitor, 1));
|
||||
|
||||
// Set up build information
|
||||
ICProjectDescriptionManager pdMgr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||
ICProjectDescription projDesc = pdMgr.createProjectDescription(project, false);
|
||||
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
|
||||
ManagedProject mProj = new ManagedProject(projDesc);
|
||||
info.setManagedProject(mProj);
|
||||
monitor.worked(1);
|
||||
|
||||
CfgHolder cfgHolder = new CfgHolder(toolChain, null);
|
||||
String s = toolChain == null ? "0" : ((ToolChain)toolChain).getId(); //$NON-NLS-1$
|
||||
Configuration config = new Configuration(mProj, (ToolChain)toolChain, ManagedBuildManager.calculateChildId(s, null), cfgHolder.getName());
|
||||
IBuilder builder = config.getEditableBuilder();
|
||||
builder.setManagedBuildOn(false);
|
||||
CConfigurationData data = config.getConfigurationData();
|
||||
projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
|
||||
monitor.worked(1);
|
||||
|
||||
pdMgr.setProjectDescription(project, projDesc);
|
||||
|
||||
monitor.done();
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
getContainer().run(true, true, op);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,210 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Wind River Systems and others.
|
||||
* 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:
|
||||
* Doug Schaefer (WRS) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.ui.wizards;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.DirectoryDialog;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.List;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* Page to select existing code location and toolchain.
|
||||
*
|
||||
* @since 7.0
|
||||
*/
|
||||
public class NewMakeProjFromExistingPage extends WizardPage {
|
||||
|
||||
Text projectName;
|
||||
Text location;
|
||||
Button langc;
|
||||
Button langcpp;
|
||||
IWorkspaceRoot root;
|
||||
List tcList;
|
||||
Map<String, IToolChain> tcMap = new HashMap<String, IToolChain>();
|
||||
|
||||
protected NewMakeProjFromExistingPage() {
|
||||
super(Messages.NewMakeProjFromExistingPage_0);
|
||||
setTitle(Messages.NewMakeProjFromExistingPage_1);
|
||||
setDescription(Messages.NewMakeProjFromExistingPage_2);
|
||||
|
||||
root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
}
|
||||
|
||||
public void createControl(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
comp.setLayout(layout);
|
||||
comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
|
||||
addProjectNameSelector(comp);
|
||||
addSourceSelector(comp);
|
||||
addLanguageSelector(comp);
|
||||
addToolchainSelector(comp);
|
||||
|
||||
setControl(comp);
|
||||
}
|
||||
|
||||
public void addProjectNameSelector(Composite parent) {
|
||||
Group group = new Group(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
group.setLayout(layout);
|
||||
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
group.setText(Messages.NewMakeProjFromExistingPage_3);
|
||||
|
||||
projectName = new Text(group, SWT.BORDER);
|
||||
projectName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
projectName.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
validateProjectName();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void validateProjectName() {
|
||||
String projectName = location.getText();
|
||||
IProject project = root.getProject(projectName);
|
||||
if (project.exists())
|
||||
setErrorMessage(Messages.NewMakeProjFromExistingPage_4);
|
||||
else
|
||||
setErrorMessage(null);
|
||||
}
|
||||
|
||||
public void addSourceSelector(Composite parent) {
|
||||
Group group = new Group(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
group.setLayout(layout);
|
||||
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
group.setText(Messages.NewMakeProjFromExistingPage_5);
|
||||
|
||||
location = new Text(group, SWT.BORDER);
|
||||
location.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
location.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
validateSource();
|
||||
}
|
||||
});
|
||||
validateSource();
|
||||
|
||||
Button browse = new Button(group, SWT.NONE);
|
||||
browse.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
|
||||
browse.setText(Messages.NewMakeProjFromExistingPage_6);
|
||||
browse.addSelectionListener(new SelectionListener() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
DirectoryDialog dialog = new DirectoryDialog(location.getShell());
|
||||
dialog.setMessage(Messages.NewMakeProjFromExistingPage_7);
|
||||
String dir = dialog.open();
|
||||
if (dir != null)
|
||||
location.setText(dir);
|
||||
}
|
||||
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void validateSource() {
|
||||
File file= new File(location.getText());
|
||||
if (file.isDirectory()) {
|
||||
setErrorMessage(null);
|
||||
projectName.setText(file.getName());
|
||||
} else
|
||||
setErrorMessage(Messages.NewMakeProjFromExistingPage_8);
|
||||
}
|
||||
|
||||
public void addLanguageSelector(Composite parent) {
|
||||
Group group = new Group(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
group.setLayout(layout);
|
||||
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
group.setText(Messages.NewMakeProjFromExistingPage_9);
|
||||
|
||||
// TODO, should be a way to dynamically list these
|
||||
langc = new Button(group, SWT.CHECK);
|
||||
langc.setText("C"); //$NON-NLS-1$
|
||||
langc.setSelection(true);
|
||||
|
||||
langcpp = new Button(group, SWT.CHECK);
|
||||
langcpp.setText("C++"); //$NON-NLS-1$
|
||||
langcpp.setSelection(true);
|
||||
}
|
||||
|
||||
public void addToolchainSelector(Composite parent) {
|
||||
Group group = new Group(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
group.setLayout(layout);
|
||||
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
group.setText(Messages.NewMakeProjFromExistingPage_10);
|
||||
|
||||
tcList = new List(group, SWT.SINGLE);
|
||||
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
tcList.add(Messages.NewMakeProjFromExistingPage_11);
|
||||
|
||||
IToolChain[] toolChains = ManagedBuildManager.getRealToolChains();
|
||||
for (IToolChain toolChain : toolChains) {
|
||||
if (toolChain.isAbstract() || toolChain.isSystemObject())
|
||||
continue;
|
||||
tcMap.put(toolChain.getUniqueRealName(), toolChain);
|
||||
}
|
||||
|
||||
ArrayList<String> names = new ArrayList<String>(tcMap.keySet());
|
||||
Collections.sort(names);
|
||||
for (String name : names)
|
||||
tcList.add(name);
|
||||
|
||||
tcList.setSelection(0); // select <none>
|
||||
}
|
||||
|
||||
public String getProjectName() {
|
||||
return projectName.getText();
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location.getText();
|
||||
}
|
||||
|
||||
public boolean isC() {
|
||||
return langc.getSelection();
|
||||
}
|
||||
|
||||
public boolean isCPP() {
|
||||
return langcpp.getSelection();
|
||||
}
|
||||
|
||||
public IToolChain getToolChain() {
|
||||
String[] selection = tcList.getSelection();
|
||||
return selection.length != 0 ? tcMap.get(selection[0]) : null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
NewMakeProjFromExisting_0=Import Existing Code
|
||||
NewMakeProjFromExisting_1=Importing Existing Code
|
||||
NewMakeProjFromExistingPage_0=Import Existing Code
|
||||
NewMakeProjFromExistingPage_1=Import Existing Code
|
||||
NewMakeProjFromExistingPage_10=Toolchain for Indexer Settings
|
||||
NewMakeProjFromExistingPage_11=<none>
|
||||
NewMakeProjFromExistingPage_2=Create a new Makefile project from existing code in that same directory
|
||||
NewMakeProjFromExistingPage_3=Project Name
|
||||
NewMakeProjFromExistingPage_4=Project already exists
|
||||
NewMakeProjFromExistingPage_5=Existing Code Location
|
||||
NewMakeProjFromExistingPage_6=Browse...
|
||||
NewMakeProjFromExistingPage_7=Select root directory of existing code
|
||||
NewMakeProjFromExistingPage_8=Not a valid directory
|
||||
NewMakeProjFromExistingPage_9=Languages
|
Loading…
Add table
Reference in a new issue