From ba4ae919eb3fc3389d3e47ab01072d2cab50fdea Mon Sep 17 00:00:00 2001 From: epugh Date: Fri, 8 Jul 2005 21:11:08 +0000 Subject: [PATCH] MPSIMIAN-14 upgrade simian git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@209890 13f79535-47bb-0310-9956-ffa450edef68 --- simian/plugin.jelly | 100 ++------ simian/project.xml | 9 +- .../org/apache/maven/simian/Duplication.java | 49 ---- .../apache/maven/simian/DuplicationArea.java | 54 ----- .../apache/maven/simian/FileSimianTask.java | 29 ++- .../org/apache/maven/simian/SimianLog.java | 219 ------------------ simian/src/plugin-resources/simian.jsl | 144 ++++++++++++ .../apache/maven/simian/SimianLogTest.java | 60 ----- simian/xdocs/changes.xml | 3 + 9 files changed, 184 insertions(+), 483 deletions(-) delete mode 100644 simian/src/main/org/apache/maven/simian/Duplication.java delete mode 100644 simian/src/main/org/apache/maven/simian/DuplicationArea.java delete mode 100644 simian/src/main/org/apache/maven/simian/SimianLog.java create mode 100755 simian/src/plugin-resources/simian.jsl delete mode 100644 simian/src/test/org/apache/maven/simian/SimianLogTest.java diff --git a/simian/plugin.jelly b/simian/plugin.jelly index 97476c59..d5c1cbec 100644 --- a/simian/plugin.jelly +++ b/simian/plugin.jelly @@ -30,14 +30,6 @@ xmlns:ant="jelly:ant" xmlns:simian="simian"> - - - - @@ -65,10 +57,11 @@ - + Generating the Simian raw report ... + + + @@ -122,86 +115,25 @@ + + + Converting the Simian report to xdoc ... + + + - - - - - - - - - - - Simian Report - - -
-

${simLog.copyright1}

-

