summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpschonbac2008-01-23 09:26:44 (EST)
committer pschonbac2008-01-23 09:26:44 (EST)
commitbfd6799a8781e32fe02e56ed9e5ff6656271ad8b (patch)
tree7895cddc5a447ff2e94750f24738b63a44679b50
parent869af3e1ceb9c9930e983093a23df2f38a85a251 (diff)
downloadorg.eclipse.xpand-bfd6799a8781e32fe02e56ed9e5ff6656271ad8b.zip
org.eclipse.xpand-bfd6799a8781e32fe02e56ed9e5ff6656271ad8b.tar.gz
org.eclipse.xpand-bfd6799a8781e32fe02e56ed9e5ff6656271ad8b.tar.bz2
Contribution by Karsten Thoms, checked in on his behalf
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolver.java17
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolverImpl.java177
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/util/GenericFileFilter.java97
-rw-r--r--tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/ProtectedRegionResolverImplTest.java69
-rw-r--r--tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/util/GenericFileFilterTest.java106
5 files changed, 377 insertions, 89 deletions
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolver.java b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolver.java
index 064e126..bcdd43a 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolver.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolver.java
@@ -11,10 +11,23 @@
package org.eclipse.internal.xpand2.pr;
+/**
+ * A ProtectedRegionResolver is responsible for resolving Protected Regions from the generated sources.
+ */
public interface ProtectedRegionResolver {
-
+ /**
+ * Retrieve a {@link ProtectedRegion} by its Id.
+ * @param id The Id of the {@link ProtectedRegion} searched for.
+ * @return The Protected Region identified by <tt>id</tt>. Returns <code>null</code> if the Protected
+ * Region is not known to the Resolver.
+ */
ProtectedRegion getProtectedRegion(String id);
+ /**
+ * Creates a {@link ProtectedRegion} instance.
+ * @param id The Protected Region's Id.
+ * @param disabled The Protected Region's activation status ( <code>true</code>: disabled, <code>false</code>: enabled)
+ * @return A new instance
+ */
ProtectedRegion createProtectedRegion(String id, boolean disabled);
-
}
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolverImpl.java b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolverImpl.java
index c1fb3bb..03256f8 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolverImpl.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/ProtectedRegionResolverImpl.java
@@ -33,6 +33,9 @@ import org.eclipse.internal.xpand2.pr.util.BASE64;
import org.eclipse.internal.xpand2.pr.util.FSIO;
import org.eclipse.internal.xpand2.pr.util.GenericFileFilter;
+/**
+ * Default implementation of the {@link ProtectedRegionResolver} interface.
+ */
public class ProtectedRegionResolverImpl implements ProtectedRegionResolver {
private static final String ENABLED = "ENABLED";
@@ -163,7 +166,7 @@ public class ProtectedRegionResolverImpl implements ProtectedRegionResolver {
private final Log log = LogFactory.getLog(getClass());
- private String srcPathes = null;
+ private File[] srcPaths = null;
private boolean defaultExcludes = true;
@@ -173,10 +176,27 @@ public class ProtectedRegionResolverImpl implements ProtectedRegionResolver {
private String ignoreList = null;
+ /**
+ * This map stores all scanned protected regions.
+ * <p>
+ * Key: Protected Region ID<br>
+ * Value: The Protected Region
+ */
private Map<String, ProtectedRegionImpl> regionMap = null;
+ /**
+ * All already queried Protected Region Ids. Is used for detecting ambigious usage of
+ * Protected Regions.
+ */
private Set<String> usedSet = null;
+ /**
+ * Retrieves all Protected Regions from a source file.
+ * @param file The source file to scan.
+ * @return All found Protected Regions in the specified file.
+ * @throws ProtectedRegionSyntaxException If one of the Protected Regions in the file is incomplete or invalid.
+ * @throws IOException On errors occuring when reading the file
+ */
protected Collection<ProtectedRegionImpl> getAllRegions(final File file) throws ProtectedRegionSyntaxException, IOException {
final List<ProtectedRegionImpl> regions = new ArrayList<ProtectedRegionImpl>();
@@ -258,86 +278,95 @@ public class ProtectedRegionResolverImpl implements ProtectedRegionResolver {
// return null;
// }
if (!usedSet.add(id)) {
+ // id was not added to usedSet -> id was already queried before!
log.warn("Protected region with ID '" + id + "' referenced more than once");
}
return regionMap.get(id);
}
- private File[] getSrcPathes() {
- if ("".equals(srcPathes)) {
- return new File[0];
- }
- final String[] s = srcPathes.split(",");
- final File[] f = new File[s.length];
- for (int i = 0; i < f.length; i++) {
- f[i] = new File(s[i]);
- }
- return f;
- }
-
- public void init() {
- if (regionMap != null)
+ /**
+ * Initializes the ProtectedRegionResolver. This starts the scan over all configured paths (property 'srcPaths').
+ * <p>
+ * A second call (already initialized) to this method will return immediately.
+ *
+ * @throws IllegalStateException If a Protected Region Id is detected the second time, i.e. it is not unique.
+ */
+ public void init() throws IllegalStateException {
+ // Already initialized?
+ if (regionMap != null) {
return;
+ }
+ // Initialize the Protected Region map
regionMap = new HashMap<String, ProtectedRegionImpl>();
usedSet = new HashSet<String>();
- final File[] sourcePath = getSrcPathes();
- if (sourcePath != null) {
- long time = 0;
- long fileCount = 0;
-
- if (log.isInfoEnabled()) {
- log.info("Source scan started ...");
- time = System.currentTimeMillis();
- }
- final GenericFileFilter filter = new GenericFileFilter(ignoreList, defaultExcludes);
+ if (srcPaths==null) {
+ log.warn("No source paths configured for scanning.");
+ // abort
+ return;
+ }
+
+ long time = 0;
+ long fileCount = 0;
- for (int i = 0; i < sourcePath.length; i += 1) {
- try {
- if (!sourcePath[i].isDirectory())
- throw new IllegalArgumentException("Source path component " + sourcePath[i]
- + " not found or no directory");
+ if (log.isInfoEnabled()) {
+ log.info("Source scan started ...");
+ time = System.currentTimeMillis();
+ }
- final File[] files = FSIO.getAllFiles(sourcePath[i], filter);
+ // create the file filter
+ final GenericFileFilter filter = new GenericFileFilter(ignoreList, defaultExcludes);
- fileCount += files.length;
+ // Scan all configured paths
+ for (int i = 0; i < srcPaths.length; i += 1) {
+ try {
+ // retrieve (recursive) all files from a path matching the configured filter
+ final File[] files = FSIO.getAllFiles(srcPaths[i], filter);
- for (int j = 0; j < files.length; j += 1) {
- final Iterator<ProtectedRegionImpl> regions = getAllRegions(files[j]).iterator();
+ fileCount += files.length;
- while (regions.hasNext()) {
- final ProtectedRegionImpl region = regions.next();
+ // scan all files
+ for (int j = 0; j < files.length; j += 1) {
+ // retrieve the Protected Regions from the current file
+ final Iterator<ProtectedRegionImpl> regions = getAllRegions(files[j]).iterator();
- final String id = region.getId();
+ while (regions.hasNext()) {
+ final ProtectedRegionImpl region = regions.next();
- if (regionMap.containsKey(id))
- throw new RuntimeException("Id '" + id + "' occuring in files " + region.getFile()
- + " and " + regionMap.get(id).getFile()
- + " is not unique");
- else {
- regionMap.put(id, region);
- }
+ final String id = region.getId();
+ // check for non-uniqueness of a Protected Region Id
+ if (regionMap.containsKey(id)) {
+ throw new IllegalStateException ("Id '" + id + "' occuring in files " + region.getFile()
+ + " and " + regionMap.get(id).getFile()
+ + " is not unique");
}
+ // Store this region
+ regionMap.put(id, region);
}
- } catch (final IOException e) {
- throw new RuntimeException("Unexpected I/O exception", e);
- } catch (final ProtectedRegionSyntaxException e) {
- throw new RuntimeException(e.getMessage(), e);
}
+ } catch (final IOException e) {
+ throw new RuntimeException("Unexpected I/O exception", e);
+ } catch (final ProtectedRegionSyntaxException e) {
+ throw new RuntimeException(e.getMessage(), e);
}
+ }
- if (log.isInfoEnabled()) {
- time = System.currentTimeMillis() - time;
+ if (log.isInfoEnabled()) {
+ time = System.currentTimeMillis() - time;
- log.info("Source scan finished in " + (time / 1000.0) + "s");
- log.info("Files scanned: " + fileCount);
- log.info("Regions found: " + regionMap.size());
- }
+ log.info("Source scan finished in " + (time / 1000.0) + "s");
+ log.info("Files scanned: " + fileCount);
+ log.info("Regions found: " + regionMap.size());
}
+
}
+ /**
+ * Dumps all known protected regions to files. For each protected region a file is created.
+ * @param dumpPath Directory where the dump files are created within.
+ */
public void reportRegions(final File dumpPath) {
final int unused = regionMap.size() - usedSet.size();
@@ -385,20 +414,56 @@ public class ProtectedRegionResolverImpl implements ProtectedRegionResolver {
}
}
+ /**
+ * This flag determines whether default file exclusion patterns should be used.
+ * @param defaultExcludes <code>true</code>: Use default file exclusion patterns, <code>false</code>: ignore them, just use
+ * the patterns specified by {@link #setIgnoreList(String) ignoreList}
+ * @see Xpand reference manual
+ */
public void setDefaultExcludes(final boolean defaultExcludes) {
this.defaultExcludes = defaultExcludes;
}
+ /**
+ * Sets the file encoding to be used when reading files.
+ * @param encoding A valid encoding string.
+ */
public void setFileEncoding(final String encoding) {
this.encoding = encoding;
}
+ /**
+ * Sets a custom list of file patterns that should be filtered during scanning of source files
+ * and directories.
+ * @param ignoreList A comma separated list of file patterns to ignore during scan.
+ */
public void setIgnoreList(final String ignoreList) {
this.ignoreList = ignoreList;
}
- public void setSrcPathes(final String srcPathes) {
- this.srcPathes = srcPathes;
+ /**
+ * Sets the source paths that should be scanned.
+ * @param srcPathsAsString A comma separated list of directory paths.
+ * @throws IllegalArgumentException If one of the passed arguments is not a directory or does not exist
+ */
+ public void setSrcPathes(final String srcPathsAsString) throws IllegalArgumentException {
+ // Split the paths and initialize the
+ // file array 'srcPaths' from it
+ if ("".equals(srcPathsAsString)) {
+ this.srcPaths = new File[0];
+ } else {
+ final String[] s = srcPathsAsString.split(",");
+ this.srcPaths = new File[s.length];
+ for (int i = 0; i < this.srcPaths.length; i++) {
+ this.srcPaths[i] = new File(s[i].trim());
+ // The configured path must point to an existing directory
+ if (!srcPaths[i].isDirectory()) {
+ throw new IllegalArgumentException("Source path component " + srcPaths[i]
+ + " not found or no directory");
+ }
+ }
+
+ }
}
public void setUseBASE64(final boolean useBASE64) {
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/util/GenericFileFilter.java b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/util/GenericFileFilter.java
index ffd5ed5..3fa484e 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/util/GenericFileFilter.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/pr/util/GenericFileFilter.java
@@ -22,26 +22,40 @@ import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+/**
+ * Configurable FilenameFilter. By default this filter does not accept well known files or directories
+ * managed by source control systems and temporary files.
+ *
+ * @see http://www.cvshome.org/docs/manual/cvs-1.11.10/cvs_18.html#SEC156
+ */
public class GenericFileFilter implements FilenameFilter {
private final Log log = LogFactory.getLog(getClass());
- // ignore list vom csv.
- // See http://www.cvshome.org/docs/manual/cvs-1.11.10/cvs_18.html#SEC156
-
- public final static String DEFAULTIGNORELIST = "RCS SCCS CVS CVS.adm " + "RCSLOG cvslog.* "
- + "tags TAGS " + ".make.state .nse_depinfo " + "*~ #* .#* ,* _$* *$ "
- + "*.old *.bak *.BAK *.orig *.rej .del-* " + "*.a *.olb *.o *.obj *.so *.exe "
+ // ignore list vom CVS and SVN.
+ public final static String DEFAULTIGNORELIST =
+ ".svn "
+ + "RCS SCCS CVS CVS.adm RCSLOG cvslog.* "
+ + "tags TAGS .make.state .nse_depinfo "
+ + "*~ #* .#* ,* _$* *$ "
+ + "*.old *.bak *.BAK *.orig *.rej .del-* "
+ + "*.a *.olb *.o *.obj *.so *.exe "
+ "*.Z *.elc *.ln " + "core "
- + ".svn";
+ ;
private String ivIgnoreList;
private List<GlobbingFileFilter> fileFilters = null;
+ /**
+ *
+ * @param aIgnoreList List of file patterns to ignore. This list can be comma-separated or space-separated.
+ * Note that file patterns containing commas can't be handled, since they will be recognized as two separated patterns.
+ * @param aDefaultexcludes <code>true</code> use the default exclude list.
+ */
public GenericFileFilter(final String aIgnoreList, final boolean aDefaultexcludes) {
ivIgnoreList = aDefaultexcludes ? DEFAULTIGNORELIST : "";
if (aIgnoreList != null) {
- ivIgnoreList += aIgnoreList;
+ ivIgnoreList += aIgnoreList.replaceAll(",", " ");
}
fileFilters = buildFileFilters(ivIgnoreList);
}
@@ -50,17 +64,28 @@ public class GenericFileFilter implements FilenameFilter {
this(aIgnoreList, false);
}
+ /**
+ * Creates the Filter with default excludes.
+ */
public GenericFileFilter() {
this(null);
}
/**
* Accept all files and directories not included in the ignore list.
+ * @param dir Directory to search in for a file
+ * @param name File name to check
+ * @return <code>true</code> when the file is accepted by the filter.
*/
public boolean accept(final File dir, final String name) {
return accept(new File(dir, name));
}
+ /**
+ * Accept all files and directories not included in the ignore list.
+ * @param file File to check
+ * @return <code>true</code> when the file is accepted by the filter.
+ */
public boolean accept(final File file) {
if (!file.isFile() && !file.isDirectory())
return false;
@@ -84,41 +109,57 @@ public class GenericFileFilter implements FilenameFilter {
private List<GlobbingFileFilter> buildFileFilters(final String aIgnoreList) {
final List<GlobbingFileFilter> fileFilters = new ArrayList<GlobbingFileFilter>();
for (final StringTokenizer st = new StringTokenizer(aIgnoreList); st.hasMoreTokens();) {
- final String pattern = st.nextToken();
+ final String pattern = st.nextToken().trim();
fileFilters.add(new GlobbingFileFilter(pattern));
}
return fileFilters;
}
+ /**
+ * File filter that accepts wildcards.
+ */
private static class GlobbingFileFilter implements FileFilter {
private String globvalue;
- public GlobbingFileFilter(final String globvalue) {
+ /**
+ * Creates a globbing file filter.
+ * @param globvalue a filename pattern
+ * @throws IllegalArgumentException The file pattern is invalid. Not accepted are the following situations:
+ * <ol>
+ * <li>The pattern contains multiple wildcards (e.g. <tt>'*test*.xml'</tt>)
+ * <li>The pattern has a wildcard in the middle (e.g. <tt>'test*.xml'</tt>)
+ * </ol>
+ */
+ public GlobbingFileFilter(final String globvalue) throws IllegalArgumentException {
+ final int pos = globvalue.indexOf("*");
+ if (pos>=0) {
+ if (pos != globvalue.lastIndexOf("*")) {
+ throw new IllegalArgumentException("GlobbingFileFilter does not support multiple stars (" + globvalue
+ + ").");
+ } else if (pos > 0 && pos < (globvalue.length() - 1)) {
+ throw new IllegalArgumentException("GlobbingFileFilter does not support stars in the middle (" + globvalue
+ + ").");
+ }
+ }
this.globvalue = globvalue;
}
+ /**
+ * @param pathname A file to check this filter against
+ * @return <code>true</code> if the filter accepts this file, <code>false</code> if it is rejected.
+ * @see FileFilter#accept(File)
+ */
public boolean accept(final File pathname) {
final int pos = globvalue.indexOf("*");
- if (pos == -1)
- // System.out.println("POS == -1 ("+globvalue+"):
- // "+pathname.getName()+":"+
- // pathname.getName().equals(globvalue));
+ if (pos == -1) {
+ // no wildcard
return pathname.getName().equals(globvalue);
- if (pos != globvalue.lastIndexOf("*"))
- throw new IllegalArgumentException("GlobbingFileFilter does not support multiple stars (" + globvalue
- + ").");
- if (pos == 0)
- // System.out.println("POS == 0 ("+globvalue+"):
- // "+pathname.getName()+", "+globvalue.substring(pos+1)+":"+
- // pathname.getName().endsWith(globvalue.substring(pos+1)));
+ } else if (pos == 0) {
return pathname.getName().endsWith(globvalue.substring(pos + 1));
- if (pos == (globvalue.length() - 1))
- // System.out.println("POS =="+pos+ "("+globvalue+"):
- // "+pathname.getName()+", "+globvalue.substring(0,pos)+":"+
- // pathname.getName().startsWith(globvalue.substring(0,pos)));
+ } else {
+ // must be 'pos == (globvalue.length() - 1)', since other situations already detected in constuctor
return pathname.getName().startsWith(globvalue.substring(0, pos));
- throw new IllegalArgumentException("GlobbingFileFilter does not support stars in the middle (" + globvalue
- + ").");
+ }
}
@Override
@@ -129,6 +170,6 @@ public class GenericFileFilter implements FilenameFilter {
@Override
public String toString() {
- return ivIgnoreList;
+ return ivIgnoreList.replaceAll("\\s+", ", ");
}
}
diff --git a/tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/ProtectedRegionResolverImplTest.java b/tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/ProtectedRegionResolverImplTest.java
index c34f7ab..714b509 100644
--- a/tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/ProtectedRegionResolverImplTest.java
+++ b/tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/ProtectedRegionResolverImplTest.java
@@ -24,11 +24,15 @@ import org.eclipse.internal.xpand2.pr.ProtectedRegionResolverImpl.ProtectedRegio
import org.eclipse.internal.xpand2.pr.util.FSIO;
+/**
+ * Unittest for class {@link ProtectedRegionResolverImpl}.
+ * @author Karsten Thoms
+ */
public class ProtectedRegionResolverImplTest extends TestCase {
private File file1;
private File tempDir;
/**
- * Provides access to protected methods
+ * Provides access to protected methods that should be tested here.
*/
class ProtectedRegionResolverTestImpl extends ProtectedRegionResolverImpl {
public Collection<ProtectedRegionImpl> _getAllRegions(final File file) throws ProtectedRegionSyntaxException, IOException {
@@ -36,22 +40,32 @@ public class ProtectedRegionResolverImplTest extends TestCase {
}
}
+ /** Instance under test */
private ProtectedRegionResolverTestImpl prResolver;
+ @Override
public void setUp () throws Exception {
prResolver = new ProtectedRegionResolverTestImpl();
+
+ // create a temporary directory for this test. The directory will be deleted automatically.
tempDir = new File(System.getProperty("java.io.tmpdir")+"/oaw/");
tempDir.mkdir();
tempDir.deleteOnExit();
+ // Use the temp dir for scanning
prResolver.setSrcPathes(tempDir.getPath());
+ // Create a test file with the content of 'testfile1.txt'
file1 = new File(tempDir.getPath(),"file1.txt");
file1.deleteOnExit();
FSIO.writeSingleFile(new FileWriter(file1), new InputStreamReader(getClass().getResourceAsStream("testfile1.txt")));
}
-
+ /**
+ * Tests method <tt>getAllRegions()</tt>.
+ * @throws Exception
+ * @since 22.01.2008
+ */
public void testGetAllRegions () throws Exception {
Collection<ProtectedRegionImpl> allRegions = prResolver._getAllRegions(file1);
assertNotNull(allRegions);
@@ -60,7 +74,10 @@ public class ProtectedRegionResolverImplTest extends TestCase {
assertEquals("Enabled protected regions", 2, allRegions.size());
}
- public void testGetProtectedRegion () throws Exception {
+ /**
+ * Tests method {@link ProtectedRegionResolverImpl#getProtectedRegion(String)}.
+ */
+ public void testGetProtectedRegion () {
assertNull ("Disabled protected region must not be found", prResolver.getProtectedRegion("region1"));
assertNotNull ("Enabled protected region must be found", prResolver.getProtectedRegion("region2"));
}
@@ -81,6 +98,11 @@ public class ProtectedRegionResolverImplTest extends TestCase {
assertEquals("disabled", false, pr.isDisabled());
}
+ /**
+ * In Bug#185493 it is reported that using '&&' as Protected Region ID.
+ * @throws Exception On any unexpected exception
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185493
+ */
public void testBug185493 () throws Exception {
File file = new File(tempDir.getPath(),"testbug185493.txt");
FSIO.writeSingleFile(new FileWriter(file), new InputStreamReader(getClass().getResourceAsStream("testbug185493.txt")));
@@ -88,4 +110,45 @@ public class ProtectedRegionResolverImplTest extends TestCase {
ProtectedRegionImpl pr = (ProtectedRegionImpl) prResolver.getProtectedRegion("&&");
assertNotNull(pr);
}
+
+ /**
+ * Bug#206137 reports that setting multiple source paths in a comma separated list will fail when
+ * {@link ProtectedRegionResolverImpl#init()} is called.
+ *
+ * @since 22.01.2008
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=206137
+ */
+ public void testBug206137 () throws Exception{
+ File dir1 = new File(tempDir, "dir1/");
+ dir1.mkdir();
+ dir1.deleteOnExit();
+
+ File dir2 = new File(tempDir, "dir2/");
+ dir2.mkdir();
+ dir2.deleteOnExit();
+
+ try {
+ // With Bug#206137 this will raise an IllegalArgumentException
+ prResolver.setSrcPathes(dir1.getAbsolutePath()+", "+dir2.getAbsolutePath());
+ prResolver.init();
+ } catch (IllegalArgumentException e) {
+ fail ("Failure of Bug#206137 detected");
+ }
+ }
+
+ /**
+ * Sets an invalid value for srcPaths and checks that the appropriate exception is thrown
+ *
+ * @since 22.01.2008
+ */
+ public void testInitWithNonExistingDir () {
+ File dir1 = new File(tempDir, getName());
+ assertFalse(dir1.exists());
+ try {
+ prResolver.setSrcPathes(dir1.getAbsolutePath());
+ fail("IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ ; // OK
+ }
+ }
}
diff --git a/tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/util/GenericFileFilterTest.java b/tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/util/GenericFileFilterTest.java
new file mode 100644
index 0000000..f46a923
--- /dev/null
+++ b/tests/org.eclipse.xpand.tests/src/org/eclipse/xpand/internal/tests/pr/util/GenericFileFilterTest.java
@@ -0,0 +1,106 @@
+package org.eclipse.xpand.internal.tests.pr.util;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.internal.xpand2.pr.util.GenericFileFilter;
+
+/**
+ * Unit test for class {@link GenericFileFilter}.
+ * @author Karsten Thoms
+ *
+ * @since 21.01.2008
+ */
+public class GenericFileFilterTest extends TestCase {
+ private static final File TMPDIR = new File(System.getProperty("java.io.tmpdir"));
+
+ /**
+ * Creates a testfile in temp dir for this test.
+ * @param extension The file extension to use
+ * @return A newly created file that will be deleted automatically on exit
+ * @throws IOException On any errors
+ * @since 21.01.2008
+ */
+ private File createTestFileByExtension (String extension) throws IOException {
+ File f = new File(TMPDIR, "GenericFileFilterTest."+extension);
+ f.createNewFile();
+ f.deleteOnExit();
+ return f;
+ }
+
+ /**
+ * Tests the filter with default extensions
+ * @throws Exception On any unexpected exception
+ * @since 21.01.2008
+ */
+ public void testDefaultExcludes () throws Exception {
+ // create without custom excludes and with default excludes option on
+ GenericFileFilter filter = new GenericFileFilter(null, true);
+
+ assertFalse("file with extension '.bak' must be excluded", filter.accept(createTestFileByExtension("bak")));
+ assertFalse("file with extension '.elc' must be excluded", filter.accept(createTestFileByExtension("elc")));
+
+ assertTrue("file with extension '.txt' must be included", filter.accept(createTestFileByExtension("txt")));
+ }
+
+ /**
+ * Tests the file filter with a comma-separated list of custom extensions. Default excludes are ignored.
+ * @throws Exception
+ * @since 21.01.2008
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=205522
+ */
+ public void testNonDefaultExcludes_CommaSeparated_withDefaultExcludes () throws Exception {
+ // create the filter and deactivate default excludes
+ GenericFileFilter filter = new GenericFileFilter("*.xml, *.hbm", true);
+
+ assertFalse("file with extension '.xml' must be excluded", filter.accept(createTestFileByExtension("xml")));
+ assertFalse("file with extension '.hbm' must be excluded", filter.accept(createTestFileByExtension("hbm")));
+ assertFalse("file with extension '.bak' must be excluded", filter.accept(createTestFileByExtension("bak")));
+
+ assertTrue("file with extension '.txt' must be included", filter.accept(createTestFileByExtension("txt")));
+ }
+
+ /**
+ * Tests the file filter with a comma-separated list of custom extensions. Default excludes are ignored.
+ * @throws Exception
+ * @since 21.01.2008
+ */
+ public void testNonDefaultExcludes_SpaceSeparated_withoutDefaultExcludes () throws Exception {
+ // create the filter and deactivate default excludes
+ GenericFileFilter filter = new GenericFileFilter("*.xml *.hbm", false);
+
+ assertFalse("file with extension '.xml' must be excluded", filter.accept(createTestFileByExtension("xml")));
+ assertFalse("file with extension '.hbm' must be excluded", filter.accept(createTestFileByExtension("hbm")));
+
+ assertTrue("file with extension '.txt' must be included", filter.accept(createTestFileByExtension("txt")));
+ assertTrue("file with extension '.bak' must be included", filter.accept(createTestFileByExtension("bak")));
+ }
+
+ /**
+ * Tests wrong custom exclude list: Wildcard in the middle of a search pattern
+ * @since 21.01.2008
+ */
+ public void testWildcardInMiddleOfCustomExclude () {
+ try {
+ new GenericFileFilter("test*.xml", false);
+ fail ("IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ ; // OK
+ }
+ }
+
+ /**
+ * Tests wrong custom exclude list: Missing separator between extensions with wildcards.
+ * @since 21.01.2008
+ */
+ public void testMultipleWildcardsInCustomExclude () {
+ try {
+ new GenericFileFilter("*.test*.xml", false);
+ fail ("IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ ; // OK
+ }
+ }
+}