|
From: <caw...@us...> - 2007-01-07 01:01:51
|
Revision: 1759
http://svn.sourceforge.net/rubyeclipse/?rev=1759&view=rev
Author: cawilliams
Date: 2007-01-06 17:01:50 -0800 (Sat, 06 Jan 2007)
Log Message:
-----------
more test cleanup - forced me to be better about how I added the new Code DuplicationDetector. implements new MultipleFileCompiler interface (which should probably be implemented by the markermanager and index for handling the files)
Modified Paths:
--------------
trunk/org.rubypeople.eclipse.shams/src/org/rubypeople/eclipse/shams/resources/ShamResource.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtCompiler.java
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtTestCase.java
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/TC_IncrementalRdtCompiler.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/CodeDuplicationDetector.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/MultipleFileCompiler.java
Modified: trunk/org.rubypeople.eclipse.shams/src/org/rubypeople/eclipse/shams/resources/ShamResource.java
===================================================================
--- trunk/org.rubypeople.eclipse.shams/src/org/rubypeople/eclipse/shams/resources/ShamResource.java 2007-01-07 00:36:02 UTC (rev 1758)
+++ trunk/org.rubypeople.eclipse.shams/src/org/rubypeople/eclipse/shams/resources/ShamResource.java 2007-01-07 01:01:50 UTC (rev 1759)
@@ -112,7 +112,7 @@
}
public IPath getLocation() {
- throw new RuntimeException("Need to implement on sham.");
+ return path;
}
public IMarker getMarker(long id) {
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtCompiler.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtCompiler.java 2007-01-07 00:36:02 UTC (rev 1758)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtCompiler.java 2007-01-07 01:01:50 UTC (rev 1759)
@@ -1,20 +1,13 @@
package org.rubypeople.rdt.internal.core.builder;
-import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.rubypeople.rdt.core.RubyCore;
-import org.rubypeople.rdt.internal.core.pmd.CPD;
-import org.rubypeople.rdt.internal.core.pmd.Match;
-import org.rubypeople.rdt.internal.core.pmd.PMD;
-import org.rubypeople.rdt.internal.core.pmd.TokenEntry;
import org.rubypeople.rdt.internal.core.symbols.SymbolIndex;
import org.rubypeople.rdt.internal.core.util.ListUtil;
@@ -23,15 +16,22 @@
protected final IProject project;
protected final IMarkerManager markerManager;
protected final SymbolIndex symbolIndex;
- protected final List compilers;
+ protected final List<SingleFileCompiler> singleFileCompilers;
+ protected final List<MultipleFileCompiler> multiFileCompilers;
public AbstractRdtCompiler(IProject project, SymbolIndex symbolIndex,
- IMarkerManager markerManager, List singleCompilers) {
+ IMarkerManager markerManager, List<SingleFileCompiler> singleCompilers, List<MultipleFileCompiler> multiFileCompilers) {
this.project = project;
this.symbolIndex = symbolIndex;
this.markerManager = markerManager;
- this.compilers = singleCompilers;
+ this.singleFileCompilers = singleCompilers;
+ this.multiFileCompilers = multiFileCompilers;
}
+
+ public AbstractRdtCompiler(IProject project, SymbolIndex symbolIndex,
+ IMarkerManager markerManager, List<SingleFileCompiler> singleCompilers) {
+ this(project, symbolIndex, markerManager, singleCompilers, new ArrayList<MultipleFileCompiler>());
+ }
protected abstract void removeMarkers(IMarkerManager markerManager);
protected abstract void flushIndexEntries(SymbolIndex symbolIndex);
@@ -47,7 +47,7 @@
analyzeFiles();
List<IFile> files = getFilesToCompile();
int fileCount = files.size();
- monitor.beginTask("Building "+project.getName() + "...", fileCount * (compilers.size() + 3));
+ monitor.beginTask("Building "+project.getName() + "...", fileCount * (singleFileCompilers.size() + multiFileCompilers.size() + 2));
monitor.subTask("Removing Markers...");
removeMarkers(markerManager);
@@ -55,53 +55,31 @@
monitor.subTask("Removing Search Indices...");
flushIndexEntries(symbolIndex);
monitor.worked(fileCount);
-
- // TODO Refactor out this stuff into a compiler, only visit files we've collected
- monitor.subTask("Finding duplicate code...");
- try {
- Iterator<Match> matches = CPD.findMatches(files);
- while (matches.hasNext()) {
- Match match = matches.next();
- addMarker(match);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- monitor.worked(fileCount);
compileFiles(files, monitor);
monitor.done();
}
- private void addMarker(Match match) {
- StringBuffer message = new StringBuffer("Found a ");
- message.append(match.getLineCount()).append(" line (").append(match.getTokenCount()).append(" tokens) duplication");
- for (Iterator occurrences = match.iterator(); occurrences.hasNext();) {
- TokenEntry mark = (TokenEntry) occurrences.next();
- // FIXME Make TokenEntry hold an IFile pointer to source file?
- IFile file = RubyCore.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(mark.getTokenSrcID()));
- markerManager.addWarning(file, message.toString(), mark.getBeginLine(), mark.getStartOffset(), mark.getStartOffset() + match.getSourceCodeSlice().length());
- }
- }
-
- private void compileFiles(List list, IProgressMonitor monitor) throws CoreException {
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- IFile file = (IFile) iter.next();
+ private void compileFiles(List<IFile> list, IProgressMonitor monitor) throws CoreException {
+ for (MultipleFileCompiler compiler : multiFileCompilers) {
+ if (monitor.isCanceled())
+ return;
+ compiler.compileFile(list, monitor);
+ }
+ for (IFile file : list) {
+ if (monitor.isCanceled())
+ return;
- if (monitor.isCanceled())
- break;
-
monitor.subTask(file.getFullPath().toString());
compileFile(file, monitor);
- }
+ }
}
private void compileFile(IFile file, IProgressMonitor monitor) throws CoreException {
- for (Iterator cIter = compilers.iterator(); cIter.hasNext();) {
+ for (Iterator cIter = singleFileCompilers.iterator(); cIter.hasNext();) {
SingleFileCompiler fileCompiler = (SingleFileCompiler) cIter.next();
fileCompiler.compileFile(file);
monitor.worked(1);
}
}
-
}
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/CodeDuplicationDetector.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/CodeDuplicationDetector.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/CodeDuplicationDetector.java 2007-01-07 01:01:50 UTC (rev 1759)
@@ -0,0 +1,49 @@
+package org.rubypeople.rdt.internal.core.builder;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.core.pmd.CPD;
+import org.rubypeople.rdt.internal.core.pmd.Match;
+import org.rubypeople.rdt.internal.core.pmd.TokenEntry;
+
+public class CodeDuplicationDetector implements MultipleFileCompiler {
+
+ private IMarkerManager markerManager;
+
+ public CodeDuplicationDetector(IMarkerManager manager) {
+ this.markerManager = manager;
+ }
+
+ public void compileFile(List<IFile> files, IProgressMonitor monitor) throws CoreException {
+ monitor.subTask("Finding duplicate code...");
+ try {
+ Iterator<Match> matches = CPD.findMatches(files);
+ while (matches.hasNext()) {
+ Match match = matches.next();
+ addMarker(match);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ monitor.worked(files.size());
+ }
+
+ private void addMarker(Match match) {
+ StringBuffer message = new StringBuffer("Found a ");
+ message.append(match.getLineCount()).append(" line (").append(match.getTokenCount()).append(" tokens) duplication");
+ for (Iterator occurrences = match.iterator(); occurrences.hasNext();) {
+ TokenEntry mark = (TokenEntry) occurrences.next();
+ // FIXME Make TokenEntry hold an IFile pointer to source file?
+ IFile file = RubyCore.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(mark.getTokenSrcID()));
+ markerManager.addWarning(file, message.toString(), mark.getBeginLine(), mark.getStartOffset(), mark.getStartOffset() + match.getSourceCodeSlice().length());
+ }
+ }
+
+}
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/MultipleFileCompiler.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/MultipleFileCompiler.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/MultipleFileCompiler.java 2007-01-07 01:01:50 UTC (rev 1759)
@@ -0,0 +1,11 @@
+package org.rubypeople.rdt.internal.core.builder;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public interface MultipleFileCompiler {
+ public void compileFile(List<IFile> file, IProgressMonitor monitor) throws CoreException;
+}
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtTestCase.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtTestCase.java 2007-01-07 00:36:02 UTC (rev 1758)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/AbstractRdtTestCase.java 2007-01-07 01:01:50 UTC (rev 1759)
@@ -15,7 +15,8 @@
import org.rubypeople.rdt.internal.core.util.ListUtil;
public abstract class AbstractRdtTestCase extends TestCase {
- static protected final String EXPECTED_TASK_NAME = "Removing Markers...";
+ static protected final String REMOVING_MARKERS_SUB_TASK = "Removing Markers...";
+ static protected final String REMOVING_INDICES_SUB_TASK = "Removing Search Indices...";
protected abstract void assertMarkersRemoved(List expectedFiles);
protected abstract void assertIndexFlushed(List expectedFiles);
@@ -69,7 +70,7 @@
compiler.compile(monitor);
- assertCompliationFor(ListUtil.create(), 2);
+ assertCompliationFor(ListUtil.create(), 0); // FIXME should be no work done for non-ruby file?
}
public void testCompileIncludesFolders() throws Exception {
@@ -88,12 +89,12 @@
setFiles(ListUtil.create(t1, t2));
compiler.compile(monitor);
-
- assertCompliationFor(ListUtil.create(t1, t2), 6);
+ int expectedWorkUnits = 8; // code analyzer, taskparser, index, markers for each file
+ assertCompliationFor(ListUtil.create(t1, t2), expectedWorkUnits);
}
public void testCancellation() throws Exception {
- monitor.cancelAfter(4);
+ monitor.cancelAfter(6);
project.addResource(t1);
project.addResource(t2);
setFiles(ListUtil.create(t1, t2));
@@ -101,9 +102,9 @@
compiler.compile(monitor);
List expectedFiles = ListUtil.create(t1);
- monitor.assertTaskBegun("Building test...", 6);
- monitor.assertDone(4);
- List subTasks = ListUtil.create(EXPECTED_TASK_NAME,
+ monitor.assertTaskBegun("Building test...", 8);
+ monitor.assertDone(6);
+ List subTasks = ListUtil.create(REMOVING_MARKERS_SUB_TASK, REMOVING_INDICES_SUB_TASK,
t1.getFullPath().toString());
monitor.assertSubTasks(subTasks);
assertMarkersRemoved(ListUtil.create(t1,t2));
@@ -129,7 +130,7 @@
protected void assertCompliationFor(List expectedFiles, int totalWork) {
monitor.assertTaskBegun("Building test...", totalWork);
monitor.assertDone(totalWork);
- List subTasks = ListUtil.create(EXPECTED_TASK_NAME);
+ List subTasks = ListUtil.create(REMOVING_MARKERS_SUB_TASK, REMOVING_INDICES_SUB_TASK);
for (Iterator iter = expectedFiles.iterator(); iter.hasNext();) {
IFile file = (IFile) iter.next();
subTasks.add(file.getFullPath().toString());
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/TC_IncrementalRdtCompiler.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/TC_IncrementalRdtCompiler.java 2007-01-07 00:36:02 UTC (rev 1758)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/TC_IncrementalRdtCompiler.java 2007-01-07 01:01:50 UTC (rev 1759)
@@ -25,7 +25,7 @@
monitor.assertTaskBegun("Building test...", 2);
monitor.assertDone(2);
- List subTasks = ListUtil.create(EXPECTED_TASK_NAME);
+ List subTasks = ListUtil.create(REMOVING_MARKERS_SUB_TASK);
monitor.assertSubTasks(subTasks);
assertMarkersRemoved(ListUtil.create(t1));
assertIndexFlushed(ListUtil.create(t1));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|