[jboss-cvs] JBossAS SVN: r91987 - in projects/vfs/branches/dml-zip-rework/src: main/java/org/jboss/virtual/spi and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 4 18:24:09 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-08-04 18:24:08 -0400 (Tue, 04 Aug 2009)
New Revision: 91987
Added:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileFilterWithAttributes.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileVisitor.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/ExtensibleFilter.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/FilterVirtualFileVisitor.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/MatchAllVirtualFileFilter.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/PathTokenizer.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixMatchFilter.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixesExcludeFilter.java
Removed:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JZipFileSystem.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java
Log:
org.jboss.virtual.plugins.vfs.helpers -> org.jboss.virtual.util
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java 2009-08-04 22:20:47 UTC (rev 91986)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -50,7 +50,7 @@
import org.jboss.virtual.spi.FileSystem;
import org.jboss.virtual.spi.RealFileSystem;
import org.jboss.virtual.spi.JavaZipFileSystem;
-import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
+import org.jboss.virtual.util.PathTokenizer;
import org.jboss.logging.Logger;
/**
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java 2009-08-04 22:20:47 UTC (rev 91986)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -34,9 +34,9 @@
import java.util.Set;
import java.util.Arrays;
-import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
-import org.jboss.virtual.plugins.vfs.helpers.MatchAllVirtualFileFilter;
-import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
+import org.jboss.virtual.util.FilterVirtualFileVisitor;
+import org.jboss.virtual.util.MatchAllVirtualFileFilter;
+import org.jboss.virtual.util.PathTokenizer;
/**
* A virtual file. This is a symbolic reference to a location in the virtual file system hierarchy. Holding a
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JZipFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JZipFileSystem.java 2009-08-04 22:20:47 UTC (rev 91986)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JZipFileSystem.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -26,7 +26,7 @@
import org.jboss.jzipfile.Zip;
import org.jboss.jzipfile.ZipCatalog;
import org.jboss.jzipfile.ZipEntryType;
-import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
+import org.jboss.virtual.util.PathTokenizer;
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.TempDir;
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java 2009-08-04 22:20:47 UTC (rev 91986)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -22,7 +22,7 @@
package org.jboss.virtual.spi;
-import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
+import org.jboss.virtual.util.PathTokenizer;
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.TempDir;
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileFilterWithAttributes.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileFilterWithAttributes.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileFilterWithAttributes.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileFilterWithAttributes.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.virtual.util;
+
+import org.jboss.virtual.VirtualFileFilterWithAttributes;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * AbstractVirtualFileFilterWithAttributes
+ *
+ * @author adrian at jboss.org
+ * @version $Revision: 44223 $
+ */
+public abstract class AbstractVirtualFileFilterWithAttributes implements VirtualFileFilterWithAttributes
+{
+ /** The attributes */
+ private VisitorAttributes attributes;
+
+ /**
+ * Create a new AbstractVirtualFileFilterWithAttributes,
+ * using {@link VisitorAttributes#DEFAULT}
+ */
+ public AbstractVirtualFileFilterWithAttributes()
+ {
+ this(null);
+ }
+
+ /**
+ * Create a new AbstractVirtualFileFilterWithAttributes.
+ *
+ * @param attributes the attributes, pass null to use {@link VisitorAttributes#DEFAULT}
+ */
+ public AbstractVirtualFileFilterWithAttributes(VisitorAttributes attributes)
+ {
+ if (attributes == null)
+ attributes = VisitorAttributes.DEFAULT;
+ this.attributes = attributes;
+ }
+
+ public VisitorAttributes getAttributes()
+ {
+ return attributes;
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileVisitor.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/AbstractVirtualFileVisitor.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileVisitor.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/AbstractVirtualFileVisitor.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,62 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.util;
+
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * AbstractVirtualFileVisitor.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractVirtualFileVisitor implements VirtualFileVisitor
+{
+ /** The attributes */
+ private final VisitorAttributes attributes;
+
+ /**
+ * Create a new AbstractVirtualFileVisitor using the default visitor attributes
+ */
+ protected AbstractVirtualFileVisitor()
+ {
+ this(null);
+ }
+
+ /**
+ * Create a new AbstractVirtualFileVisitor using the default visitor attributes
+ *
+ * @param attributes the attributes, uses the default if null
+ */
+ protected AbstractVirtualFileVisitor(VisitorAttributes attributes)
+ {
+ if (attributes == null)
+ attributes = VisitorAttributes.DEFAULT;
+ this.attributes = attributes;
+ }
+
+ public VisitorAttributes getAttributes()
+ {
+ return attributes;
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/ExtensibleFilter.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/ExtensibleFilter.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/ExtensibleFilter.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/ExtensibleFilter.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.virtual.util;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
+/**
+ * An extensible filter for VFS files. Three arrays are
+ * maintained for checking: a prefix, suffix, and match array. If the
+ * filename starts with any of the prefixes, ends with any of the
+ * suffixes, or exactly matches any of the matches, then the accepts
+ * method will return false.
+ *
+ * NOTE: the arrays *must* be sorted for the string matching to work,
+ * and suffixes use the 'reverseComparator'
+ *
+ * @author somebody at jboss.org
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 57108 $
+ */
+public class ExtensibleFilter implements VirtualFileFilter
+{
+ /**
+ * Compare the strings backwards. This assists in suffix comparisons.
+ */
+ private static final Comparator<String> reverseComparator = new Comparator<String>()
+ {
+ public int compare(String o1, String o2)
+ {
+ int idx1 = o1.length();
+ int idx2 = o2.length();
+ int comp = 0;
+
+ while (comp == 0 && idx1 > 0 && idx2 > 0)
+ comp = o1.charAt(--idx1) - o2.charAt(--idx2);
+
+ return (comp == 0) ? (idx1 - idx2) : comp;
+ }
+ };
+
+ /** the default prefix list */
+ private static final String[] DEFAULT_PREFIXES =
+ {"#", "%", ",", ".", "_$"};
+
+ /** the default suffix list */
+ private static final String[] DEFAULT_SUFFIXES =
+ {"#", "$", "%", "~", ",v", ".BAK", ".bak", ".old", ".orig", ".tmp", ".rej", ".sh" };
+
+ /** the default matches list */
+ private static final String[] DEFAULT_MATCHES =
+ {".make.state", ".nse_depinfo", "CVS", "CVS.admin", "RCS", "RCSLOG",
+ "SCCS", "TAGS", "core", "tags"};
+
+ /** The list of disallowed suffixes, sorted using reverse values */
+ private List<String> suffixes;
+
+ /** The sorted list of disallowed prefixes */
+ private List<String> prefixes;
+
+ /** The sorted list of disallowed values */
+ private List<String> matches;
+
+ /** Use the default values for suffixes, prefixes, and matches */
+ public ExtensibleFilter()
+ {
+ this(DEFAULT_MATCHES, DEFAULT_PREFIXES, DEFAULT_SUFFIXES);
+ }
+
+ /**
+ * Create using a custom set of matches, prefixes, and suffixes. If any of
+ * these arrays are null, then the corresponding default will be
+ * substituted.
+ *
+ * @param matches the matches
+ * @param prefixes the prefixes
+ * @param suffixes the suffixes
+ */
+ public ExtensibleFilter(String[] matches, String[] prefixes, String[] suffixes)
+ {
+ if( matches == null )
+ matches = DEFAULT_MATCHES;
+ Arrays.sort(matches);
+ this.matches = new ArrayList<String>(Arrays.asList(matches));
+
+ if( prefixes == null )
+ prefixes = DEFAULT_PREFIXES;
+ Arrays.sort(prefixes);
+ this.prefixes = new ArrayList<String>(Arrays.asList(prefixes));
+
+ if( suffixes == null )
+ suffixes = DEFAULT_SUFFIXES;
+ Arrays.sort(suffixes, reverseComparator);
+ this.suffixes = new ArrayList<String>(Arrays.asList(suffixes));
+ }
+
+ public void addPrefix(String prefix)
+ {
+ this.prefixes.add(prefix);
+ Collections.sort(this.prefixes);
+ }
+ public void addPrefixes(String[] prefixes)
+ {
+ this.prefixes.addAll(Arrays.asList(prefixes));
+ Collections.sort(this.prefixes);
+ }
+
+ public void delPrefix(String prefix)
+ {
+ this.prefixes.remove(prefix);
+ }
+ public void delPrefixes(String[] prefixes)
+ {
+ this.prefixes.removeAll(Arrays.asList(prefixes));
+ Collections.sort(this.prefixes);
+ }
+
+ public void addSuffix(String suffix)
+ {
+ this.suffixes.add(suffix);
+ Collections.sort(this.suffixes, reverseComparator);
+ }
+ public void addSuffixes(String[] suffixes)
+ {
+ this.suffixes.addAll(Arrays.asList(suffixes));
+ Collections.sort(this.suffixes, reverseComparator);
+ }
+
+ public void delSuffix(String suffix)
+ {
+ this.suffixes.remove(suffix);
+ }
+ public void delSuffixes(String[] suffixes)
+ {
+ this.suffixes.removeAll(Arrays.asList(suffixes));
+ Collections.sort(this.suffixes, reverseComparator);
+ }
+
+ public String[] getSuffixes()
+ {
+ String[] tmp = new String[suffixes.size()];
+ suffixes.toArray(tmp);
+ return tmp;
+ }
+ public void setSuffixes(String[] suffixes)
+ {
+ Arrays.sort(suffixes, reverseComparator);
+ this.suffixes.clear();
+ this.suffixes.addAll(Arrays.asList(suffixes));
+ }
+
+ public String[] getPrefixes()
+ {
+ String[] tmp = new String[prefixes.size()];
+ prefixes.toArray(tmp);
+ return tmp;
+ }
+ public void setPrefixes(String[] prefixes)
+ {
+ Arrays.sort(prefixes);
+ this.prefixes.clear();
+ this.prefixes.addAll(Arrays.asList(prefixes));
+ }
+
+ public String[] getMatches()
+ {
+ String[] tmp = new String[matches.size()];
+ matches.toArray(tmp);
+ return tmp;
+ }
+ public void setMatches(String[] matches)
+ {
+ Arrays.sort(matches);
+ this.matches.clear();
+ this.matches.addAll(Arrays.asList(matches));
+ }
+
+ /**
+ * If the filename matches any string in the prefix, suffix, or matches
+ * array, return false. Perhaps a bit of overkill, but this method
+ * operates in log(n) time, where n is the size of the arrays.
+ *
+ * @param file The file to be tested
+ * @return <code>false</code> if the filename matches any of the prefixes,
+ * suffixes, or matches.
+ */
+ public boolean accepts(VirtualFile file)
+ {
+ String name = file.getName();
+ // check exact match
+ int index = Collections.binarySearch(matches, name);
+ if (index >= 0)
+ return false;
+
+ // check prefix
+ index = Collections.binarySearch(prefixes, name);
+ if (index >= 0)
+ return false;
+ if (index < -1)
+ {
+ // The < 0 index gives the first index greater than name
+ int firstLessIndex = -2 - index;
+ String prefix = prefixes.get(firstLessIndex);
+ // If name starts with an ingored prefix ignore name
+ if( name.startsWith(prefix) )
+ return false;
+ }
+
+ // check suffix
+ index = Collections.binarySearch(suffixes, name, reverseComparator);
+ if (index >= 0)
+ return false;
+ if (index < -1)
+ {
+ // The < 0 index gives the first index greater than name
+ int firstLessIndex = -2 - index;
+ String suffix = suffixes.get(firstLessIndex);
+ // If name ends with an ingored suffix ignore name
+ if( name.endsWith(suffix) )
+ return false;
+ }
+
+ // everything checks out.
+ return true;
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/FilterVirtualFileVisitor.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/FilterVirtualFileVisitor.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/FilterVirtualFileVisitor.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/FilterVirtualFileVisitor.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFileFilterWithAttributes;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * A visitor based on a virtual file filter
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FilterVirtualFileVisitor extends AbstractVirtualFileVisitor
+{
+ /** The filter */
+ private final VirtualFileFilter filter;
+
+ /** What is matched */
+ private List<VirtualFile> matched;
+
+ /**
+ * Check the attributes
+ *
+ * @param filter the filter
+ * @param attributes the attributes
+ * @return the attributes
+ * @throws IllegalArgumentException for a null filter
+ */
+ private static VisitorAttributes checkAttributes(VirtualFileFilter filter, VisitorAttributes attributes)
+ {
+ if (filter == null)
+ throw new IllegalArgumentException("Null filter");
+
+ // Specified
+ if (attributes != null)
+ return attributes;
+
+ // From the filter
+ if (filter instanceof VirtualFileFilterWithAttributes)
+ return ((VirtualFileFilterWithAttributes) filter).getAttributes();
+
+ // It will use the default
+ return null;
+ }
+
+ /**
+ * Create a new FilterVirtualFileVisitor with default attributes
+ *
+ * @param filter the filter
+ * @throws IllegalArgumentException if the filter is null
+ */
+ public FilterVirtualFileVisitor(VirtualFileFilter filter)
+ {
+ this(filter, null);
+ }
+
+ /**
+ * Create a new FilterVirtualFileVisitor.
+ *
+ * @param filter the filter
+ * @param attributes the attributes, uses the default if null
+ * @throws IllegalArgumentException if the filter is null
+ */
+ public FilterVirtualFileVisitor(VirtualFileFilter filter, VisitorAttributes attributes)
+ {
+ super(checkAttributes(filter, attributes));
+ this.filter = filter;
+ }
+
+ /**
+ * Get the matched files
+ *
+ * @return the matched files
+ */
+ public List<VirtualFile> getMatched()
+ {
+ if (matched == null)
+ return Collections.emptyList();
+ else
+ return matched;
+ }
+
+ public void visit(VirtualFile virtualFile)
+ {
+ if (filter.accepts(virtualFile))
+ {
+ if (matched == null)
+ matched = new ArrayList<VirtualFile>();
+ matched.add(virtualFile);
+ }
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/MatchAllVirtualFileFilter.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/MatchAllVirtualFileFilter.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/MatchAllVirtualFileFilter.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/MatchAllVirtualFileFilter.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.util;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
+/**
+ * MatchAllVirtualFileFilter.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MatchAllVirtualFileFilter implements VirtualFileFilter
+{
+ /** The instance */
+ public static final MatchAllVirtualFileFilter INSTANCE = new MatchAllVirtualFileFilter();
+
+ /**
+ * Singleton
+ */
+ private MatchAllVirtualFileFilter()
+ {
+ }
+
+ public boolean accepts(VirtualFile file)
+ {
+ return true;
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/PathTokenizer.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/PathTokenizer.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/PathTokenizer.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,298 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PathTokenizer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="david.lloyd at jboss.com">David M. Lloyd</a>
+ * @version $Revision: 1.1 $
+ */
+ at SuppressWarnings({"StringEquality"})
+public class PathTokenizer
+{
+ /** The reverse path const */
+ private static final String CURRENT_PATH = ".";
+
+ /** The reverse path const */
+ private static final String REVERSE_PATH = "..";
+
+ /** Token states */
+ private static final int STATE_INITIAL = 0;
+ private static final int STATE_NORMAL = 1;
+ private static final int STATE_MAYBE_CURRENT_PATH = 2;
+ private static final int STATE_MAYBE_REVERSE_PATH = 3;
+
+ /**
+ * Utility class
+ */
+ private PathTokenizer()
+ {
+ }
+
+ /**
+ * Get the remaining path from some tokens
+ *
+ * @param tokens the tokens
+ * @param i the current location
+ * @param end the end index
+ * @return the remaining path
+ * @throws IllegalArgumentException for null tokens or i is out of range
+ */
+ protected static String getRemainingPath(List<String> tokens, int i, int end)
+ {
+ if (tokens == null)
+ throw new IllegalArgumentException("Null tokens");
+ if (i < 0 || i >= end)
+ throw new IllegalArgumentException("i is not in the range of tokens: 0-" + (end-1));
+
+ if (i == end-1)
+ return tokens.get(end-1);
+
+ StringBuilder buffer = new StringBuilder();
+ for (; i < end-1; ++i)
+ {
+ buffer.append(tokens.get(i));
+ buffer.append("/");
+ }
+ buffer.append(tokens.get(end-1));
+ return buffer.toString();
+ }
+
+ /**
+ * Get the tokens that comprise this path.
+ *
+ * @param path the path
+ * @return the tokens or null if the path is empty
+ * @throws IllegalArgumentException if the path is null
+ */
+ public static List<String> getTokens(String path)
+ {
+ if (path == null)
+ throw new IllegalArgumentException("Null path");
+
+ List<String> list = new ArrayList<String>();
+ getTokens(list, path);
+ return list;
+ }
+
+ /**
+ * Get the tokens that comprise this path and append them to the list.
+ *
+ * @param path the path
+ * @return the tokens or null if the path is empty
+ * @throws IllegalArgumentException if the path is null
+ */
+ public static void getTokens(List<String> list, String path)
+ {
+ int start = -1, length = path.length(), state = STATE_INITIAL;
+ char ch;
+ for (int index = 0; index < length; index ++) {
+ ch = path.charAt(index);
+ switch (ch) {
+ case '/': {
+ switch (state) {
+ case STATE_INITIAL: {
+ // skip extra leading /
+ continue;
+ }
+ case STATE_MAYBE_CURRENT_PATH: {
+ // it's '.'
+ list.add(CURRENT_PATH);
+ state = STATE_INITIAL;
+ continue;
+ }
+ case STATE_MAYBE_REVERSE_PATH: {
+ // it's '..'
+ list.add(REVERSE_PATH);
+ state = STATE_INITIAL;
+ continue;
+ }
+ case STATE_NORMAL: {
+ // it's just a normal path segment
+ list.add(path.substring(start, index));
+ state = STATE_INITIAL;
+ continue;
+ }
+ }
+ continue;
+ }
+ case '.': {
+ switch (state) {
+ case STATE_INITIAL: {
+ // . is the first char; might be a special token
+ state = STATE_MAYBE_CURRENT_PATH;
+ start = index;
+ continue;
+ }
+ case STATE_MAYBE_CURRENT_PATH: {
+ // the second . in a row...
+ state = STATE_MAYBE_REVERSE_PATH;
+ continue;
+ }
+ case STATE_MAYBE_REVERSE_PATH: {
+ // the third . in a row, guess it's just a weird path name
+ state = STATE_NORMAL;
+ continue;
+ }
+ }
+ continue;
+ }
+ default: {
+ switch (state) {
+ case STATE_INITIAL: {
+ state = STATE_NORMAL;
+ start = index;
+ continue;
+ }
+ case STATE_MAYBE_CURRENT_PATH:
+ case STATE_MAYBE_REVERSE_PATH: {
+ state = STATE_NORMAL;
+ }
+ }
+ }
+ }
+ }
+ // handle the last token
+ switch (state) {
+ case STATE_INITIAL: {
+ // trailing /
+ break;
+ }
+ case STATE_MAYBE_CURRENT_PATH: {
+ list.add(CURRENT_PATH);
+ break;
+ }
+ case STATE_MAYBE_REVERSE_PATH: {
+ list.add(REVERSE_PATH);
+ break;
+ }
+ case STATE_NORMAL: {
+ list.add(path.substring(start));
+ break;
+ }
+ }
+ return;
+ }
+
+ /**
+ * Get the remaining path from some tokens
+ *
+ * @param tokens the tokens
+ * @param i the current location
+ * @return the remaining path
+ * @throws IllegalArgumentException for null tokens or i is out of range
+ */
+ public static String getRemainingPath(List<String> tokens, int i)
+ {
+ if (tokens == null)
+ throw new IllegalArgumentException("Null tokens");
+
+ return getRemainingPath(tokens, i, tokens.size());
+ }
+
+ /**
+ * Apply any . or .. paths in the path param.
+ *
+ * @param path the path
+ * @return simple path, containing no . or .. paths
+ */
+ public static String applySpecialPaths(String path) throws IllegalArgumentException
+ {
+ List<String> tokens = getTokens(path);
+ if (tokens == null)
+ return null;
+
+ int i = 0;
+ for(int j = 0; j < tokens.size(); j++)
+ {
+ String token = tokens.get(j);
+
+ if (isCurrentToken(token))
+ continue;
+ else if (isReverseToken(token))
+ i--;
+ else
+ tokens.set(i++, token);
+
+ if (i < 0)
+ throw new IllegalArgumentException(".. on root path");
+ }
+ return getRemainingPath(tokens, 0, i);
+ }
+
+ /**
+ * Apply any . or .. paths in the pathTokens parameter, returning the minimal token list.
+ *
+ * @param pathTokens the path tokens
+ * @return the simple path tokens
+ * @throws IllegalArgumentException if reverse path goes over the top path
+ */
+ public static List<String> applySpecialPaths(List<String> pathTokens) throws IllegalArgumentException
+ {
+ final ArrayList<String> newTokens = new ArrayList<String>();
+ for (String pathToken : pathTokens)
+ {
+ if (isCurrentToken(pathToken))
+ continue;
+ else if (isReverseToken(pathToken))
+ {
+ final int size = newTokens.size();
+ if (size == 0) {
+ throw new IllegalArgumentException(".. on root path");
+ }
+ newTokens.remove(size - 1);
+ }
+ else
+ newTokens.add(pathToken);
+ }
+ return newTokens;
+ }
+
+ /**
+ * Is current token.
+ *
+ * @param token the token to check
+ * @return true if token matches current path token
+ */
+ public static boolean isCurrentToken(String token)
+ {
+ return CURRENT_PATH == token;
+ }
+
+ /**
+ * Is reverse token.
+ *
+ * @param token the token to check
+ * @return true if token matches reverse path token
+ */
+ public static boolean isReverseToken(String token)
+ {
+ return REVERSE_PATH == token;
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixMatchFilter.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/SuffixMatchFilter.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixMatchFilter.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixMatchFilter.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.virtual.util;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * Matches a file name against a list of suffixes.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author adrian at jboss.org
+ * @version $Revision: 44223 $
+ */
+public class SuffixMatchFilter extends AbstractVirtualFileFilterWithAttributes
+{
+ private static Logger log = Logger.getLogger(SuffixMatchFilter.class);
+ /** The suffixes */
+ private Collection<String> suffixes;
+ private boolean trace;
+
+ /**
+ * Create a new SuffixMatchFilter,
+ * using {@link VisitorAttributes#DEFAULT}
+ *
+ * @param suffix the suffix
+ * @throws IllegalArgumentException for a null suffix
+ */
+ public SuffixMatchFilter(String suffix)
+ {
+ this(suffix, null);
+ }
+
+ /**
+ * Create a new SuffixMatchFilter.
+ *
+ * @param suffix the suffix
+ * @param attributes the attributes, pass null to use {@link VisitorAttributes#DEFAULT}
+ * @throws IllegalArgumentException for a null suffix
+ */
+ @SuppressWarnings("unchecked")
+ public SuffixMatchFilter(String suffix, VisitorAttributes attributes)
+ {
+ this(Collections.singleton(suffix), attributes);
+ }
+ /**
+ * Create a new SuffixMatchFilter.
+ * @param suffixes - the list of file suffixes to accept.
+ * @throws IllegalArgumentException for a null suffixes
+ */
+ public SuffixMatchFilter(Collection<String> suffixes)
+ {
+ this(suffixes, null);
+ }
+ /**
+ * Create a new SuffixMatchFilter.
+ * @param suffixes - the list of file suffixes to accept.
+ * @param attributes the attributes, pass null to use {@link VisitorAttributes#DEFAULT}
+ * @throws IllegalArgumentException for a null suffixes
+ */
+ public SuffixMatchFilter(Collection<String> suffixes, VisitorAttributes attributes)
+ {
+ super(attributes == null ? VisitorAttributes.DEFAULT : attributes);
+ if (suffixes == null)
+ throw new IllegalArgumentException("Null suffixes");
+ this.suffixes = new LinkedHashSet<String>();
+ this.suffixes.addAll(suffixes);
+ trace = log.isTraceEnabled();
+ }
+
+ /**
+ * Accept any file that ends with one of the filter suffixes. This checks
+ * that the file.getName() endsWith a suffix.
+ * @return true if the file matches a suffix, false otherwise.
+ */
+ public boolean accepts(VirtualFile file)
+ {
+ String name = file.getName();
+ boolean accepts = false;
+ for(String suffix : suffixes)
+ {
+ if (name.endsWith(suffix))
+ {
+ accepts = true;
+ break;
+ }
+ }
+ if( trace )
+ log.trace(file+" accepted: "+accepts);
+ return accepts;
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixesExcludeFilter.java (from rev 91984, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/vfs/helpers/SuffixesExcludeFilter.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixesExcludeFilter.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/util/SuffixesExcludeFilter.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.virtual.util;
+
+import java.util.Collection;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
+/**
+ * Filters out a set of suffixes
+ *
+ * @author adrian at jboss.org
+ * @version $Revision: 44223 $
+ */
+public class SuffixesExcludeFilter implements VirtualFileFilter
+{
+ /** The suffixes */
+ private Collection<String> suffixes;
+
+ /**
+ * Create a new SuffixMatchFilter,
+ *
+ * @param suffixes the suffixes
+ * @throws IllegalArgumentException for null suffixes
+ */
+ public SuffixesExcludeFilter(Collection<String> suffixes)
+ {
+ if (suffixes == null)
+ throw new IllegalArgumentException("Null suffixes");
+ for (String suffix : suffixes)
+ {
+ if (suffix == null)
+ throw new IllegalArgumentException("Null suffix in " + suffixes);
+ }
+ this.suffixes = suffixes;
+ }
+
+ public boolean accepts(VirtualFile file)
+ {
+ String name = file.getName();
+ for(String suffix : suffixes)
+ {
+ if (name.endsWith(suffix))
+ return false;
+ }
+ return true;
+ }
+}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java 2009-08-04 22:20:47 UTC (rev 91986)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java 2009-08-04 22:24:08 UTC (rev 91987)
@@ -52,7 +52,7 @@
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VisitorAttributes;
-import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter;
+import org.jboss.virtual.util.SuffixMatchFilter;
/**
* Tests of the VFS implementation
@@ -624,7 +624,7 @@
expectedClasses.add(outer.getPathName() + "/jar1-filesonly.jar/org/jboss/test/vfs/support/jar1/ClassInJar1$InnerClass.class");
expectedClasses.add(outer.getPathName() + "/jar2.jar/org/jboss/test/vfs/support/jar2/ClassInJar2.class");
expectedClasses.add(outer.getPathName() + "/org/jboss/test/vfs/support/CommonClass.class");
- super.enableTrace("org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter");
+ super.enableTrace("org.jboss.virtual.util.SuffixMatchFilter");
SuffixMatchFilter classVisitor = new SuffixMatchFilter(".class", VisitorAttributes.RECURSE);
List<VirtualFile> classes = outer.getChildren(classVisitor);
int count = 0;
@@ -663,7 +663,7 @@
expectedClasses.add(rootURL.getPath() + "/jar2.jar/org/jboss/test/vfs/support/jar2/ClassInJar2.class");
// FIXME: .class files are not being copied from the resources directory
expectedClasses.add(rootURL.getPath() + "/org/jboss/test/vfs/support/CommonClass.class");
- super.enableTrace("org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter");
+ super.enableTrace("org.jboss.virtual.util.SuffixMatchFilter");
SuffixMatchFilter classVisitor = new SuffixMatchFilter(".class", VisitorAttributes.RECURSE);
List<VirtualFile> classes = testdir.getChildren(classVisitor);
int count = 0;
@@ -699,7 +699,7 @@
HashSet<String> expectedClasses = new HashSet<String>();
expectedClasses.add(rootURL.getPath() + "/org/jboss/test/vfs/support/jar1/ClassInJar1.class");
expectedClasses.add(rootURL.getPath() + "/org/jboss/test/vfs/support/jar1/ClassInJar1$InnerClass.class");
- super.enableTrace("org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter");
+ super.enableTrace("org.jboss.virtual.util.SuffixMatchFilter");
SuffixMatchFilter classVisitor = new SuffixMatchFilter(".class", VisitorAttributes.RECURSE);
List<VirtualFile> classes = testdir.getChildren(classVisitor);
int count = 0;
More information about the jboss-cvs-commits
mailing list