${simLog.copyright2}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Similarity threshold (lines)${maven.simian.linecount}
Total number of duplicate lines${simLog.totalDuplicateLineCount}
Total number of duplicate blocks${simLog.blockCount}
Total number of files with duplicates${simLog.fileWithDuplicateCount}
Total number of processed lines${simLog.loc}
Total number of processed files${simLog.fileParseCount}
Scan time${simLog.time}
-
- -
- - - - - -
- -
- -
-
-
No sources to run Simian on diff --git a/simian/project.xml b/simian/project.xml index 5b876b1b..6ed4c361 100644 --- a/simian/project.xml +++ b/simian/project.xml @@ -22,7 +22,7 @@ ../plugin-parent/project.xml maven-simian-plugin Maven Simian Plugin - 1.4.1-SNAPSHOT + 1.5-SNAPSHOT Simian Plugin for Maven Simian Plugin for Maven http://maven.apache.org/reference/plugins/simian/ @@ -89,12 +89,17 @@ Maurice Montgénie maurice@maguyane.net + + Benoit Xhenseval + benoitx@sourceforge.net + ObjectLab.co.uk + redhill simian - 1.9.1 + 2.2.4 http://www.redhillconsulting.com.au/products/simian/ diff --git a/simian/src/main/org/apache/maven/simian/Duplication.java b/simian/src/main/org/apache/maven/simian/Duplication.java deleted file mode 100644 index 841f7f25..00000000 --- a/simian/src/main/org/apache/maven/simian/Duplication.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apache.maven.simian; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import java.util.List; -import java.util.ArrayList; - -/** - * Represents a duplication. Has two or more DuplicationAreas. - * - * @author Aslak Hellesoy - * @version $Revision$ - */ -public class Duplication { - int lineCount; - - private List duplicationAreas = new ArrayList(); - - public Duplication(int lineCount) { - this.lineCount = lineCount; - } - - public void addDuplicationArea(DuplicationArea duplicationArea) { - duplicationAreas.add(duplicationArea); - } - - public int getLineCount() { - return lineCount; - } - - public DuplicationArea[] getDuplicationAreas() { - return (DuplicationArea[]) duplicationAreas.toArray(new DuplicationArea[duplicationAreas.size()]); - } -} diff --git a/simian/src/main/org/apache/maven/simian/DuplicationArea.java b/simian/src/main/org/apache/maven/simian/DuplicationArea.java deleted file mode 100644 index dd50f1ce..00000000 --- a/simian/src/main/org/apache/maven/simian/DuplicationArea.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.simian; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -/** - * Represents one area in a file containing dupe code. - * - * @author Aslak Hellesoy - * @version $Revision$ - */ -public class DuplicationArea { - private final int startLine; - private final int endLine; - private final String pathToClass; - private final String className; - - public DuplicationArea(int startLine, int endLine, String pathToClass, String className) { - this.startLine = startLine; - this.endLine = endLine; - this.pathToClass = pathToClass; - this.className = className; - } - - public int getStartLine() { - return startLine; - } - - public int getEndLine() { - return endLine; - } - - public String getPathToClass() { - return pathToClass; - } - - public String getClassName() { - return className; - } -} diff --git a/simian/src/main/org/apache/maven/simian/FileSimianTask.java b/simian/src/main/org/apache/maven/simian/FileSimianTask.java index b7198f2c..04821a0a 100644 --- a/simian/src/main/org/apache/maven/simian/FileSimianTask.java +++ b/simian/src/main/org/apache/maven/simian/FileSimianTask.java @@ -17,24 +17,14 @@ package org.apache.maven.simian; * ==================================================================== */ -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. @@ -42,13 +32,22 @@ import org.apache.tools.ant.Task; * @author Aslak Hellesoy * @version $Revision$ */ -public class FileSimianTask extends SimianTask { +public class FileSimianTask extends SimianTask +{ - public void setOutput(File output) { + /** + * Make sure the directory structure exists and + * send the output to a specified file. + */ + public void setOutput(File output) + { output.getParentFile().mkdirs(); - try { + try + { setOutput(new FileOutputStream(output)); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) + { throw new BuildException("Couldn't set output to " + output.getAbsolutePath(), e); } } diff --git a/simian/src/main/org/apache/maven/simian/SimianLog.java b/simian/src/main/org/apache/maven/simian/SimianLog.java deleted file mode 100644 index 809c0597..00000000 --- a/simian/src/main/org/apache/maven/simian/SimianLog.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.apache.maven.simian; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -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$ - */ -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) throws IOException { - this.sourceDirectory = new File(sourceDirectory).getCanonicalPath(); - } - - public void setUnitTestSourceDirectory(String unitTestSourceDirectory) throws IOException { - this.unitTestSourceDirectory = new File(unitTestSourceDirectory).getCanonicalPath(); - } - - public Duplication[] getDuplications() { - return duplications; - } - - public String getCopyright1() { - return copyright1; - } - - public String getCopyright2() { - return copyright2; - } - - private String linkify(String s) { - StringBuffer sb = new StringBuffer(); - StringTokenizer st = new StringTokenizer(s, " ", true); - while (st.hasMoreTokens()) { - String token = st.nextToken(); - if(token.startsWith("http://")) { - token = "" + token + ""; - } - sb.append(token); - } - return sb.toString(); - } - - public int getTotalDuplicateLineCount() { - return totalDuplicateLineCount; - } - - public int getLoc() { - return loc; - } - - public int getFileParseCount() { - return fileParseCount; - } - - public String getTime() { - return time; - } - - public int getBlockCount() { - return blockCount; - } - - public int getFileWithDuplicateCount() { - return fileWithDuplicateCount; - } - - public void process() throws IOException { - List duplicationList = new ArrayList(); - Duplication duplication = null; - - BufferedReader logReader = new BufferedReader( new FileReader(logFile) ); - // Skip 3 lines of header. - copyright1 = logReader.readLine(); - copyright2 = logReader.readLine(); - String line; - while( (line = logReader.readLine()) != null ) { - if( line.endsWith("duplicate lines in the following files:") ) { - // New duplication - - StringTokenizer dupeTokenizer = new StringTokenizer(line); - // Skip "Found" token - dupeTokenizer.nextToken(); - int dupeSize = Integer.parseInt(dupeTokenizer.nextToken()); - duplication = new Duplication(dupeSize); - duplicationList.add(duplication); - } else if( line.startsWith(" Between") ) { - // New duplication area within a duplication - - StringTokenizer dupeEntryTokenizer = new StringTokenizer(line); - // Skip "Between" and "lines" tokens. - dupeEntryTokenizer.nextToken(); - dupeEntryTokenizer.nextToken(); - int startLine = Integer.parseInt(dupeEntryTokenizer.nextToken()); - // Skip "and". - dupeEntryTokenizer.nextToken(); - int endLine = Integer.parseInt(dupeEntryTokenizer.nextToken()); - // Skip "in". - dupeEntryTokenizer.nextToken(); - // filePath could have spaces, we really want all tokens - StringBuffer filePathBuffer = new StringBuffer(); - while (dupeEntryTokenizer.hasMoreTokens()) - { - filePathBuffer.append(dupeEntryTokenizer.nextToken()); - filePathBuffer.append(' '); - } - String filePath = filePathBuffer.toString(); - 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, - getPathToClass(sourceDirectory, filePath).replace('/', '.')); - duplication.addDuplicationArea(duplicationArea); - } else if( line.indexOf("duplicate lines of code in") != -1 ) { - // Summary (Line 1) - StringTokenizer summaryTokenizer = new StringTokenizer(line); - // Skip "Found". - summaryTokenizer.nextToken(); - totalDuplicateLineCount = Integer.parseInt(summaryTokenizer.nextToken()); - // Skip "duplicate lines of code in". - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - blockCount = Integer.parseInt(summaryTokenizer.nextToken()); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - fileWithDuplicateCount = Integer.parseInt(summaryTokenizer.nextToken()); - } else if( line.startsWith("Processed a total of") ) { - // Summary (Line 2) - StringTokenizer summaryTokenizer = new StringTokenizer(line); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - loc = Integer.parseInt(summaryTokenizer.nextToken()); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - fileParseCount = Integer.parseInt(summaryTokenizer.nextToken()); - } else if( line.startsWith("Processing time:") ) { - StringTokenizer summaryTokenizer = new StringTokenizer(line); - summaryTokenizer.nextToken(); - summaryTokenizer.nextToken(); - time = summaryTokenizer.nextToken(); - } - } - duplications = (Duplication[]) duplicationList.toArray(new Duplication[duplicationList.size()]); - - // Set ourself on the context, so Jelly can reference us as a regular bean. - jellyContext.setVariable("simianLog", this); - } - - private String getPathToClass(String directory, String filePath) { - int classStart = directory.length() + 1; - int classEnd = filePath.lastIndexOf(".java"); - - String result = filePath.substring(classStart, classEnd).replace(File.separatorChar, '/'); - - return result; - } -} diff --git a/simian/src/plugin-resources/simian.jsl b/simian/src/plugin-resources/simian.jsl new file mode 100755 index 00000000..08810790 --- /dev/null +++ b/simian/src/plugin-resources/simian.jsl @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + Benoit Xhenseval + Simian Results + + + +
+

