platform35/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/WorkspaceTreeReader_2.java
changeset 40 eb3c938c7fef
equal deleted inserted replaced
39:2a03ec4dbf31 40:eb3c938c7fef
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2000, 2005 IBM Corporation and others.
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  * 
       
     8  * Contributors:
       
     9  *     IBM Corporation - initial API and implementation
       
    10  *******************************************************************************/
       
    11 package org.eclipse.core.internal.resources;
       
    12 
       
    13 import java.io.DataInputStream;
       
    14 import java.io.IOException;
       
    15 import java.util.ArrayList;
       
    16 import java.util.List;
       
    17 import org.eclipse.core.internal.events.BuilderPersistentInfo;
       
    18 import org.eclipse.core.internal.utils.Messages;
       
    19 import org.eclipse.core.internal.utils.Policy;
       
    20 import org.eclipse.core.internal.watson.ElementTree;
       
    21 import org.eclipse.core.resources.IProject;
       
    22 import org.eclipse.core.resources.IResourceStatus;
       
    23 import org.eclipse.core.runtime.CoreException;
       
    24 import org.eclipse.core.runtime.IProgressMonitor;
       
    25 
       
    26 /**
       
    27  * Reads version 2 of the workspace tree file format. 
       
    28  * 
       
    29  * This version differs from version 1 in the amount of information that is persisted
       
    30  * for each builder. Version 1 only stored builder names and trees. Version
       
    31  * 2 stores builder names, project names, trees, and interesting projects for
       
    32  * each builder.
       
    33  */
       
    34 public class WorkspaceTreeReader_2 extends WorkspaceTreeReader_1 {
       
    35 
       
    36 	public WorkspaceTreeReader_2(Workspace workspace) {
       
    37 		super(workspace);
       
    38 	}
       
    39 
       
    40 	protected int getVersion() {
       
    41 		return ICoreConstants.WORKSPACE_TREE_VERSION_2;
       
    42 	}
       
    43 
       
    44 	/*
       
    45 	 * overwritten from WorkspaceTreeReader_1
       
    46 	 */
       
    47 	protected void readBuildersPersistentInfo(IProject project, DataInputStream input, List builders, IProgressMonitor monitor) throws IOException {
       
    48 		monitor = Policy.monitorFor(monitor);
       
    49 		try {
       
    50 			int builderCount = input.readInt();
       
    51 			for (int i = 0; i < builderCount; i++) {
       
    52 				BuilderPersistentInfo info = readBuilderInfo(project, input, i);
       
    53 				// read interesting projects
       
    54 				int n = input.readInt();
       
    55 				IProject[] projects = new IProject[n];
       
    56 				for (int j = 0; j < n; j++)
       
    57 					projects[j] = workspace.getRoot().getProject(input.readUTF());
       
    58 				info.setInterestingProjects(projects);
       
    59 				builders.add(info);
       
    60 			}
       
    61 		} finally {
       
    62 			monitor.done();
       
    63 		}
       
    64 	}
       
    65 
       
    66 	/*
       
    67 	 * overwritten from WorkspaceTreeReader_1
       
    68 	 */
       
    69 	public void readTree(IProject project, DataInputStream input, IProgressMonitor monitor) throws CoreException {
       
    70 		monitor = Policy.monitorFor(monitor);
       
    71 		String message;
       
    72 		try {
       
    73 			message = Messages.resources_reading;
       
    74 			monitor.beginTask(message, 10);
       
    75 
       
    76 			/* read in the builder infos */
       
    77 			List infos = new ArrayList(5);
       
    78 			readBuildersPersistentInfo(project, input, infos, Policy.subMonitorFor(monitor, 1));
       
    79 
       
    80 			/* read and link the trees */
       
    81 			ElementTree[] trees = readTrees(project.getFullPath(), input, Policy.subMonitorFor(monitor, 8));
       
    82 
       
    83 			/* map builder names to trees */
       
    84 			linkBuildersToTrees(infos, trees, 0, Policy.subMonitorFor(monitor, 1));
       
    85 
       
    86 		} catch (IOException e) {
       
    87 			message = Messages.resources_readProjectTree;
       
    88 			throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, null, message, e);
       
    89 		} finally {
       
    90 			monitor.done();
       
    91 		}
       
    92 	}
       
    93 }