1 11 package org.eclipse.core.internal.resources; 12 13 import java.io.*; 14 import java.util.*; 15 import org.eclipse.core.internal.events.BuilderPersistentInfo; 16 import org.eclipse.core.internal.utils.Messages; 17 import org.eclipse.core.internal.utils.Policy; 18 import org.eclipse.core.internal.watson.ElementTree; 19 import org.eclipse.core.internal.watson.ElementTreeReader; 20 import org.eclipse.core.resources.IProject; 21 import org.eclipse.core.resources.IResourceStatus; 22 import org.eclipse.core.runtime.*; 23 24 27 public class WorkspaceTreeReader_1 extends WorkspaceTreeReader { 28 protected Workspace workspace; 29 30 public WorkspaceTreeReader_1(Workspace workspace) { 31 this.workspace = workspace; 32 } 33 34 protected int getVersion() { 35 return ICoreConstants.WORKSPACE_TREE_VERSION_1; 36 } 37 38 protected void linkBuildersToTrees(List buildersToBeLinked, ElementTree[] trees, int index, IProgressMonitor monitor) { 39 monitor = Policy.monitorFor(monitor); 40 try { 41 ArrayList infos = null; 42 String projectName = null; 43 for (int i = 0; i < buildersToBeLinked.size(); i++) { 44 BuilderPersistentInfo info = (BuilderPersistentInfo) buildersToBeLinked.get(i); 45 if (!info.getProjectName().equals(projectName)) { 46 if (infos != null) { IProject project = workspace.getRoot().getProject(projectName); 48 workspace.getBuildManager().setBuildersPersistentInfo(project, infos); 49 } 50 projectName = info.getProjectName(); 51 infos = new ArrayList(5); 52 } 53 info.setLastBuildTree(trees[index++]); 54 infos.add(info); 55 } 56 if (infos != null) { 57 IProject project = workspace.getRoot().getProject(projectName); 58 workspace.getBuildManager().setBuildersPersistentInfo(project, infos); 59 } 60 } finally { 61 monitor.done(); 62 } 63 } 64 65 protected void linkPluginsSavedStateToTrees(List states, ElementTree[] trees, IProgressMonitor monitor) { 66 monitor = Policy.monitorFor(monitor); 67 try { 68 for (int i = 0; i < states.size(); i++) { 69 SavedState state = (SavedState) states.get(i); 70 final SaveManager saveManager = workspace.getSaveManager(); 73 if (!saveManager.isOldPluginTree(state.pluginId)) { 74 state.oldTree = trees[i]; 75 } else { 76 saveManager.clearDeltaExpiration(state.pluginId); 78 } 79 } 80 } finally { 81 monitor.done(); 82 } 83 } 84 85 protected BuilderPersistentInfo readBuilderInfo(IProject project, DataInputStream input, int index) throws IOException { 86 String projectName = input.readUTF(); 88 if (project != null) 90 projectName = project.getName(); 91 String builderName = input.readUTF(); 92 return new BuilderPersistentInfo(projectName, builderName, index); 93 } 94 95 protected void readBuildersPersistentInfo(IProject project, DataInputStream input, List builders, IProgressMonitor monitor) throws IOException { 96 monitor = Policy.monitorFor(monitor); 97 try { 98 int builderCount = input.readInt(); 99 for (int i = 0; i < builderCount; i++) 100 builders.add(readBuilderInfo(project, input, i)); 101 } finally { 102 monitor.done(); 103 } 104 } 105 106 protected void readPluginsSavedStates(DataInputStream input, HashMap savedStates, List plugins, IProgressMonitor monitor) throws IOException, CoreException { 107 monitor = Policy.monitorFor(monitor); 108 try { 109 int stateCount = input.readInt(); 110 for (int i = 0; i < stateCount; i++) { 111 String pluginId = input.readUTF(); 112 SavedState state = new SavedState(workspace, pluginId, null, null); 113 savedStates.put(pluginId, state); 114 plugins.add(state); 115 } 116 } finally { 117 monitor.done(); 118 } 119 } 120 121 public ElementTree readSnapshotTree(DataInputStream input, ElementTree complete, IProgressMonitor monitor) throws CoreException { 122 monitor = Policy.monitorFor(monitor); 123 String message; 124 try { 125 message = Messages.resources_readingSnap; 126 monitor.beginTask(message, Policy.totalWork); 127 ElementTreeReader reader = new ElementTreeReader(workspace.getSaveManager()); 128 while (input.available() > 0) { 129 readWorkspaceFields(input, Policy.subMonitorFor(monitor, Policy.totalWork / 2)); 130 complete = reader.readDelta(complete, input); 131 try { 132 int version = input.readInt(); 134 if (version != getVersion()) 135 return WorkspaceTreeReader.getReader(workspace, version).readSnapshotTree(input, complete, monitor); 136 } catch (EOFException e) { 137 break; 138 } 139 } 140 return complete; 141 } catch (IOException e) { 142 message = Messages.resources_readWorkspaceSnap; 143 throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, null, message, e); 144 } finally { 145 monitor.done(); 146 } 147 } 148 149 public void readTree(DataInputStream input, IProgressMonitor monitor) throws CoreException { 150 monitor = Policy.monitorFor(monitor); 151 String message; 152 try { 153 message = Messages.resources_reading; 154 monitor.beginTask(message, Policy.totalWork); 155 readWorkspaceFields(input, Policy.subMonitorFor(monitor, Policy.opWork * 20 / 100)); 156 157 HashMap savedStates = new HashMap(20); 158 List pluginsToBeLinked = new ArrayList(20); 159 readPluginsSavedStates(input, savedStates, pluginsToBeLinked, Policy.subMonitorFor(monitor, Policy.opWork * 10 / 100)); 160 workspace.getSaveManager().setPluginsSavedState(savedStates); 161 162 List buildersToBeLinked = new ArrayList(20); 163 readBuildersPersistentInfo(null, input, buildersToBeLinked, Policy.subMonitorFor(monitor, Policy.opWork * 10 / 100)); 164 165 ElementTree[] trees = readTrees(Path.ROOT, input, Policy.subMonitorFor(monitor, Policy.opWork * 40 / 100)); 166 linkPluginsSavedStateToTrees(pluginsToBeLinked, trees, Policy.subMonitorFor(monitor, Policy.opWork * 10 / 100)); 167 linkBuildersToTrees(buildersToBeLinked, trees, pluginsToBeLinked.size(), Policy.subMonitorFor(monitor, Policy.opWork * 10 / 100)); 168 169 } catch (IOException e) { 170 message = Messages.resources_readWorkspaceTree; 171 throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, null, message, e); 172 } finally { 173 monitor.done(); 174 } 175 } 176 177 public void readTree(IProject project, DataInputStream input, IProgressMonitor monitor) throws CoreException { 178 monitor = Policy.monitorFor(monitor); 179 String message; 180 try { 181 message = Messages.resources_reading; 182 monitor.beginTask(message, 10); 183 184 int numBuilders = input.readInt(); 185 186 187 String [] builderNames = new String [numBuilders]; 188 for (int i = 0; i < numBuilders; i++) { 189 String builderName = input.readUTF(); 190 builderNames[i] = builderName; 191 } 192 monitor.worked(1); 193 194 195 ElementTree[] trees = readTrees(project.getFullPath(), input, Policy.subMonitorFor(monitor, 8)); 196 197 198 if (numBuilders > 0) { 199 ArrayList infos = new ArrayList(trees.length * 2 + 1); 200 for (int i = 0; i < numBuilders; i++) { 201 BuilderPersistentInfo info = new BuilderPersistentInfo(project.getName(), builderNames[i], -1); 202 info.setLastBuildTree(trees[i]); 203 infos.add(info); 204 } 205 workspace.getBuildManager().setBuildersPersistentInfo(project, infos); 206 } 207 monitor.worked(1); 208 209 } catch (IOException e) { 210 message = Messages.resources_readProjectTree; 211 throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, null, message, e); 212 } finally { 213 monitor.done(); 214 } 215 } 216 217 220 protected ElementTree[] readTrees(IPath root, DataInputStream input, IProgressMonitor monitor) throws IOException { 221 monitor = Policy.monitorFor(monitor); 222 try { 223 String message = Messages.resources_reading; 224 monitor.beginTask(message, 4); 225 ElementTreeReader treeReader = new ElementTreeReader(workspace.getSaveManager()); 226 ElementTree[] trees = treeReader.readDeltaChain(input); 227 monitor.worked(3); 228 if (root.isRoot()) { 229 ElementTree newTree = trees[trees.length - 1]; 232 newTree.setTreeData(workspace.tree.getTreeData()); 233 workspace.tree = newTree; 234 } else { 235 workspace.linkTrees(root, trees); 237 } 238 monitor.worked(1); 239 return trees; 240 } finally { 241 monitor.done(); 242 } 243 } 244 245 protected void readWorkspaceFields(DataInputStream input, IProgressMonitor monitor) throws IOException, CoreException { 246 monitor = Policy.monitorFor(monitor); 247 try { 248 workspace.nextNodeId = input.readLong(); 250 input.readLong(); 252 workspace.nextMarkerId = input.readLong(); 254 ((Synchronizer) workspace.getSynchronizer()).readPartners(input); 256 } finally { 257 monitor.done(); 258 } 259 } 260 } 261 | Popular Tags |