diff --git a/simian/.cvsignore b/simian/.cvsignore new file mode 100644 index 00000000..4e1b955e --- /dev/null +++ b/simian/.cvsignore @@ -0,0 +1,2 @@ +*.log +target diff --git a/simian/maven.xml b/simian/maven.xml new file mode 100644 index 00000000..defc11d9 --- /dev/null +++ b/simian/maven.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/simian/plugin.jelly b/simian/plugin.jelly new file mode 100644 index 00000000..5467ed6e --- /dev/null +++ b/simian/plugin.jelly @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Simian Report + + +
+

${simLog.copyright1}

+

${simLog.copyright2}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Similarity treshold (lines)${maven.simian.linecount}
Total number of duplicate lines${simLog.totalDuplicateLineCount}
Total number of duplicate blocks${simLog.blockCount}
Total number of files with duplicates${simLog.fileWithDuplicateCount}
Total number of processed lines${simLog.loc}
Total number of processed files${simLog.fileParseCount}
Scan time${simLog.time}
+
+ +
+ + + + + ${duplicationArea.className}(${duplicationArea.startLine}-${duplicationArea.endLine})
+
+
+
+
+ +
+ +
+
+
+
\ No newline at end of file diff --git a/simian/plugin.properties b/simian/plugin.properties new file mode 100644 index 00000000..aa809ddb --- /dev/null +++ b/simian/plugin.properties @@ -0,0 +1,7 @@ +maven.simian.linecount = 10 +maven.simian.failonduplication = false +maven.simian.ignorestrings = false +maven.simian.ignorestringcase = false +maven.simian.ignorenumbers = false +maven.simian.ignoresubtypenames = false +maven.simian.ignoremodifiers = false diff --git a/simian/project.properties b/simian/project.properties new file mode 100644 index 00000000..661f1b70 --- /dev/null +++ b/simian/project.properties @@ -0,0 +1,7 @@ +##################################################### +# Properties related to project-site +##################################################### +maven.xdoc.date=left +maven.xdoc.version=${pom.currentVersion} +maven.linkcheck.enable = true +maven.javadoc.links = http://java.sun.com/j2se/1.4.1/docs/api/ diff --git a/simian/project.xml b/simian/project.xml new file mode 100644 index 00000000..55caaa84 --- /dev/null +++ b/simian/project.xml @@ -0,0 +1,108 @@ + + + ${basedir}/../project.xml + maven-simian-plugin + Simian + 1.1 + http://maven.apache.org/reference/plugins/simian/ + + /www/maven.apache.org/reference/plugins/simian/ + + org.apache.maven.simian + + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/simian/ + http://cvs.apache.org/viewcvs/maven/src/plugins-build/simian/ + + + + + redhill + simian + 1.9.1 + http://www.redhillconsulting.com.au/products/simian/ + + + + ant + 1.5.1 + http://ant.apache.org/ + + + + commons-jelly + SNAPSHOT + http://jakarta.apache.org/commons/jelly/ + + + + commons-logging + 1.0.1 + http://jakarta.apache.org/commons/logging/ + + + + + + Simon Harris + + simon@redhillconsulting.com.au + RedHill Consulting + + Simian Core + + + + + Aslak Hellesoy + + aslak@thoughtworks.net + ThoughtWorks + + Maven Plugin + + + + + dIon gillard + dIon + dion@apache.org + ASF + + Maven Plugin + + + + + + + + Maurice Montgénie + + maurice@maguyane.net + CGSS Guyane + + Maven Plugin + + + + + + + + **/*TestCase.java + + + + + + + maven-simian-plugin + maven-changes-plugin + maven-license-plugin + maven-jxr-plugin + maven-javadoc-plugin + maven-clover-plugin + + + diff --git a/simian/src/main/org/apache/maven/simian/Duplication.java b/simian/src/main/org/apache/maven/simian/Duplication.java new file mode 100644 index 00000000..7b3122b2 --- /dev/null +++ b/simian/src/main/org/apache/maven/simian/Duplication.java @@ -0,0 +1,88 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.util.List; +import java.util.ArrayList; + +/** + * Represents a duplication. Has two or more DuplicationAreas. + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class Duplication { + int lineCount; + + private List duplicationAreas = new ArrayList(); + + public Duplication(int lineCount) { + this.lineCount = lineCount; + } + + public void addDuplicationArea(DuplicationArea duplicationArea) { + duplicationAreas.add(duplicationArea); + } + + public int getLineCount() { + return lineCount; + } + + public DuplicationArea[] getDuplicationAreas() { + return (DuplicationArea[]) duplicationAreas.toArray(new DuplicationArea[duplicationAreas.size()]); + } +} diff --git a/simian/src/main/org/apache/maven/simian/DuplicationArea.java b/simian/src/main/org/apache/maven/simian/DuplicationArea.java new file mode 100644 index 00000000..b6fd9fdc --- /dev/null +++ b/simian/src/main/org/apache/maven/simian/DuplicationArea.java @@ -0,0 +1,91 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +/** + * Represents one area in a file containing dupe code. + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class DuplicationArea { + private final int startLine; + private final int endLine; + private final String pathToClass; + + public DuplicationArea(int startLine, int endLine, String pathToClass) { + this.startLine = startLine; + this.endLine = endLine; + this.pathToClass = pathToClass; + } + + public int getStartLine() { + return startLine; + } + + public int getEndLine() { + return endLine; + } + + public String getPathToClass() { + return pathToClass; + } + + public String getClassName() { + return getPathToClass().replace('/', '.'); + } +} diff --git a/simian/src/main/org/apache/maven/simian/FileSimianTask.java b/simian/src/main/org/apache/maven/simian/FileSimianTask.java new file mode 100644 index 00000000..e90b9985 --- /dev/null +++ b/simian/src/main/org/apache/maven/simian/FileSimianTask.java @@ -0,0 +1,94 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import au.com.redhillconsulting.simian.b; +import au.com.redhillconsulting.simian.SimianTask; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.util.Iterator; +import java.util.List; +import java.util.LinkedList; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Task; + +/** + * Simian Task that writes the output to a file. + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class FileSimianTask extends SimianTask { + + public void setOutput(File output) { + output.getParentFile().mkdirs(); + try { + setOutput(new FileOutputStream(output)); + } catch (FileNotFoundException e) { + throw new BuildException("Couldn't set output to " + output.getAbsolutePath(), e); + } + } +} diff --git a/simian/src/main/org/apache/maven/simian/SimianLog.java b/simian/src/main/org/apache/maven/simian/SimianLog.java new file mode 100644 index 00000000..dff14f5d --- /dev/null +++ b/simian/src/main/org/apache/maven/simian/SimianLog.java @@ -0,0 +1,251 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.apache.commons.jelly.JellyContext; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +/** + * This class represents a model of a Simian log file. + * An instance of this class will be passed to Jelly to generate + * an xdoc document. Finally, this xdoc file is weaved into the + * Maven documentation, with links pointing to the JXR sources. + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class SimianLog { + private File logFile; + private JellyContext jellyContext; + + private Duplication[] duplications; + private String copyright1; + private String copyright2; + private int totalDuplicateLineCount; + private int loc; + private int fileParseCount; + private String time; + private int blockCount; + private int fileWithDuplicateCount; + private String sourceDirectory; + private String unitTestSourceDirectory; + + public void setLogFile(File logFile) { + this.logFile = logFile; + } + + public void setJellyContext(JellyContext jellyContext) { + this.jellyContext = jellyContext; + } + + public void setSourceDirectory(String sourceDirectory) { + this.sourceDirectory = new File(sourceDirectory).getAbsolutePath(); + } + + public void setUnitTestSourceDirectory(String unitTestSourceDirectory) { + this.unitTestSourceDirectory = new File(unitTestSourceDirectory).getAbsolutePath(); + } + + public Duplication[] getDuplications() { + return duplications; + } + + public String getCopyright1() { + return copyright1; + } + + public String getCopyright2() { + return copyright2; + } + + private String linkify(String s) { + StringBuffer sb = new StringBuffer(); + StringTokenizer st = new StringTokenizer(s, " ", true); + while (st.hasMoreTokens()) { + String token = st.nextToken(); + if(token.startsWith("http://")) { + token = "" + token + ""; + } + sb.append(token); + } + return sb.toString(); + } + + public int getTotalDuplicateLineCount() { + return totalDuplicateLineCount; + } + + public int getLoc() { + return loc; + } + + public int getFileParseCount() { + return fileParseCount; + } + + public String getTime() { + return time; + } + + public int getBlockCount() { + return blockCount; + } + + public int getFileWithDuplicateCount() { + return fileWithDuplicateCount; + } + + public void process() throws IOException { + List duplicationList = new ArrayList(); + Duplication duplication = null; + + BufferedReader logReader = new BufferedReader( new FileReader(logFile) ); + // Skip 3 lines of header. + copyright1 = logReader.readLine(); + copyright2 = logReader.readLine(); + String line; + while( (line = logReader.readLine()) != null ) { + if( line.endsWith("duplicate lines in the following files:") ) { + // New duplication + + StringTokenizer dupeTokenizer = new StringTokenizer(line); + // Skip "Found" token + dupeTokenizer.nextToken(); + int dupeSize = Integer.parseInt(dupeTokenizer.nextToken()); + duplication = new Duplication(dupeSize); + duplicationList.add(duplication); + } else if( line.startsWith(" Between") ) { + // New duplication area within a duplication + + StringTokenizer dupeEntryTokenizer = new StringTokenizer(line); + // Skip "Between" and "lines" tokens. + dupeEntryTokenizer.nextToken(); + dupeEntryTokenizer.nextToken(); + int startLine = Integer.parseInt(dupeEntryTokenizer.nextToken()); + // Skip "and". + dupeEntryTokenizer.nextToken(); + int endLine = Integer.parseInt(dupeEntryTokenizer.nextToken()); + // Skip "in". + dupeEntryTokenizer.nextToken(); + String filePath = dupeEntryTokenizer.nextToken(); + + String pathToClass = null; + if( filePath.startsWith(sourceDirectory) ) { + pathToClass = "xref/" + getPathToClass(sourceDirectory, filePath); + } else if( filePath.startsWith(unitTestSourceDirectory) ) { + pathToClass = "xref-test/" + getPathToClass(unitTestSourceDirectory, filePath); + } else { + throw new IllegalStateException( "Couldn't find relative path for " + filePath + " in " + sourceDirectory + " or " + unitTestSourceDirectory); + } + + DuplicationArea duplicationArea = new DuplicationArea(startLine, endLine, pathToClass); + duplication.addDuplicationArea(duplicationArea); + } else if( line.indexOf("duplicate lines of code in") != -1 ) { + // Summary (Line 1) + StringTokenizer summaryTokenizer = new StringTokenizer(line); + // Skip "Found". + summaryTokenizer.nextToken(); + totalDuplicateLineCount = Integer.parseInt(summaryTokenizer.nextToken()); + // Skip "duplicate lines of code in". + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + blockCount = Integer.parseInt(summaryTokenizer.nextToken()); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + fileWithDuplicateCount = Integer.parseInt(summaryTokenizer.nextToken()); + } else if( line.startsWith("Processed a total of") ) { + // Summary (Line 2) + StringTokenizer summaryTokenizer = new StringTokenizer(line); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + loc = Integer.parseInt(summaryTokenizer.nextToken()); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + fileParseCount = Integer.parseInt(summaryTokenizer.nextToken()); + } else if( line.startsWith("Processing time:") ) { + StringTokenizer summaryTokenizer = new StringTokenizer(line); + summaryTokenizer.nextToken(); + summaryTokenizer.nextToken(); + time = summaryTokenizer.nextToken(); + } + } + duplications = (Duplication[]) duplicationList.toArray(new Duplication[duplicationList.size()]); + + // Set ourself on the context, so Jelly can reference us as a regular bean. + jellyContext.setVariable("simianLog", this); + } + + private String getPathToClass(String directory, String filePath) { + int classStart = directory.length() + 1; + int classEnd = filePath.lastIndexOf(".java"); + + String result = filePath.substring(classStart, classEnd).replace(File.separatorChar, '/'); + + return result; + } +} diff --git a/simian/src/test/org/apache/maven/simian/English.java b/simian/src/test/org/apache/maven/simian/English.java new file mode 100644 index 00000000..5d135334 --- /dev/null +++ b/simian/src/test/org/apache/maven/simian/English.java @@ -0,0 +1,100 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +/** + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class English { + public void eleven() { + String one = "one"; + String two = "two"; + String three = "three"; + String four = "four"; + String five= "five"; + String six = "six"; + String seven = "seven"; + String eight = "eight"; + String nine = "nine"; + String ten = "ten"; + } + + public void ten() { + String one = "one"; + String two = "two"; + String three = "three"; + String four = "four"; + String five= "five"; + String six = "six"; + String seven = "seven"; + String eight = "eight"; + String nine = "nine"; + } + + public void nine() { + String one = "one"; + String two = "two"; + String three = "three"; + String four = "four"; + String five= "five"; + String six = "six"; + String seven = "seven"; + String eight = "eight"; + } +} diff --git a/simian/src/test/org/apache/maven/simian/FileUtils.java b/simian/src/test/org/apache/maven/simian/FileUtils.java new file mode 100644 index 00000000..638143bf --- /dev/null +++ b/simian/src/test/org/apache/maven/simian/FileUtils.java @@ -0,0 +1,108 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.util.StringTokenizer; +import java.io.File; +import java.net.URL; + +/** + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class FileUtils { + /** + * Returns the root directory of the package hierarchy where this class is + * located. This will either be a directory or a jar file. + * + * @return the root directory or jar file where the class is located. + */ + public static File getRoot(Class clazz) + { + File dir; + URL classURL = clazz.getResource( "/" + clazz.getName().replace( '.', '/' ) + ".class" ); + String classFile = classURL.getFile(); + + if( classFile.indexOf('!') != -1 ) { + // Sometimes (at least on windows) we get file:F:\bla. Convert to file:/F:/bla + if( classFile.charAt(5) != '/' ) { + classFile = "file:/" + classFile.substring(5); + } + classFile = classFile.replace( '\\','/' ); + String uriSpec = classFile.substring(0, classFile.indexOf('!')); + dir = new File( uriSpec ); + // NOTE: This used to be here, but I've replaced it with the above single + // line without understanding the ramifications. The code below needs JDK1.4 + //try { + // dir = new File( new URL( uriSpec ) ); + //} catch (URISyntaxException e) { + // System.err.println("Couldn't create URI for " + uriSpec); + // throw new IllegalStateException(e.getMessage()); + //} + } else { + dir = new File( classFile ).getParentFile(); + StringTokenizer st = new StringTokenizer( clazz.getName(), "." ); + + for( int i = 0; i < st.countTokens() - 1; i++ ) + { + dir = dir.getParentFile(); + } + } + return dir; + } +} diff --git a/simian/src/test/org/apache/maven/simian/Francais.java b/simian/src/test/org/apache/maven/simian/Francais.java new file mode 100644 index 00000000..5a88e52c --- /dev/null +++ b/simian/src/test/org/apache/maven/simian/Francais.java @@ -0,0 +1,101 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +/** + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class Francais { + public void neuf() { + String one = "one"; + String two = "two"; + String three = "three"; + String four = "four"; + String five= "five"; + String six = "six"; + String seven = "seven"; + String eight = "eight"; + } + + public void dix() { + String one = "one"; + String two = "two"; + String three = "three"; + String four = "four"; + String five= "five"; + String six = "six"; + String seven = "seven"; + String eight = "eight"; + String nine = "nine"; + } + + public void onze() { + String one = "one"; + String two = "two"; + String three = "three"; + String four = "four"; + String five= "five"; + String six = "six"; + String seven = "seven"; + String eight = "eight"; + String nine = "nine"; + String ten = "ten"; + } + +} diff --git a/simian/src/test/org/apache/maven/simian/SimianLogTestCase.java b/simian/src/test/org/apache/maven/simian/SimianLogTestCase.java new file mode 100644 index 00000000..df57e052 --- /dev/null +++ b/simian/src/test/org/apache/maven/simian/SimianLogTestCase.java @@ -0,0 +1,99 @@ +package org.apache.maven.simian; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import junit.framework.TestCase; + +import java.io.*; + +import org.apache.commons.jelly.JellyContext; + +/** + * + * @author Aslak Hellesoy + * @version $Revision: 1.1 $ + */ +public class SimianLogTestCase extends TestCase { + public void testGetDuplications() throws IOException { + SimianLog simianLog = new SimianLog(); + + File logFile = new File(FileUtils.getRoot(getClass()).getParentFile().getParentFile(), "target/simian-test/simian.log" ); + simianLog.setLogFile(logFile); + + JellyContext ctx = new JellyContext(); + simianLog.setJellyContext(ctx); + + String sourceDirectory = new File(FileUtils.getRoot(getClass()).getParentFile().getParentFile(), "src/test" ).getAbsolutePath(); + simianLog.setSourceDirectory(sourceDirectory); + + simianLog.process(); + + Duplication[] duplications = simianLog.getDuplications(); + assertEquals("There should be 1 duplication", 1, duplications.length ); + + Duplication duplication = duplications[0]; + + DuplicationArea[] duplicationAreas = duplication.getDuplicationAreas(); + assertEquals("There should be 2 duplicated areas", 2, duplicationAreas.length ); + + String pathToClass = duplicationAreas[0].getPathToClass(); + assertTrue( "The pathToClass should start with xref/org/apache/maven/simian, but was " + pathToClass, + pathToClass.startsWith("xref/org/apache/maven/simian") ); + + assertSame("The SimianLog should be on the Jelly Context", simianLog, ctx.getVariable("simianLog") ); + } +} diff --git a/simian/xdocs/changes.xml b/simian/xdocs/changes.xml new file mode 100644 index 00000000..ba8fae94 --- /dev/null +++ b/simian/xdocs/changes.xml @@ -0,0 +1,53 @@ + + + + Changes + Aslak Hellesoy + Maurice Montgenie + + + + + + + + New optional options introduced in Simian 1.9.1. + + + + + + + + Now parses test sources too. + + + + Report displays the similarity treshold. + + + + Updated to use Simian 1.9.1 + + + + Removed the simian jar from the plugin. + + + + Reset site doc colour scheme to default. + + + + + + + + First release. + + + + + + + diff --git a/simian/xdocs/goals.xml b/simian/xdocs/goals.xml new file mode 100644 index 00000000..2471ec88 --- /dev/null +++ b/simian/xdocs/goals.xml @@ -0,0 +1,24 @@ + + + + + Simian Plugin Goals + Aslak Hellesoy + + + +
+ + + + + + + +
GoalDescription
maven-simian-plugin + The default goal. This goal generates an xdoc document + containing a Simian report. +
+
+ +
diff --git a/simian/xdocs/index.xml b/simian/xdocs/index.xml new file mode 100644 index 00000000..4e0146e2 --- /dev/null +++ b/simian/xdocs/index.xml @@ -0,0 +1,26 @@ + + + + + Simian Plugin + Aslak Hellesoy + + + +
+

