Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 7-17
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Francis Lynch (Wind River) - add support for snapshot of project tree |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.core.internal.resources; |
12 |
package org.eclipse.core.internal.resources; |
12 |
|
13 |
|
|
|
14 |
import org.eclipse.core.filesystem.IFileStore; |
15 |
|
16 |
import org.eclipse.core.filesystem.EFS; |
17 |
|
18 |
import java.net.URI; |
19 |
|
13 |
import java.io.*; |
20 |
import java.io.*; |
14 |
import java.util.*; |
21 |
import java.util.*; |
|
|
22 |
import java.util.zip.*; |
15 |
import org.eclipse.core.internal.events.*; |
23 |
import org.eclipse.core.internal.events.*; |
16 |
import org.eclipse.core.internal.localstore.*; |
24 |
import org.eclipse.core.internal.localstore.*; |
17 |
import org.eclipse.core.internal.utils.*; |
25 |
import org.eclipse.core.internal.utils.*; |
Lines 708-713
Link Here
|
708 |
} |
716 |
} |
709 |
|
717 |
|
710 |
/** |
718 |
/** |
|
|
719 |
* Restores the contents of this project from a refresh snapshot, if possible. |
720 |
* Throws an exception if the snapshot is found but an error occurs when reading |
721 |
* the file. |
722 |
* @return <code><code>true</code> if the project data was restored successfully, |
723 |
* and <code>false</code> if the refresh snapshot was not found or could not be opened. |
724 |
* @exception CoreException if an error occurred reading the snapshot file. |
725 |
*/ |
726 |
protected boolean restoreFromRefreshSnapshot(Project project, |
727 |
IProgressMonitor monitor) throws CoreException { |
728 |
boolean status = true; |
729 |
IPath snapshotPath = workspace.getMetaArea().getRefreshLocationFor(project); |
730 |
java.io.File snapshotFile = snapshotPath.toFile(); |
731 |
if (!snapshotFile.exists()) |
732 |
return false; |
733 |
if (Policy.DEBUG_RESTORE) |
734 |
System.out.println("Restore project " + project.getFullPath() + ": starting..."); //$NON-NLS-1$ //$NON-NLS-2$ |
735 |
long start = System.currentTimeMillis(); |
736 |
monitor = Policy.monitorFor(monitor); |
737 |
try { |
738 |
monitor.beginTask("", 40); //$NON-NLS-1$ |
739 |
status = restoreTreeFromRefreshSnapshot(project, |
740 |
snapshotFile, Policy.subMonitorFor(monitor, 40)); |
741 |
if (status) { |
742 |
// load the project description and set internal description |
743 |
ProjectDescription description = workspace.getFileSystemManager().read(project, true); |
744 |
project.internalSetDescription(description, false); |
745 |
workspace.getMetaArea().clearRefresh(project); |
746 |
} |
747 |
} finally { |
748 |
monitor.done(); |
749 |
} |
750 |
if (Policy.DEBUG_RESTORE) |
751 |
System.out.println("Restore project " + project.getFullPath() + ": " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
752 |
return status; |
753 |
} |
754 |
|
755 |
/** |
711 |
* Reads the markers which were originally saved |
756 |
* Reads the markers which were originally saved |
712 |
* for the tree rooted by the given resource. |
757 |
* for the tree rooted by the given resource. |
713 |
*/ |
758 |
*/ |
Lines 970-975
Link Here
|
970 |
return true; |
1015 |
return true; |
971 |
} |
1016 |
} |
972 |
|
1017 |
|
|
|
1018 |
/** |
1019 |
* Restores a tree saved as a refresh snapshot to a specified URI. |
1020 |
* @return <code>true</code> if the snapshot exists, <code>false</code> otherwise. |
1021 |
* @exception CoreException if the project could not be restored. |
1022 |
*/ |
1023 |
protected boolean restoreTreeFromRefreshSnapshot(Project project, |
1024 |
java.io.File snapshotFile, IProgressMonitor monitor) throws CoreException { |
1025 |
long start = System.currentTimeMillis(); |
1026 |
monitor = Policy.monitorFor(monitor); |
1027 |
String message; |
1028 |
IPath snapshotPath = null; |
1029 |
try { |
1030 |
monitor.beginTask("", Policy.totalWork); //$NON-NLS-1$ |
1031 |
InputStream snapIn = new FileInputStream(snapshotFile); |
1032 |
ZipInputStream zip = new ZipInputStream(snapIn); |
1033 |
ZipEntry treeEntry = zip.getNextEntry(); |
1034 |
if (treeEntry == null || !treeEntry.getName().equals("resource-index.tree")) { //$NON-NLS-1$ |
1035 |
zip.close(); |
1036 |
return false; |
1037 |
} |
1038 |
DataInputStream input = new DataInputStream(zip); |
1039 |
try { |
1040 |
WorkspaceTreeReader reader = WorkspaceTreeReader.getReader(workspace, input.readInt()); |
1041 |
reader.readTree(project, input, Policy.subMonitorFor(monitor, Policy.totalWork)); |
1042 |
} finally { |
1043 |
input.close(); |
1044 |
zip.close(); |
1045 |
} |
1046 |
} catch (IOException e) { |
1047 |
snapshotPath = new Path(snapshotFile.getPath()); |
1048 |
message = NLS.bind(Messages.resources_readMeta, snapshotPath); |
1049 |
throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, snapshotPath, message, e); |
1050 |
} finally { |
1051 |
monitor.done(); |
1052 |
} |
1053 |
if (Policy.DEBUG_RESTORE_TREE) { |
1054 |
System.out.println("Restore Tree for " + project.getFullPath() + ": " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1055 |
} |
1056 |
return true; |
1057 |
} |
1058 |
|
973 |
class InternalMonitorWrapper extends ProgressMonitorWrapper{ |
1059 |
class InternalMonitorWrapper extends ProgressMonitorWrapper{ |
974 |
private boolean ignoreCancel; |
1060 |
private boolean ignoreCancel; |
975 |
|
1061 |
|
Lines 1162-1167
Link Here
|
1162 |
} |
1248 |
} |
1163 |
|
1249 |
|
1164 |
/** |
1250 |
/** |
|
|
1251 |
* Writes a snapshot of project refresh information to the specified |
1252 |
* location. |
1253 |
* @param project the project to write a refresh snapshot for |
1254 |
* @param monitor progress monitor |
1255 |
* @exception CoreException if there is a problem writing the snapshot. |
1256 |
*/ |
1257 |
public void saveRefreshSnapshot(Project project, URI snapshotLocation, |
1258 |
IProgressMonitor monitor) throws CoreException { |
1259 |
IFileStore store = EFS.getStore(snapshotLocation); |
1260 |
IPath snapshotPath = new Path(snapshotLocation.getPath()); |
1261 |
OutputStream snapOut = store.openOutputStream(EFS.NONE, monitor); |
1262 |
java.io.File tmpTree = null; |
1263 |
try { |
1264 |
tmpTree = java.io.File.createTempFile("tmp", ".tree"); //$NON-NLS-1$//$NON-NLS-2$ |
1265 |
} catch (IOException e) { |
1266 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, |
1267 |
snapshotPath, Messages.resources_copyProblem, e); |
1268 |
} |
1269 |
ZipOutputStream out = null; |
1270 |
try { |
1271 |
FileOutputStream fis = new FileOutputStream(tmpTree); |
1272 |
DataOutputStream output = new DataOutputStream(fis); |
1273 |
try { |
1274 |
output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); |
1275 |
writeTree(project, output, monitor); |
1276 |
} finally { |
1277 |
output.close(); |
1278 |
} |
1279 |
out = new ZipOutputStream(snapOut); |
1280 |
out.setLevel(Deflater.BEST_COMPRESSION); |
1281 |
ZipEntry e = new ZipEntry("resource-index.tree"); //$NON-NLS-1$ |
1282 |
out.putNextEntry(e); |
1283 |
int read = 0; |
1284 |
byte[] buffer = new byte[4096]; |
1285 |
InputStream in = new FileInputStream(tmpTree); |
1286 |
try { |
1287 |
while ((read = in.read(buffer)) >= 0) { |
1288 |
out.write(buffer, 0, read); |
1289 |
} |
1290 |
out.closeEntry(); |
1291 |
} finally { |
1292 |
in.close(); |
1293 |
} |
1294 |
out.close(); |
1295 |
} catch (IOException e) { |
1296 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, snapshotPath, Messages.resources_copyProblem, e); |
1297 |
} finally { |
1298 |
tmpTree.delete(); |
1299 |
} |
1300 |
} |
1301 |
|
1302 |
/** |
1165 |
* Writes the current state of the entire workspace tree to disk. |
1303 |
* Writes the current state of the entire workspace tree to disk. |
1166 |
* This is used during workspace save. saveTree(Project) |
1304 |
* This is used during workspace save. saveTree(Project) |
1167 |
* is used to save the state of an individual project. |
1305 |
* is used to save the state of an individual project. |