Page 1 of 1

Project / Solution / Modules statistics

PostPosted: Sat Mar 01, 2014 7:21 pm
by deezzub
Is it possible to get statistics about a Servoy project, solution and module like lines of code? Is there a "metrics" plugin, that I can use for this?

Re: Project / Solution / Modules statistics

PostPosted: Sat Mar 01, 2014 7:30 pm
by ROCLASI
Hi Sebastian,

I dunno about an Eclipse plugin but you could use the UNIX commandline for this.
Just navigate to your workspace and inside this workspace you run the following command:
Code: Select all
find . -name '*.js' | xargs wc -l

That will give you the amount of lines per .js file and total lines at the end

Hope this helps.

Re: Project / Solution / Modules statistics

PostPosted: Sat Mar 01, 2014 8:09 pm
by deezzub
ROCLASI wrote:Just navigate to your workspace and inside this workspace you run the following command:
Code: Select all
find . -name '*.js' | xargs wc -l

That will give you the amount of lines per .js file and total lines at the end


Hi Robert, thanks that helps, really good. :) I improved it a little bit for my needs. ;)

Code: Select all
find . -name '*.js' | xargs wc -l | sort -k1n


If anyone knows about a good Eclipse plugin, please let me know.

Re: Project / Solution / Modules statistics

PostPosted: Sat Mar 01, 2014 8:55 pm
by ROCLASI
Nice!
Although I don't see exactly the need for the -k1 flag.

Also if you don't want to see the files with no lines at all you can use the following command:
Code: Select all
find . -name '*.js' | xargs wc -l | awk -F ' ' {'if ($1 != 0) print$0'} | sort -n


As for Eclipse metric plugins, the ones I can find are very Java focused. I don't know how well they work with Servoy/Javascript projects/code.
Like this one: http://sourceforge.net/projects/metrics2/

Hope this gets you further.

Re: Project / Solution / Modules statistics

PostPosted: Sun Mar 02, 2014 4:47 pm
by deezzub
ROCLASI wrote:Also if you don't want to see the files with no lines at all you can use the following command:
Code: Select all
find . -name '*.js' | xargs wc -l | awk -F ' ' {'if ($1 != 0) print$0'} | sort -n


I get different counts for the line numbers for the same files. Do you know why? How can I get the sorted line numbers, only for the solution / project folders?

ROCLASI wrote:As for Eclipse metric plugins, the ones I can find are very Java focused. I don't know how well they work with Servoy/Javascript projects/code.
Like this one: http://sourceforge.net/projects/metrics2/


I already tried that plugin. It seems, that it does not work with Serclipse.

Re: Project / Solution / Modules statistics

PostPosted: Sun Mar 02, 2014 6:27 pm
by ROCLASI
Hi Sebastian,

deezzub wrote:I get different counts for the line numbers for the same files. Do you know why?

What do you mean ? You see different numbers each time you run it ? Or do you see the same file twice (or more) in the result list ?
I don't see either in my environment. Are you sure they are the same files ?

deezzub wrote:How can I get the sorted line numbers, only for the solution / project folders

You can sort over multiple fields by using the -k argument more than once. In this case I made it use the slash (-t'/') as the separator instead of the default space so I can make it sort on the project name first (-k2,2), then the line count (-k1,1) and then any subdirectory or file inside the project (-k3,3) like so:
Code: Select all
find . -name '*.js' | xargs wc -l | awk -F ' ' {'if ($1 != 0) print$0'} | sort -r -t'/' -k2,2 -k1,1 -k3,3

I added the -r so the biggest files show first in each project. Sadly it also means that the project name sort is reversed so project names starting with A will be at the bottom. I haven't found a way yet to set the sort order per field.

Hope this helps.

Re: Project / Solution / Modules statistics

PostPosted: Sun Mar 02, 2014 9:56 pm
by ROCLASI
Hi Sebastian,

deezzub wrote:How can I get the sorted line numbers, only for the solution / project folders


After rereading your question I see that you actually wanted to get the totals per project itself, not per file.
That is a bit harder to do with a oneliner. I came up with the following shell script:
Code: Select all
#!/bin/bash
# Count Lines Of Code (in your Servoy workspace)
# Written by Robert Ivens

# Get passed argument and place it in a variable
Wrkspc=$1

# Check if there was an argument passed
if [ -z "$1" ]
then
        # No path given, lets assume the current one
        Wrkspc=$(pwd)
fi

# Get all directories in the workspace and loop through them
for Dir in $(find $Wrkspc/* -maxdepth 0 -type d );
do
        # Get the foldername only
        FolderName=$(basename $Dir)

        # Get the line count from all .js files inside this directory
        Count=$(( find $Dir -name '*.js' -print0 | xargs -0 cat ) | wc -l)

        # Print the Count and Foldername using a format
        printf "%10s %-100s\n" $Count $FolderName
done


Just run it inside your workspace or pass the path of your workspace as an argument.
The result list is unsorted but you can just pipe it into the sort command.

Hope this helps.