mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 461394.
[Autotools] Add import wizard Change-Id: Idc221696f6c09e470eab1c19bf8646691d0a380e Signed-off-by: mazab <mohamed_azab@mentor.com>
This commit is contained in:
parent
f38dd92fb6
commit
65bac9ae34
6 changed files with 393 additions and 1 deletions
|
@ -18,6 +18,9 @@ NewCCWizardV2.name=GNU C++ Autotools Project
|
|||
|
||||
Autotools.wizard.name=GNU Autotools Build Wizard
|
||||
|
||||
Autotools.import.wizard.name=Existing code as Autotools project
|
||||
Autotools.import.wizard.description=Create a new Autotools project from existing code in that same directory
|
||||
|
||||
Autoconf.editor.name=Autoconf Editor
|
||||
|
||||
BuildProperty.value.name.default=Default;
|
||||
|
|
|
@ -531,4 +531,17 @@
|
|||
</with>
|
||||
</definition>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.importWizards">
|
||||
<wizard
|
||||
category="org.eclipse.cdt.ui.importWizardCategory"
|
||||
class="org.eclipse.cdt.internal.autotools.ui.wizards.AutotoolsProjectImportWizard"
|
||||
icon="icons/ac16/convert_normal.gif"
|
||||
id="org.eclipse.cdt.autotools.ui.wizards.importWizaed"
|
||||
name="%Autotools.import.wizard.name">
|
||||
<description>
|
||||
%Autotools.import.wizard.description
|
||||
</description>
|
||||
</wizard>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Mentor Graphics Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Mohamed Azab (Mentor Graphics) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.autotools.ui.wizards;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin;
|
||||
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.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IProjectType;
|
||||
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.cdt.managedbuilder.ui.wizards.CfgHolder;
|
||||
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
|
||||
import org.eclipse.cdt.managedbuilder.ui.wizards.NewMakeProjFromExisting;
|
||||
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.IPath;
|
||||
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.ui.IWorkbench;
|
||||
import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class AutotoolsProjectImportWizard extends NewMakeProjFromExisting {
|
||||
private final String TITLE = "Import Existing code as Autotools project";
|
||||
private static final String PREFIX = "WizardAutotoolsConversion"; //$NON-NLS-1$
|
||||
protected static final String CONF_TITLE = PREFIX + ".config.title"; //$NON-NLS-1$
|
||||
protected static final String CONF_DESC = PREFIX + ".config.desc"; //$NON-NLS-1$
|
||||
|
||||
private AutotoolsProjectImportWizardPage page;
|
||||
protected CProjectPlatformPage projectConfigurationPage;
|
||||
|
||||
@Override
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
||||
setWindowTitle(TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages() {
|
||||
page = new AutotoolsProjectImportWizardPage();
|
||||
addPage(page);
|
||||
|
||||
// Add the configuration selection page
|
||||
projectConfigurationPage = new CProjectPlatformPage(PREFIX, this);
|
||||
projectConfigurationPage.setTitle(AutotoolsUIPlugin
|
||||
.getResourceString(CONF_TITLE));
|
||||
projectConfigurationPage.setDescription(AutotoolsUIPlugin
|
||||
.getResourceString(CONF_DESC));
|
||||
addPage(projectConfigurationPage);
|
||||
|
||||
// add custom pages
|
||||
MBSCustomPageManager.init();
|
||||
|
||||
// add stock pages
|
||||
MBSCustomPageManager.addStockPage(projectConfigurationPage,
|
||||
CProjectPlatformPage.PAGE_ID);
|
||||
|
||||
}
|
||||
|
||||
public IProjectType getProjectType() {
|
||||
return projectConfigurationPage.getProjectType();
|
||||
}
|
||||
|
||||
public IConfiguration[] getSelectedConfigurations() {
|
||||
return projectConfigurationPage.getSelectedConfigurations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish() {
|
||||
final String projectName = page.getProjectName();
|
||||
final String locationStr = 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("Creating Autotools project", 10);
|
||||
|
||||
// Create Project
|
||||
try {
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IProject project = workspace.getRoot().getProject(
|
||||
projectName);
|
||||
|
||||
IProjectDescription description = workspace
|
||||
.newProjectDescription(projectName);
|
||||
IPath defaultLocation = workspace.getRoot().getLocation()
|
||||
.append(projectName);
|
||||
Path location = new Path(locationStr);
|
||||
if (!location.isEmpty()
|
||||
&& !location.equals(defaultLocation)) {
|
||||
description.setLocation(location);
|
||||
}
|
||||
|
||||
CCorePlugin.getDefault().createCDTProject(description,
|
||||
project, monitor);
|
||||
|
||||
// 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);
|
||||
|
||||
// Convert the created project to an Autotools project
|
||||
((AutotoolsProjectImportWizardPage) page).convertProject(
|
||||
project, monitor, projectName);
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
monitor.done();
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
getContainer().run(true, true, op);
|
||||
} catch (InvocationTargetException e) {
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Mentor Graphics Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Mohamed Azab (Mentor Graphics) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.autotools.ui.wizards;
|
||||
|
||||
import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature;
|
||||
import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants;
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.core.IProjectType;
|
||||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
|
||||
import org.eclipse.cdt.managedbuilder.ui.wizards.NewMakeProjFromExistingPage;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
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.Group;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class AutotoolsProjectImportWizardPage extends
|
||||
NewMakeProjFromExistingPage {
|
||||
private Button langc;
|
||||
private Button langcpp;
|
||||
|
||||
protected AutotoolsProjectImportWizardPage() {
|
||||
setTitle(AutotoolsWizardMessages
|
||||
.getResourceString("ImportWizardPage.title"));
|
||||
setDescription(AutotoolsWizardMessages
|
||||
.getResourceString("ImportWizardPage.description"));
|
||||
}
|
||||
|
||||
protected IProjectType getProjectType() {
|
||||
return ((AutotoolsProjectImportWizard) getWizard()).getProjectType();
|
||||
}
|
||||
|
||||
protected IConfiguration[] getSelectedConfigurations() {
|
||||
return ((AutotoolsProjectImportWizard) getWizard())
|
||||
.getSelectedConfigurations();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
setControl(comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
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("Select project language");
|
||||
|
||||
SelectionListener cListener = new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
validatePage();
|
||||
}
|
||||
};
|
||||
|
||||
langc = ControlFactory.createRadioButton(group,
|
||||
CUIMessages.ConvertProjectWizardPage_CProject, "C ", //$NON-NLS-1$
|
||||
cListener);
|
||||
langc.setSelection(true);
|
||||
|
||||
langcpp = ControlFactory.createRadioButton(group,
|
||||
CUIMessages.ConvertProjectWizardPage_CppProject, "C++ ", //$NON-NLS-1$
|
||||
cListener);
|
||||
langcpp.setSelection(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IToolChain getToolChain() {
|
||||
return getSelectedConfigurations()[0].getToolChain();
|
||||
}
|
||||
|
||||
public void convertProject(IProject project, IProgressMonitor monitor,
|
||||
String projectID) throws CoreException {
|
||||
monitor.beginTask(
|
||||
AutotoolsUIPlugin
|
||||
.getResourceString("WizardMakeProjectConversion.monitor.convertingToMakeProject"), 7); //$NON-NLS-1$
|
||||
IConfiguration defaultCfg = null;
|
||||
try {
|
||||
monitor.subTask(AutotoolsUIPlugin
|
||||
.getResourceString("adding project nature"));
|
||||
ManagedCProjectNature.addManagedNature(project,
|
||||
new SubProgressMonitor(monitor, 1));
|
||||
AutotoolsNewProjectNature.addAutotoolsNature(project,
|
||||
new SubProgressMonitor(monitor, 1));
|
||||
monitor.subTask(AutotoolsUIPlugin
|
||||
.getResourceString("adding builder"));
|
||||
AutotoolsNewProjectNature.addAutotoolsBuilder(project,
|
||||
new SubProgressMonitor(monitor, 1));
|
||||
project.setPersistentProperty(
|
||||
AutotoolsPropertyConstants.SCANNER_USE_MAKE_W,
|
||||
AutotoolsPropertyConstants.TRUE);
|
||||
// Specify false for override in next call as override can cause the
|
||||
// method to throw an
|
||||
// exception.
|
||||
CCorePlugin.getDefault()
|
||||
.mapCProjectOwner(project, projectID, false);
|
||||
// Add the ManagedProject to the project
|
||||
IManagedProject newManagedProject = null;
|
||||
IManagedBuildInfo info = null;
|
||||
try {
|
||||
info = ManagedBuildManager.createBuildInfo(project);
|
||||
newManagedProject = ManagedBuildManager.createManagedProject(
|
||||
project, getProjectType());
|
||||
if (newManagedProject != null) {
|
||||
for (int i = 0; i < getSelectedConfigurations().length; i++) {
|
||||
IConfiguration config = getSelectedConfigurations()[i];
|
||||
int id = ManagedBuildManager.getRandomNumber();
|
||||
IConfiguration newConfig = newManagedProject
|
||||
.createConfiguration(config, config.getId()
|
||||
+ "." + id); //$NON-NLS-1$
|
||||
newConfig.setArtifactName(newManagedProject
|
||||
.getDefaultArtifactName());
|
||||
}
|
||||
// Now add the first supported config in the list as the
|
||||
// default
|
||||
IConfiguration[] newConfigs = newManagedProject
|
||||
.getConfigurations();
|
||||
for (int i = 0; i < newConfigs.length; i++) {
|
||||
if (newConfigs[i].isSupported()) {
|
||||
defaultCfg = newConfigs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultCfg == null && newConfigs.length > 0)
|
||||
defaultCfg = newConfigs[0];
|
||||
|
||||
if (defaultCfg != null) {
|
||||
ManagedBuildManager.setDefaultConfiguration(project,
|
||||
defaultCfg);
|
||||
ManagedBuildManager.setSelectedConfiguration(project,
|
||||
defaultCfg);
|
||||
}
|
||||
ManagedBuildManager.setNewProjectVersion(project);
|
||||
}
|
||||
} catch (BuildException e) {
|
||||
AutotoolsUIPlugin.log(e);
|
||||
}
|
||||
|
||||
// Save the build options
|
||||
monitor.subTask(AutotoolsUIPlugin
|
||||
.getResourceString("saving project"));
|
||||
if (info != null) {
|
||||
info.setValid(true);
|
||||
ManagedBuildManager.saveBuildInfo(project, true);
|
||||
}
|
||||
} finally {
|
||||
monitor.done();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isC() {
|
||||
return langc.getSelection();
|
||||
}
|
||||
|
||||
public boolean isCPP() {
|
||||
return langcpp.getSelection();
|
||||
}
|
||||
}
|
|
@ -366,3 +366,7 @@ ProjectConvert.noConverterErrordialog.message=There are no converters available
|
|||
|
||||
ProjectConvert.title=Project Converters for {0}
|
||||
ProjectConvert.convertersList=Converters List
|
||||
|
||||
# ----------- Import Wizard Page ----------
|
||||
ImportWizardPage.title=Import Existing code
|
||||
ImportWizardPage.description=Create a new Autotools project from existing code in that same directory
|
||||
|
|
|
@ -97,7 +97,7 @@ public class CProjectPlatformPage extends WizardPage {
|
|||
* @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
|
||||
*/
|
||||
public boolean canFlipToNextPage() {
|
||||
return validatePage();
|
||||
return validatePage() && getNextPage() != null;
|
||||
}
|
||||
|
||||
private void createConfigSelectionGroup (Composite parent) {
|
||||
|
|
Loading…
Add table
Reference in a new issue