Add the simian plugin from Aslak
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fcf4518581
commit
760d65fd53
2
simian/.cvsignore
Normal file
2
simian/.cvsignore
Normal file
@ -0,0 +1,2 @@
|
||||
*.log
|
||||
target
|
||||
49
simian/maven.xml
Normal file
49
simian/maven.xml
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<project
|
||||
default="jar:install"
|
||||
xmlns:j="jelly:core"
|
||||
xmlns:ant="jelly:ant">
|
||||
|
||||
<preGoal name="test:compile">
|
||||
<attainGoal name="simian:test"/>
|
||||
</preGoal>
|
||||
|
||||
<goal name="simian:test" prereqs="java:compile">
|
||||
|
||||
<taskdef name="simian" classname="org.apache.maven.simian.FileSimianTask">
|
||||
<classpath>
|
||||
<pathelement location="${maven.build.dest}"/>
|
||||
<pathelement location="${pom.getPluginContext('maven-clover-plugin').getVariable('maven.build.clover.classes')}"/>
|
||||
<pathelement location="${pom.getDependencyPath('redhill:simian')}"/>
|
||||
</classpath>
|
||||
</taskdef>
|
||||
|
||||
<simian output="${maven.build.dir}/simian-test/simian.log"
|
||||
lineCount="10"
|
||||
failOnDuplication="false">
|
||||
<fileset dir="${pom.build.unitTestSourceDirectory}" includes="**/*.java"/>
|
||||
</simian>
|
||||
|
||||
</goal>
|
||||
|
||||
<postGoal name="dist:prepare-src-filesystem">
|
||||
<ant:copy todir="${maven.dist.src.assembly.dir}">
|
||||
<ant:fileset dir="${basedir}">
|
||||
<ant:include name="plugin.jelly"/>
|
||||
<ant:include name="plugin.properties"/>
|
||||
<ant:include name="xdocs/**/*"/>
|
||||
<ant:include name="lib/**/*"/>
|
||||
</ant:fileset>
|
||||
</ant:copy>
|
||||
</postGoal>
|
||||
|
||||
<preGoal name="dist:prepare-bin-filesystem">
|
||||
<attainGoal name="site"/>
|
||||
</preGoal>
|
||||
|
||||
<postGoal name="dist:prepare-bin-filesystem">
|
||||
<copy file="${pom.getDependencyPath('redhill:simian')}" todir="${maven.dist.bin.assembly.dir}"/>
|
||||
</postGoal>
|
||||
|
||||
</project>
|
||||
154
simian/plugin.jelly
Normal file
154
simian/plugin.jelly
Normal file
@ -0,0 +1,154 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
! Maven plugin for Simian
|
||||
!
|
||||
! Author: Aslak Hellesoy (aslak@thoughtworks.com)
|
||||
-->
|
||||
<project
|
||||
xmlns:j="jelly:core"
|
||||
xmlns:define="jelly:define"
|
||||
xmlns:doc="doc"
|
||||
xmlns:ant="jelly:ant"
|
||||
xmlns:simian="simian">
|
||||
|
||||
<define:taglib uri="simian">
|
||||
<define:jellybean
|
||||
name="simianLog"
|
||||
className="org.apache.maven.simian.SimianLog"
|
||||
method="process"
|
||||
/>
|
||||
</define:taglib>
|
||||
|
||||
<goal name="maven-simian-plugin"
|
||||
description="Generate Simian (Code Similarity Analyzer) report."
|
||||
prereqs="maven-simian-plugin:report"/>
|
||||
|
||||
<goal name="maven-simian-plugin:register">
|
||||
<j:if test="${sourcesPresent}">
|
||||
<doc:registerReport
|
||||
name="Simian Report"
|
||||
pluginName="maven-simian-plugin"
|
||||
link="simian-report"
|
||||
description="Simian (Code Similarity Analyzer) report."/>
|
||||
</j:if>
|
||||
</goal>
|
||||
|
||||
<goal name="maven-simian-plugin:deregister">
|
||||
<doc:deregisterReport name="Simian"/>
|
||||
</goal>
|
||||
|
||||
<goal name="maven-simian-plugin:analyze">
|
||||
|
||||
<ant:taskdef name="simian" classname="org.apache.maven.simian.FileSimianTask">
|
||||
<ant:classpath>
|
||||
<ant:pathelement location="${plugin.dir}"/>
|
||||
<ant:pathelement location="${plugin.getDependencyPath('redhill:simian')}"/>
|
||||
</ant:classpath>
|
||||
</ant:taskdef>
|
||||
|
||||
<ant:simian output="${maven.build.dir}/generated-xdocs/simian.log"
|
||||
lineCount="${maven.simian.linecount}"
|
||||
failOnDuplication="${maven.simian.failonduplication}">
|
||||
<ant:fileset dir="${pom.build.sourceDirectory}" includes="**/*.java"/>
|
||||
<ant:fileset dir="${pom.build.unitTestSourceDirectory}" includes="**/*.java"/>
|
||||
|
||||
<!-- debut ajout momo -->
|
||||
<j:set var="ignoreStrings" value="${maven.simian.ignorestrings}"/>
|
||||
<j:if test="${ignoreStrings == 'true'}">
|
||||
<ant:setProperty name="ignoreStrings" value="${ignoreStrings}" />
|
||||
</j:if>
|
||||
|
||||
<j:set var="ignoreStringCase" value="${maven.simian.ignorestringcase}"/>
|
||||
<j:if test="${ignoreStringCase == 'true'}">
|
||||
<ant:setProperty name="ignoreStringCase" value="${ignoreStringCase}" />
|
||||
</j:if>
|
||||
|
||||
<j:set var="ignoreNumbers" value="${maven.simian.ignorenumbers}"/>
|
||||
<j:if test="${ignoreNumbers == 'true'}">
|
||||
<ant:setProperty name="ignoreNumbers" value="${ignoreNumbers}" />
|
||||
</j:if>
|
||||
|
||||
<j:set var="ignoreSubtypeNames" value="${maven.simian.ignoresubtypenames}"/>
|
||||
<j:if test="${ignoreSubtypeNames == 'true'}">
|
||||
<ant:setProperty name="ignoreSubtypeNames" value="${ignoreSubtypeNames}" />
|
||||
</j:if>
|
||||
|
||||
<j:set var="ignoreModifiers" value="${maven.simian.ignoremodifiers}"/>
|
||||
<j:if test="${ignoreModifiers == 'true'}">
|
||||
<ant:setProperty name="ignoreModifiers" value="${ignoreModifiers}" />
|
||||
</j:if>
|
||||
<!-- fin ajout momo -->
|
||||
</ant:simian>
|
||||
|
||||
</goal>
|
||||
|
||||
<goal name="maven-simian-plugin:report" prereqs="maven-simian-plugin:analyze">
|
||||
<simian:simianLog
|
||||
logFile="${maven.build.dir}/generated-xdocs/simian.log"
|
||||
jellyContext="${context}"
|
||||
sourceDirectory="${pom.build.sourceDirectory}"
|
||||
unitTestSourceDirectory="${pom.build.unitTestSourceDirectory}"
|
||||
/>
|
||||
<j:set var="simLog" value="${context.getVariable('simianLog')}"/>
|
||||
|
||||
<j:file name="${maven.build.dir}/generated-xdocs/simian-report.xml" prettyPrint="true">
|
||||
<j:whitespace xmlns="dummy">
|
||||
|
||||
<document>
|
||||
<properties>
|
||||
<title>Simian Report</title>
|
||||
</properties>
|
||||
<body>
|
||||
<section name="Summary">
|
||||
<p>${simLog.copyright1}</p>
|
||||
<p>${simLog.copyright2}</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Similarity treshold (lines)</td>
|
||||
<td>${maven.simian.linecount}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total number of duplicate lines</td>
|
||||
<td>${simLog.totalDuplicateLineCount}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total number of duplicate blocks</td>
|
||||
<td>${simLog.blockCount}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total number of files with duplicates</td>
|
||||
<td>${simLog.fileWithDuplicateCount}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total number of processed lines</td>
|
||||
<td>${simLog.loc}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total number of processed files</td>
|
||||
<td>${simLog.fileParseCount}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Scan time</td>
|
||||
<td>${simLog.time}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section name="Duplications">
|
||||
<j:forEach var="duplication" items="${simLog.duplications}">
|
||||
<subsection name="Duplication: ${duplication.lineCount} lines">
|
||||
<j:forEach var="duplicationArea" items="${duplication.duplicationAreas}">
|
||||
<j:set var="className" value="${duplicationArea.className}"/>
|
||||
<a href="${duplicationArea.pathToClass}.html#${duplicationArea.startLine}">${duplicationArea.className}(${duplicationArea.startLine}-${duplicationArea.endLine})</a><br/>
|
||||
</j:forEach>
|
||||
</subsection>
|
||||
</j:forEach>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
|
||||
</j:whitespace>
|
||||
</j:file>
|
||||
</goal>
|
||||
</project>
|
||||
7
simian/plugin.properties
Normal file
7
simian/plugin.properties
Normal file
@ -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
|
||||
7
simian/project.properties
Normal file
7
simian/project.properties
Normal file
@ -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/
|
||||
108
simian/project.xml
Normal file
108
simian/project.xml
Normal file
@ -0,0 +1,108 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<project>
|
||||
<extend>${basedir}/../project.xml</extend>
|
||||
<id>maven-simian-plugin</id>
|
||||
<name>Simian</name>
|
||||
<currentVersion>1.1</currentVersion>
|
||||
<url>http://maven.apache.org/reference/plugins/simian/</url>
|
||||
|
||||
<siteDirectory>/www/maven.apache.org/reference/plugins/simian/</siteDirectory>
|
||||
|
||||
<package>org.apache.maven.simian</package>
|
||||
|
||||
<repository>
|
||||
<connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/simian/</connection>
|
||||
<url>http://cvs.apache.org/viewcvs/maven/src/plugins-build/simian/</url>
|
||||
</repository>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>redhill</groupId>
|
||||
<artifactId>simian</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<url>http://www.redhillconsulting.com.au/products/simian/</url>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<id>ant</id>
|
||||
<version>1.5.1</version>
|
||||
<url>http://ant.apache.org/</url>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<id>commons-jelly</id>
|
||||
<version>SNAPSHOT</version>
|
||||
<url>http://jakarta.apache.org/commons/jelly/</url>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<id>commons-logging</id>
|
||||
<version>1.0.1</version>
|
||||
<url>http://jakarta.apache.org/commons/logging/</url>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Simon Harris</name>
|
||||
<id></id>
|
||||
<email>simon@redhillconsulting.com.au</email>
|
||||
<organization>RedHill Consulting</organization>
|
||||
<roles>
|
||||
<role>Simian Core</role>
|
||||
</roles>
|
||||
</developer>
|
||||
|
||||
<developer>
|
||||
<name>Aslak Hellesoy</name>
|
||||
<id></id>
|
||||
<email>aslak@thoughtworks.net</email>
|
||||
<organization>ThoughtWorks</organization>
|
||||
<roles>
|
||||
<role>Maven Plugin</role>
|
||||
</roles>
|
||||
</developer>
|
||||
|
||||
<developer>
|
||||
<name>dIon gillard</name>
|
||||
<id>dIon</id>
|
||||
<email>dion@apache.org</email>
|
||||
<organization>ASF</organization>
|
||||
<roles>
|
||||
<role>Maven Plugin</role>
|
||||
</roles>
|
||||
</developer>
|
||||
|
||||
</developers>
|
||||
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Maurice Montgénie</name>
|
||||
<id></id>
|
||||
<email>maurice@maguyane.net</email>
|
||||
<organization>CGSS Guyane</organization>
|
||||
<roles>
|
||||
<role>Maven Plugin</role>
|
||||
</roles>
|
||||
</contributor>
|
||||
</contributors>
|
||||
|
||||
<build>
|
||||
<unitTest>
|
||||
<includes>
|
||||
<include>**/*TestCase.java</include>
|
||||
</includes>
|
||||
</unitTest>
|
||||
</build>
|
||||
|
||||
<reports>
|
||||
<!-- Make sure to run plugin:install before site -->
|
||||
<report>maven-simian-plugin</report>
|
||||
<report>maven-changes-plugin</report>
|
||||
<report>maven-license-plugin</report>
|
||||
<report>maven-jxr-plugin</report>
|
||||
<report>maven-javadoc-plugin</report>
|
||||
<report>maven-clover-plugin</report>
|
||||
</reports>
|
||||
|
||||
</project>
|
||||
88
simian/src/main/org/apache/maven/simian/Duplication.java
Normal file
88
simian/src/main/org/apache/maven/simian/Duplication.java
Normal file
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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()]);
|
||||
}
|
||||
}
|
||||
91
simian/src/main/org/apache/maven/simian/DuplicationArea.java
Normal file
91
simian/src/main/org/apache/maven/simian/DuplicationArea.java
Normal file
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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('/', '.');
|
||||
}
|
||||
}
|
||||
94
simian/src/main/org/apache/maven/simian/FileSimianTask.java
Normal file
94
simian/src/main/org/apache/maven/simian/FileSimianTask.java
Normal file
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
251
simian/src/main/org/apache/maven/simian/SimianLog.java
Normal file
251
simian/src/main/org/apache/maven/simian/SimianLog.java
Normal file
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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 = "<a href=\"" + token + "\">" + token + "</a>";
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
100
simian/src/test/org/apache/maven/simian/English.java
Normal file
100
simian/src/test/org/apache/maven/simian/English.java
Normal file
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @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";
|
||||
}
|
||||
}
|
||||
108
simian/src/test/org/apache/maven/simian/FileUtils.java
Normal file
108
simian/src/test/org/apache/maven/simian/FileUtils.java
Normal file
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
101
simian/src/test/org/apache/maven/simian/Francais.java
Normal file
101
simian/src/test/org/apache/maven/simian/Francais.java
Normal file
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @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";
|
||||
}
|
||||
|
||||
}
|
||||
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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") );
|
||||
}
|
||||
}
|
||||
53
simian/xdocs/changes.xml
Normal file
53
simian/xdocs/changes.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0"?>
|
||||
<document>
|
||||
<properties>
|
||||
<title>Changes</title>
|
||||
<author email="rinkrank at codehaus.org">Aslak Hellesoy</author>
|
||||
<author email="maurice@maguyane.net">Maurice Montgenie</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
|
||||
<release version="1.1.1" date="2003-07-09 (In JIRA)">
|
||||
|
||||
<action dev="maurice" type="add">
|
||||
New optional options introduced in Simian 1.9.1.
|
||||
</action>
|
||||
|
||||
</release>
|
||||
|
||||
<release version="1.1" date="2003-07-08 (In JIRA)">
|
||||
|
||||
<action dev="rinkrank" type="add">
|
||||
Now parses test sources too.
|
||||
</action>
|
||||
|
||||
<action dev="rinkrank" type="add">
|
||||
Report displays the similarity treshold.
|
||||
</action>
|
||||
|
||||
<action dev="rinkrank" type="update">
|
||||
Updated to use Simian 1.9.1
|
||||
</action>
|
||||
|
||||
<action dev="rinkrank" type="update">
|
||||
Removed the simian jar from the plugin.
|
||||
</action>
|
||||
|
||||
<action dev="rinkrank" type="fix">
|
||||
Reset site doc colour scheme to default.
|
||||
</action>
|
||||
|
||||
</release>
|
||||
|
||||
<release version="1.0-alpha-1" date="2003-06-25 (In JIRA)">
|
||||
|
||||
<action dev="rinkrank" type="add">
|
||||
First release.
|
||||
</action>
|
||||
|
||||
</release>
|
||||
|
||||
</body>
|
||||
</document>
|
||||
|
||||
24
simian/xdocs/goals.xml
Normal file
24
simian/xdocs/goals.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<document>
|
||||
|
||||
<properties>
|
||||
<title>Simian Plugin Goals</title>
|
||||
<author email="aslak@thoughtworks.net">Aslak Hellesoy</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
<section name="Goals">
|
||||
<table>
|
||||
<tr><th>Goal</th><th>Description</th></tr>
|
||||
<a name="sim" />
|
||||
<tr>
|
||||
<td>maven-simian-plugin</td>
|
||||
<td>
|
||||
The default goal. This goal generates an xdoc document
|
||||
containing a Simian report.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
26
simian/xdocs/index.xml
Normal file
26
simian/xdocs/index.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0"?>
|
||||
<document>
|
||||
|
||||
<properties>
|
||||
<title>Simian Plugin</title>
|
||||
<author email="aslak@thoughtworks.net">Aslak Hellesoy</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
<section name="Simian Plugin">
|
||||
<p>
|
||||
This plugin generates xdoc documentation containing a
|
||||
<a href="http://www.redhillconsulting.com.au/mimeo.html">Simian</a>
|
||||
(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.
|
||||
</p>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
40
simian/xdocs/installation.xml
Normal file
40
simian/xdocs/installation.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0"?>
|
||||
<document>
|
||||
|
||||
<properties>
|
||||
<title>Simian Plugin Installation</title>
|
||||
<author email="aslak@thoughtworks.net">Aslak Hellesoy</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
<section name="Simian Plugin Installation">
|
||||
<p>
|
||||
As long as this plugin is not a standard Maven plugin, it must
|
||||
be installed manually. This is very easy.
|
||||
</p>
|
||||
<p>
|
||||
If you have a binary distribution of the plugin, just copy the plugin jar file
|
||||
to your <code>$MAVEN_HOME/plugins</code> directory. and the simian
|
||||
jar file to <code>$MAVEN_HOME/repository/simian/jars</code>.
|
||||
</p>
|
||||
<p>
|
||||
If you have a source distribution of the plugin, installing the plugin is just as easy.
|
||||
Just run
|
||||
</p>
|
||||
<source>maven plugin:install</source>
|
||||
<p>
|
||||
from the root directory of the unpacked distribution.
|
||||
</p>
|
||||
<p>
|
||||
To enable the plugin add the following to your project.xml's
|
||||
/project/reports node:
|
||||
</p>
|
||||
<source><report>maven-simian-plugin</report></source>
|
||||
<p>
|
||||
For further details about how to use the plugin, see the
|
||||
<a href="goals.html">Goals</a> and <a href="properties.html">Properties</a>
|
||||
pages.
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
16
simian/xdocs/navigation.xml
Normal file
16
simian/xdocs/navigation.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<project name="Maven Simian Plugin">
|
||||
|
||||
<title>Maven Simian Plugin</title>
|
||||
|
||||
<body>
|
||||
<links>
|
||||
<item name="Simian" href="http://www.redhillconsulting.com.au/products/simian/"/>
|
||||
</links>
|
||||
<menu name="Overview">
|
||||
<item name="Installation" href="/installation.html" />
|
||||
<item name="Goals" href="/goals.html" />
|
||||
<item name="Properties" href="/properties.html" />
|
||||
</menu>
|
||||
</body>
|
||||
</project>
|
||||
67
simian/xdocs/properties.xml
Normal file
67
simian/xdocs/properties.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<document>
|
||||
|
||||
<properties>
|
||||
<title>Simian Properties</title>
|
||||
<author email="aslak@thoughtworks.net">Aslak Hellesoy</author>
|
||||
<author email="maurice@maguyane.net">Maurice Montgénie</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
<section name="Simian Properties">
|
||||
<table>
|
||||
<tr><th>Property</th><th>Optional?</th><th>Description</th></tr>
|
||||
<tr>
|
||||
<td>maven.simian.linecount</td>
|
||||
<td>Yes (default = 10)</td>
|
||||
<td>
|
||||
Specifies the minimum number of lines that is considered a match.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>maven.simian.failonduplication</td>
|
||||
<td>Yes (default = false)</td>
|
||||
<td>
|
||||
Specifies whether the build should fail if a match is found.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>maven.simian.ignorestrings</td>
|
||||
<td>Yes (default = false)</td>
|
||||
<td>
|
||||
Ignore strings (Java, C#, C, C++, JavaScript, COBOL): "one" and "two" would both match.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>maven.simian.ignorestringcase</td>
|
||||
<td>Yes (default = false)</td>
|
||||
<td>
|
||||
Ignore string case (Java, C#, C, C++, JavaScript, COBOL): "Hello, World" and "HELLO, WORLD" would both match.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>maven.simian.ignorenumbers</td>
|
||||
<td>Yes (default = false)</td>
|
||||
<td>
|
||||
Ignore numbers (Java, C#, C, C++, JavaScript, COBOL): int x = 1; and int x = 576; would both match.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>maven.simian.ignoresubtypenames</td>
|
||||
<td>Yes (default = false)</td>
|
||||
<td>
|
||||
Ignore subtype names (Java): BufferedReader, StringReader and Reader would all match.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>maven.simian.ignoremodifiers</td>
|
||||
<td>Yes (default = false)</td>
|
||||
<td>
|
||||
Ignore modifiers (Java, C#, C, C++, JavaScript): public, protected, static, etc.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
Loading…
x
Reference in New Issue
Block a user