mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
[264276] - applied patch to allow to create simple folders in templates
This commit is contained in:
parent
c3755751d8
commit
5088255e3c
4 changed files with 87 additions and 12 deletions
|
@ -589,6 +589,12 @@
|
|||
<simple name="projectName"/>
|
||||
<simple name="path"/>
|
||||
</processType>
|
||||
<processType
|
||||
name="CreateFolder"
|
||||
processRunner="org.eclipse.cdt.core.templateengine.process.processes.CreateFolder">
|
||||
<simple name="projectName"/>
|
||||
<simple name="path"/>
|
||||
</processType>
|
||||
<processType
|
||||
name="AddLink"
|
||||
processRunner="org.eclipse.cdt.core.templateengine.process.processes.AddLink">
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue