Script to Find all Eclipse Projects and Workspaces Under a Directory

Introduction

When working on many different projects or experiments one often opens a new Eclipse workspace to reduce the clutter in the IDE.  This can sometime lead to misplaced projects.   To resolve this problem here is a script that will search for all the workspaces and projects below the current working directory.

 

Script

Eclipse workspaces are identified through their associated .metadata directory. 

The directory structure is:

./path_to_workspace/.metadata
./path_to_workspace/project1
./path_to_workspace/project2
etc...

We utilize the shell command find to locate the .metadata directories and use Awk to parse and display the results.

The find method will find all the files/directories below the current directory ‘.’ with the name .metadata.   

This information is piped ‘|’ through to an Awk script that does the parsing/display.  The elements of interest in the Awk script are:

  • FS – assign the field separator which in our case will be a slash ‘/’
  • NF – number of fields with respect
  • system – allows us to call out to the ls system command

 

find . -name ".metadata" |
awk '
BEGIN {
	FS="/";
}
{
	print "-----------------------------------------------";
	print "Workspace: "  $(NF-1) ;
	workspaceDirectory = ""
	seperator = "/"
	for(i = 1; i < NF; i ++)
		workspaceDirectory = workspaceDirectory $(i) seperator;
	print "Directory: " workspaceDirectory;
	print "-----------------------------------------------";
	system("ls "'workspaceDirectory');
	print "";

}
'

 

Example Output

 

-----------------------------------------------
Workspace: phonegap
Directory: ./workspaces/phonegap/
-----------------------------------------------
Dom
webflow

-----------------------------------------------
Workspace: workspace
Directory: ./workspace/
-----------------------------------------------
Angler
Angular
Boot
JAXB
JPA
RemoteSystemsTempFiles
Rest
Restful
Servers
ssl

Summary

This is a very simple utility and it returns the directory listing of the Eclipse workspace’s directory so if there are any files/directories that are in that workspace directory they will be listed along with the projects.  The script can be improved but it represents the 90% solution.

About The Author

David Sells is a computer consultant in Toronto, Ontario who specializes in Java Enterprise Development. He has  provided innovative solutions for clients including: IBM, Goldman Sachs, Merrill Lynch and Deutsche Bank.

He also holds the following certifications:

  • Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5 (2009)
  • Sun Certified Web Component Developer
  • Sun Certified Java Programmer.

Contact: david@persistentdesigns.com

 

 

 

Comments are closed.