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:
dion committed 2003-07-10 07:37:00 +00:00
1 parent fcf4518581
commit 760d65fd53
20 files changed
+1485

No files matched your search

@@ -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()]);
}
}
@@ -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('/', '.');
}
}
@@ -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);
}
}
}
@@ -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;
}
}
@@ -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";
}
}
@@ -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;
}
}
@@ -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") );
}
}