+ The following document contains the results of + Simian .

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Similarity threshold (lines)
Total number of duplicate lines
Total number of duplicate blocks
Total number of files with duplicates
Total number of processed lines
Total number of processed files
Scan time ms.
+ +
+
+ + + + + + + + + + + +
+ +
+
+
diff --git a/simian/src/test/org/apache/maven/simian/SimianLogTest.java b/simian/src/test/org/apache/maven/simian/SimianLogTest.java deleted file mode 100644 index a32b1dd6..00000000 --- a/simian/src/test/org/apache/maven/simian/SimianLogTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.apache.maven.simian; - -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -import junit.framework.TestCase; - -import java.io.*; - -import org.apache.commons.jelly.JellyContext; - -/** - * - * @author Aslak Hellesoy - * @version $Revision$ - */ -public class SimianLogTest extends TestCase { - public void testGetDuplications() throws IOException { - SimianLog simianLog = new SimianLog(); - - File logFile = new File(FileUtils.getRoot(getClass()).getParentFile().getParentFile(), "target/simian-test/simian.log" ); - simianLog.setLogFile(logFile); - - JellyContext ctx = new JellyContext(); - simianLog.setJellyContext(ctx); - - String sourceDirectory = new File(FileUtils.getRoot(getClass()).getParentFile().getParentFile(), "src/test" ).getAbsolutePath(); - simianLog.setSourceDirectory(sourceDirectory); - - simianLog.process(); - - Duplication[] duplications = simianLog.getDuplications(); - assertEquals("There should be 1 duplication", 1, duplications.length ); - - Duplication duplication = duplications[0]; - - DuplicationArea[] duplicationAreas = duplication.getDuplicationAreas(); - assertEquals("There should be 2 duplicated areas", 2, duplicationAreas.length ); - - String pathToClass = duplicationAreas[0].getPathToClass(); - assertTrue( "The pathToClass should start with xref/org/apache/maven/simian, but was " + pathToClass, - pathToClass.startsWith("xref/org/apache/maven/simian") ); - - assertSame("The SimianLog should be on the Jelly Context", simianLog, ctx.getVariable("simianLog") ); - } -} diff --git a/simian/xdocs/changes.xml b/simian/xdocs/changes.xml index a5c79a20..c7783a0f 100644 --- a/simian/xdocs/changes.xml +++ b/simian/xdocs/changes.xml @@ -25,6 +25,9 @@ Maurice Montg?nie + + Upgrade to Simian 2.2.4 and XML file output from Simian. + Ant dependency changed to 1.5.3.1.