+ This plugin generates xdoc documentation containing a + Simian + (Similarity Analyser) report. Simian identifies duplicated lines in + Java and C# source code. Ie. lines of code that occur more than once + across an entire source tree. +

+

+ Duplicate code should always be refactored. It is therefore recommended + that the maven.simian.failonduplication property be set to true and that the + maven.simian.linecount property be small. This will make it easier + to always have duplicates factored out in the codebase. +

+
+ + diff --git a/simian/xdocs/installation.xml b/simian/xdocs/installation.xml new file mode 100644 index 00000000..42b8ab20 --- /dev/null +++ b/simian/xdocs/installation.xml @@ -0,0 +1,40 @@ + + + + + Simian Plugin Installation + Aslak Hellesoy + + + +
+

+ As long as this plugin is not a standard Maven plugin, it must + be installed manually. This is very easy. +

+

+ If you have a binary distribution of the plugin, just copy the plugin jar file + to your $MAVEN_HOME/plugins directory. and the simian + jar file to $MAVEN_HOME/repository/simian/jars. +

+

+ If you have a source distribution of the plugin, installing the plugin is just as easy. + Just run +

+ maven plugin:install +

+ from the root directory of the unpacked distribution. +

+

+ To enable the plugin add the following to your project.xml's + /project/reports node: +

