1 11 package org.eclipse.ui.externaltools.internal.variables; 12 13 import java.util.LinkedHashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.IResourceDelta; 18 import org.eclipse.core.resources.IResourceDeltaVisitor; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.variables.IDynamicVariable; 21 import org.eclipse.core.variables.IDynamicVariableResolver; 22 import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder; 23 24 public class BuildFilesResolver implements IDynamicVariableResolver 25 { 26 private static final char ARG_REMOVED = 'r'; 27 private static final char ARG_CHANGED = 'c'; 28 private static final char ARG_ADDED = 'a'; 29 private static final char ARG_DIRS = 'd'; 30 private static final char ARG_FILES = 'f'; 31 32 private static final String FILE_LIST_SEPARATOR = " "; 36 public String resolveValue(IDynamicVariable variable, String argument) throws CoreException 37 { 38 String result = null; 39 40 IResourceDelta buildDelta = ExternalToolBuilder.getBuildDelta(); 41 if (buildDelta != null) 42 { 43 final StringBuffer fileList = new StringBuffer (); 44 final Set changedResources = new LinkedHashSet (); 45 46 int deltas = 0; 49 boolean dirs = false, files = false; 50 if (argument != null) 51 { 52 if (argument.indexOf(ARG_ADDED) > -1) 54 { 55 deltas |= IResourceDelta.ADDED; 56 } 57 if (argument.indexOf(ARG_CHANGED) > -1) 58 { 59 deltas |= IResourceDelta.CHANGED; 60 } 61 if (argument.indexOf(ARG_REMOVED) > -1) 62 { 63 deltas |= IResourceDelta.REMOVED; 64 } 65 66 if (argument.indexOf(ARG_DIRS) > -1) 68 { 69 dirs = true; 70 } 71 if (argument.indexOf(ARG_FILES) > -1) 72 { 73 files = true; 74 } 75 76 } 77 if (deltas == 0) 78 { 79 deltas = IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED; 80 } 81 if (!dirs && !files) 82 { 83 dirs = true; 84 files = true; 85 } 86 final int trackDeltas = deltas; 87 final boolean trackDirs = dirs; 88 final boolean trackFiles = files; 89 90 91 buildDelta.accept(new IResourceDeltaVisitor() 92 { 93 public boolean visit(IResourceDelta delta) throws CoreException 94 { 95 IResource resource = delta.getResource(); 96 97 boolean isTracked = (delta.getKind() & trackDeltas) > 0; 99 if (isTracked) 100 { 101 isTracked = trackDirs && resource.getType() != IResource.FILE; 103 isTracked |= trackFiles && resource.getType() == IResource.FILE; 105 } 106 107 if (isTracked) 109 { 110 String osPath = resource.getLocation().toOSString(); 111 if (changedResources.add(osPath)) 112 { 113 if (fileList.length() > 0) 114 { 115 fileList.append(FILE_LIST_SEPARATOR); 116 } 117 118 osPath = osPath.replaceAll("\"", "\\\\\""); fileList.append("\"" + osPath + "\""); } 127 } 128 return true; 129 } 130 }, deltas); 131 result = fileList.toString(); 132 } 133 134 return result; 135 } 136 } | Popular Tags |