|
From: <pat...@us...> - 2009-08-14 21:45:44
|
Revision: 921
http://cishell.svn.sourceforge.net/cishell/?rev=921&view=rev
Author: pataphil
Date: 2009-08-14 21:45:32 +0000 (Fri, 14 Aug 2009)
Log Message:
-----------
* Fixed file copy bug.
Modified Paths:
--------------
trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/BasicTemplate.java
trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmTemplate.java
trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmWizard.java
Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/BasicTemplate.java
===================================================================
--- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/BasicTemplate.java 2009-08-14 17:41:28 UTC (rev 920)
+++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/BasicTemplate.java 2009-08-14 21:45:32 UTC (rev 921)
@@ -46,6 +46,7 @@
import org.eclipse.pde.ui.templates.OptionTemplateSection;
import org.eclipse.pde.ui.templates.TemplateOption;
+// TODO Could we safely reduce some of the method visibilities here?
public abstract class BasicTemplate extends OptionTemplateSection {
protected final String sectionID;
protected Map valueMap;
@@ -125,6 +126,10 @@
return value;
}
+ public boolean shouldProcessFile(File file) {
+ return true;
+ }
+
public void execute(IProject project,
IPluginModelBase model,
IProgressMonitor monitor) throws CoreException {
@@ -134,12 +139,12 @@
updateModel(monitor);
}
- public void generateFiles(IProgressMonitor progressMonitor)
+ protected void generateFiles(IProgressMonitor progressMonitor)
throws CoreException {
generateFiles(progressMonitor, getTemplateLocation());
}
- public void generateFiles(IProgressMonitor progressMonitor,
+ protected void generateFiles(IProgressMonitor progressMonitor,
URL locationURL) throws CoreException {
progressMonitor.setTaskName(
PDEUIMessages.AbstractTemplateSection_generating);
@@ -167,8 +172,12 @@
return;
}
- generateFiles(
- templateDirectory, project, true, false, progressMonitor);
+ generateFiles(templateDirectory,
+ project,
+ true,
+ false,
+ true,
+ progressMonitor);
} else if ("jar".equals(resolvedLocationURLProtocol)) {
int exclamationIndex = resolvedLocationURLFileName.indexOf('!');
@@ -223,17 +232,21 @@
progressMonitor.worked(1);
}
- private void generateFiles(
+ protected void generateFiles(
File sourceFile,
IContainer destinationContainer,
boolean isFirstLevel,
boolean isBinaryFile,
+ boolean shouldProcessAsTemplate,
IProgressMonitor progressMonitor) throws CoreException {
File[] sourceSubFiles = sourceFile.listFiles();
for (int ii = 0; ii < sourceSubFiles.length; ii++) {
File sourceSubFile = sourceSubFiles[ii];
+ boolean shouldProcessSubFileAsTemplate =
+ shouldProcessAsTemplate && shouldProcessFile(sourceSubFile);
+
if (sourceSubFile.isDirectory()) {
IContainer subDestinationContainer = null;
@@ -260,8 +273,15 @@
continue;
}
- String folderName = getProcessedString(
- sourceSubFile.getName(), sourceSubFile.getName());
+ String folderName;
+
+ if (shouldProcessSubFileAsTemplate) {
+ folderName = getProcessedString(
+ sourceSubFile.getName(), sourceSubFile.getName());
+ } else {
+ folderName = sourceSubFile.getName();
+ }
+
subDestinationContainer =
destinationContainer.getFolder(new Path(folderName));
}
@@ -276,6 +296,7 @@
subDestinationContainer,
false,
isBinaryFile,
+ shouldProcessSubFileAsTemplate,
progressMonitor);
} else {
if (isOkToCreateFile(sourceSubFile)) {
@@ -291,6 +312,7 @@
inputStream,
destinationContainer,
isBinaryFile,
+ shouldProcessSubFileAsTemplate,
progressMonitor);
} catch (IOException ioException1) {
} finally {
@@ -306,7 +328,7 @@
}
}
- private void generateFiles(
+ protected void generateFiles(
ZipFile zipFile,
IPath filePath,
IContainer destinationContainer,
@@ -314,8 +336,9 @@
boolean isBinary,
IProgressMonitor progressMonitor) throws CoreException {
int pathLength = filePath.segmentCount();
- // Immidiate children
- Map childZipEntries = new HashMap(); // "dir/" or "dir/file.java"
+ // Immediate children.
+ // "dir/" or "dir/file.java"
+ Map childZipEntries = new HashMap();
for (Enumeration zipEntries = zipFile.entries();
zipEntries.hasMoreElements();) {
@@ -327,7 +350,7 @@
}
if (!filePath.isPrefixOf(entryPath)) {
- // not a descendant
+ // Not a descendant.
continue;
}
@@ -404,6 +427,7 @@
inputStream,
destinationContainer,
isBinary,
+ true,
progressMonitor);
} catch (IOException ioException1) {
} finally {
@@ -457,7 +481,7 @@
return source;
}
- int location = -1;
+ int locationIndex = -1;
StringBuffer buffer = new StringBuffer();
boolean shouldReplace = false;
@@ -466,7 +490,7 @@
if (currentCharacter == '$') {
if (shouldReplace) {
- String key = source.substring(location, ii);
+ String key = source.substring(locationIndex, ii);
String value;
if (key.length() == 0) {
@@ -479,7 +503,7 @@
shouldReplace = false;
} else {
shouldReplace = true;
- location = ii + 1;
+ locationIndex = ii + 1;
continue;
}
@@ -495,17 +519,30 @@
InputStream inputStream,
IContainer destinationContainer,
boolean isBinary,
+ boolean shouldProcessSubFileAsTemplate,
IProgressMonitor progressMonitor) throws CoreException {
- String targetFileName = getProcessedString(fileName, fileName);
+ String targetFileName;
+
+ if (shouldProcessSubFileAsTemplate) {
+ targetFileName = getProcessedString(fileName, fileName);
+ } else {
+ targetFileName = fileName;
+ }
progressMonitor.subTask(targetFileName);
IFile destinationFile =
destinationContainer.getFile(new Path(targetFileName));
try {
- InputStream processedInputStream =
- getProcessedStream(fileName, inputStream, isBinary);
+ InputStream processedInputStream;
+ if (shouldProcessSubFileAsTemplate) {
+ processedInputStream =
+ getProcessedStream(fileName, inputStream, isBinary);
+ } else {
+ processedInputStream = inputStream;
+ }
+
if (destinationFile.exists()) {
destinationFile.setContents(
processedInputStream, true, true, progressMonitor);
Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmTemplate.java
===================================================================
--- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmTemplate.java 2009-08-14 17:41:28 UTC (rev 920)
+++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmTemplate.java 2009-08-14 21:45:32 UTC (rev 921)
@@ -13,6 +13,9 @@
* ***************************************************************************/
package org.cishell.templates.wizards.staticexecutable;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -182,6 +185,18 @@
{ MENU_END_LABEL, MENU_END_DESCRIPTION }
};
+ public static final String[] IGNORED_REPLACEMENT_STRING_FILES =
+ new String[] {
+ "ant.sh",
+ "build.xml"
+ };
+
+ public static final String[] IGNORED_REPLACEMENT_STRING_DIRECTORIES =
+ new String[] {
+ "l10n",
+ "lib"
+ };
+
private WizardNewProjectCreationPage createProjectPage;
private WizardPage bundlePropertiesPage;
private ChooseExecutableFilesPage chooseExecutableFilesPage;
@@ -327,6 +342,32 @@
super.execute(project, model, monitor);
}
+
+ public boolean shouldProcessFile(File file) {
+ String fileName = file.getName();
+ String filePath = file.getParent();
+
+ for (int ii = 0; ii < IGNORED_REPLACEMENT_STRING_FILES.length; ii++) {
+ if (IGNORED_REPLACEMENT_STRING_FILES[ii].equals(fileName)) {
+ return false;
+ }
+ }
+
+ /* TODO What if the path happens to include an ignored string,
+ * like "lib", but without the meaning intended here?
+ * Like ".../workspace/reginald_libby/...".
+ */
+ for (int ii = 0;
+ ii < IGNORED_REPLACEMENT_STRING_DIRECTORIES.length;
+ ii++) {
+ if (filePath.contains(
+ IGNORED_REPLACEMENT_STRING_DIRECTORIES[ii])) {
+ return false;
+ }
+ }
+
+ return true;
+ }
protected void updateModel(IProgressMonitor monitor) throws CoreException {
}
Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmWizard.java
===================================================================
--- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmWizard.java 2009-08-14 17:41:28 UTC (rev 920)
+++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/staticexecutable/NewStaticExecutableAlgorithmWizard.java 2009-08-14 21:45:32 UTC (rev 921)
@@ -102,7 +102,8 @@
*/
public ITemplateSection[] createTemplateSections() {
template = new NewStaticExecutableAlgorithmTemplate();
- return new ITemplateSection[]{template};
+
+ return new ITemplateSection[] { template };
}
public boolean performFinish() {
@@ -206,9 +207,7 @@
/**
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
*/
- public void init(IWorkbench workbench, IStructuredSelection selection) {
-
- }
+ public void init(IWorkbench workbench, IStructuredSelection selection) {}
private void copyTemplateOptionFile(TemplateOption templateOption,
String directoryPath,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|