From 6f36a51b5b821cf50432a1e2f056653e53612dd1 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Fri, 4 Dec 2015 13:38:37 -0500 Subject: [PATCH] Bug 174176 - initial contrib of CMake support. Change-Id: I7f0417bd92415aa9abb24ebabe849d9e4f75cea5 --- .../eclipse/cdt/build/core/IToolChain.java | 2 + .../cdt/build/gcc/core/GCCToolChain.java | 10 +- build/org.eclipse.cdt.cmake-feature/.project | 17 +++ .../build.properties | 1 + .../feature.properties | 29 +++++ .../org.eclipse.cdt.cmake-feature/feature.xml | 34 ++++++ build/org.eclipse.cdt.cmake-feature/pom.xml | 18 +++ build/org.eclipse.cdt.cmake.core/.classpath | 7 ++ build/org.eclipse.cdt.cmake.core/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 17 +++ build/org.eclipse.cdt.cmake.core/about.html | 24 ++++ .../build.properties | 6 + build/org.eclipse.cdt.cmake.core/plugin.xml | 89 ++++++++++++++ build/org.eclipse.cdt.cmake.core/pom.xml | 17 +++ .../eclipse/cdt/cmake/core/CMakeNature.java | 48 ++++++++ .../cdt/cmake/core/CMakeProjectGenerator.java | 73 ++++++++++++ .../cdt/cmake/core/internal/Activator.java | 61 ++++++++++ .../internal/CMakeBuildConfiguration.java | 88 ++++++++++++++ .../CMakeBuildConfigurationFactory.java | 82 +++++++++++++ .../cdt/cmake/core/internal/CMakeBuilder.java | 66 +++++++++++ .../core/internal/CMakeLaunchDescriptor.java | 49 ++++++++ .../internal/CMakeLaunchDescriptorType.java | 39 ++++++ ...CMakeLocalLaunchConfigurationProvider.java | 111 ++++++++++++++++++ .../CMakeLocalRunLaunchConfigDelegate.java | 37 ++++++ .../internal/CMakeScannerInfoProvider.java | 45 +++++++ .../core/internal/CMakeTemplateGenerator.java | 62 ++++++++++ .../templates/simple/CMakeLists.txt | 3 + .../templates/simple/main.cpp | 4 + build/org.eclipse.cdt.cmake.ui/.classpath | 7 ++ build/org.eclipse.cdt.cmake.ui/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 15 +++ build/org.eclipse.cdt.cmake.ui/about.html | 24 ++++ .../org.eclipse.cdt.cmake.ui/build.properties | 6 + .../icons/newcc_app.gif | Bin 0 -> 630 bytes build/org.eclipse.cdt.cmake.ui/plugin.xml | 17 +++ build/org.eclipse.cdt.cmake.ui/pom.xml | 17 +++ .../cdt/cmake/ui/internal/Activator.java | 50 ++++++++ .../ui/internal/NewCMakeProjectWizard.java | 45 +++++++ pom.xml | 4 + 41 files changed, 1293 insertions(+), 1 deletion(-) create mode 100644 build/org.eclipse.cdt.cmake-feature/.project create mode 100644 build/org.eclipse.cdt.cmake-feature/build.properties create mode 100644 build/org.eclipse.cdt.cmake-feature/feature.properties create mode 100644 build/org.eclipse.cdt.cmake-feature/feature.xml create mode 100644 build/org.eclipse.cdt.cmake-feature/pom.xml create mode 100644 build/org.eclipse.cdt.cmake.core/.classpath create mode 100644 build/org.eclipse.cdt.cmake.core/.project create mode 100644 build/org.eclipse.cdt.cmake.core/.settings/org.eclipse.jdt.core.prefs create mode 100644 build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF create mode 100644 build/org.eclipse.cdt.cmake.core/about.html create mode 100644 build/org.eclipse.cdt.cmake.core/build.properties create mode 100644 build/org.eclipse.cdt.cmake.core/plugin.xml create mode 100644 build/org.eclipse.cdt.cmake.core/pom.xml create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeNature.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeProjectGenerator.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationFactory.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuilder.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptor.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptorType.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalLaunchConfigurationProvider.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeScannerInfoProvider.java create mode 100644 build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeTemplateGenerator.java create mode 100644 build/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt create mode 100644 build/org.eclipse.cdt.cmake.core/templates/simple/main.cpp create mode 100644 build/org.eclipse.cdt.cmake.ui/.classpath create mode 100644 build/org.eclipse.cdt.cmake.ui/.project create mode 100644 build/org.eclipse.cdt.cmake.ui/.settings/org.eclipse.jdt.core.prefs create mode 100644 build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF create mode 100644 build/org.eclipse.cdt.cmake.ui/about.html create mode 100644 build/org.eclipse.cdt.cmake.ui/build.properties create mode 100644 build/org.eclipse.cdt.cmake.ui/icons/newcc_app.gif create mode 100644 build/org.eclipse.cdt.cmake.ui/plugin.xml create mode 100644 build/org.eclipse.cdt.cmake.ui/pom.xml create mode 100644 build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java create mode 100644 build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java diff --git a/build/org.eclipse.cdt.build.core/src/org/eclipse/cdt/build/core/IToolChain.java b/build/org.eclipse.cdt.build.core/src/org/eclipse/cdt/build/core/IToolChain.java index fbf0a4ac8e6..186fb7db4df 100644 --- a/build/org.eclipse.cdt.build.core/src/org/eclipse/cdt/build/core/IToolChain.java +++ b/build/org.eclipse.cdt.build.core/src/org/eclipse/cdt/build/core/IToolChain.java @@ -27,6 +27,8 @@ public interface IToolChain { String getName(); + String getCommand(); + boolean supports(ILaunchTarget target); IExtendedScannerInfo getScannerInfo(String command, List args, List includePaths, diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java index 8af950559f4..75c7b3d1c10 100644 --- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java +++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java @@ -46,8 +46,9 @@ import org.osgi.service.prefs.Preferences; */ public class GCCToolChain implements IToolChain { - private IToolChainType type; + private final IToolChainType type; private final String name; + private String command; private String version; private String target; @@ -55,11 +56,13 @@ public class GCCToolChain implements IToolChain { this.type = type; getVersion(path.resolve(command).toString()); this.name = command + '-' + version; + this.command = command; } protected GCCToolChain(IToolChainType type, String name) { this.type = type; this.name = name; + // TODO need to pull the other info out of preferences } @Override @@ -72,6 +75,11 @@ public class GCCToolChain implements IToolChain { return name; } + @Override + public String getCommand() { + return command; + } + private static Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$ private static Pattern targetPattern = Pattern.compile("Target: (.*)"); //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.cmake-feature/.project b/build/org.eclipse.cdt.cmake-feature/.project new file mode 100644 index 00000000000..4bfc1eda8ff --- /dev/null +++ b/build/org.eclipse.cdt.cmake-feature/.project @@ -0,0 +1,17 @@ + + + org.eclipse.cdt.cmake-feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/build/org.eclipse.cdt.cmake-feature/build.properties b/build/org.eclipse.cdt.cmake-feature/build.properties new file mode 100644 index 00000000000..64f93a9f0b7 --- /dev/null +++ b/build/org.eclipse.cdt.cmake-feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/build/org.eclipse.cdt.cmake-feature/feature.properties b/build/org.eclipse.cdt.cmake-feature/feature.properties new file mode 100644 index 00000000000..3703525e4d7 --- /dev/null +++ b/build/org.eclipse.cdt.cmake-feature/feature.properties @@ -0,0 +1,29 @@ +############################################################################### +# 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 +############################################################################### +# features.properties +# contains externalized strings for feature.xml +# "%foo" in feature.xml corresponds to the key "foo" in this file +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# This file should be translated. + +# "featureName" property - name of the feature +featureName=C/C++ CMake Support + +# "providerName" property - name of the company that provides the feature +providerName=Eclipse CDT + +# "description" property - description of the feature +description=Support for projects built using CMake + +# copyright +copyright=\ +Copyright (c) 2015 QNX Software Systems and others.\n\ +All rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\n\ +which accompanies this distribution, and is available at\n\ +http://www.eclipse.org/legal/epl-v10.html diff --git a/build/org.eclipse.cdt.cmake-feature/feature.xml b/build/org.eclipse.cdt.cmake-feature/feature.xml new file mode 100644 index 00000000000..faa10624dfb --- /dev/null +++ b/build/org.eclipse.cdt.cmake-feature/feature.xml @@ -0,0 +1,34 @@ + + + + + %description + + + + %copyright + + + + %license + + + + + + + diff --git a/build/org.eclipse.cdt.cmake-feature/pom.xml b/build/org.eclipse.cdt.cmake-feature/pom.xml new file mode 100644 index 00000000000..661dbc01945 --- /dev/null +++ b/build/org.eclipse.cdt.cmake-feature/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + org.eclipse.cdt + cdt-parent + 8.8.0-SNAPSHOT + ../../pom.xml + + + org.eclipse.cdt.features + 1.0.0-SNAPSHOT + org.eclipse.cdt.cmake + eclipse-feature + diff --git a/build/org.eclipse.cdt.cmake.core/.classpath b/build/org.eclipse.cdt.cmake.core/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/build/org.eclipse.cdt.cmake.core/.project b/build/org.eclipse.cdt.cmake.core/.project new file mode 100644 index 00000000000..f5c8e485e7b --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.cdt.cmake.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/build/org.eclipse.cdt.cmake.core/.settings/org.eclipse.jdt.core.prefs b/build/org.eclipse.cdt.cmake.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..3cacc90d5e9 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: CDT CMake Core +Bundle-SymbolicName: org.eclipse.cdt.cmake.core;singleton:=true +Bundle-Version: 1.0.0.qualifier +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.build.core;bundle-version="1.0.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.cdt.cmake.core diff --git a/build/org.eclipse.cdt.cmake.core/about.html b/build/org.eclipse.cdt.cmake.core/about.html new file mode 100644 index 00000000000..d7c511887d6 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/about.html @@ -0,0 +1,24 @@ + + +About + + +

About This Content

+ +

June 22, 2007

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/build/org.eclipse.cdt.cmake.core/build.properties b/build/org.eclipse.cdt.cmake.core/build.properties new file mode 100644 index 00000000000..bdcc25a2886 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.xml diff --git a/build/org.eclipse.cdt.cmake.core/plugin.xml b/build/org.eclipse.cdt.cmake.core/plugin.xml new file mode 100644 index 00000000000..c71cca8788c --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/plugin.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/org.eclipse.cdt.cmake.core/pom.xml b/build/org.eclipse.cdt.cmake.core/pom.xml new file mode 100644 index 00000000000..b8037822038 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + org.eclipse.cdt + cdt-parent + 8.8.0-SNAPSHOT + ../../pom.xml + + + 1.0.0-SNAPSHOT + org.eclipse.cdt.cmake.core + eclipse-plugin + \ No newline at end of file diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeNature.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeNature.java new file mode 100644 index 00000000000..0e774d55f3c --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeNature.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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; + +import org.eclipse.cdt.cmake.core.internal.Activator; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +public class CMakeNature implements IProjectNature { + + public static final String ID = Activator.getId() + ".cmakeNature"; //$NON-NLS-1$ + + private IProject project; + + public static boolean hasNature(IProject project) { + try { + return project.hasNature(ID); + } catch (CoreException e) { + Activator.log(e); + return false; + } + } + + @Override + public void configure() throws CoreException { + } + + @Override + public void deconfigure() throws CoreException { + } + + @Override + public IProject getProject() { + return project; + } + + @Override + public void setProject(IProject project) { + this.project = project; + } + +} 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 new file mode 100644 index 00000000000..8ce37d691a5 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeProjectGenerator.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * 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; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.cmake.core.internal.CMakeBuilder; +import org.eclipse.cdt.cmake.core.internal.CMakeTemplateGenerator; +import org.eclipse.cdt.core.CCProjectNature; +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.core.resources.ICommand; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +public class CMakeProjectGenerator { + + private final IProject project; + + public CMakeProjectGenerator(IProject project) { + this.project = project; + } + + 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); + } + + 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); + + ICommand command = projDesc.newCommand(); + command.setBuilderName(CMakeBuilder.ID); + command.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false); + projDesc.setBuildSpec(new ICommand[] { command }); + + project.setDescription(projDesc, monitor); + + IPathEntry[] entries = new IPathEntry[] { CoreModel.newOutputEntry(sourceFolder.getFullPath()) }; + CoreModel.getDefault().create(project).setRawPathEntries(entries, monitor); + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java new file mode 100644 index 00000000000..0f78429c888 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/Activator.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * 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 org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public class Activator extends Plugin { + + private static Activator plugin; + + public void start(BundleContext bundleContext) throws Exception { + super.start(bundleContext); + Activator.plugin = this; + } + + public void stop(BundleContext bundleContext) throws Exception { + super.stop(bundleContext); + Activator.plugin = null; + } + + public static Activator getPlugin() { + return plugin; + } + + public static String getId() { + return plugin.getBundle().getSymbolicName(); + } + + public static void log(Throwable e) { + if (e instanceof CoreException) { + plugin.getLog().log(((CoreException) e).getStatus()); + } else { + plugin.getLog().log(errorStatus(e.getLocalizedMessage(), e)); + } + } + + public static void error(String message, Throwable cause) { + plugin.getLog().log(errorStatus(message, cause)); + } + + public static IStatus errorStatus(String message, Throwable cause) { + return new Status(IStatus.ERROR, getId(), message, cause); + } + + public static T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + +} 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 new file mode 100644 index 00000000000..239e519397b --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; + +import org.eclipse.cdt.build.core.CBuildConfiguration; +import org.eclipse.cdt.build.core.IToolChain; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.LanguageManager; +import org.eclipse.cdt.core.parser.IExtendedScannerInfo; +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; + +public class CMakeBuildConfiguration extends CBuildConfiguration { + + public CMakeBuildConfiguration(IBuildConfiguration config) { + super(config); + } + + public CMakeBuildConfiguration(IBuildConfiguration config, IToolChain toolChain) { + super(config, toolChain); + } + + private IFolder getBuildFolder() { + String configName = getBuildConfiguration().getName(); + if (configName.isEmpty()) { + configName = "default"; //$NON-NLS-1$ + } + + try { + // TODO should really be passing a monitor in here or create this in + // a better spot. should also throw the core exception + IFolder buildRootFolder = getProject().getFolder("build"); //$NON-NLS-1$ + if (!buildRootFolder.exists()) { + buildRootFolder.create(IResource.FORCE | IResource.DERIVED, true, new NullProgressMonitor()); + } + IFolder buildFolder = buildRootFolder.getFolder(configName); + if (!buildFolder.exists()) { + buildFolder.create(true, true, new NullProgressMonitor()); + } + return buildFolder; + } catch (CoreException e) { + Activator.log(e); + } + return null; + } + + public Path getBuildDirectory() { + return getBuildFolder().getLocation().toFile().toPath(); + } + + @Override + public IScannerInfo getScannerInfo(IResource resource) throws IOException { + IScannerInfo info = super.getScannerInfo(resource); + if (info == null) { + ILanguage language = LanguageManager.getInstance() + .getLanguage(CCorePlugin.getContentType(getProject(), resource.getName()), getProject()); // $NON-NLS-1$ + Path dir = Paths.get(getProject().getLocationURI()); + + // TODO this is where we need to pass the compile options for this + // file. + + IExtendedScannerInfo extendedInfo = getToolChain().getScannerInfo(getToolChain().getCommand(), + Arrays.asList("-c", new File(resource.getLocationURI()).getAbsolutePath()), //$NON-NLS-1$ + Collections.emptyList(), resource, dir); + putScannerInfo(language, extendedInfo); + info = extendedInfo; + } + return info; + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationFactory.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationFactory.java new file mode 100644 index 00000000000..f527069ab50 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfigurationFactory.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.build.core.IToolChain; +import org.eclipse.cdt.build.core.IToolChainManager; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; + +public class CMakeBuildConfigurationFactory implements IAdapterFactory { + + private static IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class); + private static Map cache = new HashMap<>(); + + @Override + public Class[] getAdapterList() { + return new Class[] { CMakeBuildConfiguration.class }; + } + + @SuppressWarnings("unchecked") + @Override + public T getAdapter(Object adaptableObject, Class adapterType) { + if (adapterType.equals(CMakeBuildConfiguration.class) && adaptableObject instanceof IBuildConfiguration) { + IBuildConfiguration config = (IBuildConfiguration) adaptableObject; + synchronized (cache) { + CMakeBuildConfiguration cmakeConfig = cache.get(config); + if (cmakeConfig == null) { + if (!config.getName().equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) { + cmakeConfig = new CMakeBuildConfiguration(config); + cache.put(config, cmakeConfig); + return (T) cmakeConfig; + } else { + // Default to local + ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class); + ILaunchTarget localTarget = targetManager + .getLaunchTargetsOfType(ILaunchTargetManager.localLaunchTargetTypeId)[0]; + Collection toolChains = toolChainManager.getToolChainsSupporting(localTarget); + if (!toolChains.isEmpty()) { + // TODO propery handle when we have more than one + cmakeConfig = new CMakeBuildConfiguration(config, toolChains.iterator().next()); + cache.put(config, cmakeConfig); + return (T) cmakeConfig; + } + + // Just find a combination that works + for (ILaunchTarget target : targetManager.getLaunchTargets()) { + if (!target.equals(localTarget)) { + toolChains = toolChainManager.getToolChainsSupporting(target); + if (!toolChains.isEmpty()) { + // TODO propery handle when we have more + // than one + cmakeConfig = new CMakeBuildConfiguration(config, toolChains.iterator().next()); + cache.put(config, cmakeConfig); + return (T) cmakeConfig; + } + } + } + + // TODO if we don't have a target, need another way to + // match whatever qtInstalls we have with matching + // toolchains + } + } else { + return (T) cmakeConfig; + } + } + } + return null; + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuilder.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuilder.java new file mode 100644 index 00000000000..8ccc61d862c --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuilder.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.build.core.IConsoleService; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +public class CMakeBuilder extends IncrementalProjectBuilder { + + public static final String ID = Activator.getId() + ".cmakeBuilder"; //$NON-NLS-1$ + + @Override + protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { + IProject project = getProject(); + try { + IConsoleService console = Activator.getService(IConsoleService.class); + CMakeBuildConfiguration cmakeConfig = project.getActiveBuildConfig() + .getAdapter(CMakeBuildConfiguration.class); + Path buildDir = cmakeConfig.getBuildDirectory(); + + 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$ + new File(project.getLocationURI()).getAbsolutePath()); + ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile()); + cmakeConfig.getToolChain().setEnvironment(processBuilder.environment()); + Process process = processBuilder.start(); + console.writeOutput(String.join(" ", command) + '\n'); //$NON-NLS-1$ + console.monitor(process, null, buildDir); + } + + // TODO need to figure out which builder to call. Hardcoding to make + // for now. + List command = Arrays.asList("make"); + ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile()); // $NON-NLS-1$ + cmakeConfig.getToolChain().setEnvironment(processBuilder.environment()); + Process process = processBuilder.start(); + console.writeOutput(String.join(" ", command) + '\n'); //$NON-NLS-1$ + console.monitor(process, null, buildDir); + + project.refreshLocal(IResource.DEPTH_INFINITE, monitor); + return new IProject[] { project }; + } catch (IOException e) { + throw new CoreException(Activator.errorStatus("Building " + project.getName(), e)); + } + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptor.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptor.java new file mode 100644 index 00000000000..cd1cff81eee --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptor.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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 org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.launchbar.core.ILaunchDescriptor; +import org.eclipse.launchbar.core.ILaunchDescriptorType; + +public class CMakeLaunchDescriptor extends PlatformObject implements ILaunchDescriptor { + + private final CMakeLaunchDescriptorType type; + private final IProject project; + + public CMakeLaunchDescriptor(CMakeLaunchDescriptorType type, IProject project) { + this.type = type; + this.project = project; + } + + @Override + public String getName() { + return project.getName(); + } + + @Override + public ILaunchDescriptorType getType() { + return type; + } + + public IProject getProject() { + return project; + } + + @SuppressWarnings("unchecked") + @Override + public T getAdapter(Class adapter) { + if (adapter.equals(IProject.class)) { + return (T) project; + } else { + return super.getAdapter(adapter); + } + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptorType.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptorType.java new file mode 100644 index 00000000000..4a66f37d933 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLaunchDescriptorType.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.cmake.core.CMakeNature; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.launchbar.core.ILaunchDescriptor; +import org.eclipse.launchbar.core.ILaunchDescriptorType; + +public class CMakeLaunchDescriptorType implements ILaunchDescriptorType { + + private Map descriptors = new HashMap<>(); + + @Override + public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException { + if (launchObject instanceof IProject) { + IProject project = (IProject) launchObject; + if (CMakeNature.hasNature(project)) { + CMakeLaunchDescriptor desc = descriptors.get(project); + if (desc == null) { + desc = new CMakeLaunchDescriptor(this, project); + descriptors.put(project, desc); + } + return desc; + } + } + return null; + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalLaunchConfigurationProvider.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalLaunchConfigurationProvider.java new file mode 100644 index 00000000000..55d40734a0c --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalLaunchConfigurationProvider.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * 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.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.launchbar.core.AbstractLaunchConfigProvider; +import org.eclipse.launchbar.core.ILaunchDescriptor; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; + +public class CMakeLocalLaunchConfigurationProvider extends AbstractLaunchConfigProvider { + + private Map configs = new HashMap<>(); + + @Override + public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { + return ILaunchTargetManager.localLaunchTargetTypeId.equals(target.getTypeId()); + } + + @Override + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) + throws CoreException { + return DebugPlugin.getDefault().getLaunchManager() + .getLaunchConfigurationType(CMakeLocalRunLaunchConfigDelegate.TYPE_ID); + } + + // TODO the rest here is the same as the Qt provider. Opportunity to create + // a common super class + + @Override + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) + throws CoreException { + ILaunchConfiguration config = null; + IProject project = descriptor.getAdapter(IProject.class); + if (project != null) { + config = configs.get(project); + if (config == null) { + config = createLaunchConfiguration(descriptor, target); + // launch config added will get called below to add it to the + // configs map + } + } + return config; + } + + @Override + protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target, + ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { + super.populateLaunchConfiguration(descriptor, target, workingCopy); + + // Set the project and the connection + CMakeLaunchDescriptor qtDesc = (CMakeLaunchDescriptor) descriptor; + workingCopy.setMappedResources(new IResource[] { qtDesc.getProject() }); + } + + @Override + public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { + if (ownsLaunchConfiguration(configuration)) { + IProject project = configuration.getMappedResources()[0].getProject(); + configs.put(project, configuration); + return true; + } + return false; + } + + @Override + public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { + for (Entry entry : configs.entrySet()) { + if (configuration.equals(entry.getValue())) { + configs.remove(entry.getKey()); + return true; + } + } + return false; + } + + @Override + public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException { + // TODO not sure I care + return false; + } + + @Override + public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException { + IProject project = descriptor.getAdapter(IProject.class); + if (project != null) { + configs.remove(project); + } + } + + @Override + public void launchTargetRemoved(ILaunchTarget target) throws CoreException { + // nothing to do since the Local connection can't be removed + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java new file mode 100644 index 00000000000..2bb8db73679 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeLocalRunLaunchConfigDelegate.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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 org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; +import org.eclipse.launchbar.core.target.launch.LaunchConfigurationTargetedDelegate; + +public class CMakeLocalRunLaunchConfigDelegate extends LaunchConfigurationTargetedDelegate + implements ILaunchConfigurationDelegate { + + public static final String TYPE_ID = "org.eclipse.cdt.cmake.core.localLunchConfigurationType"; //$NON-NLS-1$ + + @Override + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) + throws CoreException { + // TODO need to find the binary and launch it. + } + + @Override + protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException { + // 1. Extract project from configuration + // TODO dependencies too. + IProject project = configuration.getMappedResources()[0].getProject(); + return new IProject[] { project }; + } + +} diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeScannerInfoProvider.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeScannerInfoProvider.java new file mode 100644 index 00000000000..634d3c8412d --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeScannerInfoProvider.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.IOException; + +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; +import org.eclipse.cdt.core.parser.IScannerInfoProvider; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; + +public class CMakeScannerInfoProvider implements IScannerInfoProvider { + + @Override + public IScannerInfo getScannerInformation(IResource resource) { + try { + IProject project = resource.getProject(); + IBuildConfiguration config = project.getActiveBuildConfig(); + CMakeBuildConfiguration cmakeConfig = config.getAdapter(CMakeBuildConfiguration.class); + if (cmakeConfig != null) { + return cmakeConfig.getScannerInfo(resource); + } + } catch (CoreException | IOException e) { + Activator.log(e); + } + return null; + } + + @Override + public void subscribe(IResource resource, IScannerInfoChangeListener listener) { + } + + @Override + public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) { + } + +} 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 new file mode 100644 index 00000000000..f611e5b827c --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeTemplateGenerator.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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 new file mode 100644 index 00000000000..7f201943264 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required (VERSION 2.6) +project (${projectName}) +add_executable(${projectName} src/main.cpp) diff --git a/build/org.eclipse.cdt.cmake.core/templates/simple/main.cpp b/build/org.eclipse.cdt.cmake.core/templates/simple/main.cpp new file mode 100644 index 00000000000..c493b4a5566 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.core/templates/simple/main.cpp @@ -0,0 +1,4 @@ + +int main(int argc, char **argv) { + return 0; +} diff --git a/build/org.eclipse.cdt.cmake.ui/.classpath b/build/org.eclipse.cdt.cmake.ui/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/build/org.eclipse.cdt.cmake.ui/.project b/build/org.eclipse.cdt.cmake.ui/.project new file mode 100644 index 00000000000..c65bf192fcd --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/.project @@ -0,0 +1,28 @@ + + + org.eclipse.cdt.cmake.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/build/org.eclipse.cdt.cmake.ui/.settings/org.eclipse.jdt.core.prefs b/build/org.eclipse.cdt.cmake.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..646ba27efe6 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: CDT CMake UI +Bundle-SymbolicName: org.eclipse.cdt.cmake.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.cdt.cmake.ui.internal.Activator +Bundle-Vendor: Eclipse CDT +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.build.ui;bundle-version="1.0.0", + org.eclipse.cdt.cmake.core +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy diff --git a/build/org.eclipse.cdt.cmake.ui/about.html b/build/org.eclipse.cdt.cmake.ui/about.html new file mode 100644 index 00000000000..d7c511887d6 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/about.html @@ -0,0 +1,24 @@ + + +About + + +

About This Content

+ +

June 22, 2007

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/build/org.eclipse.cdt.cmake.ui/build.properties b/build/org.eclipse.cdt.cmake.ui/build.properties new file mode 100644 index 00000000000..bdcc25a2886 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.xml diff --git a/build/org.eclipse.cdt.cmake.ui/icons/newcc_app.gif b/build/org.eclipse.cdt.cmake.ui/icons/newcc_app.gif new file mode 100644 index 0000000000000000000000000000000000000000..4b39411daf59ff4a97fdcfa0a6dae3c84fc04956 GIT binary patch literal 630 zcmZ?wbhEHb6krfwc*el+^ueRBrp+5qzu0^3p-b5+xAN6)6{|ff*Z9`1_pMnM*syWe znfpKg{MSgD=GU;=zhQORyaR<()?a`4^2eY58Ji#GZhe%$?NP<9CoKn_O*r=A#_R9j z|NQ^_`~SB;|9}4df92)pH$VTs|MmaV@Bddn|9|!K|LdRs-~Iak@%R6)fBygY`~T(7 z|8IW%fBWnImp}hs{rdmz_y5m-{(t}b|M$QD-~RsJdF=SVzwevM9eZo-I;tF+%N(1_ z9shng-&bSTQR(pa^ZBh4mA6h(-ZfoqcC*#gdYdT?Hh-Qko>wWhtWj!Nlho2CsdZiQ z>-$XB_n9v1G+)?ev9Qf@cC+>GyUjC8gg5n@tnM~@aB1ED|Nj{V4k-R)VPs$kW6%LP z0Td?;?3WwDnwnc$+u9vlSXfwl*g3cunH^0#n?yuJMa0Ax3Z8RFRzN8s;Xg-p^8sfi1I}f z6J8x{1sw%#?T|3v`@H&!ANkbO_!RYh!~EVUsjKtzDmY|(cyL5mJKzqZ!1YIrJbe67 z2LzH@PjE0^l&W#K$k=+EPqr;$r=ilZw#kM*c{4UB9%GRUE9mh!*wDz%Z<=}Q%Z0;U Ue9~4;uQo86Xap>1WMHrc0INa$RR910 literal 0 HcmV?d00001 diff --git a/build/org.eclipse.cdt.cmake.ui/plugin.xml b/build/org.eclipse.cdt.cmake.ui/plugin.xml new file mode 100644 index 00000000000..04262b00495 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/plugin.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/build/org.eclipse.cdt.cmake.ui/pom.xml b/build/org.eclipse.cdt.cmake.ui/pom.xml new file mode 100644 index 00000000000..981d204f6bc --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + org.eclipse.cdt + cdt-parent + 8.8.0-SNAPSHOT + ../../pom.xml + + + 1.0.0-SNAPSHOT + org.eclipse.cdt.cmake.ui + eclipse-plugin + \ No newline at end of file diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java new file mode 100644 index 00000000000..a8318124293 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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 org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +public class Activator extends AbstractUIPlugin { + + private static Activator plugin; + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + public static Activator getPlugin() { + return plugin; + } + + public static String getId() { + return plugin.getBundle().getSymbolicName(); + } + + public static IStatus errorStatus(String message, Throwable cause) { + return new Status(IStatus.ERROR, getId(), message, cause); + } + + public static void log(Exception e) { + if (e instanceof CoreException) { + plugin.getLog().log(((CoreException) e).getStatus()); + } else { + plugin.getLog().log(errorStatus(e.getLocalizedMessage(), e)); + } + } + +} 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 new file mode 100644 index 00000000000..f49597c783f --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java @@ -0,0 +1,45 @@ +/** + * The activator class controls the plug-in life cycle + */ +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; + +public class NewCMakeProjectWizard extends BasicNewProjectResourceWizard { + + @Override + public boolean performFinish() { + if (!super.performFinish()) { + return false; + } + + IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() { + @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); + } + } + }); + + try { + getContainer().run(false, true, op); + } catch (InvocationTargetException | InterruptedException e) { + return false; + } + return true; + } + +} diff --git a/pom.xml b/pom.xml index 9208c69e2be..1be8f0698ae 100644 --- a/pom.xml +++ b/pom.xml @@ -218,6 +218,10 @@ qt/org.eclipse.cdt.qt.ui.tests qt/org.eclipse.cdt.qt-feature + + build/org.eclipse.cdt.cmake.core + build/org.eclipse.cdt.cmake.ui + build/org.eclipse.cdt.cmake-feature xlc/org.eclipse.cdt.errorparsers.xlc.tests