Changeset 1172

Show
Ignore:
Timestamp:
05/21/08 07:38:44 (3 months ago)
Author:
fraserofthenight
Message:

Removed some of the confusing stuff from the old builder interface. There's now a much more uniform (and Eclipse-happy) builder interface.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.launching/plugin.xml

    r1170 r1172  
    173173         point="descent.launching.dBuilders"> 
    174174      <builder 
    175             class="descent.internal.launching.debuild.DebuildBuilderNew
     175            class="descent.internal.launching.debuild.DebuildBuilder
    176176            id="descent.launching.builders.debuildBuilder" 
    177177            launchConfigurationType="descent.launching.builders.debuild"> 
  • trunk/descent.launching/src/descent/internal/launching/LaunchingPlugin.java

    r1170 r1172  
    8181    public static final String PLUGIN_ID = "descent.launching"; //$NON-NLS-1$ 
    8282    public static final String ID_PLUGIN = PLUGIN_ID; 
     83     
     84    // The build group identifier 
    8385    public static final String ID_BUILD_GROUP = "descent.launching.builders"; //$NON-NLS-1$ 
    8486     
     
    9597     */ 
    9698    public static final String ID_EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRIES = "runtimeClasspathEntries"; //$NON-NLS-1$ 
     99     
     100    /** 
     101     * Identifier for 'dBuilders' extension point 
     102     */ 
     103    public static final String ID_EXTENSION_POINT_D_BUILDERS = "dBuilders"; 
    97104     
    98105    /** 
  • trunk/descent.launching/src/descent/internal/launching/debuild/BuildRequest.java

    r1101 r1172  
    44import java.util.HashSet; 
    55import java.util.List; 
    6 import java.util.Set; 
    76 
    87import org.eclipse.core.runtime.CoreException; 
     8import org.eclipse.debug.core.ILaunchConfiguration; 
    99 
    1010import descent.core.IJavaProject; 
    1111import descent.core.JavaCore; 
    12 import descent.launching.IExecutableTarget; 
    1312import descent.launching.IVMInstall; 
    1413import descent.launching.JavaRuntime; 
     
    2120 * of this type will exist per DebuildBuilder, and this object should 
    2221 * generally simply serve as a wrapper for abstracting getting information 
    23  * that the build needs from the {@link IExecutableTarget}. 
    24  *  
    25  * Note that many of these methods are simply wrappers for  
    26  * <code>IExecutableTarget</code> methods. This is okay, since it helps abstract 
    27  * these things from the builder if that interface ever changes. 
     22 * that the build needs from the {@link ILaunchConfiguration}. 
    2823 * 
    2924 * @author Robert Fraser 
     
    3126/* package */ class BuildRequest 
    3227{ 
    33     /** 
    34      * Information about the executable target to be built (is it debug? 
    35      * should we optimize? Add unit tests? etc., etc.) 
    36      */ 
    37     private final IExecutableTarget target; 
     28    private final ILaunchConfiguration config; 
    3829    private final IJavaProject project; 
    3930    private final IVMInstall compilerType; 
    4031     
    41     public BuildRequest(IExecutableTarget target
    42     { 
    43         this.target = target
    44         this.project = target.getProject(); 
     32    public BuildRequest(ILaunchConfiguration config
     33    { 
     34        this.config = config
     35        this.project = null; // TODO config.getProject(); 
    4536         
    4637        IVMInstall compilerType = null; 
     
    7768    public String[] getModules() 
    7869    { 
    79         return target.getModules(); 
     70        // TODO return config.getModules(); 
     71        return null; 
    8072    } 
    8173     
     
    8577    public String[] getDefaultImportPath() 
    8678    { 
    87         return target.getDefaultImportPath(); 
     79        // TODO return config.getDefaultImportPath(); 
     80        return null; 
    8881    } 
    8982     
     
    109102         
    110103        // Set the executable-target-specific options 
    111         opts.addDebugInfo = target.getAddDebugInfo(); 
    112         opts.addUnittests = target.getAddUnittests(); 
    113         opts.addAssertsAndContracts = target.getAddAssertsAndContracts(); 
    114         opts.inlineFunctions = target.getInlineFunctions(); 
    115         opts.optimizeCode = target.getOptimizeCode(); 
    116         opts.instrumentForCoverage = target.getInstrumentForCoverage(); 
    117         opts.instrumentForProfile = target.getInstrumentForProfile(); 
    118         for(String ident : target.getDefaultVersionIdents()) 
    119            opts.debugIdents.add(ident); 
    120         for(String ident : target.getDefaultDebugIdents()) 
    121            opts.debugIdents.add(ident); 
     104     // TODO opts.addDebugInfo = config.getAddDebugInfo(); 
     105     // TODO opts.addUnittests = config.getAddUnittests(); 
     106     // TODO opts.addAssertsAndContracts = config.getAddAssertsAndContracts(); 
     107     // TODO opts.inlineFunctions = config.getInlineFunctions(); 
     108     // TODO opts.optimizeCode = config.getOptimizeCode(); 
     109     // TODO opts.instrumentForCoverage = config.getInstrumentForCoverage(); 
     110     // TODO opts.instrumentForProfile = config.getInstrumentForProfile(); 
     111     // TODO for(String ident : config.getDefaultVersionIdents()) 
     112     // TODO opts.debugIdents.add(ident); 
     113     // TODO for(String ident : config.getDefaultDebugIdents()) 
     114     // TODO opts.debugIdents.add(ident); 
    122115         
    123116        // Set the project-specific options 
  • trunk/descent.launching/src/descent/internal/launching/debuild/DebuildBuilder.java

    r1170 r1172  
    77import java.util.Set; 
    88 
     9import org.eclipse.core.runtime.CoreException; 
    910import org.eclipse.core.runtime.IProgressMonitor; 
    1011import org.eclipse.core.runtime.NullProgressMonitor; 
     
    1617import descent.core.IJavaProject; 
    1718import descent.core.JavaModelException; 
    18 import descent.launching.BuildCancelledException; 
    1919import descent.launching.IDBuilder; 
    20 import descent.launching.IExecutableTarget; 
    2120import descent.launching.compiler.BuildError; 
    2221import descent.launching.compiler.BuildResponse; 
     
    2625import descent.launching.compiler.IResponseInterpreter; 
    2726 
    28 /** 
    29  * The main engine of the descent remote builder. Given an executable target 
    30  * (info on what type of executable is needed) and a project, performs the 
    31  * build. The publuc interface of this class can be accessed via the 
    32  * {@link #build(IExecutableTarget, IProgressMonitor)} method, 
    33  * which will initiat a build. 
    34  *  
    35  * @author Robert Fraser 
    36  */ 
    37 public class DebuildBuilder 
     27// TODO recomment 
     28public class DebuildBuilder implements IDBuilder 
    3829{     
    39     /** 
    40      * Public interface to the debuild builder, which initiates a new build 
    41      * based on the given executable target. The target 
    42      * should contain information on what is to be built. Returns the path to 
    43      * the executable file if one is built (or already exists in the project) 
    44      * or null if the project could not be built. 
    45      *  
    46      * @param target information about the target executable to be built 
    47      * @param pm     a monitor to track the progress of the build 
    48      * @return       the path to the executable file or null if one could not 
    49      *               be built due to an error 
    50      */ 
    51     public static String build(IExecutableTarget target, IProgressMonitor pm) 
    52     { 
    53         DebuildBuilder builder = new DebuildBuilder(new BuildRequest(target)); 
    54         return builder.build(pm); 
    55     } 
    56      
    5730    /* package */ static final boolean DEBUG = true; 
    58      
    5931    /* package */ static final String EXECUTABLE_FILE_PREFIX = "-"; 
    6032     
    61     //-------------------------------------------------------------------------- 
    62      
    63     private final BuildRequest req; 
    64     private final ErrorReporter err; 
     33    private BuildRequest req; 
     34    private ErrorReporter err; 
    6535     
    6636    private List<File> importPath; 
     
    6838    private List<GroupedCompile> groupedCompiles; 
    6939    private CompileOptions opts; 
    70      
    71     private DebuildBuilder(BuildRequest req) 
     40     
     41    public String build(ILaunchConfiguration config, IProgressMonitor pm) 
     42            throws CoreException 
    7243    { 
    73         this.req = req; 
    74         this.err = new ErrorReporter(req.getProject()); 
    75     } 
    76      
    77     private String build(IProgressMonitor pm) 
    78     { 
     44        // TODO remove 
     45        if(true) 
     46        { 
     47            System.out.println("We here, baby!"); 
     48            return null; 
     49        } 
     50         
    7951        if(null == pm) 
    8052            pm = new NullProgressMonitor(); 
    8153         
    8254        if(pm.isCanceled()) 
    83             throw new BuildCancelledException()
     55            return null
    8456         
    8557        try 
     
    8759            pm.beginTask("Building D application", 100); 
    8860             
    89             // Usually, a little work has been done by now. Move the progress bar to keep the 
    90            // user in a pleasent and productive mood 
     61            req = new BuildRequest(config); 
     62            err = new ErrorReporter(req.getProject()); 
    9163            pm.worked(5); // 5 
    9264             
     
    9870             
    9971            if(pm.isCanceled()) 
    100                 throw new BuildCancelledException()
     72                return null
    10173             
    10274            // Then, recursively collect dependancies for all the object files 
     
    10880             
    10981            if(pm.isCanceled()) 
    110                 throw new BuildCancelledException()
     82                return null
    11183             
    11284            // Then, get the compile options we should use and apply them to 
     
    11890             
    11991            if(pm.isCanceled()) 
    120                 throw new BuildCancelledException()
     92                return null
    12193             
    12294            // Create a set of grouped compiles for each compile group we need 
     
    12597             
    12698            if(pm.isCanceled()) 
    127                 throw new BuildCancelledException()
     99                return null
    128100             
    129101            // Perform each compile operation 
     
    137109        catch(Exception e) 
    138110        { 
    139             if(DEBUG && !(e instanceof BuildCancelledException)
     111            if(DEBUG
    140112                e.printStackTrace(); 
    141113            if(e instanceof RuntimeException) 
     
    224196            { 
    225197                if(pm.isCanceled()) 
    226                     throw new BuildCancelledException()
     198                    return null
    227199                 
    228200                // Get & setup a new compile command 
     
    274246             
    275247            if(pm.isCanceled()) 
    276                 throw new BuildCancelledException()
     248                return null
    277249             
    278250            // Create the linker command 
  • trunk/descent.launching/src/descent/internal/launching/debuild/RecursiveDependancyCollector.java

    r1101 r1172  
    2323import descent.core.IParent; 
    2424import descent.core.JavaModelException; 
    25 import descent.launching.BuildCancelledException; 
    26  
    2725/** 
    2826 * Class that can recurse through dependancies to generate a list of all files 
     
    9189                // is good! 
    9290                if(pm.isCanceled()) 
    93                     throw new BuildCancelledException()
     91                    return null
    9492                 
    9593                collectRecursive(moduleName); 
  • trunk/descent.launching/src/descent/launching/BuilderLaunchDelegate.java

    r1170 r1172  
    33import org.eclipse.core.runtime.CoreException; 
    44import org.eclipse.core.runtime.IProgressMonitor; 
     5import org.eclipse.core.runtime.IStatus; 
     6import org.eclipse.core.runtime.Status; 
    57import org.eclipse.debug.core.ILaunch; 
    68import org.eclipse.debug.core.ILaunchConfiguration; 
    79import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; 
     10 
     11import descent.internal.launching.LaunchingPlugin; 
    812 
    913/** 
     
    2024            ILaunch launch, IProgressMonitor pm) throws CoreException 
    2125    { 
    22         // TODO get the builder type & perform the build 
     26        // Get the builder and call its build method... pretty simple, actually 
     27        String configTypeId = config.getType().getIdentifier(); 
     28        IDBuilderType builderType = BuilderRegistry.getInstance().getBuilderForLaunchConfigurationType(configTypeId); 
     29        if(null == builderType) 
     30            throw error("Could not find builder for launch configuration type " + configTypeId); 
     31         
     32        IDBuilder builder = builderType.getBuilder(); 
     33        if(null == builder) 
     34            throw error("Could not create builder for builder type " + builderType.getIdentifier()); 
     35         
     36        builder.build(config, pm); 
     37    } 
     38     
     39    private static CoreException error(String message) 
     40    { 
     41        return new CoreException(new Status(IStatus.ERROR,  
     42                LaunchingPlugin.PLUGIN_ID, message)); 
    2343    } 
    2444} 
  • trunk/descent.launching/src/descent/launching/BuilderRegistry.java

    r1170 r1172  
    11package descent.launching; 
    22 
     3import java.util.ArrayList; 
     4import java.util.List; 
     5 
     6import org.eclipse.core.runtime.CoreException; 
     7import org.eclipse.core.runtime.IConfigurationElement; 
     8import org.eclipse.core.runtime.IExtensionPoint; 
     9import org.eclipse.core.runtime.Platform; 
     10 
     11import descent.internal.launching.LaunchingPlugin; 
     12 
     13/** 
     14 * Class used to get information about what types of D builders have been configured 
     15 * for use with Descent. 
     16 *  
     17 * @author Robert Fraser 
     18 */ 
    319public class BuilderRegistry 
    420{ 
     21    private class DBuilderType implements IDBuilderType 
     22    { 
     23        // Attributes defined in the schema 
     24        private static final String ATTR_ID = "id"; 
     25        private static final String ATTR_CLASS = "class"; 
     26        private static final String ATTR_LAUNCH_CONFIGURATION_TYPE = "launchConfigurationType"; 
     27         
     28        private final IConfigurationElement info; 
    529 
     30        private DBuilderType(IConfigurationElement info) 
     31        {  
     32            this.info = info; 
     33        } 
     34         
     35        /* (non-Javadoc) 
     36         * @see descent.launching.IDBuilderType#getBuilder() 
     37         */ 
     38        public IDBuilder getBuilder() throws CoreException 
     39        { 
     40            return (IDBuilder) info.createExecutableExtension(ATTR_CLASS); 
     41        } 
     42         
     43        /* (non-Javadoc) 
     44         * @see descent.launching.IDBuilderType#getIdentifier() 
     45         */ 
     46        public String getIdentifier() 
     47        { 
     48            return info.getAttribute(ATTR_ID); 
     49        } 
     50         
     51        /* (non-Javadoc) 
     52         * @see descent.launching.IDBuilderType#getLaunchConfigurationType() 
     53         */ 
     54        public String getLaunchConfigurationType() 
     55        { 
     56            return info.getAttribute(ATTR_LAUNCH_CONFIGURATION_TYPE); 
     57        } 
     58    } 
     59     
     60    private List<DBuilderType> builders; 
     61     
     62    /** 
     63     * Gets info about all the builders registered with this plugin 
     64     *  
     65     * @return the list of all builders associated with this plugin 
     66     */ 
     67    public IDBuilderType[] getBuilders() 
     68    { 
     69        if(null == builders) 
     70            loadBuilders(); 
     71         
     72        return builders.toArray(new IDBuilderType[builders.size()]); 
     73    } 
     74     
     75    /** 
     76     * Gets the builder associated with the given id. I'm not sure if Eclipse 
     77     * allows multiple things to have the same "id" property, but if it does, 
     78     * that would be an undefined condition for this method. 
     79     *  
     80     * @param id the id to look up 
     81     * @return   the builder associated with the id or <code>null</code> if none 
     82     *           was found 
     83     */ 
     84    public IDBuilderType getBuilderById(String id) 
     85    { 
     86        if(null == builders) 
     87            loadBuilders(); 
     88         
     89        for(IDBuilderType builder : builders) 
     90        { 
     91            if(builder.getIdentifier().equals(id)) 
     92                return builder; 
     93        } 
     94        return null; 
     95    } 
     96     
     97    /** 
     98     * Gets the builder associated with the given launch configuration type. Note 
     99     * that if multiple builders are associated with the same launch configuration 
     100     * type, the one which is returned is undefined, so don't let this happen. 
     101     *  
     102     * @param launchConfigurationType the launch configuration type to look up 
     103     * @return                        the associated builder or <code>null</code> 
     104     *                                if none was found 
     105     */ 
     106    public IDBuilderType getBuilderForLaunchConfigurationType( 
     107            String launchConfigurationType) 
     108    { 
     109        if(null == builders) 
     110            loadBuilders(); 
     111         
     112        for(IDBuilderType builder : builders) 
     113        { 
     114            if(builder.getLaunchConfigurationType().equals(launchConfigurationType)) 
     115                return builder; 
     116        } 
     117        return null; 
     118    } 
     119     
     120    /** 
     121     * Gets the builder type associated with the default descent builder 
     122     *  
     123     * @return the builder type associated with the default descent builder 
     124     */ 
     125    public IDBuilderType getDescentBuilder() 
     126    { 
     127        return getBuilderById(IDescentBuilderConstants.ID_DESCENT_BUILDER); 
     128    } 
     129     
     130    private synchronized void loadBuilders() 
     131    { 
     132        if(null != builders) 
     133            return; 
     134         
     135        builders = new ArrayList<DBuilderType>(); 
     136        IExtensionPoint extensionPoint = Platform.getExtensionRegistry(). 
     137                getExtensionPoint(LaunchingPlugin.ID_PLUGIN, 
     138                LaunchingPlugin.ID_EXTENSION_POINT_D_BUILDERS); 
     139        IConfigurationElement[] infos = extensionPoint.getConfigurationElements(); 
     140         
     141        for(IConfigurationElement info : infos) 
     142        { 
     143            DBuilderType builder = new DBuilderType(info); 
     144            builders.add(builder); 
     145        } 
     146    } 
     147     
     148    //-------------------------------------------------------------------------- 
     149    // Instance management 
     150     
     151    private static BuilderRegistry instance; 
     152     
     153    /** 
     154     * Gets the instance of the singleton. 
     155     *  
     156     * @return the singleton instance 
     157     */ 
     158    public static synchronized BuilderRegistry getInstance() 
     159    { 
     160        if(null == instance) 
     161            instance = new BuilderRegistry(); 
     162         
     163        return instance; 
     164    } 
     165     
     166    private BuilderRegistry() 
     167    { 
     168        // Should not be called outside this class 
     169    } 
    6170} 
  • trunk/descent.launching/src/descent/launching/IDBuilder.java

    r1170 r1172  
    11package descent.launching; 
    22 
     3import org.eclipse.core.runtime.CoreException; 
    34import org.eclipse.core.runtime.IProgressMonitor; 
    45import org.eclipse.debug.core.ILaunchConfiguration; 
    56 
     7/** 
     8 * Interface which should be implemented by all builder providers. Provides a 
     9 * mechanism for building a D application, library, dynamic library or associated 
     10 * resource(s). Builders may be associated with one or more run configurations 
     11 * or as part of the Eclipse build cycle, as well as being invoked manually, so 
     12 * there is no guarantee that it is actually being invoked within a launch despite 
     13 * the fact that all configurations are done using a {@link ILaunchConfiguration}. 
     14 *  
     15 * Implementations must have a no-element constructor unless they follow the 
     16 * design pattern laid out in  
     17 * {@link org.eclipse.core.runtime.IConfigurationElement#createExecutableExtension(String)} 
     18 * A new builder instance will be constructed on each build. The constructor should 
     19 * run fairly quickly, as there is no progress monitor running during this phase 
     20 * of the build. 
     21 *  
     22 * @author Robert Fraser 
     23 */ 
    624public interface IDBuilder 
    725{ 
    8     public String build(ILaunchConfiguration config, IProgressMonitor pm)
     26    public String build(ILaunchConfiguration config, IProgressMonitor pm) throws CoreException
    927} 
  • trunk/descent.unittest/testdata/src/sample/foo/module3.d

    r1113 r1172  
    11module sample.foo.module3; 
    2  
    3 // You get nothing! Ha ha, you are so STUUUPID!