Changeset 1216

Show
Ignore:
Timestamp:
07/07/08 01:48:55 (2 months ago)
Author:
fraserofthenight
Message:

Started making some changes, but it seems I need to approach this a different way.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.building/src/descent/internal/building/BuilderUtil.java

    r1197 r1216  
    121121            return false; 
    122122         
    123         for(int i = 0; i < len; i++) 
    124             if(!isValidIdChar(id.charAt(i))) 
     123        if(!isValidIdStart(id.charAt(0))) 
     124            return false; 
     125        for(int i = 1; i < len; i++) 
     126            if(!isValidIdPart(id.charAt(i))) 
    125127                return false; 
    126128        return true; 
     
    156158    } 
    157159     
    158     private static boolean isValidIdChar(char c) 
    159     { 
    160         return  
    161             (c >= 'a' && c <= 'z') ||  
    162             (c >= 'A' && c <= 'Z') ||  
    163             (c >= '0' && c <= '9') || 
    164             c == '_' || 
    165             c >= 128; // Assume anything in unicode is OK 
     160    private static boolean isValidIdStart(char c) 
     161    { 
     162        return Character.isJavaIdentifierStart(c) && !(c == '$'); 
     163    } 
     164     
     165    private static boolean isValidIdPart(char c) 
     166    { 
     167        return Character.isJavaIdentifierPart(c) && !(c == '$'); 
    166168    } 
    167169     
     
    262264        return JavaRuntime.getVMInstall(project); 
    263265    } 
     266     
     267    /** 
     268     * This method is needed since  
     269     * {@link ILaunchConfiguration#contentsEqual(ILaunchConfiguration)} compares 
     270     * the paths of launch configurations as well, and the getInfo method is not 
     271     * publicly available. 
     272     */ 
     273    public static boolean launchConfigsEqual(ILaunchConfiguration config, 
     274            ILaunchConfiguration other) throws CoreException 
     275    { 
     276        return config.getName().equals(other.getName()) && 
     277                config.getType().equals(other.getType()) && 
     278                config.getAttributes().equals(other.getAttributes()); 
     279    } 
    264280} 
  • trunk/descent.building/src/descent/internal/building/debuild/BuildRequest.java

    r1202 r1216  
    11package descent.internal.building.debuild; 
    22 
     3import java.io.File; 
    34import java.util.ArrayList; 
     5import java.util.Iterator; 
    46import java.util.List; 
    57 
     8import org.eclipse.core.resources.IFolder; 
    69import org.eclipse.core.resources.ResourcesPlugin; 
    710import org.eclipse.core.runtime.CoreException; 
     11import org.eclipse.core.runtime.IPath; 
    812import org.eclipse.debug.core.ILaunchConfiguration; 
    913 
     
    3539    private final IVMInstall compilerInstall; 
    3640    private final ICompilerInterface compilerInterface; 
    37      
     41    private final IFolder outputResource; 
     42     
     43    // For version/debug settings 
    3844    private final IJavaProject sourceProject; 
    39      
    4045    private final Integer versionLevel; 
    4146    private final List<String> versionIdents; 
     
    5863        } 
    5964        compilerInterface = BuilderUtil.getCompilerInterface(compilerInstall); 
     65        outputResource = setOutputResource(); 
    6066         
    6167        // Set debug/version settings 
    6268        sourceProject = getSourceProject(); 
    63          
    6469        debugLevel = getLevel(ATTR_DEBUG_LEVEL, JavaCore.COMPILER_DEBUG_LEVEL); 
    6570        versionLevel = getLevel(ATTR_VERSION_LEVEL, JavaCore.COMPILER_VERSION_LEVEL); 
     
    8388    { 
    8489        return compilerInterface; 
     90    } 
     91     
     92    /** 
     93     * Gets the associated launch configuration. Using the specific methods 
     94     * should be preferred to this for getting information from the config. 
     95     */ 
     96    public ILaunchConfiguration getLaunchConfig() 
     97    { 
     98        return config; 
    8599    } 
    86100     
     
    161175    } 
    162176     
     177    public IFolder getOutputResource() 
     178    { 
     179        return outputResource; 
     180    } 
     181     
     182    public File getOutputLocation() 
     183    { 
     184        return new File(BuilderUtil.getAbsolutePath(outputResource.getFullPath())); 
     185    } 
     186     
    163187    //-------------------------------------------------------------------------- 
    164188    // Private methods 
     189     
     190    private IFolder setOutputResource() 
     191    { 
     192        try 
     193        { 
     194            IPath outputLoc = project.getOutputLocation().addTrailingSeparator() 
     195                    .append(config.getName()); 
     196            return project.getCorrespondingResource().getWorkspace().getRoot(). 
     197                getFolder(outputLoc); 
     198        } 
     199        catch(JavaModelException e) 
     200        { 
     201            throw new DebuildException(e); 
     202        } 
     203    } 
    165204     
    166205    private final IJavaProject initializeProject() 
     
    216255        if(removePredefined) 
    217256        { 
    218             for(String ident : idents) 
     257            Iterator<String> iter = idents.iterator(); 
     258            while(iter.hasNext()) 
     259            { 
     260                String ident = iter.next(); 
    219261                if(BuilderUtil.isPredefinedVersion(ident)) 
    220                     idents.remove(ident); 
     262                    iter.remove(); 
     263            } 
    221264        } 
    222265        return idents; 
  • trunk/descent.building/src/descent/internal/building/debuild/DebuildBuilder.java

    r1197 r1216  
    77import java.util.Set; 
    88 
     9import org.eclipse.core.resources.IFile; 
     10import org.eclipse.core.resources.IFolder; 
     11import org.eclipse.core.resources.IResource; 
    912import org.eclipse.core.runtime.CoreException; 
    1013import org.eclipse.core.runtime.IProgressMonitor; 
    1114import org.eclipse.core.runtime.NullProgressMonitor; 
     15import org.eclipse.debug.core.DebugPlugin; 
    1216import org.eclipse.debug.core.ILaunchConfiguration; 
     17import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 
    1318 
    1419import descent.core.IClasspathEntry; 
     
    1924import descent.building.IDBuilder; 
    2025 
    21 // TODO recomment 
    2226public class DebuildBuilder implements IDBuilder 
    2327{    
    2428    /* package */ static final boolean DEBUG = true; 
    25     /* package */ static final String EXECUTABLE_FILE_PREFIX = "-"; 
     29     
     30    /** 
     31     * Note: don't use this as the main null progress monitor, since its  
     32     * canceleld state is not garunteed. 
     33     */ 
     34    private static final IProgressMonitor NO_MONITOR = new NullProgressMonitor(); 
    2635     
    2736    private BuildRequest req; 
     
    3140    public String build(ILaunchConfiguration config, IProgressMonitor pm) 
    3241            throws CoreException 
    33     { 
    34         // TODO remove 
    35         if(true) 
    36             return null; 
    37          
     42    {    
    3843        if(null == pm) 
    3944            pm = new NullProgressMonitor(); 
     
    4449        try 
    4550        {    
     51            // Create the build request & error reporter 
    4652            pm.beginTask("Building D application", 100); 
    47              
    4853            req = new BuildRequest(config); 
    4954            err = new ErrorReporter(req.getProject()); 
    5055            pm.worked(5); // 5 
     56             
     57            // If the launch configuration has changed, clear the output folder 
     58            // to do a full rebuild 
     59            managePrecomiledResources(); 
     60            pm.worked(5); // 10 
    5161             
    52             IJavaProject project = req.getProject(); 
    53              
    54             // First, create the import path from the project properties, etc. 
     62            // Create the import path  
    5563            createImportPath(); 
    56             pm.worked(10); // 15 
     64            pm.worked(5); // 15 
    5765             
    5866            if(pm.isCanceled()) 
     
    6573        { 
    6674            err.projectError(e.getMessage()); 
    67             return null; 
    68              
     75            throw e; // TODO remove 
    6976        } 
    7077        catch(Exception e) 
     
    8390    } 
    8491     
    85     private void createImportPath() 
     92    /** 
     93     * If the launch configuration has changed, all pre-compiled resources need to 
     94     * be removed and a full rebuild done (PERHAPS a more selective mechanism -- if 
     95     * the user just changed the output file, for example, no rebuild is needed). 
     96     * This method detects if the current launch configuration is different than the 
     97     * existing launch configuration and if so deletes everything in the folder. 
     98     *  
     99     * @param config 
     100     */ 
     101    private void managePrecomiledResources() 
     102    { 
     103        // TODO this doesn't work (it adds a new launch). FInd out if there's a way 
     104        // not to, alternatively a new serialization mechanism needs to be created 
     105        // (or maybe just somehow store the age/revision of the last change). 
     106        try 
     107        { 
     108            // Check if the folder exists 
     109            IFolder folder = req.getOutputResource(); 
     110            if(!folder.exists()) 
     111            { 
     112                folder.create(true, true, NO_MONITOR); 
     113                createConfigFile(); 
     114                return; 
     115            } 
     116 
     117            folder.refreshLocal(IResource.DEPTH_INFINITE, NO_MONITOR); 
     118            IResource launchConfigFile = folder.findMember(getLaunchConfigFilename()); 
     119            if(null == launchConfigFile || !(launchConfigFile instanceof IFile)) 
     120            { 
     121                System.out.println("File doesn't exist!"); 
     122                clearOutputFolder(); 
     123                createConfigFile(); 
     124                return; 
     125            } 
     126             
     127            ILaunchConfiguration launchConfig = DebugPlugin.getDefault(). 
     128                    getLaunchManager().getLaunchConfiguration((IFile) launchConfigFile); 
     129            if(!BuilderUtil.launchConfigsEqual(launchConfig, req.getLaunchConfig())) 
     130            { 
     131                System.out.println("Not equal!"); 
     132                clearOutputFolder(); 
     133                createConfigFile(); 
     134                return; 
     135            } 
     136             
     137            // If we get here, we can safely use any object files already 
     138            // generated for incremental compilation. 
     139            System.out.println("Contents saved!!!"); 
     140        } 
     141        catch(CoreException e) 
     142        { 
     143            throw new DebuildException(String.format( 
     144                    "Error preparing output folder: %1$s", e.getMessage())); 
     145        } 
     146         
     147    } 
     148     
     149    private String getLaunchConfigFilename() 
     150    { 
     151        return req.getLaunchConfig().getName().concat("."). 
     152                concat(ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION); 
     153    } 
     154 
     155    private void createConfigFile() throws CoreException 
     156    { 
     157        ILaunchConfiguration config = req.getLaunchConfig(); 
     158        ILaunchConfigurationWorkingCopy copy = config.copy(config.getName()); 
     159        copy.setContainer(req.getOutputResource()); 
     160        copy.doSave(); 
     161    } 
     162     
     163    private void clearOutputFolder() throws CoreException 
     164    { 
     165        System.out.println("Folder cleared!!!"); 
     166         
     167        IFolder outputFolder = req.getOutputResource(); 
     168        IResource[] members = outputFolder.members(); 
     169        for(IResource file : members) 
     170        { 
     171            try 
     172            { 
     173                file.delete(true, NO_MONITOR); 
     174            } 
     175            catch(CoreException e) 
     176            { 
     177                throw new DebuildException(String.format( 
     178                        "Error deleting resource %1$s: %2$s",  
     179                        file.getFullPath().toString(), e.getMessage())); 
     180            } 
     181        } 
     182    } 
     183 
     184    private void createImportPath() 
    86185    { 
    87186        try 
  • trunk/descent.building/src/descent/internal/building/debuild/DebuildException.java

    r1174 r1216  
    1414        super(msg); 
    1515    } 
     16     
     17    public DebuildException(Exception e) 
     18    { 
     19        super(e); 
     20    } 
    1621}