ITKv4 CPDProposal: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
 
(One intermediate revision by the same user not shown)
Line 19: Line 19:


* So you first need to copy all the ITK sources and change the extension of all *.txx files to .cc
* So you first need to copy all the ITK sources and change the extension of all *.txx files to .cc
* Then first replace existing /path/to/pmd/bin/cpd.sh by this one
* Then first replace existing /path/to/pmd/bin/cpd.sh by the following:
 
<pre>
#!/bin/sh
 
## This will work in the majority of shells out there...
 
## This will parse a directory named on the command line and produce a
## cut and paste report for c++ files in that directory (or 'c', if you
## set the environment variable LANGUAGE to 'c').
 
## Note that other rules are only for Java code not C source.
 
## If you run into java.lang.OutOfMemoryError, try setting the environment
## variable HEAPSIZE to e.g. 1024m
 
DIRECTORY=$1
 
if [ -z "$1" ]; then
script=`basename $0`
echo "Usage:"
echo " $script <directory>"
exit 1
fi
 
# OS specific support.  $var _must_ be set to either true or false.
cygwin=false;
case "`uname`" in
  CYGWIN*) cygwin=true ;;
esac
 
SCRIPT_DIR=`dirname $0`
CWD="$PWD"
 
cd "$SCRIPT_DIR/../lib"
LIB_DIR=`pwd -P`
 
# If cygwin, convert to Unix form before manipulating
if $cygwin ; then
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
 
classpath=$CLASSPATH
 
build_dir="$SCRIPT_DIR/../build"
 
if [ -d "$build_dir" ]; then
cd "$build_dir"
build_dir=`pwd -P`
classpath=$classpath:$build_dir
fi
 
cd "$CWD"
 
for jarfile in `ls $LIB_DIR/*.jar`; do
classpath=$classpath:$jarfile
done
 
HEAPSIZE=${HEAPSIZE:-1024m}
LANGUAGE=${LANGUAGE:-cpp}
MINIMUM_TOKENS=${MINIMUM_TOKENS:-$2}
 
case "$HEAPSIZE" in
[1-9]*[mgMG]) HEAPSIZE=-Xmx$HEAPSIZE ;;
'') ;;
*) echo "HEAPSIZE '$HEAPSIZE' unknown (try: 512m)"
  exit 1
esac
 
case "$LANGUAGE" in
c|cpp|fortran|java|jsp|php|ruby) ;;
*) echo "Language '$LANGUAGE' unknown (try: c, cpp, fortran, java, jsp, php, ruby)"
  exit 1
esac
 
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
  classpath=`cygpath --path --windows "$classpath"`
  DIRECTORY=`cygpath --windows "$DIRECTORY"`
fi
 
java $HEAPSIZE -cp $classpath net.sourceforge.pmd.cpd.CPD --minimum-tokens $MINIMUM_TOKENS --files $DIRECTORY --language $LANGUAGE --format net.sourceforge.pmd.cpd.XMLRenderer
</pre>
* Then run
 
<pre>
$ cd /path/to/pmd/bin
$ cd /path/to/pmd/bin
$ ./cpd.sh /path/to/Insight/Code 500
$ ./cpd.sh /path/to/Insight/Code 500
</pre>


=== Long term solution ===
=== Long term solution ===
Line 27: Line 118:
* Modify CPPLanguage.java in order to make CPD work with txx file.
* Modify CPPLanguage.java in order to make CPD work with txx file.
* Debug see http://sourceforge.net/projects/pmd/forums/forum/188192/topic/3778230
* Debug see http://sourceforge.net/projects/pmd/forums/forum/188192/topic/3778230
== Results ==
* minimumtokencount=500 [[File:ITKCodeToken500.xml]]
* minimumtokencount=200 [[File:ITKCodeToken200.xml]]
* minimumtokencount=100 [[File:ITKCodeToken100.xml]]

Latest revision as of 18:41, 27 July 2010

CPD

What is CPD?

  • CPD aims to detect code duplication.
  • CPD is part of PMD project

http://pmd.sourceforge.net/cpd.html

Download CPD

http://sourceforge.net/projects/pmd/files/

How to use CPD on ITK Code?

  • Currently, CPD only support the following extensions for c++ files ".h", ".c", ".cpp", ".cxx", ".cc", ".C".

Short term solution

  • So you first need to copy all the ITK sources and change the extension of all *.txx files to .cc
  • Then first replace existing /path/to/pmd/bin/cpd.sh by the following:
#!/bin/sh

## This will work in the majority of shells out there...

## This will parse a directory named on the command line and produce a
## cut and paste report for c++ files in that directory (or 'c', if you
## set the environment variable LANGUAGE to 'c').

## Note that other rules are only for Java code not C source.

## If you run into java.lang.OutOfMemoryError, try setting the environment
## variable HEAPSIZE to e.g. 1024m

DIRECTORY=$1

if [ -z "$1" ]; then
				script=`basename $0`
				echo "Usage:"
				echo " $script <directory>"
				exit 1
fi

# OS specific support.  $var _must_ be set to either true or false.
cygwin=false;
case "`uname`" in
  CYGWIN*) cygwin=true ;;
esac

SCRIPT_DIR=`dirname $0`
CWD="$PWD"

cd "$SCRIPT_DIR/../lib"
LIB_DIR=`pwd -P`

# If cygwin, convert to Unix form before manipulating
if $cygwin ; then
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
 [ -n "$CLASSPATH" ] &&
    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

classpath=$CLASSPATH

build_dir="$SCRIPT_DIR/../build"

if [ -d "$build_dir" ]; then
				cd "$build_dir"
				build_dir=`pwd -P`
				classpath=$classpath:$build_dir
fi

cd "$CWD"

for jarfile in `ls $LIB_DIR/*.jar`; do
				classpath=$classpath:$jarfile
done

HEAPSIZE=${HEAPSIZE:-1024m}
LANGUAGE=${LANGUAGE:-cpp}
MINIMUM_TOKENS=${MINIMUM_TOKENS:-$2}

case "$HEAPSIZE" in
[1-9]*[mgMG]) HEAPSIZE=-Xmx$HEAPSIZE ;;
'') ;;
*) echo "HEAPSIZE '$HEAPSIZE' unknown (try: 512m)"
   exit 1
esac

case "$LANGUAGE" in
c|cpp|fortran|java|jsp|php|ruby) ;;
*) echo "Language '$LANGUAGE' unknown (try: c, cpp, fortran, java, jsp, php, ruby)"
   exit 1
esac

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
  classpath=`cygpath --path --windows "$classpath"`
  DIRECTORY=`cygpath --windows "$DIRECTORY"`
fi

java $HEAPSIZE -cp $classpath net.sourceforge.pmd.cpd.CPD --minimum-tokens $MINIMUM_TOKENS --files $DIRECTORY --language $LANGUAGE --format net.sourceforge.pmd.cpd.XMLRenderer
  • Then run
$ cd /path/to/pmd/bin
$ ./cpd.sh /path/to/Insight/Code 500

Long term solution

Results