diff options
Diffstat (limited to 'bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/util/Util.java')
-rw-r--r-- | bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/util/Util.java | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/util/Util.java b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/util/Util.java index c02abbc4..353ef3e1 100644 --- a/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/util/Util.java +++ b/bundles/org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/util/Util.java @@ -20,6 +20,9 @@ import java.io.UnsupportedEncodingException; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.wst.jsdt.core.IIncludePathEntry; import org.eclipse.wst.jsdt.core.ast.IExpression; import org.eclipse.wst.jsdt.core.ast.IFieldReference; @@ -112,7 +115,7 @@ public class Util implements SuffixConstants { * If a length is specified (ie. if length != -1), only length bytes * are returned. Otherwise all bytes in the stream are returned. * Note this doesn't close the stream. - * @throws IOException if a problem occurred reading the stream. + * @throws IOException if a problem occured reading the stream. */ public static byte[] getInputStreamAsByteArray(InputStream stream, int length) throws IOException { @@ -309,12 +312,22 @@ public class Util implements SuffixConstants { public final static boolean isArchiveFileName(String name) { int nameLength = name == null ? 0 : name.length(); int suffixLength = SUFFIX_ZIP.length; + if (nameLength == suffixLength) { + for (int i = 0; i < suffixLength; i++) { + char c = name.charAt(nameLength - i - 1); + int suffixIndex = suffixLength - i - 1; + if (c != SUFFIX_zip[suffixIndex] && c != SUFFIX_ZIP[suffixIndex]) + break; + } + } + + suffixLength = SUFFIX_JAR.length; if (nameLength < suffixLength) return false; for (int i = 0; i < suffixLength; i++) { char c = name.charAt(nameLength - i - 1); int suffixIndex = suffixLength - i - 1; - if (c != SUFFIX_zip[suffixIndex] && c != SUFFIX_ZIP[suffixIndex]) return false; + if (c != SUFFIX_jar[suffixIndex] && c != SUFFIX_JAR[suffixIndex]) return false; } return true; } @@ -334,7 +347,7 @@ public class Util implements SuffixConstants { return true; } /** - * Returns true iff str.toLowerCase().endsWith(".js") + * Returns true iff str.toLowerCase().endsWith(".class") * implementation is not creating extra strings. */ public final static boolean isClassFileName(String name) { @@ -392,7 +405,7 @@ public class Util implements SuffixConstants { } } } - if (EclipseUtil.pathMatch(path, folderPattern)) { + if (pathMatch(path, folderPattern)) { break inclusionCheck; } } @@ -403,7 +416,7 @@ public class Util implements SuffixConstants { } if (exclusionPatterns != null) { for (int i = 0, length = exclusionPatterns.length; i < length; i++) { - if (EclipseUtil.pathMatch(path, exclusionPatterns[i])) { + if (pathMatch(path, exclusionPatterns[i])) { return true; } } @@ -426,7 +439,7 @@ public class Util implements SuffixConstants { return true; } /** - * Returns true iff str.toLowerCase().endsWith(".js") + * Returns true if str.toLowerCase().endsWith(".js") * implementation is not creating extra strings. */ public final static boolean isJavaFileName(String name) { @@ -550,6 +563,7 @@ public class Util implements SuffixConstants { } else { currExpr = null; + selector = null; } } else if (currExpr instanceof IThisReference) { @@ -568,4 +582,53 @@ public class Util implements SuffixConstants { return selector; } + + /** + * <p>Determine if the given path is a match for the given match path. If one path is + * file system absolute and another is relative or absolute to the workspace then the + * path that is not file system absolute will be converted to file system absolute. + * The matching pattern can contain *, **, or ? wild cards.</p> + * + * @param pathChars check to see if this path matches the <code>matchpathChars</code> + * @param matchPathChars check to see if the given <code>pathChars</code> match this pattern + * @return <code>true</code> if the given <code>pathChars</code> match the given given + * <code>matchPathChars<code>, <code>false</code> otherwise. + */ + public static boolean pathMatch(char[] pathChars, char[] matchPathChars) { + IPath path = new Path(new String(pathChars)); + IPath matchPath = new Path(new String(matchPathChars)); + + //determine if either path is file system absolute + IPath fileSystemWorkspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation(); + boolean isPathFileSystemAbsolute = fileSystemWorkspacePath.isPrefixOf(path); + boolean isMatchPathFileSystemAbsolute = fileSystemWorkspacePath.isPrefixOf(matchPath); + + /* if the two paths are not both file system absolute or both workspace absolute + * then transform the none file system absolute path to file system absolute + */ + if((!isPathFileSystemAbsolute && isMatchPathFileSystemAbsolute) || (isPathFileSystemAbsolute && !isMatchPathFileSystemAbsolute)){ + if(!isPathFileSystemAbsolute) { + boolean hadTrailingSeparator = path.hasTrailingSeparator(); + path = ResourcesPlugin.getWorkspace().getRoot().getFile(path).getLocation(); + if(hadTrailingSeparator) { + path = path.addTrailingSeparator(); + } + } + + if(!isMatchPathFileSystemAbsolute) { + boolean hadTrailingSeparator = matchPath.hasTrailingSeparator(); + matchPath = ResourcesPlugin.getWorkspace().getRoot().getFile(matchPath).getLocation(); + if(hadTrailingSeparator) { + matchPath = matchPath.addTrailingSeparator(); + } + } + } + + //be sure both are absolute now (fixes 'project1\file.js' to '\project1\file.js') + path = path.makeAbsolute(); + matchPath = matchPath.makeAbsolute(); + + return CharOperation.pathMatch(matchPath.toPortableString().toCharArray(), path.toPortableString().toCharArray(), true, IPath.SEPARATOR); + } + } |