mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Bug 416471: Support for extra ILanguageSettingsProviders in new projects
This change introduces three new ProcessRunners that can be used in the New Project wizard's template.xml files. These will be used by two new Qt project wizards that I will introduce in a second patch. The three new rules are: 1) "AddMakeTarget" which creates new Make Targets (in the Make Targets view) for the new projects. 2) "SetEnvironmentVariable" which sets an environment variable in all of the new project's build configurations. 3) "ExtraLanguageSettingsProvider" which modifies the new project's build configurations to include a new ILanguageSettingsProvider. The first two are straightforward, the third is a bit different. Instead of creating a new Toolchain or Configuration it modifies the Configurations that were created for the new project. In this case the only modification is to add the extra ILanguageSettingsProvider, but it might be useful to extend this to other customizations as well. Change-Id: I30710400e9b0dffcbe6e8965ce7ce2078c1c99ca Signed-off-by: Andrew Eidsness <eclipse@jfront.com> Reviewed-on: https://git.eclipse.org/r/16817 Reviewed-by: Andrew Gvozdev <angvoz.dev@gmail.com> IP-Clean: Andrew Gvozdev <angvoz.dev@gmail.com> Tested-by: Andrew Gvozdev <angvoz.dev@gmail.com>
This commit is contained in:
parent
411734ee3b
commit
a0a2059fdd
9 changed files with 357 additions and 6 deletions
|
@ -183,4 +183,16 @@
|
|||
/>
|
||||
</extension>
|
||||
|
||||
<extension point="org.eclipse.cdt.core.templateProcessTypes">
|
||||
<processType
|
||||
name="AddMakeTarget"
|
||||
processRunner="org.eclipse.cdt.make.internal.core.templateengine.AddMakeTarget">
|
||||
<simple name="projectName"/>
|
||||
<simple name="targetName"/>
|
||||
<simple name="makeTarget" external="true" nullable="true"/>
|
||||
<simple name="buildCommand" external="true" nullable="true"/>
|
||||
<simple name="buildArguments" external="true" nullable="true"/>
|
||||
</processType>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.core.templateengine;
|
||||
|
||||
import org.eclipse.cdt.core.templateengine.TemplateCore;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
|
||||
import org.eclipse.cdt.make.core.IMakeCommonBuildInfo;
|
||||
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||
import org.eclipse.cdt.make.core.IMakeTargetManager;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* A step that can be used by the New Project template.xml file to add make targets to
|
||||
* newly created C/C++ projects. E.g.,
|
||||
* <pre>
|
||||
* <process type="org.eclipse.cdt.make.core.AddMakeTarget">
|
||||
* <simple name="projectName" value="$(projectName)"/>
|
||||
* <simple name="targetName" value="build-debug"/>
|
||||
* <simple name="makeTarget" value="debug"/>
|
||||
* </process>
|
||||
* </pre>
|
||||
* The rule's parameters are used to populate fields in the "Create|Modify Make Target"
|
||||
* dialog box (which is opened from the Make Target view). The two mandatory parameters
|
||||
* are projectName and targetName. There are also three optional parameters:
|
||||
* <p>
|
||||
* <u>makeTarget</u>: The name of the make target to run, defaults to targetName<br>
|
||||
* <u>buildCommand</u>: The build command to execute, e.g., "make"<br>
|
||||
* <u>buildArguments</u>: The arguments that should be passed to the build command, e.g., "-s"<br>
|
||||
*/
|
||||
public class AddMakeTarget extends ProcessRunner {
|
||||
|
||||
private static final String BUILDER_ID = "org.eclipse.cdt.build.MakeTargetBuilder"; //$NON-NLS-1$
|
||||
|
||||
private static final String PROJECTNAME_VARNAME = "projectName"; //$NON-NLS-1$
|
||||
private static final String TARGETNAME_VARNAME = "targetName"; //$NON-NLS-1$
|
||||
private static final String MAKETARGET_VARNAME = "makeTarget"; //$NON-NLS-1$
|
||||
private static final String BUILDCOMMAND_VARNAME = "buildCommand"; //$NON-NLS-1$
|
||||
private static final String BUILDARGUMENTS_COMMAND_VARNAME = "buildArguments"; //$NON-NLS-1$
|
||||
|
||||
private static final String BUILDCOMMAND_DEFAULT = "make"; //$NON-NLS-1$
|
||||
private static final String BUILDARGUMENTS_DEFAULT = ""; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
|
||||
IProject project = null;
|
||||
String targetName = null;
|
||||
String makeTarget = null;
|
||||
String buildCommand = null;
|
||||
String buildArguments = null;
|
||||
|
||||
for (ProcessArgument arg : args) {
|
||||
String argName = arg.getName();
|
||||
if (PROJECTNAME_VARNAME.equals(argName))
|
||||
project = ResourcesPlugin.getWorkspace().getRoot().getProject(arg.getSimpleValue());
|
||||
else if (TARGETNAME_VARNAME.equals(argName))
|
||||
targetName = arg.getSimpleValue();
|
||||
else if (MAKETARGET_VARNAME.equals(argName))
|
||||
makeTarget = arg.getSimpleValue();
|
||||
else if (BUILDCOMMAND_VARNAME.equals(argName))
|
||||
buildCommand = arg.getSimpleValue();
|
||||
else if(BUILDARGUMENTS_COMMAND_VARNAME.equals(argName))
|
||||
buildArguments = arg.getSimpleValue();
|
||||
}
|
||||
|
||||
if (project == null)
|
||||
throw missingArgException(processId, PROJECTNAME_VARNAME);
|
||||
if (targetName == null)
|
||||
throw missingArgException(processId, TARGETNAME_VARNAME);
|
||||
|
||||
IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager();
|
||||
try {
|
||||
IMakeTarget target = makeTargetManager.createTarget(project, targetName, BUILDER_ID);
|
||||
|
||||
target.setBuildAttribute(IMakeTarget.BUILD_TARGET, makeTarget == null ? targetName : makeTarget);
|
||||
|
||||
target.setUseDefaultBuildCmd(buildCommand == null);
|
||||
target.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, buildCommand == null ? BUILDCOMMAND_DEFAULT : buildCommand);
|
||||
target.setBuildAttribute(IMakeCommonBuildInfo.BUILD_ARGUMENTS, buildArguments == null ? BUILDARGUMENTS_DEFAULT : buildArguments);
|
||||
|
||||
makeTargetManager.addTarget(target);
|
||||
} catch(CoreException e) {
|
||||
throw new ProcessFailureException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -584,6 +584,12 @@
|
|||
processRunner="org.eclipse.cdt.managedbuilder.templateengine.processes.GenerateMakefileWithBuildDescription">
|
||||
<simple name="projectName"/>
|
||||
</processType>
|
||||
<processType
|
||||
name="AddLanguageSettingsProvider"
|
||||
processRunner="org.eclipse.cdt.managedbuilder.templateengine.processes.AddLanguageSettingsProvider">
|
||||
<simple name="projectName"/>
|
||||
<simpleArray name="languageSettingsProviderIds"/>
|
||||
</processType>
|
||||
</extension>
|
||||
<extension
|
||||
id="headlessbuild"
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.templateengine.processes;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.templateengine.TemplateCore;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* A configurable stage of the New Project wizard that is able to add implementations of
|
||||
* {@link ILanguageSettingsProvider} to the new project's build configurations.
|
||||
* E.g.,
|
||||
* <pre>
|
||||
<process type="org.eclipse.cdt.managedbuilder.core.AddLanguageSettingsProvider">
|
||||
<simple name="projectName" value="$(projectName)"/>
|
||||
<simple-array name="languageSettingsProviders">
|
||||
<element value="org.eclipse.cdt.qt.core.QtPathsProvider"/>
|
||||
</simple-array>
|
||||
</process>
|
||||
* </pre>
|
||||
*
|
||||
* @since 8.3
|
||||
*/
|
||||
public class AddLanguageSettingsProvider extends ProcessRunner {
|
||||
|
||||
private static final String PROJECTNAME_VARNAME = "projectName"; //$NON-NLS-1$
|
||||
private static final String PROVIDERS_VARNAME = "languageSettingsProviderIds"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
|
||||
IProject project = null;
|
||||
String[] extraProviderIds = null;
|
||||
|
||||
for (ProcessArgument arg : args) {
|
||||
String argName = arg.getName();
|
||||
if (PROJECTNAME_VARNAME.equals(argName))
|
||||
project = ResourcesPlugin.getWorkspace().getRoot().getProject(arg.getSimpleValue());
|
||||
else if(PROVIDERS_VARNAME.equals(argName))
|
||||
extraProviderIds = arg.getSimpleArrayValue();
|
||||
}
|
||||
|
||||
if (project == null)
|
||||
throw missingArgException(processId, PROJECTNAME_VARNAME);
|
||||
if (extraProviderIds == null)
|
||||
throw missingArgException(processId, PROVIDERS_VARNAME);
|
||||
|
||||
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||
ICProjectDescription des = mngr.getProjectDescription(project, true);
|
||||
ICConfigurationDescription[] configDescs = des.getConfigurations();
|
||||
|
||||
for (ICConfigurationDescription configDesc : configDescs)
|
||||
if (configDesc instanceof ILanguageSettingsProvidersKeeper) {
|
||||
IConfiguration config = ManagedBuildManager.getConfigurationForDescription(configDesc);
|
||||
|
||||
// Create a merged array of the old and new ids
|
||||
String[] ids = config.getDefaultLanguageSettingsProviderIds();
|
||||
String[] newIds = new String[ids.length + extraProviderIds.length];
|
||||
System.arraycopy(ids, 0, newIds, 0, ids.length);
|
||||
System.arraycopy(extraProviderIds, 0, newIds, ids.length, extraProviderIds.length);
|
||||
|
||||
ILanguageSettingsProvidersKeeper keeper = (ILanguageSettingsProvidersKeeper) configDesc;
|
||||
keeper.setLanguageSettingProviders(LanguageSettingsManager.createLanguageSettingsProviders(newIds));
|
||||
}
|
||||
|
||||
try {
|
||||
mngr.setProjectDescription(project, des);
|
||||
} catch(CoreException e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -782,6 +782,17 @@
|
|||
name="natureId">
|
||||
</simple>
|
||||
</processType>
|
||||
<processType
|
||||
name="SetEnvironmentVariable"
|
||||
processRunner="org.eclipse.cdt.core.templateengine.process.processes.SetEnvironmentVariable">
|
||||
<simple name="projectName"/>
|
||||
<complexArray name="variables">
|
||||
<baseType>
|
||||
<simple name="name"/>
|
||||
<simple name="value"/>
|
||||
</baseType>
|
||||
</complexArray>
|
||||
</processType>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.CProjectDescriptionStorage">
|
||||
|
|
|
@ -19,6 +19,11 @@ public class TemplateEngineMessages {
|
|||
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
|
||||
.getBundle(BUNDLE_NAME);
|
||||
|
||||
/**
|
||||
* @since 5.6
|
||||
*/
|
||||
public static String ProcessRunner_missingArg;
|
||||
|
||||
private TemplateEngineMessages() {
|
||||
}
|
||||
|
||||
|
|
|
@ -30,3 +30,4 @@ ProcessRunner.error=-->Error:
|
|||
ProcessRunner.success=-->Success:
|
||||
ProcessRunner.info=-->Info:
|
||||
ProcessHelper.fileNotFound=File not found: ''{0}''
|
||||
ProcessRunner_missingArg = ILanguageSettingsProvider failure: argument {0} not found
|
||||
|
|
|
@ -15,25 +15,34 @@ import org.eclipse.cdt.core.templateengine.TemplateEngineMessages;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
|
||||
/**
|
||||
* Abstract ProcessRunner class provides the methods to implement for processes.
|
||||
*/
|
||||
public abstract class ProcessRunner {
|
||||
|
||||
|
||||
private ProcessParameter[] params = new ProcessParameter[0];
|
||||
|
||||
|
||||
void setProcessParameters(ProcessParameter[] params) {
|
||||
this.params = params == null ? new ProcessParameter[0] : params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Process Parameters.
|
||||
*/
|
||||
public ProcessParameter[] getProcessParameters() {
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 5.6
|
||||
*/
|
||||
protected ProcessFailureException missingArgException(String processId, String varname) {
|
||||
String msg = MessageFormat.format(TemplateEngineMessages.ProcessRunner_missingArg, varname);
|
||||
return new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the whether the arguments are matching the required parameters.
|
||||
*/
|
||||
|
@ -54,7 +63,7 @@ public abstract class ProcessRunner {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the String containing the mismatching message
|
||||
* if the arguments are not matching the required parameters.
|
||||
|
@ -95,7 +104,7 @@ public abstract class ProcessRunner {
|
|||
return processId + TemplateEngineMessages.getString("ProcessRunner.info") + msg; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param template
|
||||
* @param args
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.templateengine.process.processes;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.envvar.IContributedEnvironment;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.templateengine.TemplateCore;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
|
||||
import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* A template process for setting an environment variable in all of the new project's
|
||||
* build configurations. E.g.,
|
||||
* <pre>
|
||||
* <process type="org.eclipse.cdt.core.SetEnvironmentVariable">
|
||||
* <simple name="projectName" value="$(projectName)"/>
|
||||
* <complex-array name="variables">
|
||||
* <element>
|
||||
* <simple name="name" value="QMAKE"/>
|
||||
* <simple name="value" value="$(qmake)"/>
|
||||
* </element>
|
||||
* </complex-array>
|
||||
* </process>
|
||||
* </pre>
|
||||
* This will create an environment variable called "QMAKE" and will set the value to
|
||||
* be the value entered in a field (called qmake) in the New Project wizard.
|
||||
*
|
||||
* @since 5.6
|
||||
*/
|
||||
public class SetEnvironmentVariable extends ProcessRunner {
|
||||
|
||||
private static final String PROJECTNAME_VARNAME = "projectName"; //$NON-NLS-1$
|
||||
private static final String VARIABLES_VARNAME = "variables"; //$NON-NLS-1$
|
||||
private static final String VARIABLES_NAME_VARNAME = "name"; //$NON-NLS-1$
|
||||
private static final String VARIABLES_VALUE_VARNAME = "value"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
|
||||
|
||||
IProject project = null;
|
||||
Map<String, String> envVars = new LinkedHashMap<String, String>();
|
||||
|
||||
for (ProcessArgument arg : args) {
|
||||
String argName = arg.getName();
|
||||
if (PROJECTNAME_VARNAME.equals(argName))
|
||||
project = ResourcesPlugin.getWorkspace().getRoot().getProject(arg.getSimpleValue());
|
||||
else if(VARIABLES_VARNAME.equals(argName)) {
|
||||
|
||||
for(ProcessArgument[] envVarArgs : arg.getComplexArrayValue()) {
|
||||
String name = null;
|
||||
String value = null;
|
||||
|
||||
for(ProcessArgument varArg : envVarArgs) {
|
||||
String varArgName = varArg.getName();
|
||||
if (VARIABLES_NAME_VARNAME.equals(varArgName))
|
||||
name = varArg.getSimpleValue();
|
||||
else if(VARIABLES_VALUE_VARNAME.equals(varArgName))
|
||||
value = varArg.getSimpleValue();
|
||||
}
|
||||
|
||||
if (name == null)
|
||||
throw missingArgException(processId, VARIABLES_NAME_VARNAME);
|
||||
if (value == null)
|
||||
throw missingArgException(processId, VARIABLES_VALUE_VARNAME);
|
||||
|
||||
envVars.put(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (project == null)
|
||||
throw missingArgException(processId, PROJECTNAME_VARNAME);
|
||||
|
||||
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||
ICProjectDescription des = mngr.getProjectDescription(project, true);
|
||||
ICConfigurationDescription[] configDescs = des.getConfigurations();
|
||||
IContributedEnvironment ice = CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment();
|
||||
|
||||
for(Map.Entry<String, String> envVar : envVars.entrySet()) {
|
||||
String name = envVar.getKey();
|
||||
String value = envVar.getValue();
|
||||
|
||||
for (ICConfigurationDescription configDesc : configDescs)
|
||||
ice.addVariable(name, value, IEnvironmentVariable.ENVVAR_REPLACE, null, configDesc);
|
||||
}
|
||||
|
||||
try {
|
||||
mngr.setProjectDescription(project, des);
|
||||
} catch(CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue