Changeset 1216
- Timestamp:
- 07/07/08 01:48:55 (2 months ago)
- Files:
-
- trunk/descent.building/src/descent/building/compiler/IObjectFile.java (added)
- trunk/descent.building/src/descent/internal/building/BuilderUtil.java (modified) (3 diffs)
- trunk/descent.building/src/descent/internal/building/debuild/BuildRequest.java (modified) (6 diffs)
- trunk/descent.building/src/descent/internal/building/debuild/DebuildBuilder.java (modified) (6 diffs)
- trunk/descent.building/src/descent/internal/building/debuild/DebuildException.java (modified) (1 diff)
- trunk/descent.building/src/descent/internal/building/debuild/ObjectFileFactory.java (added)
- trunk/descent.building/src/descent/internal/building/debuild/RecursiveDependancyCollector.java (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.building/src/descent/internal/building/BuilderUtil.java
r1197 r1216 121 121 return false; 122 122 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))) 125 127 return false; 126 128 return true; … … 156 158 } 157 159 158 private static boolean isValidId Char(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 OK160 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 == '$'); 166 168 } 167 169 … … 262 264 return JavaRuntime.getVMInstall(project); 263 265 } 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 } 264 280 } trunk/descent.building/src/descent/internal/building/debuild/BuildRequest.java
r1202 r1216 1 1 package descent.internal.building.debuild; 2 2 3 import java.io.File; 3 4 import java.util.ArrayList; 5 import java.util.Iterator; 4 6 import java.util.List; 5 7 8 import org.eclipse.core.resources.IFolder; 6 9 import org.eclipse.core.resources.ResourcesPlugin; 7 10 import org.eclipse.core.runtime.CoreException; 11 import org.eclipse.core.runtime.IPath; 8 12 import org.eclipse.debug.core.ILaunchConfiguration; 9 13 … … 35 39 private final IVMInstall compilerInstall; 36 40 private final ICompilerInterface compilerInterface; 37 41 private final IFolder outputResource; 42 43 // For version/debug settings 38 44 private final IJavaProject sourceProject; 39 40 45 private final Integer versionLevel; 41 46 private final List<String> versionIdents; … … 58 63 } 59 64 compilerInterface = BuilderUtil.getCompilerInterface(compilerInstall); 65 outputResource = setOutputResource(); 60 66 61 67 // Set debug/version settings 62 68 sourceProject = getSourceProject(); 63 64 69 debugLevel = getLevel(ATTR_DEBUG_LEVEL, JavaCore.COMPILER_DEBUG_LEVEL); 65 70 versionLevel = getLevel(ATTR_VERSION_LEVEL, JavaCore.COMPILER_VERSION_LEVEL); … … 83 88 { 84 89 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; 85 99 } 86 100 … … 161 175 } 162 176 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 163 187 //-------------------------------------------------------------------------- 164 188 // 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 } 165 204 166 205 private final IJavaProject initializeProject() … … 216 255 if(removePredefined) 217 256 { 218 for(String ident : idents) 257 Iterator<String> iter = idents.iterator(); 258 while(iter.hasNext()) 259 { 260 String ident = iter.next(); 219 261 if(BuilderUtil.isPredefinedVersion(ident)) 220 idents.remove(ident); 262 iter.remove(); 263 } 221 264 } 222 265 return idents; trunk/descent.building/src/descent/internal/building/debuild/DebuildBuilder.java
r1197 r1216 7 7 import java.util.Set; 8 8 9 import org.eclipse.core.resources.IFile; 10 import org.eclipse.core.resources.IFolder; 11 import org.eclipse.core.resources.IResource; 9 12 import org.eclipse.core.runtime.CoreException; 10 13 import org.eclipse.core.runtime.IProgressMonitor; 11 14 import org.eclipse.core.runtime.NullProgressMonitor; 15 import org.eclipse.debug.core.DebugPlugin; 12 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 13 18 14 19 import descent.core.IClasspathEntry; … … 19 24 import descent.building.IDBuilder; 20 25 21 // TODO recomment22 26 public class DebuildBuilder implements IDBuilder 23 27 { 24 28 /* 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(); 26 35 27 36 private BuildRequest req; … … 31 40 public String build(ILaunchConfiguration config, IProgressMonitor pm) 32 41 throws CoreException 33 { 34 // TODO remove 35 if(true) 36 return null; 37 42 { 38 43 if(null == pm) 39 44 pm = new NullProgressMonitor(); … … 44 49 try 45 50 { 51 // Create the build request & error reporter 46 52 pm.beginTask("Building D application", 100); 47 48 53 req = new BuildRequest(config); 49 54 err = new ErrorReporter(req.getProject()); 50 55 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 51 61 52 IJavaProject project = req.getProject(); 53 54 // First, create the import path from the project properties, etc. 62 // Create the import path 55 63 createImportPath(); 56 pm.worked( 10); // 1564 pm.worked(5); // 15 57 65 58 66 if(pm.isCanceled()) … … 65 73 { 66 74 err.projectError(e.getMessage()); 67 return null; 68 75 throw e; // TODO remove 69 76 } 70 77 catch(Exception e) … … 83 90 } 84 91 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() 86 185 { 87 186 try trunk/descent.building/src/descent/internal/building/debuild/DebuildException.java
r1174 r1216 14 14 super(msg); 15 15 } 16 17 public DebuildException(Exception e) 18 { 19 super(e); 20 } 16 21 }
