Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rennie2013-07-31 16:44:16 +0000
committerMike Rennie2013-07-31 16:44:16 +0000
commitd975f27f12707ae6598994c5e3c6bd5e271d46c4 (patch)
treec7d1b2b1a202e19c0c2ccaaff959f4dd25286f0d /org.eclipse.debug.examples.core/src_ant/org
parent4fcde1ffaf34791bd406d47ce72d17e2801432a3 (diff)
downloadeclipse.platform.debug-d975f27f12707ae6598994c5e3c6bd5e271d46c4.tar.gz
eclipse.platform.debug-d975f27f12707ae6598994c5e3c6bd5e271d46c4.tar.xz
eclipse.platform.debug-d975f27f12707ae6598994c5e3c6bd5e271d46c4.zip
Bug 352626 - Move platform debug to Java 1.6 BREE
Diffstat (limited to 'org.eclipse.debug.examples.core/src_ant/org')
-rw-r--r--org.eclipse.debug.examples.core/src_ant/org/eclipse/debug/examples/ant/tasks/PreProcessor.java65
1 files changed, 35 insertions, 30 deletions
diff --git a/org.eclipse.debug.examples.core/src_ant/org/eclipse/debug/examples/ant/tasks/PreProcessor.java b/org.eclipse.debug.examples.core/src_ant/org/eclipse/debug/examples/ant/tasks/PreProcessor.java
index dc19387ac..d51bba239 100644
--- a/org.eclipse.debug.examples.core/src_ant/org/eclipse/debug/examples/ant/tasks/PreProcessor.java
+++ b/org.eclipse.debug.examples.core/src_ant/org/eclipse/debug/examples/ant/tasks/PreProcessor.java
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2005, 2013 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * 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:
* IBM Corporation - initial API and implementation
* Bjorn Freeman-Benson - initial API and implementation
@@ -17,7 +17,6 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.regex.Matcher;
@@ -31,7 +30,7 @@ import org.apache.tools.ant.util.FileUtils;
/**
* Java preprocessor for code examples. Used to export source code for
- * example plug-ins with parts of code missing/inserted etc., for
+ * example plug-ins with parts of code missing/inserted etc., for
* various exercises.
* <p>
* The preprocessor looks for #ifdef statements in java comments, and is
@@ -46,52 +45,52 @@ import org.apache.tools.ant.util.FileUtils;
* </p>
*/
public class PreProcessor extends Task {
-
- private Vector fFileSets = new Vector();
+
+ private Vector<FileSet> fFileSets = new Vector<FileSet>();
private File fDestDir = null;
- private Set fSymbols = new HashSet();
+ private Set<String> fSymbols = new HashSet<String>();
private FileUtils fUtils = FileUtils.getFileUtils();
-
+
// possible states
private static final int STATE_OUTSIDE_CONDITION = 0;
private static final int STATE_TRUE_CONDITION = 1;
private static final int STATE_FALSE_CONDITION = 2;
private static final int STATE_POST_TRUE_CONDITION = 3;
-
+
// matchers
private Matcher IF_DEF_MATCHER = Pattern.compile("#ifdef\\s+\\w+").matcher(""); //$NON-NLS-1$ //$NON-NLS-2$
private Matcher ELSE_IF_MATCHER = Pattern.compile("#elseif\\s+\\w+").matcher(""); //$NON-NLS-1$ //$NON-NLS-2$
private Matcher ELSE_MATCHER = Pattern.compile("#else$|#else\\W+").matcher(""); //$NON-NLS-1$ //$NON-NLS-2$
private Matcher END_MATCHER = Pattern.compile("#endif").matcher(""); //$NON-NLS-1$ //$NON-NLS-2$
-
+
/**
* Constructs a new preprocessor task
*/
public PreProcessor() {
}
-
+
/**
* Adds a set of files to process.
- *
+ *
* @param set a set of files to process
*/
public void addFileset(FileSet set) {
fFileSets.addElement(set);
}
-
+
/**
* Sets the destination directory for processed files.
- *
+ *
* @param destDir destination directory for processed files
*/
public void setDestdir(File destDir) {
fDestDir = destDir;
}
-
+
/**
* Sets the symbols that are "on" for the preprocessing.
- *
+ *
* @param symbols symbols that are "on" for the preprocessing
*/
public void setSymbols(String symbols) {
@@ -104,6 +103,7 @@ public class PreProcessor extends Task {
}
}
+ @Override
public void execute() throws BuildException {
if (fSymbols.size() == 0) {
throw new BuildException("No symbols specified for preprocessor"); //$NON-NLS-1$
@@ -115,7 +115,7 @@ public class PreProcessor extends Task {
throw new BuildException("destdir does not exist: " + fDestDir.getAbsolutePath()); //$NON-NLS-1$
}
StringBuffer buf = new StringBuffer("Symbols: "); //$NON-NLS-1$
- String[] symbols = (String[]) fSymbols.toArray(new String[fSymbols.size()]);
+ String[] symbols = fSymbols.toArray(new String[fSymbols.size()]);
for (int i = 0; i < symbols.length; i++) {
String symbol = symbols[i];
buf.append(symbol);
@@ -124,10 +124,8 @@ public class PreProcessor extends Task {
}
}
log(buf.toString());
-
- Iterator fileSets = fFileSets.iterator();
- while (fileSets.hasNext()) {
- FileSet fileSet = (FileSet) fileSets.next();
+
+ for (FileSet fileSet : fFileSets) {
DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
String[] includedFiles = scanner.getIncludedFiles();
File baseDir = fileSet.getDir(getProject());
@@ -136,14 +134,13 @@ public class PreProcessor extends Task {
processFile(baseDir, fileName, fDestDir);
}
}
-
}
/**
* Process the file
* @param baseDir base directory source file is relative to
* @param fileName source file name
- * @param destDir root destination directory
+ * @param destDir root destination directory
*/
private void processFile(File baseDir, String fileName, File destDir) throws BuildException {
File destFile = new File(destDir, fileName);
@@ -167,21 +164,27 @@ public class PreProcessor extends Task {
}
} else {
// write new file
- FileWriter writer;
+ FileWriter writer = null;
try {
writer = new FileWriter(destFile);
writer.write(contents);
- writer.close();
} catch (IOException e) {
throw new BuildException(e);
+ } finally {
+ try {
+ if (writer != null) {
+ writer.close();
+ }
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
}
-
}
}
/**
* Pre-processes a file
- *
+ *
* @param srcFile the file to process
* @param strip chars to strip off lines in a true condition, or <code>null</code>
* @return
@@ -213,7 +216,7 @@ public class PreProcessor extends Task {
state = STATE_TRUE_CONDITION;
} else {
state = STATE_FALSE_CONDITION;
- }
+ }
} else if (elseif) {
throw new BuildException("#elseif encountered without corresponding #ifdef"); //$NON-NLS-1$
} else if (elze) {
@@ -261,6 +264,8 @@ public class PreProcessor extends Task {
throw new BuildException("illegal nested #ifdef"); //$NON-NLS-1$
}
break;
+ default:
+ break;
}
if (!commandLine) {
if (state == STATE_OUTSIDE_CONDITION || state == STATE_TRUE_CONDITION) {
@@ -273,8 +278,8 @@ public class PreProcessor extends Task {
buffer.append("\n"); //$NON-NLS-1$
written = true;
}
- }
- changed = changed || !written;
+ }
+ changed = changed || !written;
line = reader.readLine();
}
}

Back to the top