diff options
author | Doug Schaefer | 2013-01-12 05:54:08 +0000 |
---|---|---|
committer | Doug Schaefer | 2013-01-12 05:57:49 +0000 |
commit | 09357c4df6205e576e46ae8194d82e6f7dad7653 (patch) | |
tree | afd7aca91b6970b42758d847d558c4364911e2ec /core/org.eclipse.cdt.core | |
parent | 5cb3203f4a6c8627a90649a7dcd8075651a17bbc (diff) | |
download | org.eclipse.cdt-09357c4df6205e576e46ae8194d82e6f7dad7653.tar.gz org.eclipse.cdt-09357c4df6205e576e46ae8194d82e6f7dad7653.tar.xz org.eclipse.cdt-09357c4df6205e576e46ae8194d82e6f7dad7653.zip |
Added support for Qt. Extended AddFiles template to change start/end
patterns.
Diffstat (limited to 'core/org.eclipse.cdt.core')
4 files changed, 87 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index f58003a9329..d65aa20c4ff 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -757,6 +757,20 @@ <simple name="valueName"/> <simple name="appName"/> </processType> + <processType + name="AddFiles2" + processRunner="org.eclipse.cdt.core.templateengine.process.processes.AddFiles"> + <simple name="projectName"/> + <simple name="startPattern"/> + <simple name="endPattern"/> + <complexArray name="files"> + <baseType> + <simple name="source"/> + <simple name="target"/> + <simple name="replaceable"/> + </baseType> + </complexArray> + </processType> </extension> <extension point="org.eclipse.cdt.core.CProjectDescriptionStorage"> diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessHelper.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessHelper.java index 465432cac9a..44c779f40ee 100644 --- a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessHelper.java +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/ProcessHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Symbian Software Limited and others. + * Copyright (c) 2007, 2013 Symbian Software Limited 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 @@ -9,6 +9,7 @@ * Bala Torati (Symbian) - Initial API and implementation * Mark Espiritu (VastSystems) - bug 215283 * Raphael Zulliger (Indel AG) - [367482] fixed resource leak + * Doug Schaefer (QNX) - added different start and end patterns for macros *******************************************************************************/ package org.eclipse.cdt.core.templateengine.process; @@ -77,21 +78,35 @@ public class ProcessHelper { * @since 4.0 */ public static Set<String> getReplaceKeys(String str) { + return getReplaceKeys(str, START_PATTERN, END_PATTERN); + } + + /** + * This method returns a vector of all replace marker strings. (e.g., + * $(item), vector contains 'item' as one item) is the end pattern. + * + * @param str A given string possibly containing markers. + * @param startPattern token to start macro replacement + * @param endPattern token to end macro replacement + * @return the set of names occurring within markers + * @since 5.5 + */ + public static Set<String> getReplaceKeys(String str, String startPattern, String endPattern) { Set<String> replaceStrings = new HashSet<String>(); int start= 0; int end= 0; - while ((start = str.indexOf(START_PATTERN, start)) >= 0) { - end = str.indexOf(END_PATTERN, start); + while ((start = str.indexOf(startPattern, start)) >= 0) { + end = str.indexOf(endPattern, start); if (end != -1) { - replaceStrings.add(str.substring(start + START_PATTERN.length(), end)); - start = end + END_PATTERN.length(); + replaceStrings.add(str.substring(start + startPattern.length(), end)); + start = end + endPattern.length(); } else { start++; } } return replaceStrings; } - + /** * This method takes a URL as parameter to read the contents, and to add * into a string buffer. @@ -183,12 +198,24 @@ public class ProcessHelper { * * @since 4.0 */ - public static String getValueAfterExpandingMacros(String string, Set<String> macros, - Map<String, String> valueStore) { + public static String getValueAfterExpandingMacros(String string, Set<String> macros, Map<String, String> valueStore) { + return getValueAfterExpandingMacros(string, macros, valueStore, START_PATTERN, END_PATTERN); + } + + /** + * @param string + * @param macros + * @param valueStore + * @return the macro value after expanding the macros. + * + * @since 5.5 + */ + public static String getValueAfterExpandingMacros(String string, Set<String> macros, Map<String, String> valueStore, + String startPattern, String endPattern) { for (String key : macros) { String value = valueStore.get(key); if (value != null) { - string = string.replace(START_PATTERN + key + END_PATTERN, value); + string = string.replace(startPattern + key + endPattern, value); } } return string; @@ -203,4 +230,5 @@ public class ProcessHelper { public static String getReplaceMarker(String macro) { return START_PATTERN + macro + END_PATTERN; } + } diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java index e6674033e7c..1f4fa400dfe 100644 --- a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Symbian Software Limited and others. + * Copyright (c) 2007, 2013 Symbian Software Limited 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 @@ -7,6 +7,7 @@ * * Contributors: * Bala Torati (Symbian) - Initial API and implementation + * Doug Schaefer (QNX) - Added overridable start and end patterns *******************************************************************************/ package org.eclipse.cdt.core.templateengine.process.processes; @@ -29,7 +30,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; - /** * Adds Files to the Project */ @@ -40,9 +40,30 @@ public class AddFiles extends ProcessRunner { */ @Override public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException { - String projectName = args[0].getSimpleValue(); - IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - ProcessArgument[][] files = args[1].getComplexArrayValue(); + IProject projectHandle = null; + ProcessArgument[][] files = null; + String startPattern = null; + String endPattern = null; + + for (ProcessArgument arg : args) { + String argName = arg.getName(); + if (argName.equals("projectName")) { //$NON-NLS-1$ + projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(arg.getSimpleValue()); + } else if (argName.equals("files")) { //$NON-NLS-1$ + files = arg.getComplexArrayValue(); + } else if (argName.equals("startPattern")) { //$NON-NLS-1$ + startPattern = arg.getSimpleValue(); + } else if (argName.equals("endPattern")) { //$NON-NLS-1$ + endPattern = arg.getSimpleValue(); + } + } + + if (projectHandle == null) + throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFiles.8"))); //$NON-NLS-1$ + + if (files == null) + throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFiles.9"))); //$NON-NLS-1$ + for(int i=0; i<files.length; i++) { ProcessArgument[] file = files[i]; String fileSourcePath = file[0].getSimpleValue(); @@ -67,7 +88,12 @@ public class AddFiles extends ProcessRunner { } catch (IOException e) { throw new ProcessFailureException(Messages.getString("AddFiles.3") + fileSourcePath); //$NON-NLS-1$ } - fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore()); + if (startPattern != null && endPattern != null) + fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents, startPattern, endPattern), template.getValueStore(), + startPattern, endPattern); + else + fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore()); + contents = new ByteArrayInputStream(fileContents.getBytes()); } else { try { diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties index d8d5f2d2cd3..d100e9797dd 100644 --- a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties +++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties @@ -9,13 +9,15 @@ # Bala Torati (Symbian) - Initial API and implementation ############################################################################### -AddFiles.1=Add File failure: template source not found: +AddFiles.1=Add Files failure: template source not found: AddFiles.2=Add Files failure: template source not found: AddFiles.3=Add Files failure: cannot read template source: -AddFiles.4=Add File failure: cannot read template source: +AddFiles.4=Add Files failure: cannot read template source: AddFiles.5=Add Files failure: File already exists. AddFiles.6=Add Files failure: AddFiles.7=Add Files failure: +AddFiles.8=Add Files failure: projectName not specified +AddFiles.9=Add Files failure: No files AddFile.0=Add File failure: template source not found: AddFile.1=Add File failure: template source not found: AddFile.2=Add File failure: cannot read template source: |