diff --git a/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF index 8aba316323f..e7db1577fc6 100644 --- a/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF @@ -7,10 +7,10 @@ Bundle-Activator: org.eclipse.cdt.cmake.core.internal.Activator Bundle-Vendor: Eclipse CDT Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources;bundle-version="3.11.0", - org.freemarker;bundle-version="2.3.22", org.eclipse.debug.core;bundle-version="3.10.0", org.eclipse.launchbar.core;bundle-version="2.0.0", - org.eclipse.cdt.core;bundle-version="5.12.0" + org.eclipse.cdt.core;bundle-version="5.12.0", + org.eclipse.tools.templates.freemarker;bundle-version="1.0.0";visibility:=reexport Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.cdt.cmake.core diff --git a/build/org.eclipse.cdt.cmake.core/plugin.xml b/build/org.eclipse.cdt.cmake.core/plugin.xml index 7b159d8230e..32a9f20cc16 100644 --- a/build/org.eclipse.cdt.cmake.core/plugin.xml +++ b/build/org.eclipse.cdt.cmake.core/plugin.xml @@ -9,23 +9,6 @@ class="org.eclipse.cdt.cmake.core.CMakeNature"> - - - - - - - - @@ -43,14 +26,6 @@ value="org.eclipse.cdt.cmake.core.cmakeNature"> - - - - - - + point="org.eclipse.cdt.core.buildConfigProvider"> + class="org.eclipse.cdt.cmake.core.internal.CMakeBuildConfigurationProvider" + id="org.eclipse.cdt.cmake.core.provider" + natureId="org.eclipse.cdt.cmake.core.cmakeNature"> - diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeProjectGenerator.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeProjectGenerator.java index c0ae251a073..7b348fd28c7 100644 --- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeProjectGenerator.java +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeProjectGenerator.java @@ -7,59 +7,64 @@ *******************************************************************************/ package org.eclipse.cdt.cmake.core; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.List; import java.util.Map; -import org.eclipse.cdt.cmake.core.internal.CMakeTemplateGenerator; +import org.eclipse.cdt.cmake.core.internal.Activator; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.build.CBuilder; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.tools.templates.freemarker.FMProjectGenerator; +import org.eclipse.tools.templates.freemarker.SourceRoot; +import org.osgi.framework.Bundle; -public class CMakeProjectGenerator { +public class CMakeProjectGenerator extends FMProjectGenerator { - private final IProject project; - - public CMakeProjectGenerator(IProject project) { - this.project = project; + public CMakeProjectGenerator(String manifestFile) { + super(manifestFile); } - public void generate(IProgressMonitor monitor) throws CoreException { - // Generate the files - IFolder sourceFolder = project.getFolder("src"); //$NON-NLS-1$ - if (!sourceFolder.exists()) { - sourceFolder.create(true, true, monitor); + @Override + protected void initProjectDescription(IProjectDescription description) { + description + .setNatureIds( + new String[] { CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID, CMakeNature.ID }); + ICommand command = description.newCommand(); + CBuilder.setupBuilder(command); + description.setBuildSpec(new ICommand[] { command }); + } + + @Override + public Bundle getSourceBundle() { + return Activator.getPlugin().getBundle(); + } + + @Override + public void generate(Map model, IProgressMonitor monitor) throws CoreException { + super.generate(model, monitor); + + // Create the source folders + IProject project = getProject(); + List entries = new ArrayList<>(); + for (SourceRoot srcRoot : getManifest().getSrcRoots()) { + IFolder sourceFolder = project.getFolder(srcRoot.getDir()); + if (!sourceFolder.exists()) { + sourceFolder.create(true, true, monitor); + } + + entries.add(CoreModel.newSourceEntry(sourceFolder.getFullPath())); } - - CMakeTemplateGenerator templateGen = new CMakeTemplateGenerator(); - Map fmModel = new HashMap<>(); - fmModel.put("projectName", project.getName()); //$NON-NLS-1$ - - IFile sourceFile = sourceFolder.getFile("main.cpp"); //$NON-NLS-1$ - templateGen.generateFile(fmModel, "simple/main.cpp", sourceFile, monitor); //$NON-NLS-1$ - sourceFile = project.getFile("CMakeLists.txt"); //$NON-NLS-1$ - templateGen.generateFile(fmModel, "simple/CMakeLists.txt", sourceFile, monitor); //$NON-NLS-1$ - - // Set up the project - IProjectDescription projDesc = project.getDescription(); - String[] oldIds = projDesc.getNatureIds(); - String[] newIds = new String[oldIds.length + 3]; - System.arraycopy(oldIds, 0, newIds, 0, oldIds.length); - newIds[newIds.length - 3] = CProjectNature.C_NATURE_ID; - newIds[newIds.length - 2] = CCProjectNature.CC_NATURE_ID; - newIds[newIds.length - 1] = CMakeNature.ID; - projDesc.setNatureIds(newIds); - - project.setDescription(projDesc, monitor); - - IPathEntry[] entries = new IPathEntry[] { CoreModel.newOutputEntry(sourceFolder.getFullPath()) }; - CoreModel.getDefault().create(project).setRawPathEntries(entries, monitor); + CoreModel.getDefault().create(project).setRawPathEntries(entries.toArray(new IPathEntry[entries.size()]), + monitor); } } diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java index 0b33e646af7..755d19ad6fe 100644 --- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java @@ -52,7 +52,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { if (!Files.exists(buildDir.resolve("Makefile"))) { //$NON-NLS-1$ // TODO assuming cmake is in the path here, probably need a // preference in case it isn't. - List command = Arrays.asList("cmake", //$NON-NLS-1$ + List command = Arrays.asList("/usr/local/bin/cmake", //$NON-NLS-1$ "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", new File(project.getLocationURI()).getAbsolutePath()); //$NON-NLS-1$ ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile()); Process process = processBuilder.start(); diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java new file mode 100644 index 00000000000..51f6d313f22 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationProvider.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2016 QNX Software 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 + *******************************************************************************/ +package org.eclipse.cdt.cmake.core.internal; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.core.build.ICBuildConfiguration; +import org.eclipse.cdt.core.build.ICBuildConfigurationProvider; +import org.eclipse.cdt.core.build.IToolChain; +import org.eclipse.cdt.core.build.IToolChainManager; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; + +public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProvider { + + public static final String ID = "org.eclipse.cdt.cmake.core.provider"; //$NON-NLS-1$ + + @Override + public String getId() { + return ID; + } + + @Override + public ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name) throws CoreException { + if (config.getName().equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) { + IToolChain toolChain = null; + + // try the toolchain for the local target + Map properties = new HashMap<>(); + properties.put(IToolChain.ATTR_OS, Platform.getOS()); + properties.put(IToolChain.ATTR_ARCH, Platform.getOSArch()); + IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class); + for (IToolChain tc : toolChainManager.getToolChainsMatching(properties)) { + toolChain = tc; + break; + } + + // local didn't work, try and find one that does + if (toolChain == null) { + for (IToolChain tc : toolChainManager.getToolChainsMatching(new HashMap<>())) { + toolChain = tc; + break; + } + } + + if (toolChain != null) { + return new CMakeBuildConfiguration(config, name, toolChain); + } else { + // No valid combinations + return null; + } + } else { + return new CMakeBuildConfiguration(config, name); + } + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeTemplateGenerator.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeTemplateGenerator.java deleted file mode 100644 index f611e5b827c..00000000000 --- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeTemplateGenerator.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 QNX Software 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 - *******************************************************************************/ -package org.eclipse.cdt.cmake.core.internal; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.charset.StandardCharsets; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; - -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; - -public class CMakeTemplateGenerator { - - private final Configuration config; - - public CMakeTemplateGenerator() throws CoreException { - config = new Configuration(Configuration.VERSION_2_3_22); - URL templateDirURL = FileLocator.find(Activator.getPlugin().getBundle(), new Path("/templates"), null); //$NON-NLS-1$ - try { - config.setDirectoryForTemplateLoading(new File(FileLocator.toFileURL(templateDirURL).toURI())); - } catch (IOException | URISyntaxException e) { - throw new CoreException(Activator.errorStatus("Template configuration", e)); - } - } - - public void generateFile(final Object model, String templateFile, final IFile outputFile, IProgressMonitor monitor) - throws CoreException { - try { - final Template template = config.getTemplate(templateFile); - try (StringWriter writer = new StringWriter()) { - template.process(model, writer); - try (ByteArrayInputStream in = new ByteArrayInputStream( - writer.getBuffer().toString().getBytes(StandardCharsets.UTF_8))) { - if (outputFile.exists()) { - outputFile.setContents(in, true, true, monitor); - } else { - outputFile.create(in, true, monitor); - } - } - } - } catch (IOException | TemplateException e) { - throw new CoreException(Activator.errorStatus("Processing template " + templateFile, e)); - } - } - -} diff --git a/build/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt b/build/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt index 7f201943264..010d47aa33a 100644 --- a/build/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt +++ b/build/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt @@ -1,3 +1,5 @@ cmake_minimum_required (VERSION 2.6) + project (${projectName}) -add_executable(${projectName} src/main.cpp) + +add_executable(${projectName} src/${projectName}.cpp) diff --git a/build/org.eclipse.cdt.cmake.core/templates/simple/manifest.xml b/build/org.eclipse.cdt.cmake.core/templates/simple/manifest.xml new file mode 100644 index 00000000000..fb88868dd9b --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/templates/simple/manifest.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF index 180b8de1179..a3b64a155fd 100644 --- a/build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF @@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources;bundle-version="3.11.0", org.eclipse.ui, org.eclipse.ui.ide, - org.eclipse.cdt.cmake.core + org.eclipse.cdt.cmake.core, + org.eclipse.tools.templates.ui;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy diff --git a/build/org.eclipse.cdt.cmake.ui/icons/cmake_logo-main.png b/build/org.eclipse.cdt.cmake.ui/icons/cmake_logo-main.png new file mode 100644 index 00000000000..f31af16c272 Binary files /dev/null and b/build/org.eclipse.cdt.cmake.ui/icons/cmake_logo-main.png differ diff --git a/build/org.eclipse.cdt.cmake.ui/plugin.xml b/build/org.eclipse.cdt.cmake.ui/plugin.xml index 264bb850600..3edcc339bcd 100644 --- a/build/org.eclipse.cdt.cmake.ui/plugin.xml +++ b/build/org.eclipse.cdt.cmake.ui/plugin.xml @@ -1,18 +1,6 @@ - - - - + + + + + diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java index 55b167f004c..0e4e431da92 100644 --- a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java @@ -1,49 +1,40 @@ -/******************************************************************************* - * Copyright (c) 2015 QNX Software 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 - *******************************************************************************/ package org.eclipse.cdt.cmake.ui.internal; -import java.lang.reflect.InvocationTargetException; - import org.eclipse.cdt.cmake.core.CMakeProjectGenerator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; -import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tools.templates.core.IGenerator; +import org.eclipse.tools.templates.ui.TemplateWizard; +import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; -public class NewCMakeProjectWizard extends BasicNewProjectResourceWizard { +public class NewCMakeProjectWizard extends TemplateWizard { + + private WizardNewProjectCreationPage mainPage; @Override - public boolean performFinish() { - if (!super.performFinish()) { - return false; - } - - IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() { + public void addPages() { + mainPage = new WizardNewProjectCreationPage("basicNewProjectPage") { //$NON-NLS-1$ @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - monitor.beginTask("Generating project", 1); - CMakeProjectGenerator generator = new CMakeProjectGenerator(getNewProject()); - generator.generate(monitor); - monitor.done(); - } catch (CoreException e) { - Activator.log(e); - } + public void createControl(Composite parent) { + super.createControl(parent); + createWorkingSetGroup((Composite) getControl(), getSelection(), + new String[] { "org.eclipse.ui.resourceWorkingSetPage" }); //$NON-NLS-1$ + Dialog.applyDialogFont(getControl()); } - }); + }; + mainPage.setTitle("New Arduino Project"); //$NON-NLS-1$ + mainPage.setDescription("Specify properties of new Arduino project."); //$NON-NLS-1$ + this.addPage(mainPage); + } - try { - getContainer().run(false, true, op); - } catch (InvocationTargetException | InterruptedException e) { - return false; + @Override + protected IGenerator getGenerator() { + CMakeProjectGenerator generator = new CMakeProjectGenerator("templates/simple/manifest.xml"); //$NON-NLS-1$ + generator.setProjectName(mainPage.getProjectName()); + if (!mainPage.useDefaults()) { + generator.setLocationURI(mainPage.getLocationURI()); } - return true; + return generator; } } diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF index 262e811d3e3..3b80b6d016b 100644 --- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF @@ -122,6 +122,7 @@ Require-Bundle: org.eclipse.cdt.core;bundle-version="[5.2.0,7.0.0)", org.eclipse.ui.views;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)", com.ibm.icu;bundle-version="4.4.2", - org.eclipse.e4.ui.css.swt.theme + org.eclipse.e4.ui.css.swt.theme, + org.eclipse.tools.templates.ui;bundle-version="1.1.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 2d6978947e7..c62374ffdeb 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -534,8 +534,8 @@ Index.menu=Index C.Cpp.Index.menu=C/C++ &Index CDTWizard=CDT New Project Wizard -CDTproject=CDT Project -CDTproject.desc=Create a new language-neutral project +CDTproject=C/C++ Project +CDTproject.desc=Create a new C or C++ project CPPproject=C++ Project CPPproject.desc=Create a new C++ project Cproject=C Project diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 930033961e3..78f6a992e8c 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -458,6 +458,20 @@ %Cproject.desc + + + %CDTproject.desc + + @@ -4933,5 +4947,12 @@ + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/project/NewCDTProjectWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/project/NewCDTProjectWizard.java new file mode 100644 index 00000000000..1e74e5c6103 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/project/NewCDTProjectWizard.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2016 QNX Software 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 + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards.project; + +import org.eclipse.tools.templates.ui.NewWizard; + +public class NewCDTProjectWizard extends NewWizard { + + private static final String cdtTag = "org.eclipse.cdt.ui.cdtTag"; //$NON-NLS-1$ + + public NewCDTProjectWizard() { + super(cdtTag); + setTemplateSelectionPageTitle("Templates for New C/C++ Project"); + } + +} diff --git a/debug/org.eclipse.cdt.debug.application.product/debug.product b/debug/org.eclipse.cdt.debug.application.product/debug.product index 3d89ba2fe3c..40040a378d1 100644 --- a/debug/org.eclipse.cdt.debug.application.product/debug.product +++ b/debug/org.eclipse.cdt.debug.application.product/debug.product @@ -264,6 +264,7 @@ Java and all Java-based trademarks are trademarks of Oracle Corporation in the U + @@ -312,6 +313,7 @@ Java and all Java-based trademarks are trademarks of Oracle Corporation in the U + @@ -345,7 +347,10 @@ Java and all Java-based trademarks are trademarks of Oracle Corporation in the U + + + diff --git a/qt/org.eclipse.cdt.qt.ui/icons/qt_logo.png b/qt/org.eclipse.cdt.qt.ui/icons/qt_logo.png new file mode 100644 index 00000000000..528cdef4d64 Binary files /dev/null and b/qt/org.eclipse.cdt.qt.ui/icons/qt_logo.png differ diff --git a/qt/org.eclipse.cdt.qt.ui/plugin.xml b/qt/org.eclipse.cdt.qt.ui/plugin.xml index de058a0092e..ae4644538db 100644 --- a/qt/org.eclipse.cdt.qt.ui/plugin.xml +++ b/qt/org.eclipse.cdt.qt.ui/plugin.xml @@ -131,16 +131,19 @@ label="Qt"> - - A single C++ file with empty setup() and loop() functions. + + + +