Show all Java imports given a root package

February 26 2009

here’s a simple shell script to collect all imports in Java source code files, given a root package.


find src -iname *.java \
| xargs grep -i "import another.project" \
| cut -d " " -f 2 | cut -d "." -f 1-3 \
| sort | uniq

results look like this:


another.project.domain
another.project.presentation
another.project.util

change “1-3” to reflect how deep the filter should be.

thanx to Andrea for showing me cut command. i would have used my belowed write-only awk!

Advertisements

One Response to “Show all Java imports given a root package”

  1. fabiobeta Says:

    Bellissimo! :)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: