author | timkelly |
Thu, 30 Jul 2009 11:56:23 -0500 | |
changeset 40 | eb3c938c7fef |
permissions | -rw-r--r-- |
40
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
1 |
/******************************************************************************* |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
2 |
* Copyright (c) 2004, 2009 IBM Corporation and others. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
3 |
* All rights reserved. This program and the accompanying materials |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
5 |
* which accompanies this distribution, and is available at |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
7 |
* |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
8 |
* Contributors: |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
9 |
* IBM Corporation - initial API and implementation |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
10 |
*******************************************************************************/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
11 |
package org.eclipse.core.internal.resources; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
12 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
13 |
import org.eclipse.core.internal.utils.FileUtil; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
14 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
15 |
import java.io.*; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
16 |
import java.util.ArrayList; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
17 |
import java.util.List; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
18 |
import org.eclipse.core.filesystem.EFS; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
19 |
import org.eclipse.core.filesystem.IFileStore; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
20 |
import org.eclipse.core.internal.events.ILifecycleListener; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
21 |
import org.eclipse.core.internal.events.LifecycleEvent; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
22 |
import org.eclipse.core.internal.utils.*; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
23 |
import org.eclipse.core.internal.watson.*; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
24 |
import org.eclipse.core.resources.*; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
25 |
import org.eclipse.core.runtime.*; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
26 |
import org.eclipse.core.runtime.content.*; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
27 |
import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
28 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
29 |
import org.eclipse.osgi.util.NLS; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
30 |
import org.osgi.framework.Bundle; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
31 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
32 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
33 |
* Keeps a cache of recently read content descriptions. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
34 |
* |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
35 |
* @since 3.0 |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
36 |
* @see IFile#getContentDescription() |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
37 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
38 |
public class ContentDescriptionManager implements IManager, IRegistryChangeListener, IContentTypeManager.IContentTypeChangeListener, ILifecycleListener { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
39 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
40 |
* This job causes the content description cache and the related flags |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
41 |
* in the resource tree to be flushed. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
42 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
43 |
private class FlushJob extends WorkspaceJob { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
44 |
private final List toFlush; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
45 |
private boolean fullFlush; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
46 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
47 |
public FlushJob() { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
48 |
super(Messages.resources_flushingContentDescriptionCache); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
49 |
setSystem(true); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
50 |
setUser(false); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
51 |
setPriority(LONG); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
52 |
setRule(workspace.getRoot()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
53 |
toFlush = new ArrayList(5); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
54 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
55 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
56 |
/* (non-Javadoc) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
57 |
* See Job#belongsTo(Object) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
58 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
59 |
public boolean belongsTo(Object family) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
60 |
return FAMILY_DESCRIPTION_CACHE_FLUSH.equals(family); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
61 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
62 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
63 |
/* (non-Javadoc) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
64 |
* See WorkspaceJob#runInWorkspace(IProgressMonitor) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
65 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
66 |
public IStatus runInWorkspace(final IProgressMonitor monitor) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
67 |
if (monitor.isCanceled()) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
68 |
return Status.CANCEL_STATUS; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
69 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
70 |
monitor.beginTask("", Policy.opWork); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
71 |
//note that even though we are running in a workspace job, we |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
72 |
//must do a begin/endOperation to re-acquire the workspace lock |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
73 |
final ISchedulingRule rule = workspace.getRoot(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
74 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
75 |
workspace.prepareOperation(rule, monitor); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
76 |
workspace.beginOperation(true); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
77 |
//don't do anything if the system is shutting down or has been shut down |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
78 |
//it is too late to change the workspace at this point anyway |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
79 |
if (systemBundle.getState() != Bundle.STOPPING) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
80 |
doFlushCache(monitor, getPathsToFlush()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
81 |
} finally { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
82 |
workspace.endOperation(rule, false, Policy.subMonitorFor(monitor, Policy.endOpWork)); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
83 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
84 |
} catch (OperationCanceledException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
85 |
return Status.CANCEL_STATUS; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
86 |
} catch (CoreException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
87 |
return e.getStatus(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
88 |
} finally { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
89 |
monitor.done(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
90 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
91 |
return Status.OK_STATUS; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
92 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
93 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
94 |
private IPath[] getPathsToFlush() { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
95 |
synchronized (toFlush) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
96 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
97 |
if (fullFlush) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
98 |
return null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
99 |
int size = toFlush.size(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
100 |
return (size == 0) ? null : (IPath[]) toFlush.toArray(new IPath[size]); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
101 |
} finally { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
102 |
fullFlush = false; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
103 |
toFlush.clear(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
104 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
105 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
106 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
107 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
108 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
109 |
* @param project project to flush, or null for a full flush |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
110 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
111 |
void flush(IProject project) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
112 |
if (Policy.DEBUG_CONTENT_TYPE_CACHE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
113 |
Policy.debug("Scheduling flushing of content type cache for " + (project == null ? Path.ROOT : project.getFullPath())); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
114 |
synchronized (toFlush) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
115 |
if (!fullFlush) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
116 |
if (project == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
117 |
fullFlush = true; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
118 |
else |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
119 |
toFlush.add(project.getFullPath()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
120 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
121 |
schedule(1000); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
122 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
123 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
124 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
125 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
126 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
127 |
* An input stream that only opens the file if bytes are actually requested. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
128 |
* @see #readDescription(File) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
129 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
130 |
class LazyFileInputStream extends InputStream { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
131 |
private InputStream actual; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
132 |
private IFileStore target; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
133 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
134 |
LazyFileInputStream(IFileStore target) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
135 |
this.target = target; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
136 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
137 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
138 |
public int available() throws IOException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
139 |
if (actual == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
140 |
return 0; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
141 |
return actual.available(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
142 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
143 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
144 |
public void close() throws IOException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
145 |
if (actual == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
146 |
return; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
147 |
actual.close(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
148 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
149 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
150 |
private void ensureOpened() throws IOException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
151 |
if (actual != null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
152 |
return; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
153 |
if (target == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
154 |
throw new FileNotFoundException(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
155 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
156 |
actual = target.openInputStream(EFS.NONE, null); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
157 |
} catch (CoreException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
158 |
throw new IOException(e.getMessage()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
159 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
160 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
161 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
162 |
public int read() throws IOException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
163 |
ensureOpened(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
164 |
return actual.read(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
165 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
166 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
167 |
public int read(byte[] b, int off, int len) throws IOException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
168 |
ensureOpened(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
169 |
return actual.read(b, off, len); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
170 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
171 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
172 |
public long skip(long n) throws IOException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
173 |
ensureOpened(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
174 |
return actual.skip(n); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
175 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
176 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
177 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
178 |
private static final QualifiedName CACHE_STATE = new QualifiedName(ResourcesPlugin.PI_RESOURCES, "contentCacheState"); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
179 |
private static final QualifiedName CACHE_TIMESTAMP = new QualifiedName(ResourcesPlugin.PI_RESOURCES, "contentCacheTimestamp"); //$NON-NLS-1$\ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
180 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
181 |
public static final String FAMILY_DESCRIPTION_CACHE_FLUSH = ResourcesPlugin.PI_RESOURCES + ".contentDescriptionCacheFamily"; //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
182 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
183 |
//possible values for the CACHE_STATE property |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
184 |
public static final byte EMPTY_CACHE = 1; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
185 |
public static final byte USED_CACHE = 2; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
186 |
public static final byte INVALID_CACHE = 3; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
187 |
public static final byte FLUSHING_CACHE = 4; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
188 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
189 |
// This state indicates that FlushJob is scheduled and full flush is going to be performed. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
190 |
// In the meantime the cache was discarded. It is used as a temporary cache till the FlushJob start. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
191 |
public static final byte ABOUT_TO_FLUSH = 5; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
192 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
193 |
private static final String PT_CONTENTTYPES = "contentTypes"; //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
194 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
195 |
private Cache cache; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
196 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
197 |
private byte cacheState; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
198 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
199 |
private FlushJob flushJob; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
200 |
private ProjectContentTypes projectContentTypes; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
201 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
202 |
Workspace workspace; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
203 |
protected final Bundle systemBundle = Platform.getBundle("org.eclipse.osgi"); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
204 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
205 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
206 |
* @see IContentTypeManager.IContentTypeChangeListener#contentTypeChanged(IContentTypeManager.ContentTypeChangeEvent) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
207 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
208 |
public void contentTypeChanged(ContentTypeChangeEvent event) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
209 |
if (Policy.DEBUG_CONTENT_TYPE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
210 |
Policy.debug("Content type settings changed for " + event.getContentType()); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
211 |
invalidateCache(true, null); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
212 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
213 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
214 |
synchronized void doFlushCache(final IProgressMonitor monitor, IPath[] toClean) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
215 |
// nothing to be done if no information cached |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
216 |
if (getCacheState() != INVALID_CACHE && getCacheState() != ABOUT_TO_FLUSH) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
217 |
if (Policy.DEBUG_CONTENT_TYPE_CACHE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
218 |
Policy.debug("Content type cache flush not performed"); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
219 |
return; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
220 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
221 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
222 |
setCacheState(FLUSHING_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
223 |
// flush the MRU cache |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
224 |
cache.discardAll(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
225 |
if (toClean == null || toClean.length == 0) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
226 |
// no project was added, must be a global flush |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
227 |
clearContentFlags(Path.ROOT, monitor); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
228 |
else { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
229 |
// flush a project at a time |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
230 |
for (int i = 0; i < toClean.length; i++) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
231 |
clearContentFlags(toClean[i], monitor); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
232 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
233 |
} catch (CoreException ce) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
234 |
setCacheState(INVALID_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
235 |
throw ce; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
236 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
237 |
// done cleaning (only if we didn't fail) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
238 |
setCacheState(EMPTY_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
239 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
240 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
241 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
242 |
* Clears the content related flags for every file under the given root. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
243 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
244 |
private void clearContentFlags(IPath root, final IProgressMonitor monitor) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
245 |
long flushStart = System.currentTimeMillis(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
246 |
if (Policy.DEBUG_CONTENT_TYPE_CACHE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
247 |
Policy.debug("Flushing content type cache for " + root); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
248 |
// discard content type related flags for all files in the tree |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
249 |
IElementContentVisitor visitor = new IElementContentVisitor() { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
250 |
public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object elementContents) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
251 |
if (monitor.isCanceled()) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
252 |
throw new OperationCanceledException(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
253 |
if (elementContents == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
254 |
return false; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
255 |
ResourceInfo info = (ResourceInfo) elementContents; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
256 |
if (info.getType() != IResource.FILE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
257 |
return true; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
258 |
info = workspace.getResourceInfo(requestor.requestPath(), false, true); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
259 |
if (info == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
260 |
return false; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
261 |
info.clear(ICoreConstants.M_CONTENT_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
262 |
return true; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
263 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
264 |
}; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
265 |
new ElementTreeIterator(workspace.getElementTree(), root).iterate(visitor); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
266 |
if (Policy.DEBUG_CONTENT_TYPE_CACHE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
267 |
Policy.debug("Content type cache for " + root + " flushed in " + (System.currentTimeMillis() - flushStart) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
268 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
269 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
270 |
Cache getCache() { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
271 |
return cache; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
272 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
273 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
274 |
/** Public so tests can examine it. */ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
275 |
public synchronized byte getCacheState() { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
276 |
if (cacheState != 0) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
277 |
// we have read/set it before, no nead to read property |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
278 |
return cacheState; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
279 |
String persisted; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
280 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
281 |
persisted = workspace.getRoot().getPersistentProperty(CACHE_STATE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
282 |
cacheState = persisted != null ? Byte.parseByte(persisted) : INVALID_CACHE; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
283 |
} catch (NumberFormatException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
284 |
cacheState = INVALID_CACHE; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
285 |
} catch (CoreException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
286 |
Policy.log(e.getStatus()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
287 |
cacheState = INVALID_CACHE; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
288 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
289 |
return cacheState; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
290 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
291 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
292 |
public long getCacheTimestamp() throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
293 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
294 |
return Long.parseLong(workspace.getRoot().getPersistentProperty(CACHE_TIMESTAMP)); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
295 |
} catch (NumberFormatException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
296 |
return 0; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
297 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
298 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
299 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
300 |
public IContentTypeMatcher getContentTypeMatcher(Project project) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
301 |
return projectContentTypes.getMatcherFor(project); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
302 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
303 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
304 |
public IContentDescription getDescriptionFor(File file, ResourceInfo info) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
305 |
if (ProjectContentTypes.usesContentTypePreferences(file.getFullPath().segment(0))) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
306 |
// caching for project containing project specific settings is not supported |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
307 |
return readDescription(file); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
308 |
if (getCacheState() == INVALID_CACHE) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
309 |
// discard the cache, so it can be used before the flush job starts |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
310 |
setCacheState(ABOUT_TO_FLUSH); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
311 |
cache.discardAll(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
312 |
// the cache is not good, flush it |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
313 |
flushJob.schedule(1000); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
314 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
315 |
if (getCacheState() != ABOUT_TO_FLUSH) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
316 |
// first look for the flags in the resource info to avoid looking in the cache |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
317 |
// don't need to copy the info because the modified bits are not in the deltas |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
318 |
if (info == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
319 |
return null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
320 |
if (info.isSet(ICoreConstants.M_NO_CONTENT_DESCRIPTION)) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
321 |
// presumably, this file has no known content type |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
322 |
return null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
323 |
if (info.isSet(ICoreConstants.M_DEFAULT_CONTENT_DESCRIPTION)) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
324 |
// this file supposedly has a default content description for an "obvious" content type |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
325 |
IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
326 |
// try to find the obvious content type matching its name |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
327 |
IContentType type = contentTypeManager.findContentTypeFor(file.getName()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
328 |
if (type != null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
329 |
// we found it, we are done |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
330 |
return type.getDefaultDescription(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
331 |
// for some reason, there was no content type for this file name |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
332 |
// fix this and keep going |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
333 |
info.clear(ICoreConstants.M_CONTENT_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
334 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
335 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
336 |
synchronized (this) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
337 |
// tries to get a description from the cache |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
338 |
Cache.Entry entry = cache.getEntry(file.getFullPath()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
339 |
if (entry != null && entry.getTimestamp() == getTimestamp(info)) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
340 |
// there was a description in the cache, and it was up to date |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
341 |
return (IContentDescription) entry.getCached(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
342 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
343 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
344 |
// either we didn't find a description in the cache, or it was not up-to-date - has to be read again |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
345 |
// reading description can call 3rd party code, so don't synchronize it |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
346 |
IContentDescription newDescription = readDescription(file); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
347 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
348 |
synchronized (this) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
349 |
// tries to get a description from the cache |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
350 |
Cache.Entry entry = cache.getEntry(file.getFullPath()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
351 |
if (entry != null && entry.getTimestamp() == getTimestamp(info)) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
352 |
// there was a description in the cache, and it was up to date |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
353 |
return (IContentDescription) entry.getCached(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
354 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
355 |
if (getCacheState() != ABOUT_TO_FLUSH) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
356 |
// we are going to add an entry to the cache or update the resource info - remember that |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
357 |
setCacheState(USED_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
358 |
if (newDescription == null) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
359 |
// no content type exists for this file name/contents - remember this |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
360 |
info.set(ICoreConstants.M_NO_CONTENT_DESCRIPTION); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
361 |
return null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
362 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
363 |
if (newDescription.getContentType().getDefaultDescription().equals(newDescription)) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
364 |
// we got a default description |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
365 |
IContentType defaultForName = Platform.getContentTypeManager().findContentTypeFor(file.getName()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
366 |
if (newDescription.getContentType().equals(defaultForName)) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
367 |
// it is a default description for the obvious content type given its file name, we don't have to cache |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
368 |
info.set(ICoreConstants.M_DEFAULT_CONTENT_DESCRIPTION); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
369 |
return newDescription; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
370 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
371 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
372 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
373 |
// we actually got a description filled by a describer (or a default description for a non-obvious type) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
374 |
if (entry == null) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
375 |
// there was no entry before - create one |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
376 |
entry = cache.addEntry(file.getFullPath(), newDescription, getTimestamp(info)); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
377 |
else { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
378 |
// just update the existing entry |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
379 |
entry.setTimestamp(info.getContentId()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
380 |
entry.setCached(newDescription); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
381 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
382 |
return newDescription; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
383 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
384 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
385 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
386 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
387 |
* Returns a timestamp that uniquely identifies a particular content state |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
388 |
* of a particular resource. For use as a key in a content type cache. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
389 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
390 |
private long getTimestamp(ResourceInfo info) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
391 |
return info.getContentId() + info.getNodeId(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
392 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
393 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
394 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
395 |
* Marks the cache as invalid. Does not do anything if the cache is new. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
396 |
* Optionally causes the cached information to be actually flushed. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
397 |
* |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
398 |
* @param flush whether the cached information should be flushed |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
399 |
* @see #doFlushCache(IProgressMonitor, IPath[]) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
400 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
401 |
public synchronized void invalidateCache(boolean flush, IProject project) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
402 |
if (getCacheState() == EMPTY_CACHE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
403 |
// cache has not been touched, nothing to do |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
404 |
return; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
405 |
// mark the cache as invalid |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
406 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
407 |
setCacheState(INVALID_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
408 |
} catch (CoreException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
409 |
Policy.log(e.getStatus()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
410 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
411 |
if (Policy.DEBUG_CONTENT_TYPE_CACHE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
412 |
Policy.debug("Invalidated cache for " + (project == null ? Path.ROOT : project.getFullPath())); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
413 |
if (flush) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
414 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
415 |
// discard the cache, so it can be used before the flush job starts |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
416 |
setCacheState(ABOUT_TO_FLUSH); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
417 |
cache.discardAll(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
418 |
} catch (CoreException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
419 |
Policy.log(e.getStatus()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
420 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
421 |
// the cache is not good, flush it |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
422 |
flushJob.flush(project); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
423 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
424 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
425 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
426 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
427 |
* Tries to obtain a content description for the given file. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
428 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
429 |
private IContentDescription readDescription(File file) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
430 |
if (Policy.DEBUG_CONTENT_TYPE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
431 |
Policy.debug("reading contents of " + file); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
432 |
// tries to obtain a description for this file contents |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
433 |
InputStream contents = new LazyFileInputStream(file.getStore()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
434 |
try { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
435 |
IContentTypeMatcher matcher = getContentTypeMatcher((Project) file.getProject()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
436 |
return matcher.getDescriptionFor(contents, file.getName(), IContentDescription.ALL); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
437 |
} catch (IOException e) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
438 |
String message = NLS.bind(Messages.resources_errorContentDescription, file.getFullPath()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
439 |
throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, file.getFullPath(), message, e); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
440 |
} finally { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
441 |
FileUtil.safeClose(contents); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
442 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
443 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
444 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
445 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
446 |
* @see IRegistryChangeListener#registryChanged(IRegistryChangeEvent) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
447 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
448 |
public void registryChanged(IRegistryChangeEvent event) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
449 |
// no changes related to the content type registry |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
450 |
if (event.getExtensionDeltas(Platform.PI_RUNTIME, PT_CONTENTTYPES).length == 0) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
451 |
return; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
452 |
invalidateCache(true, null); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
453 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
454 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
455 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
456 |
* @see ILifecycleListener#handleEvent(LifecycleEvent) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
457 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
458 |
public void handleEvent(LifecycleEvent event) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
459 |
//TODO are these the only events we care about? |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
460 |
switch (event.kind) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
461 |
case LifecycleEvent.PRE_PROJECT_CHANGE : |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
462 |
// if the project changes, its natures may have changed as well (content types may be associated to natures) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
463 |
case LifecycleEvent.PRE_PROJECT_DELETE : |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
464 |
// if the project gets deleted, we may get confused if it is recreated again (content ids might match) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
465 |
case LifecycleEvent.PRE_PROJECT_MOVE : |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
466 |
// if the project moves, resource paths (used as keys in the in-memory cache) will have changed |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
467 |
invalidateCache(true, (IProject) event.resource); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
468 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
469 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
470 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
471 |
synchronized void setCacheState(byte newCacheState) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
472 |
if (cacheState == newCacheState) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
473 |
return; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
474 |
workspace.getRoot().setPersistentProperty(CACHE_STATE, Byte.toString(newCacheState)); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
475 |
cacheState = newCacheState; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
476 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
477 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
478 |
private void setCacheTimeStamp(long timeStamp) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
479 |
workspace.getRoot().setPersistentProperty(CACHE_TIMESTAMP, Long.toString(timeStamp)); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
480 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
481 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
482 |
public void shutdown(IProgressMonitor monitor) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
483 |
if (getCacheState() != INVALID_CACHE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
484 |
// remember the platform timestamp for which we have a valid cache |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
485 |
setCacheTimeStamp(Platform.getStateStamp()); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
486 |
Platform.getContentTypeManager().removeContentTypeChangeListener(this); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
487 |
Platform.getExtensionRegistry().removeRegistryChangeListener(this); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
488 |
cache.dispose(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
489 |
cache = null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
490 |
flushJob.cancel(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
491 |
flushJob = null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
492 |
projectContentTypes = null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
493 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
494 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
495 |
public void startup(IProgressMonitor monitor) throws CoreException { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
496 |
workspace = (Workspace) ResourcesPlugin.getWorkspace(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
497 |
cache = new Cache(100, 1000, 0.1); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
498 |
projectContentTypes = new ProjectContentTypes(workspace); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
499 |
getCacheState(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
500 |
if (cacheState == FLUSHING_CACHE || cacheState == ABOUT_TO_FLUSH) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
501 |
// in case we died before completing the last flushing |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
502 |
setCacheState(INVALID_CACHE); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
503 |
flushJob = new FlushJob(); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
504 |
// the cache is stale (plug-ins that might be contributing content types were added/removed) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
505 |
if (getCacheTimestamp() != Platform.getStateStamp()) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
506 |
invalidateCache(false, null); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
507 |
// register a lifecycle listener |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
508 |
workspace.addLifecycleListener(this); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
509 |
// register a content type change listener |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
510 |
Platform.getContentTypeManager().addContentTypeChangeListener(this); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
511 |
// register a registry change listener |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
512 |
Platform.getExtensionRegistry().addRegistryChangeListener(this, Platform.PI_RUNTIME); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
513 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
514 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
515 |
public void projectPreferencesChanged(IProject project) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
516 |
if (Policy.DEBUG_CONTENT_TYPE) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
517 |
Policy.debug("Project preferences changed for " + project); //$NON-NLS-1$ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
518 |
projectContentTypes.contentTypePreferencesChanged(project); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
519 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
520 |
} |