Changeset 3784


Ignore:
Timestamp:
May 25, 2008, 12:30:18 AM (12 years ago)
Author:
yura
Message:
Location:
devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core/RfpAbstractBuilder.java

    r3783 r3784  
    5353    }
    5454
    55     private void compileModules (final SortedSet<String> modulesToRecompile, IProgressMonitor monitor)
     55    protected void compileModules (final SortedSet<String> modulesToRecompile, IProgressMonitor monitor)
    5656            throws CoreException {
    5757        IWorkspace workspace = ResourcesPlugin.getWorkspace();
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core/RfpBuilder.java

    r3783 r3784  
    77import java.util.Arrays;
    88import java.util.HashMap;
    9 import java.util.Map;
    109import java.util.Set;
    1110import java.util.SortedMap;
     
    2322import org.eclipse.core.resources.IResourceDeltaVisitor;
    2423import org.eclipse.core.resources.IResourceVisitor;
    25 import org.eclipse.core.resources.IWorkspace;
    26 import org.eclipse.core.resources.IWorkspaceRunnable;
    27 import org.eclipse.core.resources.IncrementalProjectBuilder;
    28 import org.eclipse.core.resources.ResourcesPlugin;
    2924import org.eclipse.core.runtime.CoreException;
    3025import org.eclipse.core.runtime.IPath;
    3126import org.eclipse.core.runtime.IProgressMonitor;
    32 import org.eclipse.core.runtime.OperationCanceledException;
    3327import org.eclipse.core.runtime.QualifiedName;
    3428import org.eclipse.jdt.core.IClasspathContainer;
     
    5145import org.refal.rfpdt.compiler.SrcPosition;
    5246
    53 public class RfpBuilder extends IncrementalProjectBuilder {
    54     private RfpProject getRfpProject () {
    55         return RfpCore.getRfpProject(getProject());
    56     }
    57 
     47public class RfpBuilder extends RfpAbstractBuilder {
    5848    private void deleteClassFiles (IFile file) {
    5949        RfpProject rfpProject = getRfpProject();
     
    265255    }
    266256
    267     /*
    268      * (non-Javadoc)
    269      *
    270      * @see org.eclipse.core.internal.events.InternalBuilder#build(int, java.util.Map,
    271      *      org.eclipse.core.runtime.IProgressMonitor)
    272      */
    273     @SuppressWarnings("unchecked")
     257    private static void deleteMarkers (IFile file) {
     258        try {
     259            file.deleteMarkers(RfpCore.MARKER_ID, false, IResource.DEPTH_ZERO);
     260        } catch (CoreException e) {
     261            RfpCore.log(e);
     262        }
     263    }
     264
    274265    @Override
    275     protected IProject[] build (int kind, Map args, IProgressMonitor monitor) throws CoreException {
    276         if (kind == FULL_BUILD)
    277             fullBuild(monitor);
    278         else {
    279             RfpProject rfpProject = getRfpProject();
    280             IResourceDelta delta = getDelta(rfpProject.getProject());
    281             if (delta == null || delta.findMember(rfpProject.getFile(".classpath").getProjectRelativePath()) != null)
    282                 fullBuild(monitor);
    283             else
    284                 incrementalBuild(delta, monitor);
    285         }
    286         return null;
    287     }
    288 
    289     @SuppressWarnings("unchecked")
    290     private void checkAndCompileModuleImplem (IResource resource) {
    291         if (!RfpProject.isRfFile(resource))
     266    protected void checkAndCompileModuleImplem (String moduleName) {
     267        IFile file = getRfpProject().getSource(moduleName, "rf");       
     268        if (!RfpProject.isRfFile(file))
    292269            return;
    293         IFile file = (IFile) resource;
    294270        deleteMarkers(file);
    295271        CompilerEnvironment environment = new IdeCompilerEnvironment(getRfpProject(), file);
     
    324300    }
    325301
    326     private boolean checkCancel (IProgressMonitor monitor) {
    327         if (monitor.isCanceled())
    328             // Discard build state if necessary
    329             throw new OperationCanceledException();
    330 
    331         // if (isInterrupted()) { // FIXME: should cancel current job
    332         // and rescedule auto-builds.
    333         // return true;
    334         // }
    335         return false;
     302    private SortedSet<String> getNamesOfImportedModules (IFile file) {
     303        SortedSet<String> moduleNameSet = new TreeSet<String>();
     304        try {
     305            String asString = file.getPersistentProperty(IMPORTED_MODULES_PROPKEY);
     306            if (asString == null)
     307                return moduleNameSet;
     308            moduleNameSet.addAll(Arrays.asList(asString.split(",")));
     309        } catch (CoreException e) {}
     310        return moduleNameSet;
    336311    }
    337312
     
    363338    }
    364339
    365     private void compileEachModule (SortedSet<String> modulesToRecompile, IProgressMonitor monitor) {
    366         monitor.beginTask("Recompile modules", modulesToRecompile.size());
    367         for (String moduleName : modulesToRecompile) {
    368             if (checkCancel(monitor))
    369                 return;
    370             monitor.subTask("Compiling the module " + moduleName);
    371             checkAndCompileModuleImplem(getRfpProject().getSource(moduleName, "rf"));
    372             // try {
    373             // Thread.sleep(1000);
    374             // } catch (InterruptedException e) {
    375             // }
    376             monitor.worked(1);
    377         }
    378         monitor.done();
    379     }
    380 
    381     private void compileModules (final SortedSet<String> modulesToRecompile, IProgressMonitor monitor)
    382             throws CoreException {
    383         // workspace.run(action, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
    384         IWorkspace workspace = ResourcesPlugin.getWorkspace();
    385         workspace.run(new IWorkspaceRunnable() {
    386             public void run (IProgressMonitor monitor) throws CoreException {
    387                 compileEachModule(modulesToRecompile, monitor);
    388             }
    389         }, workspace.getRoot(), 0, monitor);
    390     }
    391 
    392     private static void deleteMarkers (IFile file) {
    393         try {
    394             file.deleteMarkers(RfpCore.MARKER_ID, false, IResource.DEPTH_ZERO);
    395         } catch (CoreException e) {
    396             RfpCore.log(e);
    397         }
    398     }
    399 
    400     private void fullBuild (final IProgressMonitor monitor) throws CoreException {
    401         final SortedSet<String> modulesToRecompile = new TreeSet<String>();
    402         final RfpProject rfpProject = getRfpProject();
    403         try {
    404             getProject().accept(new IResourceVisitor() {
    405                 public boolean visit (IResource resource) throws CoreException {
    406                     if (RfpProject.isRfFile(resource)) {
    407                         String moduleName = rfpProject.getModuleName((IFile) resource);
    408                         if (moduleName != null)
    409                             modulesToRecompile.add(moduleName);
    410                     }
    411                     return true;
    412                 }
    413             });
    414             compileModules(modulesToRecompile, monitor);
    415         } catch (CoreException e) {
    416             RfpCore.log(e);
    417         }
    418     }
    419 
    420     private SortedSet<String> getNamesOfImportedModules (IFile file) {
    421         SortedSet<String> moduleNameSet = new TreeSet<String>();
    422         try {
    423             String asString = file.getPersistentProperty(IMPORTED_MODULES_PROPKEY);
    424             if (asString == null)
    425                 return moduleNameSet;
    426             moduleNameSet.addAll(Arrays.asList(asString.split(",")));
    427         } catch (CoreException e) {}
    428         return moduleNameSet;
    429     }
    430 
    431     private void incrementalBuild (IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
     340    @Override
     341    protected void incrementalBuild (IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
    432342        final SortedSet<String> modulesToRecompile = new TreeSet<String>();
    433343        final SortedMap<String, SortedSet<String>> dependencies = collectDependencies();
     
    457367                }
    458368            });
    459         } catch (CoreException e) {}
     369        } catch (CoreException e) {
     370            RfpCore.log(e);
     371        }
    460372        compileModules(modulesToRecompile, monitor);
    461373    }
Note: See TracChangeset for help on using the changeset viewer.