Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out if resource is used

I am looking for an efficient way to find out if a resource (mostly a drawable) is used in Java or in an XML file.

The problem is, that on my current project the drawables are changed often and now I have some drawables, which might never be used.

Is there a tool/way to find those unused drawables without search each filename in the whole project?

like image 679
WarrenFaith Avatar asked Sep 21 '10 11:09

WarrenFaith


People also ask

How to find the resource usage of a user in Linux?

There are a lot of options/commands available in Linux to find the same. Normally, we use the “ps” and “top” commands. Separating or sorting Unix user with their own resource usage is quit hard for a beginner.

How do I read data from an existing resource?

You can set the value to true if you need to create the resource; otherwise, if you just want to read data from an existing resource, you can set it to false. Next up, get data about the resource using the ternary operator supplying it to count, next do the same for creating the resource:

What does'the requested resource is in use'mean?

- Malware and viruses are one potential cause for the 'The requested resource is in use' error; if you're running antivirus software already, try removing any virus definitions from your system before attempting to restart.

How do I get more information about resources in a server?

In the Object Explorer, Right-click the Server name at the top and choose Reports. Some of the reports that are used most often are available directly off the Reports Menu while others are available from Standard Reports. Let’s look at some of the options we have available to get more resource information.


2 Answers

I wrote a tool based on python to solve this problem. As this is not the place to share it directly, I created a project page which is now offline.

UPDATE:
The development has stopped since Lint can do the same and is already included in the Android SDK.

like image 186
WarrenFaith Avatar answered Sep 26 '22 10:09

WarrenFaith


I just wrote this bash script just for fun:

PROJECT="/path/to/the/project" for file in $(ls $PROJECT/res/drawable -l | awk '{ print $8}' | sed 's/\..\+//g'); do count=0; for SRCFILE in `find $PROJECT -name "*.xml" -print 2> /dev/null`; do let "count+=$(grep -c @drawable/$file $SRCFILE)"; done; for SRCFILE in `find $PROJECT -name "*.java" -print 2> /dev/null`; do let "count+=$(grep -c R.drawable.$file $SRCFILE)"; done; if [ $count -lt 1 ]; then echo -e "\e[0;31m$file\e[0m not used"; else echo -e "\e[0;32m$file\e[0m used"; fi; done;  

It works fine, though I'm a bash newbie so it can be highly improved:

alt text

It searches drawables resources only (@drawable/name on the XML files, and R.drawable.name on the Java files).

By the way, I didn't know that boxscore and calendarlogos were not being used in my project. Another funny fact is that most users don't use Linux, so this won't help too many people.


For MacOs would be something like this:

PROJECT="/path/to/the/project" for file in $(ls -l $PROJECT/res/drawable | awk '{ print $9}' | sed 's/\..\+//g'); do count=0; for SRCFILE in `find $PROJECT -name "*.xml" -print 2> /dev/null`; do let "count+=$(grep -c @drawable/$file $SRCFILE)"; done; for SRCFILE in `find $PROJECT -name "*.java" -print 2> /dev/null`; do let "count+=$(grep -c R.drawable.$file $SRCFILE)"; done; if [ $count -lt 1 ]; then echo -e "$file not used"; else echo -e "$file used"; fi; done;  
like image 36
Cristian Avatar answered Sep 23 '22 10:09

Cristian