Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Sennikovsky2007-04-26 13:07:39 -0400
committerMikhail Sennikovsky2007-04-26 13:07:39 -0400
commitc5603e5a0edba5569a4835e2ffed9d14c1958c9d (patch)
tree7fe1781e1c8833334c2b73ee9776c22369aeb56a /core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes
parent6741a8d019b2908ddd9ae80d086448eff4fba303 (diff)
downloadorg.eclipse.cdt-c5603e5a0edba5569a4835e2ffed9d14c1958c9d.tar.gz
org.eclipse.cdt-c5603e5a0edba5569a4835e2ffed9d14c1958c9d.tar.xz
org.eclipse.cdt-c5603e5a0edba5569a4835e2ffed9d14c1958c9d.zip
Template Engine submission from Bala Torati (Symbian) with some modifications and bug-fixes (see Bug 160012)
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/AddFile.java90
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java107
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddLink.java58
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Append.java67
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AppendCreate.java89
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Copy.java86
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateResourceIdentifier.java42
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java148
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Messages.java32
-rw-r--r--core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties58
10 files changed, 777 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFile.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFile.java
new file mode 100644
index 0000000000..245867027b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFile.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+
+/**
+ * Adds File to the project
+ */
+public class AddFile extends ProcessRunner {
+
+ /**
+ * This method Adds the File to the corresponding Project.
+ */
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String projectName = args[0].getSimpleValue();
+ ProcessArgument file = args[1];
+ ProcessArgument[] fileMembers = file.getComplexValue();
+ String fileSourcePath = fileMembers[0].getSimpleValue();
+ String fileTargetPath = fileMembers[1].getSimpleValue();
+ boolean replaceable = fileMembers[2].getSimpleValue().equals("true"); //$NON-NLS-1$
+
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ URL path;
+ try {
+ path = TemplateEngineHelper.getTemplateResourceURLRelativeToTemplate(template, fileSourcePath);
+ if (path == null) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.0") + fileSourcePath)); //$NON-NLS-1$
+ }
+ } catch (IOException e1) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.1") + fileSourcePath)); //$NON-NLS-1$
+ }
+
+ InputStream contents = null;
+ if (replaceable) {
+ String fileContents;
+ try {
+ fileContents = ProcessHelper.readFromFile(path);
+ } catch (IOException e) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.2") + fileSourcePath)); //$NON-NLS-1$
+ }
+ fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore());
+ contents = new ByteArrayInputStream(fileContents.getBytes());
+ } else {
+ try {
+ contents = path.openStream();
+ } catch (IOException e) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.3") + fileSourcePath)); //$NON-NLS-1$
+ }
+ }
+
+ try {
+ IFile iFile = projectHandle.getFile(fileTargetPath);
+ if (!iFile.getParent().exists()) {
+ ProcessHelper.mkdirs(projectHandle, projectHandle.getFolder(iFile.getParent().getProjectRelativePath()));
+ }
+ iFile.create(contents, true, null);
+ iFile.refreshLocal(IResource.DEPTH_ONE, null);
+ projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.4") + e.getMessage()), e); //$NON-NLS-1$
+ }
+ }
+}
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
new file mode 100644
index 0000000000..bd11bf6026
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddFiles.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+
+/**
+ * Adds Files to the Project
+ */
+public class AddFiles extends ProcessRunner {
+
+ /**
+ * This method Adds the list of Files to the corresponding Project.
+ */
+ 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();
+ for(int i=0; i<files.length; i++) {
+ ProcessArgument[] file = files[i];
+ String fileSourcePath = file[0].getSimpleValue();
+ String fileTargetPath = file[1].getSimpleValue();
+ boolean replaceable = file[2].getSimpleValue().equals("true"); //$NON-NLS-1$
+
+ URL path;
+ try {
+ path = TemplateEngineHelper.getTemplateResourceURLRelativeToTemplate(template, fileSourcePath);
+ if (path == null) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFiles.1") + fileSourcePath)); //$NON-NLS-1$
+ }
+ } catch (IOException e1) {
+ throw new ProcessFailureException(Messages.getString("AddFiles.2") + fileSourcePath); //$NON-NLS-1$
+ }
+
+ InputStream contents = null;
+ if (replaceable) {
+ String fileContents;
+ try {
+ fileContents = ProcessHelper.readFromFile(path);
+ } catch (IOException e) {
+ throw new ProcessFailureException(Messages.getString("AddFiles.3") + fileSourcePath); //$NON-NLS-1$
+ }
+ fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore());
+ contents = new ByteArrayInputStream(fileContents.getBytes());
+ } else {
+ try {
+ contents = path.openStream();
+ } catch (IOException e) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFiles.4") + fileSourcePath)); //$NON-NLS-1$
+ }
+ }
+
+ try {
+ IFile iFile = projectHandle.getFile(fileTargetPath);
+ if (!iFile.getParent().exists()) {
+ ProcessHelper.mkdirs(projectHandle, projectHandle.getFolder(iFile.getParent().getProjectRelativePath()));
+ }
+
+ if (iFile.exists()) {
+ // honor the replaceable flag and replace the file contents if the file already exists.
+ if (replaceable) {
+ iFile.setContents(contents, true, true, null);
+ } else {
+ throw new ProcessFailureException(Messages.getString("AddFiles.5")); //$NON-NLS-1$
+ }
+
+ } else {
+ iFile.create(contents, true, null);
+ iFile.refreshLocal(IResource.DEPTH_ONE, null);
+ }
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("AddFiles.6") + e.getMessage(), e); //$NON-NLS-1$
+ }
+ }
+ try {
+ projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("AddFiles.7") + e.getMessage(), e); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddLink.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddLink.java
new file mode 100644
index 0000000000..930bfe6545
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AddLink.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.File;
+
+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.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+
+/**
+ * Adds a Link to the Project.
+ */
+public class AddLink extends ProcessRunner {
+
+ /**
+ * This method Adds a Link to the Project.
+ */
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String projectName = args[0].getSimpleValue();
+ String fileSourcePath = args[1].getSimpleValue();
+ String targetPath = args[2].getSimpleValue();
+
+ File sourceFile = new java.io.File(fileSourcePath);
+
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ try {
+ IFile file = projectHandle.getFile(targetPath);
+ if (!file.getParent().exists()) {
+ ProcessHelper.mkdirs(projectHandle, projectHandle.getFolder(file.getParent().getProjectRelativePath()));
+ }
+ file.createLink(Path.fromOSString(sourceFile.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL | IResource.BACKGROUND_REFRESH, null);
+ file.refreshLocal(IResource.DEPTH_ONE, null);
+ projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("AddLink.0") + e.getMessage(), e); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Append.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Append.java
new file mode 100644
index 0000000000..5577b702a2
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Append.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+
+/**
+ * Append the contents to the file.
+ */
+public class Append extends ProcessRunner {
+
+ /**
+ * This method Appends the contents to a file.
+ */
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ ProcessArgument[][] files = args[0].getComplexArrayValue();
+ for(int i=0; i<files.length; i++) {
+ ProcessArgument[] file = files[i];
+ String sourcePath = file[0].getSimpleValue();
+ URL sourceURL;
+ try {
+ sourceURL = TemplateEngineHelper.getTemplateResourceURLRelativeToTemplate(template, sourcePath);
+ if (sourceURL == null) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("Append.0") + sourcePath)); //$NON-NLS-1$
+ }
+ } catch (IOException e1) {
+ throw new ProcessFailureException(Messages.getString("Append.1") + sourcePath); //$NON-NLS-1$
+ }
+ File targetFile = new File(file[1].getSimpleValue());
+ boolean replaceable = file[2].getSimpleValue().equals("true"); //$NON-NLS-1$
+ String fileContents;
+ try {
+ fileContents = ProcessHelper.readFromFile(sourceURL);
+ } catch (IOException e1) {
+ throw new ProcessFailureException(Messages.getString("Append.3") + sourcePath); //$NON-NLS-1$
+ }
+ if (replaceable) {
+ fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore());
+ }
+ try {
+ ProcessHelper.appendFile(fileContents, targetFile);
+ } catch (IOException e) {
+ throw new ProcessFailureException(Messages.getString("Append.4"), e); //$NON-NLS-1$
+ }
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AppendCreate.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AppendCreate.java
new file mode 100644
index 0000000000..63e49f1e95
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/AppendCreate.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+
+/*
+ * Appends a file to an existing file if present. If not, create the file
+ */
+public class AppendCreate extends ProcessRunner {
+ 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();
+ for(int i=0; i<files.length; i++) {
+ ProcessArgument[] file = files[i];
+ String sourcePath = file[0].getSimpleValue();
+ String targetPath = file[1].getSimpleValue();
+ boolean replaceable = file[2].getSimpleValue().equals("true"); //$NON-NLS-1$
+
+ URL sourceURL;
+ try {
+ sourceURL = TemplateEngineHelper.getTemplateResourceURLRelativeToTemplate(template, sourcePath);
+ if (sourceURL == null) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AppendCreate.1") + sourcePath)); //$NON-NLS-1$
+ }
+ } catch (IOException e1) {
+ throw new ProcessFailureException(Messages.getString("AppendCreate.2") + sourcePath); //$NON-NLS-1$
+ }
+ String fileContents;
+ try {
+ fileContents = ProcessHelper.readFromFile(sourceURL);
+ } catch (IOException e1) {
+ throw new ProcessFailureException(Messages.getString("AppendCreate.3") + sourcePath); //$NON-NLS-1$
+ }
+ if (replaceable) {
+ fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore());
+ }
+ try {
+ // Check whether the file exists
+ IFile iFile = projectHandle.getFile(targetPath);
+ if (!iFile.getParent().exists()) {
+ ProcessHelper.mkdirs(projectHandle, projectHandle.getFolder(iFile.getParent().getProjectRelativePath()));
+ }
+ InputStream contents = new ByteArrayInputStream(fileContents.getBytes());;
+ if (!iFile.exists()) {
+ // Create the file
+ iFile.create(contents, true, null);
+ iFile.refreshLocal(IResource.DEPTH_ONE, null);
+
+ } else {
+ // Append the file keeping the history
+ iFile.appendContents(contents, true, true, null);
+ }
+ // Update the project
+ projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("AppendCreate.4"), e); //$NON-NLS-1$
+ }
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Copy.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Copy.java
new file mode 100644
index 0000000000..be02c089a9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Copy.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.cdt.core.templateengine.TemplateCore;
+import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
+import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
+import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
+import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+
+/**
+ * Copies a File to the Project.
+ */
+public class Copy extends ProcessRunner {
+
+ /**
+ * This method Copies a File to the Project.
+ */
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ ProcessArgument[][] files = args[0].getComplexArrayValue();
+ for(int i=0; i<files.length; i++) {
+ ProcessArgument[] file = files[i];
+ String sourcePath = file[0].getSimpleValue();
+ URL sourceURL;
+ try {
+ sourceURL = TemplateEngineHelper.getTemplateResourceURLRelativeToTemplate(template, sourcePath);
+ if (sourceURL == null) {
+ throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("Copy.0") + sourcePath)); //$NON-NLS-1$
+ }
+ } catch (IOException e1) {
+ throw new ProcessFailureException(Messages.getString("Copy.1") + sourcePath); //$NON-NLS-1$
+ }
+ File targetFile = new File(file[1].getSimpleValue());
+ boolean replaceable = file[2].getSimpleValue().equals("true"); //$NON-NLS-1$
+ if (replaceable) {
+ String fileContents;
+ try {
+ fileContents = ProcessHelper.readFromFile(sourceURL);
+ } catch (IOException e1) {
+ throw new ProcessFailureException(Messages.getString("Copy.3") + sourcePath); //$NON-NLS-1$
+ }
+ fileContents = ProcessHelper.getValueAfterExpandingMacros(fileContents, ProcessHelper.getReplaceKeys(fileContents), template.getValueStore());
+ if (!targetFile.getParentFile().exists()) {
+ targetFile.getParentFile().mkdirs();
+ }
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(targetFile);
+ writer.write(fileContents);
+ } catch (IOException e) {
+ throw new ProcessFailureException(Messages.getString("Copy.4"), e); //$NON-NLS-1$
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException ioe) {// ignore
+ }
+ }
+ }
+ } else {
+ try {
+ ProcessHelper.copyBinaryFile(sourceURL, targetFile);
+ } catch (IOException e) {
+ throw new ProcessFailureException(Messages.getString("Copy.5"), e); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateResourceIdentifier.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateResourceIdentifier.java
new file mode 100644
index 0000000000..65046b5857
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateResourceIdentifier.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+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.runtime.IProgressMonitor;
+
+
+/**
+ * Creates a template macro value that can be used as a pseudo-unique resource identifier.
+ * It is based on the name of the application and is in the form of four capital letters.
+ * e.g. Helloworld => HELL
+ */
+public class CreateResourceIdentifier extends ProcessRunner {
+
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ String valueName = args[0].getSimpleValue();
+ String appName = args[1].getSimpleValue();
+
+ String value = ""; //$NON-NLS-1$
+ if (appName.length() >= 4) {
+ value = appName.substring(0, 4).toUpperCase();
+ } else {
+ value = appName.toUpperCase();
+ for (int i=0; i<4-appName.length(); i++) {
+ value = value + "X"; //$NON-NLS-1$
+ }
+ }
+ template.getValueStore().put(valueName, value);
+ }
+}
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
new file mode 100644
index 0000000000..bda5d6b94b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/CreateSourceFolder.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.IPathEntry;
+import org.eclipse.cdt.core.settings.model.CSourceEntry;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.settings.model.ICSourceEntry;
+import org.eclipse.cdt.core.settings.model.WriteAccessException;
+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;
+
+
+/**
+ * Creates a include Folder to the project.
+ */
+public class CreateSourceFolder extends ProcessRunner {
+
+ public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
+ createSourceFolder(args[0].getSimpleValue(), args[1].getSimpleValue(), monitor);
+ }
+
+ protected void createSourceFolder(String projectName, String targetPath, IProgressMonitor monitor) throws ProcessFailureException {
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ if (!projectHandle.exists()) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.0") + projectName); //$NON-NLS-1$
+ }
+
+ 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) {
+ if(CCorePlugin.getDefault().isNewStyleProject(cProject.getProject())){
+ //create source folder for new style project
+ createNewStyleProjectFolder(monitor, projectHandle, folder);
+ } else {
+ //create source folder for all other projects
+ createFolder(targetPath, monitor, projPath, cProject);
+ }
+ }
+ } catch (WriteAccessException e) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.2") + e.getMessage(), e); //$NON-NLS-1$
+ } catch (CoreException e) {
+ throw new ProcessFailureException(Messages.getString("CreateSourceFolder.2") + e.getMessage(), e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @param monitor
+ * @param projectHandle
+ * @param folder
+ * @throws CoreException
+ * @throws WriteAccessException
+ */
+ private void createNewStyleProjectFolder(IProgressMonitor monitor, IProject projectHandle, IFolder folder) throws CoreException, WriteAccessException {
+ ICSourceEntry newEntry = new CSourceEntry(folder, null, 0);
+ ICProjectDescription description = CCorePlugin.getDefault().getProjectDescription(projectHandle);
+
+ ICConfigurationDescription configs[] = description.getConfigurations();
+ for(int i=0; i < configs.length; i++){
+ ICConfigurationDescription config = configs[i];
+ ICSourceEntry[] entries = config.getSourceEntries();
+ Set set = new HashSet();
+ for (int j=0; j < entries.length; j++) {
+ set.add(entries[j]);
+ }
+ set.add(newEntry);
+ config.setSourceEntries((ICSourceEntry[])set.toArray(new ICSourceEntry[set.size()]));
+ }
+
+ CCorePlugin.getDefault().setProjectDescription(projectHandle, description, false, monitor);
+ }
+
+ /**
+ * @param targetPath
+ * @param monitor
+ * @param projPath
+ * @param cProject
+ * @throws CModelException
+ */
+ private void createFolder(String targetPath, IProgressMonitor monitor, IPath projPath, ICProject cProject) throws CModelException {
+ IPathEntry[] entries = cProject.getRawPathEntries();
+ List/*<IPathEntry>*/ newEntries = new ArrayList/*<IPathEntry>*/(entries.length + 1);
+
+ int projectEntryIndex= -1;
+ IPath path = projPath.append(targetPath);
+
+ for (int i = 0; i < entries.length; i++) {
+ IPathEntry curr = entries[i];
+ if (path.equals(curr.getPath())) {
+ // just return if this folder exists already
+ return;
+ }
+ if (projPath.equals(curr.getPath())) {
+ projectEntryIndex = i;
+ }
+ newEntries.add(curr);
+ }
+
+ IPathEntry newEntry = CoreModel.newSourceEntry(path);
+
+ if (projectEntryIndex != -1) {
+ newEntries.set(projectEntryIndex, newEntry);
+ } else {
+ newEntries.add(CoreModel.newSourceEntry(path));
+ }
+
+ cProject.setRawPathEntries((IPathEntry[])newEntries.toArray(new IPathEntry[newEntries.size()]), monitor);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Messages.java b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Messages.java
new file mode 100644
index 0000000000..863aaef9f1
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/Messages.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Bala Torati (Symbian) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.templateengine.process.processes;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.core.templateengine.process.processes.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
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
new file mode 100644
index 0000000000..833b13cab3
--- /dev/null
+++ b/core/org.eclipse.cdt.core/templateengine/org/eclipse/cdt/core/templateengine/process/processes/messages.properties
@@ -0,0 +1,58 @@
+###############################################################################
+# Copyright (c) 2007 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:
+# Bala Torati (Symbian) - Initial API and implementation
+###############################################################################
+
+AddFiles.1=Add File 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.5=Add Files failure: File already exists.
+AddFiles.6=Add Files failure:
+AddFiles.7=Add Files failure:
+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:
+AddFile.3=Add File failure: cannot read template source:
+AddFile.4=Add File failure:
+AddLink.0=Add Link failure:
+SetMBSBooleanOptionValue.0=SetMBSBooleanOptionValue failure:
+SetMBSBooleanOptionValue.3=SetMBSBooleanOptionValue failure: No such file exists:
+SetMBSStringOptionValue.0=SetMBSStringOptionValue failure:
+SetMBSStringOptionValue.3=SetMBSStringOptionValue failure: No such file exists:
+SetMBSStringListOptionValues.0=SetMBSStringListOptionValues failure:
+SetMBSStringListOptionValues.3=SetMBSStringListOptionValues failure: No such file exists:
+NewManagedProject.3=New Project failure:
+NewManagedProject.4=New Project failure:
+NewManagedProject.5=New Project failure: project already existing in work space:
+AppendCreate.1=Add File failure: template source not found:
+AppendCreate.2=Append failure: template source not found:
+AppendCreate.3=Append failure: cannot read template source:
+AppendCreate.4=Append failure: failed while trying to append contents.
+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.2=Create Source Folder failure:
+CreateIncludeFolder.3=Create Include Folder failure: while setting include path:
+ExcludeResources.0=ExcludeResources can only process CDT Managed projects
+Copy.0=Add File failure: template source not found:
+Copy.1=Copy failure: template source not found:
+Copy.3=Copy failure: cannot read template source:
+Copy.4=Copy failure: failed while copying contents.
+Copy.5=Copy failure: failed while copying contents.
+NewProject.7=New Project failure:
+NewProject.8=New Project failure:
+NewProject.9=New Project failure: project already existing in work space:
+Append.0=Add File failure: template source not found:
+Append.1=Copy failure: template source not found:
+Append.3=Copy failure: cannot read template source:
+Append.4=Append failure: failed while trying to append contents.

Back to the top