Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2009-03-12 14:26:20 -0400
committerAlena Laskavaia2009-03-12 14:26:20 -0400
commit5088255e3ce53a1a3d14e3d0b48e9d6dd83fa0a5 (patch)
treec6481c576c3cb17a3cca84dc276728340c1a0f19 /core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes
parentc3755751d8c803430cd2f8b081d0439c4a858244 (diff)
downloadorg.eclipse.cdt-5088255e3ce53a1a3d14e3d0b48e9d6dd83fa0a5.tar.gz
org.eclipse.cdt-5088255e3ce53a1a3d14e3d0b48e9d6dd83fa0a5.tar.xz
org.eclipse.cdt-5088255e3ce53a1a3d14e3d0b48e9d6dd83fa0a5.zip
[264276] - applied patch to allow to create simple folders in templates
Diffstat (limited to 'core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes')
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateFolder.java75
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java14
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties4
3 files changed, 81 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateFolder.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateFolder.java
new file mode 100644
index 0000000000..025ae15156
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateFolder.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Gvozdev (Quoin Inc.) - Initial API and implementation extracted from CreateSourceFolder.java.
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+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.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+
+/**
+ * Creates regular folder in the project.
+ * @since 5.1
+ */
+public class CreateFolder extends ProcessRunner {
+
+ /**
+ * @see org.eclipse.cdt.core.templateengine.process.ProcessRunner#process(org.eclipse.cdt.core.templateengine.TemplateCore, org.eclipse.cdt.core.templateengine.process.ProcessArgument[], java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ createFolder(args[0].getSimpleValue(), args[1].getSimpleValue(), monitor);
+ }
+
+ /**
+ * Creates specified folder in the project recursively.
+ *
+ * @param projectName - name of the project.
+ * @param targetPath - relative path to the new folder.
+ * @param monitor - progress monitor.
+ * @throws ProcessFailureException if there is a problem with creating new folder.
+ */
+ public static void createFolder(String projectName, String targetPath, IProgressMonitor monitor) throws ProcessFailureException {
+ //If the targetPath is an empty string, there will be no folder to create.
+ // Also this is not an error. So just return gracefully.
+ if (targetPath == null || targetPath.length()==0) {
+ return;
+ }
+
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ if (!projectHandle.exists()) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.0") + projectName); //$NON-NLS-1$
+ }
+
+ IPath path = new Path(targetPath);
+
+ try {
+ for (int i=1;i<=path.segmentCount();i++) {
+ IFolder subfolder = projectHandle.getFolder(path.uptoSegment(i));
+ if (!subfolder.exists()) {
+ subfolder.create(true, true, monitor);
+ }
+ }
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.1") + e.getMessage(), e); //$NON-NLS-1$
+ }
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java
index a8ed7dd565..d3ab14fa71 100644
--- a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java
@@ -60,18 +60,12 @@ public class CreateSourceFolder extends ProcessRunner {
if (!projectHandle.exists()) {
throw new ProcessFailureException(Messages.getString("CreateSourceFolder.0") + projectName); //$NON-NLS-1$
}
-
+
+ CreateFolder.createFolder(projectName, targetPath, monitor);
+
IPath projPath = projectHandle.getFullPath();
-
IFolder folder = projectHandle.getFolder(targetPath);
- if (!folder.exists()) {
- try {
- folder.create(true, true, monitor);
- } catch (CoreException e) {
- throw new ProcessFailureException(Messages.getString("CreateSourceFolder.1") + e.getMessage(), e); //$NON-NLS-1$
- }
- }
-
+
try {
ICProject cProject = CoreModel.getDefault().create(projectHandle);
if (cProject != null) {
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 7bb543cff5..0009bf051b 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
@@ -39,8 +39,8 @@ AppendToMBSStringOptionValue.0=AppendToMBSStringOptionValue failure:
AppendToMBSStringOptionValue.3=AppendToMBSStringOptionValue failure: No such file exists:
AppendToMBSStringListOptionValues.0=AppendToMBSStringListOptionValues failure:
AppendToMBSStringListOptionValues.3=AppendToMBSStringListOptionValues failure: No such file exists:
-CreateSourceFolder.0=Create Source Folder failure: project does not exist:
-CreateSourceFolder.1=Create Source Folder failure:
+CreateSourceFolder.0=Create Folder failure: project does not exist:
+CreateSourceFolder.1=Create Folder failure:
CreateSourceFolder.2=Create Source Folder failure:
CreateIncludeFolder.3=Create Include Folder failure: while setting include path:
ExcludeResources.0=ExcludeResources can only process CDT Managed projects

Back to the top