Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25492/src/org/rubypeople/rdt/internal/core/builder Modified Files: RubyBuilder.java IndexUpdater.java SingleFileCompiler.java ProjectFileFinder.java IncrementalFileFinder.java Added Files: RubyCodeAnalyzer.java AbstractRdtCompiler.java IncrementalRdtCompiler.java CleanRdtCompiler.java IFileProvider.java Removed Files: RubyCompiler.java RdtCompiler.java IFileFinder.java Log Message: 1) refactored RubyBuilder again, this time with better unit tests. 2) refactored Location (and SymbolIndex) to be IFile based, rather than IPath based. 3) general improvement on maintainence of the SymbolIndex. Index: RubyBuilder.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/RubyBuilder.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** RubyBuilder.java 23 Oct 2005 00:03:16 -0000 1.15 --- RubyBuilder.java 12 Nov 2005 19:15:58 -0000 1.16 *************** *** 13,17 **** import java.util.Date; - import java.util.List; import java.util.Map; --- 13,16 ---- *************** *** 21,29 **** import org.eclipse.core.runtime.IProgressMonitor; import org.rubypeople.rdt.core.RubyCore; public class RubyBuilder extends IncrementalProjectBuilder { - private static final int TOTAL_WORK = 10000; private static boolean verbose; --- 20,28 ---- import org.eclipse.core.runtime.IProgressMonitor; import org.rubypeople.rdt.core.RubyCore; + import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; public class RubyBuilder extends IncrementalProjectBuilder { private static boolean verbose; *************** *** 32,63 **** protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { this.currentProject = getProject(); - monitor.beginTask("build", TOTAL_WORK); - IProject[] returnProjects = new IProject[0]; if (currentProject == null || !currentProject.isAccessible()) ! return returnProjects; if (verbose) RubyCore.trace("Started " + buildType(kind) + " build of " + buildDescription()); //$NON-NLS-1$ ! MarkerManager rubyMarkerManager = new MarkerManager(); ! if (!isPartialBuild(kind)) ! rubyMarkerManager.removeProblemsAndTasksFor(currentProject); ! ! List files = createFileFinder(kind).findFiles(); ! doCompile(files, monitor); ! RubyCore.trace("Finished build of " + buildDescription()); //$NON-NLS-1$ ! return returnProjects; } private String buildType(int kind) { return isPartialBuild(kind) ? "Incremental" : "Full"; } - private IFileFinder createFileFinder(int kind) { - if (isPartialBuild(kind)) - return new IncrementalFileFinder(getDelta(currentProject)); - return new ProjectFileFinder(currentProject); - } - private String buildDescription() { return currentProject.getName() + " @ " + new Date(System.currentTimeMillis()); --- 31,59 ---- protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { this.currentProject = getProject(); if (currentProject == null || !currentProject.isAccessible()) ! return null; if (verbose) RubyCore.trace("Started " + buildType(kind) + " build of " + buildDescription()); //$NON-NLS-1$ ! AbstractRdtCompiler compiler = createCompiler(kind); ! compiler.compile(monitor); ! if (verbose) ! RubyCore.trace("Finished build of " + buildDescription()); //$NON-NLS-1$ ! return null; } + + private AbstractRdtCompiler createCompiler(int kind) { + SymbolIndex symbolIndex = RubyCore.getPlugin().getSymbolIndex(); + if (isPartialBuild(kind)) + return new IncrementalRdtCompiler(currentProject, getDelta(currentProject), symbolIndex); + return new CleanRdtCompiler(currentProject, symbolIndex); + + } private String buildType(int kind) { return isPartialBuild(kind) ? "Incremental" : "Full"; } private String buildDescription() { return currentProject.getName() + " @ " + new Date(System.currentTimeMillis()); *************** *** 67,74 **** return kind == INCREMENTAL_BUILD || kind == AUTO_BUILD; } - - protected void doCompile(List files, IProgressMonitor monitor) { - new RubyCompiler(TOTAL_WORK/files.size()).compile(files, monitor); - } public static void setVerbose(boolean verbose) { --- 63,66 ---- Index: SingleFileCompiler.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/SingleFileCompiler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SingleFileCompiler.java 13 Oct 2005 23:56:06 -0000 1.2 --- SingleFileCompiler.java 12 Nov 2005 19:15:58 -0000 1.3 *************** *** 16,20 **** import org.eclipse.core.runtime.CoreException; ! interface SingleFileCompiler { public void compileFile(IFile file) throws CoreException; } \ No newline at end of file --- 16,20 ---- import org.eclipse.core.runtime.CoreException; ! public interface SingleFileCompiler { public void compileFile(IFile file) throws CoreException; } \ No newline at end of file --- NEW FILE: CleanRdtCompiler.java --- package org.rubypeople.rdt.internal.core.builder; import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; public class CleanRdtCompiler extends AbstractRdtCompiler { private List projectFiles; public CleanRdtCompiler(IProject project, SymbolIndex symbolIndex) { this(project, symbolIndex, new MarkerManager()); } public CleanRdtCompiler(IProject project, SymbolIndex symbolIndex, IMarkerManager markerManager, List singleCompilers) { super(project, symbolIndex, markerManager, singleCompilers); } private CleanRdtCompiler(IProject project, SymbolIndex symbolIndex, MarkerManager markerManager) { this(project,symbolIndex, markerManager, compilers(markerManager)); } protected void flushIndexEntries(SymbolIndex symbolIndex) { symbolIndex.flush(project); } protected void removeMarkers(IMarkerManager markerManager) { markerManager.removeProblemsAndTasksFor(project); } protected List getFilesToClear() { return projectFiles; } protected List getFilesToCompile() { return projectFiles; } protected void analyzeFiles() throws CoreException { ProjectFileFinder finder = new ProjectFileFinder(project); projectFiles = finder.findFiles(); } } --- NEW FILE: AbstractRdtCompiler.java --- package org.rubypeople.rdt.internal.core.builder; 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.IProgressMonitor; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; import org.rubypeople.rdt.internal.core.util.ListUtil; public abstract class AbstractRdtCompiler { protected final IProject project; protected final IMarkerManager markerManager; protected final SymbolIndex symbolIndex; protected final List compilers; public AbstractRdtCompiler(IProject project, SymbolIndex symbolIndex, IMarkerManager markerManager, List singleCompilers) { this.project = project; this.symbolIndex = symbolIndex; this.markerManager = markerManager; this.compilers = singleCompilers; } protected abstract void removeMarkers(IMarkerManager markerManager); protected abstract void flushIndexEntries(SymbolIndex symbolIndex); protected abstract List getFilesToCompile(); protected abstract void analyzeFiles() throws CoreException; protected static List compilers(MarkerManager markerManager) { return ListUtil.create(new RubyCodeAnalyzer(markerManager), new TaskCompiler(markerManager)); } public void compile(IProgressMonitor monitor) throws CoreException { analyzeFiles(); List list = getFilesToCompile(); monitor.beginTask("Building "+project.getName() + "...", list.size() * compilers.size() + 2); monitor.subTask("Removing Markers..."); removeMarkers(markerManager); monitor.worked(1); flushIndexEntries(symbolIndex); monitor.worked(1); compileFiles(list, monitor); monitor.done(); } private void compileFiles(List list, IProgressMonitor monitor) throws CoreException { for (Iterator iter = list.iterator(); iter.hasNext();) { IFile file = (IFile) iter.next(); 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();) { SingleFileCompiler fileCompiler = (SingleFileCompiler) cIter.next(); fileCompiler.compileFile(file); monitor.worked(1); } } } --- NEW FILE: RubyCodeAnalyzer.java --- /* * Author: David Corbin * * Copyright (c) 2005 RubyPeople. * * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use * RDT except in compliance with the License. For further information see * org.rubypeople.rdt/rdt.license. */ package org.rubypeople.rdt.internal.core.builder; import java.io.InputStreamReader; import java.io.Reader; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.jruby.ast.Node; import org.jruby.lexer.yacc.SyntaxException; import org.rubypeople.rdt.core.RubyCore; import org.rubypeople.rdt.internal.core.parser.ImmediateWarnings; import org.rubypeople.rdt.internal.core.parser.RubyParser; public final class RubyCodeAnalyzer implements SingleFileCompiler { private final IMarkerManager markerManager; private RubyParser parser; private final IndexUpdater indexUpdater; public RubyCodeAnalyzer(IMarkerManager markerManager) { this(markerManager, new RubyParser(new ImmediateWarnings(markerManager)), new IndexUpdater(((RubyCore) RubyCore.getPlugin()).getSymbolIndex())); } public RubyCodeAnalyzer(IMarkerManager markerManager, RubyParser parser, IndexUpdater indexUpdater) { this.markerManager = markerManager; this.parser = parser; this.indexUpdater = indexUpdater; } public void compileFile(IFile file) throws CoreException { Reader reader = new InputStreamReader(file.getContents()); try { Node rootNode = parser.parse(file, reader); indexUpdater.update(file, rootNode); } catch (SyntaxException e) { markerManager.createSyntaxError(file, e); } finally { IoUtils.closeQuietly(reader); } } } Index: ProjectFileFinder.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/ProjectFileFinder.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ProjectFileFinder.java 16 Oct 2005 17:29:21 -0000 1.3 --- ProjectFileFinder.java 12 Nov 2005 19:15:58 -0000 1.4 *************** *** 20,24 **** import org.eclipse.core.runtime.CoreException; ! final class ProjectFileFinder implements IFileFinder { private final IProject project; --- 20,24 ---- import org.eclipse.core.runtime.CoreException; ! final class ProjectFileFinder implements IFileProvider { private final IProject project; --- NEW FILE: IFileProvider.java --- /* ?* Author: David Corbin ?* ?* Copyright (c) 2005 RubyPeople. ?* ?* This file is part of the Ruby Development Tools (RDT) plugin for eclipse. * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use * RDT except in compliance with the License. For further information see * org.rubypeople.rdt/rdt.license. ?*/ package org.rubypeople.rdt.internal.core.builder; import java.util.List; import org.eclipse.core.runtime.CoreException; interface IFileProvider { public List findFiles() throws CoreException; } --- RdtCompiler.java DELETED --- --- RubyCompiler.java DELETED --- --- IFileFinder.java DELETED --- Index: IndexUpdater.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/IndexUpdater.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** IndexUpdater.java 23 Oct 2005 22:24:27 -0000 1.7 --- IndexUpdater.java 12 Nov 2005 19:15:58 -0000 1.8 *************** *** 36,40 **** public void update(IFile file, Node rootNode) { ! index.flush(file.getFullPath()); processNode(file, rootNode); } --- 36,40 ---- public void update(IFile file, Node rootNode) { ! index.flush(file); processNode(file, rootNode); } Index: IncrementalFileFinder.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/IncrementalFileFinder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IncrementalFileFinder.java 13 Oct 2005 23:56:07 -0000 1.2 --- IncrementalFileFinder.java 12 Nov 2005 19:15:58 -0000 1.3 *************** *** 19,23 **** import org.eclipse.core.resources.IResourceDelta; ! class IncrementalFileFinder implements IFileFinder { private final IResourceDelta delta; --- 19,23 ---- import org.eclipse.core.resources.IResourceDelta; ! class IncrementalFileFinder implements IFileProvider { private final IResourceDelta delta; --- NEW FILE: IncrementalRdtCompiler.java --- package org.rubypeople.rdt.internal.core.builder; 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.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.runtime.CoreException; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; import org.rubypeople.rdt.internal.core.util.Util; public class IncrementalRdtCompiler extends AbstractRdtCompiler { private List filesToCompile; private List filesToClear; private final IResourceDelta rootDelta; public IncrementalRdtCompiler(IProject project, IResourceDelta delta, SymbolIndex symbolIndex, IMarkerManager markerManager, List singleCompilers) { super(project, symbolIndex, markerManager, singleCompilers); this.rootDelta = delta; } public IncrementalRdtCompiler(IProject project, IResourceDelta delta, SymbolIndex symbolIndex) { this(project, delta, symbolIndex, new MarkerManager()); } private IncrementalRdtCompiler(IProject project, IResourceDelta delta, SymbolIndex symbolIndex, MarkerManager manager) { this(project, delta, symbolIndex, manager, compilers(manager)); } protected void removeMarkers(IMarkerManager markerManager) { for (Iterator iter = filesToClear.iterator(); iter.hasNext();) { IFile file = (IFile) iter.next(); markerManager.removeProblemsAndTasksFor(file); } } protected void flushIndexEntries(SymbolIndex symbolIndex) { for (Iterator iter = filesToClear.iterator(); iter.hasNext();) { IFile file = (IFile) iter.next(); symbolIndex.flush(file); } } protected List getFilesToCompile() { return filesToCompile; } protected void analyzeFiles() throws CoreException { filesToClear = new ArrayList(); filesToCompile = new ArrayList(); rootDelta.accept(new IResourceDeltaVisitor() { public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); if (isRubyFile(resource)) { if (delta.getKind() == IResourceDelta.REMOVED) { filesToClear.add(resource); } else if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) { filesToCompile.add(resource); } } return true; } private boolean isRubyFile(IResource resource) { return resource instanceof IFile && Util.isRubyLikeFileName(resource.getName()); }}); filesToClear.addAll(filesToCompile); } } |