Suraj Acharya writes:
> I made the following changes to allow me to use wildcards in the
> classpath and sourcepath
> variables. The file expansion included with jde which expands
> specially named directories (for example "lib") didn't do the job for
> me because:
Thanks, Suraj. I will consider your contribution for inclusion in the
next release.
Paul
>
> 1) My project has a bunch of library directories under a common root:
> extensions/
> foo/lib/{a,b,c,d}.jar
> bar/lib/{e,f}.jar
> baz/lib/{x,y,z}.jar
> ....
>
> Without the wildcard expansion my classpath looked like this :
> ("extensions/foo/lib", "extensions/bar/lib", "extensions/baz/lib",
> ...), with the wildcards I can say ("extensions/*/lib/*.jar")
>
> 2) Jde's file expansion only worked on jde-global-classpath
>
>
> Suraj
>
> (defun jde-search-src-dirs (class)
> "Return the directory containing the source file for a class.
> CLASS is the fully qualified name of the class."
> (let ((file (concat
> (jde-parse-get-unqualified-name class)
> ".java"))
> (package (jde-parse-get-package-from-name class)))
> (catch 'found
> - (loop for dir in jde-sourcepath do
> + (loop for dir in (jde-expand-wildcards-and-normalize jde-sourcepath) do
> (progn
> - (setq
> - dir
> - (jde-normalize-path dir 'jde-sourcepath))
> (if (file-exists-p (expand-file-name file dir))
> (throw 'found dir)
> (let* ((pkg-path (subst-char-in-string ?. ?/ package))
> (pkg-dir (expand-file-name pkg-path dir))
> (file-path (expand-file-name file pkg-dir)))
> (if (file-exists-p file-path)
> (throw 'found pkg-dir)))))))))
>
>
>
>
> (defun jde-open-get-path-prefix-list ()
> "Builds all the path prefixes used to search for the full qualified
> source file. For this method to work `jde-sourcepath' needs to be set."
> (if jde-sourcepath
> - (append (jde-normalize-paths jde-sourcepath 'jde-sourcepath))
> + (append (jde-expand-wildcards-and-normalize jde-sourcepath
> 'jde-sourcepath))
> (error (concat "For this method to work the variable "
> "jde-sourcepath needs to be set"))))
>
> (defun jde-expand-classpath (classpath &optional symbol)
> "If `jde-expand-classpath-p' is nonnil, replaces paths to
> directories that match `jde-lib-directory-names' with paths to jar or
> zip files in those directories, excepting those specified by
> `jde-lib-excluded-file-names'. This function assumes that the
> existing paths are already normalized."
> - (if jde-expand-classpath-p
> - (let (paths)
> - (loop for path in classpath do
> - (if (and
> - (file-exists-p path)
> - (file-directory-p path)
> - (let ((dir-name (file-name-nondirectory path)))
> - (member-if
> - (lambda (lib-name)
> - (string-match lib-name dir-name))
> - jde-lib-directory-names)))
> - (progn
> - (setq paths
> - (append
> - paths
> - (jde-expand-directory
> - path
> - "\\.jar$"
> - jde-lib-excluded-file-names
> - symbol)))
> - (setq paths
> - (append
> - paths
> - (jde-expand-directory
> - path
> - "\\.zip$"
> - jde-lib-excluded-file-names
> - symbol))))
> - (setq paths (append paths (list path)))))
> - paths)
> - classpath))
> + (if (or jde-expand-classpath-p jde-expand-wildcards-in-paths-p)
> + (mapcan (lambda (path)
> + (cond
> + ((and jde-expand-classpath-p (file-exists-p path)
> + (file-directory-p path)
> + (let ((dir-name (file-name-nondirectory path)))
> + (member-if
> + (lambda (lib-name)
> + (string-match lib-name dir-name))
> + jde-lib-directory-names)))
> + (append
> + (jde-expand-directory
> + path
> + "\\.jar$"
> + jde-lib-excluded-file-names
> + symbol)
> + (jde-expand-directory
> + path
> + "\\.zip$"
> + jde-lib-excluded-file-names
> + symbol)))
> + (jde-expand-wildcards-in-paths-p
> + (let ((exp-paths (file-expand-wildcards path)))
> + (if exp-paths exp-paths (list path))))
> + (t (list path))))
> + classpath)
> + classpath))
>
> +(defcustom jde-expand-wildcards-in-paths-p t
> + "Expands entries in the 'jde-global-classpath and 'jde-sourcepath
> which are wildcards patterns into a list of matching files or
> directories which are interpolated into classpath or sourcepath list.
> This expansion is done in the functions 'jde-open-get-path-prefix-list
> and 'jde-search-src-dirs for 'jde-sourcepath and in
> 'jde-normalize-paths for 'jde-global-classpath."
> + :group 'jde-project
> + :type 'boolean)
> +
> +(defun jde-expand-wildcards-and-normalize (path &optional symbol)
> + "Expand any entries with wildcard patterns in path and interpolate
> them into the result"
> + (if jde-expand-wildcards-in-paths-p
> + (mapcan
> + (lambda (path)
> + (let ((exp-paths (file-expand-wildcards path)))
> + (if exp-paths exp-paths (list path))))
> + (jde-normalize-paths path symbol))
> + (jde-normalize-paths path symbol)
> + ))