+ <report>maven-simian-plugin</report> +

+ For further details about how to use the plugin, see the + Goals and Properties + pages. +

+
+ +
diff --git a/simian/xdocs/navigation.xml b/simian/xdocs/navigation.xml new file mode 100644 index 00000000..71d95d00 --- /dev/null +++ b/simian/xdocs/navigation.xml @@ -0,0 +1,16 @@ + + + + Maven Simian Plugin + + + + + + + + + + + + diff --git a/simian/xdocs/properties.xml b/simian/xdocs/properties.xml new file mode 100644 index 00000000..4a435177 --- /dev/null +++ b/simian/xdocs/properties.xml @@ -0,0 +1,67 @@ + + + + + Simian Properties + Aslak Hellesoy + Maurice Montgénie + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyOptional?Description
maven.simian.linecountYes (default = 10) + Specifies the minimum number of lines that is considered a match. +
maven.simian.failonduplicationYes (default = false) + Specifies whether the build should fail if a match is found. +
maven.simian.ignorestringsYes (default = false) + Ignore strings (Java, C#, C, C++, JavaScript, COBOL): "one" and "two" would both match. +
maven.simian.ignorestringcaseYes (default = false) + Ignore string case (Java, C#, C, C++, JavaScript, COBOL): "Hello, World" and "HELLO, WORLD" would both match. +
maven.simian.ignorenumbersYes (default = false) + Ignore numbers (Java, C#, C, C++, JavaScript, COBOL): int x = 1; and int x = 576; would both match. +
maven.simian.ignoresubtypenamesYes (default = false) + Ignore subtype names (Java): BufferedReader, StringReader and Reader would all match. +
maven.simian.ignoremodifiersYes (default = false) + Ignore modifiers (Java, C#, C, C++, JavaScript): public, protected, static, etc. +
+
+ +