|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ptp.rdt.ui.subsystems; |
| 12 |
|
| 13 |
import java.io.IOException; |
| 14 |
import java.lang.reflect.InvocationTargetException; |
| 15 |
import java.net.URI; |
| 16 |
import java.net.URISyntaxException; |
| 17 |
import java.util.ArrayList; |
| 18 |
import java.util.Collections; |
| 19 |
import java.util.HashSet; |
| 20 |
import java.util.Iterator; |
| 21 |
import java.util.LinkedList; |
| 22 |
import java.util.List; |
| 23 |
import java.util.Set; |
| 24 |
|
| 25 |
import org.eclipse.cdt.core.CCProjectNature; |
| 26 |
import org.eclipse.cdt.core.CProjectNature; |
| 27 |
import org.eclipse.cdt.core.index.IIndexFileLocation; |
| 28 |
import org.eclipse.cdt.core.model.CModelException; |
| 29 |
import org.eclipse.cdt.core.model.CoreModelUtil; |
| 30 |
import org.eclipse.cdt.core.model.ICContainer; |
| 31 |
import org.eclipse.cdt.core.model.ICElement; |
| 32 |
import org.eclipse.cdt.core.model.ICProject; |
| 33 |
import org.eclipse.cdt.core.model.IParent; |
| 34 |
import org.eclipse.cdt.core.model.ITranslationUnit; |
| 35 |
import org.eclipse.core.resources.IFile; |
| 36 |
import org.eclipse.core.resources.IProject; |
| 37 |
import org.eclipse.core.resources.IResource; |
| 38 |
import org.eclipse.core.resources.IResourceVisitor; |
| 39 |
import org.eclipse.core.resources.IWorkspace; |
| 40 |
import org.eclipse.core.resources.IWorkspaceRoot; |
| 41 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 42 |
import org.eclipse.core.runtime.AssertionFailedException; |
| 43 |
import org.eclipse.core.runtime.CoreException; |
| 44 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 45 |
import org.eclipse.core.runtime.IStatus; |
| 46 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 47 |
import org.eclipse.core.runtime.Status; |
| 48 |
import org.eclipse.dstore.core.model.DataElement; |
| 49 |
import org.eclipse.dstore.core.model.DataStore; |
| 50 |
import org.eclipse.dstore.core.model.DataStoreResources; |
| 51 |
import org.eclipse.dstore.core.model.DataStoreSchema; |
| 52 |
import org.eclipse.ptp.internal.rdt.core.IRemoteIndexerInfoProvider; |
| 53 |
import org.eclipse.ptp.internal.rdt.core.Serializer; |
| 54 |
import org.eclipse.ptp.internal.rdt.core.callhierarchy.CalledByResult; |
| 55 |
import org.eclipse.ptp.internal.rdt.core.callhierarchy.CallsToResult; |
| 56 |
import org.eclipse.ptp.internal.rdt.core.contentassist.Proposal; |
| 57 |
import org.eclipse.ptp.internal.rdt.core.contentassist.RemoteContentAssistInvocationContext; |
| 58 |
import org.eclipse.ptp.internal.rdt.core.includebrowser.IIndexIncludeValue; |
| 59 |
import org.eclipse.ptp.internal.rdt.core.index.RemoteIndexerProgress; |
| 60 |
import org.eclipse.ptp.internal.rdt.core.index.RemoteIndexerTask; |
| 61 |
import org.eclipse.ptp.internal.rdt.core.miners.CDTMiner; |
| 62 |
import org.eclipse.ptp.internal.rdt.core.model.Scope; |
| 63 |
import org.eclipse.ptp.internal.rdt.core.navigation.OpenDeclarationResult; |
| 64 |
import org.eclipse.ptp.internal.rdt.core.search.RemoteSearchMatch; |
| 65 |
import org.eclipse.ptp.internal.rdt.core.search.RemoteSearchQuery; |
| 66 |
import org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem; |
| 67 |
import org.eclipse.ptp.internal.rdt.core.typehierarchy.THGraph; |
| 68 |
import org.eclipse.ptp.rdt.core.RDTLog; |
| 69 |
import org.eclipse.ptp.rdt.core.resources.RemoteNature; |
| 70 |
import org.eclipse.ptp.rdt.core.serviceproviders.IIndexServiceProvider; |
| 71 |
import org.eclipse.ptp.rdt.ui.messages.Messages; |
| 72 |
import org.eclipse.ptp.rdt.ui.serviceproviders.RemoteCIndexServiceProvider2; |
| 73 |
import org.eclipse.ptp.services.core.IService; |
| 74 |
import org.eclipse.ptp.services.core.IServiceConfiguration; |
| 75 |
import org.eclipse.ptp.services.core.IServiceProvider; |
| 76 |
import org.eclipse.ptp.services.core.ServiceModelManager; |
| 77 |
|
| 78 |
/** |
| 79 |
* An RSE subsystem which is used to provide C/C++ indexing services from a Miner |
| 80 |
* running on a remote host. |
| 81 |
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as |
| 82 |
* part of a work in progress. There is no guarantee that this API will work or |
| 83 |
* that it will remain the same. Please do not use this API without consulting |
| 84 |
* with the RDT team. |
| 85 |
* |
| 86 |
* @author crecoskie |
| 87 |
* |
| 88 |
*/ |
| 89 |
public class RemoteCIndexSubsystem2 implements ICIndexSubsystem { |
| 90 |
|
| 91 |
private Set<IProject> fInitializedProjects = new HashSet<IProject>(); |
| 92 |
private ProjectChangeListener fProjectOpenListener = new ProjectChangeListener(this); |
| 93 |
private final RemoteCIndexServiceProvider2 fProvider; |
| 94 |
private DStoreServerRunner fDataStoreRunner = null; |
| 95 |
|
| 96 |
public RemoteCIndexSubsystem2(RemoteCIndexServiceProvider2 provider) { |
| 97 |
// fRemoteServices = services; |
| 98 |
// fRemoteConnection = connection; |
| 99 |
fProvider = provider; |
| 100 |
ResourcesPlugin.getWorkspace().addResourceChangeListener(fProjectOpenListener); |
| 101 |
} |
| 102 |
|
| 103 |
/* (non-Javadoc) |
| 104 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#checkAllProjects(org.eclipse.core.runtime.IProgressMonitor) |
| 105 |
*/ |
| 106 |
public void checkAllProjects(IProgressMonitor monitor) { |
| 107 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 108 |
IWorkspaceRoot workspaceRoot = workspace.getRoot(); |
| 109 |
|
| 110 |
for (IProject project : workspaceRoot.getProjects()) { |
| 111 |
// is the project open? if not, there's not much we can do |
| 112 |
if (!project.isOpen()) |
| 113 |
continue; |
| 114 |
|
| 115 |
// is this an RDT C/C++ project? |
| 116 |
// check the project natures... we care about the project if it has |
| 117 |
// both the remote nature and |
| 118 |
// at least one of the CDT natures |
| 119 |
try { |
| 120 |
if (!project.hasNature(RemoteNature.REMOTE_NATURE_ID) |
| 121 |
|| !(project.hasNature(CProjectNature.C_NATURE_ID) |
| 122 |
|| project.hasNature(CCProjectNature.CC_NATURE_ID))) |
| 123 |
continue; |
| 124 |
|
| 125 |
checkProject(project, monitor); |
| 126 |
} catch (Throwable e) { |
| 127 |
RDTLog.logError(e); |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
/* (non-Javadoc) |
| 133 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#checkProject(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IProgressMonitor) |
| 134 |
*/ |
| 135 |
public void checkProject(IProject project, IProgressMonitor monitor) { |
| 136 |
if (project == null || fInitializedProjects.contains(project)) { |
| 137 |
return; |
| 138 |
} |
| 139 |
try { |
| 140 |
initializeScope(project, monitor); |
| 141 |
} catch (CoreException e) { |
| 142 |
RDTLog.logError(e); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
/* (non-Javadoc) |
| 147 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#computeCompletionProposals(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.ptp.internal.rdt.core.contentassist.RemoteContentAssistInvocationContext, org.eclipse.cdt.core.model.ITranslationUnit) |
| 148 |
*/ |
| 149 |
public List<Proposal> computeCompletionProposals(Scope scope, RemoteContentAssistInvocationContext context, ITranslationUnit unit) { |
| 150 |
DataStore dataStore = getDataStore(); |
| 151 |
if (dataStore == null) |
| 152 |
{ |
| 153 |
return Collections.emptyList(); |
| 154 |
} |
| 155 |
|
| 156 |
DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_CONTENT_ASSIST_COMPUTE_PROPOSALS); |
| 157 |
|
| 158 |
if (queryCmd == null) |
| 159 |
{ |
| 160 |
return Collections.emptyList(); |
| 161 |
} |
| 162 |
|
| 163 |
NullProgressMonitor monitor = new NullProgressMonitor(); |
| 164 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 165 |
ArrayList<Object> args = new ArrayList<Object>(); |
| 166 |
|
| 167 |
// need to know the scope |
| 168 |
DataElement dataElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName()); |
| 169 |
args.add(dataElement); |
| 170 |
|
| 171 |
// invocation context |
| 172 |
args.add(createSerializableElement(dataStore, context)); |
| 173 |
|
| 174 |
// translation unit |
| 175 |
args.add(createSerializableElement(dataStore, unit)); |
| 176 |
|
| 177 |
// execute the command |
| 178 |
DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot()); |
| 179 |
|
| 180 |
try |
| 181 |
{ |
| 182 |
smonitor.waitForUpdate(status, monitor); |
| 183 |
if (monitor.isCanceled()) |
| 184 |
{ |
| 185 |
cancelOperation(monitor, status.getParent()); |
| 186 |
} |
| 187 |
} |
| 188 |
catch (Exception e) |
| 189 |
{ |
| 190 |
RDTLog.logError(e); |
| 191 |
} |
| 192 |
|
| 193 |
DataElement element = status.get(0); |
| 194 |
String data = element.getName(); |
| 195 |
try |
| 196 |
{ |
| 197 |
Object result = Serializer.deserialize(data); |
| 198 |
if (result == null || !(result instanceof List<?>)) |
| 199 |
{ |
| 200 |
return Collections.emptyList(); |
| 201 |
} |
| 202 |
return (List<Proposal>) result; |
| 203 |
} catch (IOException e) { |
| 204 |
RDTLog.logError(e); |
| 205 |
} catch (ClassNotFoundException e) { |
| 206 |
RDTLog.logError(e); |
| 207 |
} |
| 208 |
return Collections.emptyList(); |
| 209 |
} |
| 210 |
|
| 211 |
/* (non-Javadoc) |
| 212 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#computeTypeGraph(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ICElement, org.eclipse.core.runtime.IProgressMonitor) |
| 213 |
*/ |
| 214 |
public THGraph computeTypeGraph(Scope scope, ICElement input, IProgressMonitor monitor) { |
| 215 |
Object result = sendRequest(CDTMiner.C_TYPE_HIERARCHY_COMPUTE_TYPE_GRAPH, new Object[] { scope, getBaseURI(), input }, monitor); |
| 216 |
if (result == null) { |
| 217 |
return new THGraph(); |
| 218 |
} |
| 219 |
return (THGraph) result; |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Shutdown and clean up the subsystem |
| 224 |
*/ |
| 225 |
public void dispose() { |
| 226 |
if (fDataStoreRunner != null) { |
| 227 |
fDataStoreRunner.cancel(); |
| 228 |
} |
| 229 |
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fProjectOpenListener); |
| 230 |
} |
| 231 |
|
| 232 |
// scope management |
| 233 |
|
| 234 |
/* (non-Javadoc) |
| 235 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findInclude(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, java.lang.String, int, org.eclipse.core.runtime.IProgressMonitor) |
| 236 |
*/ |
| 237 |
public IIndexIncludeValue findInclude(Scope scope, IIndexFileLocation location, String name, int offset, IProgressMonitor monitor) |
| 238 |
{ |
| 239 |
Object result = sendRequest(CDTMiner.C_INCLUDES_FIND_INCLUDE, new Object[] { scope, getBaseURI(), location, name, offset}, monitor); |
| 240 |
if (result == null) |
| 241 |
{ |
| 242 |
return null; |
| 243 |
} |
| 244 |
|
| 245 |
return (IIndexIncludeValue) result; |
| 246 |
} |
| 247 |
|
| 248 |
/* (non-Javadoc) |
| 249 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findIncludedBy(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, org.eclipse.core.runtime.IProgressMonitor) |
| 250 |
*/ |
| 251 |
public IIndexIncludeValue[] findIncludedBy(Scope scope, IIndexFileLocation location, IProgressMonitor monitor) |
| 252 |
{ |
| 253 |
Object result = sendRequest(CDTMiner.C_INCLUDES_FIND_INCLUDED_BY, new Object[] { scope, getBaseURI(), location }, monitor); |
| 254 |
if (result == null) |
| 255 |
{ |
| 256 |
return new IIndexIncludeValue[0]; |
| 257 |
} |
| 258 |
|
| 259 |
return (IIndexIncludeValue[]) result; |
| 260 |
} |
| 261 |
|
| 262 |
/* (non-Javadoc) |
| 263 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findIncludesTo(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, org.eclipse.core.runtime.IProgressMonitor) |
| 264 |
*/ |
| 265 |
public IIndexIncludeValue[] findIncludesTo(Scope scope, IIndexFileLocation location, IProgressMonitor monitor) |
| 266 |
{ |
| 267 |
Object result = sendRequest(CDTMiner.C_INCLUDES_FIND_INCLUDES_TO, new Object[] { scope, getBaseURI(), location }, monitor); |
| 268 |
if (result == null) |
| 269 |
{ |
| 270 |
return new IIndexIncludeValue[0]; |
| 271 |
} |
| 272 |
|
| 273 |
return (IIndexIncludeValue[]) result; |
| 274 |
} |
| 275 |
|
| 276 |
/* (non-Javadoc) |
| 277 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findTypeHierarchyInput(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ICElement) |
| 278 |
*/ |
| 279 |
public ICElement[] findTypeHierarchyInput(Scope scope, ICElement memberInput) { |
| 280 |
Object result = sendRequest(CDTMiner.C_TYPE_HIERARCHY_FIND_INPUT1, new Object[] { scope, getBaseURI(), memberInput }, null); |
| 281 |
if (result == null) { |
| 282 |
return new ICElement[] { null, null }; |
| 283 |
} |
| 284 |
return (ICElement[]) result; |
| 285 |
} |
| 286 |
|
| 287 |
/* (non-Javadoc) |
| 288 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#findTypeHierarchyInput(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ITranslationUnit, int, int) |
| 289 |
*/ |
| 290 |
public ICElement[] findTypeHierarchyInput(Scope scope, ITranslationUnit unit, int selectionStart, int selectionLength) { |
| 291 |
Object result = sendRequest(CDTMiner.C_TYPE_HIERARCHY_FIND_INPUT2, new Object[] { scope, getBaseURI(), unit, new Integer(selectionStart), new Integer(selectionLength)}, null); |
| 292 |
if (result == null) { |
| 293 |
return new ICElement[] { null, null }; |
| 294 |
} |
| 295 |
return (ICElement[]) result; |
| 296 |
} |
| 297 |
|
| 298 |
/* (non-Javadoc) |
| 299 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCallees(org.eclipse.ptp.internal.rdt.core.model.Scope, java.lang.String, java.lang.String, int, int, org.eclipse.core.runtime.IProgressMonitor) |
| 300 |
*/ |
| 301 |
public CallsToResult getCallees(Scope scope, ICElement subject, IProgressMonitor monitor) { |
| 302 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.6") + subject, 100); //$NON-NLS-1$ |
| 303 |
Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_CALLS, new Object[] { scope, getBaseURI(), subject }, null); |
| 304 |
if (result == null) { |
| 305 |
return new CallsToResult(); |
| 306 |
} |
| 307 |
return (CallsToResult) result; |
| 308 |
} |
| 309 |
|
| 310 |
/* (non-Javadoc) |
| 311 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCallers(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ICElement, org.eclipse.core.runtime.IProgressMonitor) |
| 312 |
*/ |
| 313 |
public CalledByResult getCallers(Scope scope, ICElement subject, IProgressMonitor monitor) { |
| 314 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.5") + subject, 100); //$NON-NLS-1$ |
| 315 |
Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_CALLERS, new Object[] { scope, getBaseURI(), subject }, null); |
| 316 |
if (result == null) { |
| 317 |
return new CalledByResult(); |
| 318 |
} |
| 319 |
return (CalledByResult) result; |
| 320 |
} |
| 321 |
|
| 322 |
/* (non-Javadoc) |
| 323 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCHDefinitions(org.eclipse.ptp.internal.rdt.core.model.Scope, java.lang.String, java.lang.String, int, int, org.eclipse.core.runtime.IProgressMonitor) |
| 324 |
*/ |
| 325 |
public ICElement[] getCHDefinitions(Scope scope, ICElement subject, IProgressMonitor monitor) { |
| 326 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.7") + subject, 100); //$NON-NLS-1$ |
| 327 |
Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_DEFINITIONS_FROM_ELEMENT, new Object[] { scope, getBaseURI(), subject }, null); |
| 328 |
if (result == null) { |
| 329 |
return new ICElement[0]; |
| 330 |
} |
| 331 |
return (ICElement[]) result; |
| 332 |
} |
| 333 |
|
| 334 |
// call hierarchy |
| 335 |
|
| 336 |
/* (non-Javadoc) |
| 337 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getCHDefinitions(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ITranslationUnit, int, int, org.eclipse.core.runtime.IProgressMonitor) |
| 338 |
*/ |
| 339 |
public ICElement[] getCHDefinitions(Scope scope, ITranslationUnit unit, int selectionStart, int selectionLength, IProgressMonitor monitor) { |
| 340 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.7") + unit, 100); //$NON-NLS-1$ |
| 341 |
Object result = sendRequest(CDTMiner.C_CALL_HIERARCHY_GET_DEFINITIONS_FROM_WORKING_COPY, new Object[] { scope, getBaseURI(), unit, selectionStart, selectionLength }, null); |
| 342 |
if (result == null) { |
| 343 |
return new ICElement[0]; |
| 344 |
} |
| 345 |
return (ICElement[]) result; |
| 346 |
} |
| 347 |
|
| 348 |
/* (non-Javadoc) |
| 349 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#getModel(org.eclipse.cdt.core.model.ITranslationUnit, org.eclipse.core.runtime.IProgressMonitor) |
| 350 |
*/ |
| 351 |
public ITranslationUnit getModel(ITranslationUnit unit, IProgressMonitor monitor) { |
| 352 |
Object result = sendRequest(CDTMiner.C_MODEL_BUILDER, new Object[] {unit}, monitor); |
| 353 |
if (result == null) |
| 354 |
{ |
| 355 |
return null; |
| 356 |
} |
| 357 |
|
| 358 |
//the working copy |
| 359 |
return (ITranslationUnit) result; |
| 360 |
} |
| 361 |
|
| 362 |
/* (non-Javadoc) |
| 363 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#indexDelta(org.eclipse.ptp.internal.rdt.core.model.Scope, java.util.List, java.util.List, java.util.List, org.eclipse.core.runtime.IProgressMonitor) |
| 364 |
*/ |
| 365 |
public IStatus indexDelta(Scope scope, |
| 366 |
IRemoteIndexerInfoProvider provider, |
| 367 |
List<ICElement> newElements, List<ICElement> changedElements, |
| 368 |
List<ICElement> deletedElements, IProgressMonitor monitor, |
| 369 |
RemoteIndexerTask task) { |
| 370 |
DataStore dataStore = getDataStore(); |
| 371 |
|
| 372 |
if (dataStore != null) |
| 373 |
{ |
| 374 |
|
| 375 |
DataElement result = getDataStore().createObject(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR, "index"); //$NON-NLS-1$ |
| 376 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 377 |
|
| 378 |
int workCount = newElements.size() + changedElements.size(); |
| 379 |
|
| 380 |
monitor.beginTask("Incrementally Indexing...", workCount); //$NON-NLS-1$ |
| 381 |
|
| 382 |
DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_INDEX_DELTA); |
| 383 |
if (queryCmd != null) |
| 384 |
{ |
| 385 |
|
| 386 |
ArrayList<Object> args = new ArrayList<Object>(); |
| 387 |
|
| 388 |
// need to know the scope |
| 389 |
DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName()); |
| 390 |
args.add(scopeElement); |
| 391 |
|
| 392 |
|
| 393 |
String serializedProvider = null; |
| 394 |
try { |
| 395 |
serializedProvider = Serializer.serialize(provider); |
| 396 |
} catch (IOException e) { |
| 397 |
RDTLog.logError(e); |
| 398 |
} |
| 399 |
|
| 400 |
DataElement providerElement = dataStore.createObject(null, CDTMiner.T_INDEX_SCANNER_INFO_PROVIDER, serializedProvider); |
| 401 |
args.add(providerElement); |
| 402 |
|
| 403 |
|
| 404 |
// iterate through the additions and create an object for each addition |
| 405 |
Iterator<ICElement> iterator = newElements.iterator(); |
| 406 |
|
| 407 |
while(iterator.hasNext()) { |
| 408 |
ICElement element = iterator.next(); |
| 409 |
|
| 410 |
// figure out the path to the element on the remote machine |
| 411 |
String remotePath = convertURIToRemotePath(element.getLocationURI()); |
| 412 |
|
| 413 |
DataElement addedElement = dataStore.createObject(null, CDTMiner.T_INDEX_DELTA_ADDED, remotePath); |
| 414 |
args.add(addedElement); |
| 415 |
} |
| 416 |
|
| 417 |
// iterate through the changed elements and create an object for each change |
| 418 |
iterator = changedElements.iterator(); |
| 419 |
|
| 420 |
while(iterator.hasNext()) { |
| 421 |
ICElement element = iterator.next(); |
| 422 |
|
| 423 |
// figure out the path to the element on the remote machine |
| 424 |
String remotePath = convertURIToRemotePath(element.getLocationURI()); |
| 425 |
|
| 426 |
DataElement changedElement = dataStore.createObject(null, CDTMiner.T_INDEX_DELTA_CHANGED, remotePath); |
| 427 |
args.add(changedElement); |
| 428 |
} |
| 429 |
|
| 430 |
// iterate through the deleted elements and create an object for each change |
| 431 |
iterator = deletedElements.iterator(); |
| 432 |
|
| 433 |
while(iterator.hasNext()) { |
| 434 |
ICElement element = iterator.next(); |
| 435 |
|
| 436 |
// figure out the path to the element on the remote machine |
| 437 |
String remotePath = convertURIToRemotePath(element.getLocationURI()); |
| 438 |
|
| 439 |
DataElement deletedElement = dataStore.createObject(null, CDTMiner.T_INDEX_DELTA_REMOVED, remotePath); |
| 440 |
args.add(deletedElement); |
| 441 |
} |
| 442 |
|
| 443 |
DataElement status = dataStore.command(queryCmd, args, result); |
| 444 |
|
| 445 |
//poll for progress information until the operation is done or canceled |
| 446 |
while (!status.getName().equals("done") && !status.getName().equals("cancelled") && !monitor.isCanceled()) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 447 |
|
| 448 |
RemoteIndexerProgress progress = getIndexerProgress(status); |
| 449 |
task.updateProgressInformation(progress); |
| 450 |
try { |
| 451 |
Thread.sleep(100); |
| 452 |
} catch (InterruptedException e) { |
| 453 |
RDTLog.logError(e); |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
try { |
| 458 |
smonitor.waitForUpdate(status, monitor); |
| 459 |
if (monitor.isCanceled()) |
| 460 |
cancelOperation(monitor, status.getParent()); |
| 461 |
} catch (Exception e) { |
| 462 |
RDTLog.logError(e); |
| 463 |
} |
| 464 |
|
| 465 |
monitor.done(); |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
return Status.OK_STATUS; |
| 470 |
} |
| 471 |
|
| 472 |
/* (non-Javadoc) |
| 473 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#isIndexed(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.index.IIndexFileLocation, org.eclipse.core.runtime.IProgressMonitor) |
| 474 |
*/ |
| 475 |
public boolean isIndexed(Scope scope, IIndexFileLocation location, IProgressMonitor monitor) |
| 476 |
{ |
| 477 |
Object result = sendRequest(CDTMiner.C_INCLUDES_IS_INDEXED, new Object[] { scope, getBaseURI(), location }, monitor); |
| 478 |
if (result != null) |
| 479 |
{ |
| 480 |
return Boolean.parseBoolean(result.toString()); |
| 481 |
} |
| 482 |
|
| 483 |
return false; |
| 484 |
} |
| 485 |
|
| 486 |
/* (non-Javadoc) |
| 487 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#moveIndexFile(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
| 488 |
*/ |
| 489 |
public String moveIndexFile(String scopeName, String newIndexLocation, IProgressMonitor monitor) { |
| 490 |
String actualLocation = sendRequestStringResult(CDTMiner.C_MOVE_INDEX_FILE, new Object[] {scopeName, newIndexLocation}, monitor); |
| 491 |
return actualLocation; |
| 492 |
} |
| 493 |
|
| 494 |
/* (non-Javadoc) |
| 495 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#openDeclaration(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.cdt.core.model.ITranslationUnit, java.lang.String, int, int, org.eclipse.core.runtime.IProgressMonitor) |
| 496 |
*/ |
| 497 |
public OpenDeclarationResult openDeclaration(Scope scope, ITranslationUnit unit, String selectedText, int selectionStart, int selectionLength, IProgressMonitor monitor) { |
| 498 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.9"), 100); //$NON-NLS-1$ |
| 499 |
Object result = sendRequest(CDTMiner.C_NAVIGATION_OPEN_DECLARATION, new Object[] {scope, unit, selectedText, selectionStart, selectionLength}, monitor); |
| 500 |
if(result == null) |
| 501 |
return OpenDeclarationResult.failureUnexpectedError(); |
| 502 |
return (OpenDeclarationResult)result; |
| 503 |
} |
| 504 |
|
| 505 |
/* (non-Javadoc) |
| 506 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#registerScope(org.eclipse.ptp.internal.rdt.core.model.Scope, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor) |
| 507 |
*/ |
| 508 |
public IStatus registerScope(Scope scope, List<ICElement> elements, String configLocation, IProgressMonitor monitor) |
| 509 |
{ |
| 510 |
DataStore dataStore = getDataStore(); |
| 511 |
|
| 512 |
if (dataStore != null) |
| 513 |
{ |
| 514 |
|
| 515 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 516 |
|
| 517 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.3"), 100); //$NON-NLS-1$ |
| 518 |
|
| 519 |
DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_SCOPE_REGISTER); |
| 520 |
if (queryCmd != null) |
| 521 |
{ |
| 522 |
|
| 523 |
ArrayList<Object> args = new ArrayList<Object>(); |
| 524 |
|
| 525 |
// need to know the scope |
| 526 |
DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName()); |
| 527 |
args.add(scopeElement); |
| 528 |
|
| 529 |
// need to know where to find the pdom file for the scope |
| 530 |
DataElement configElement = dataStore.createObject(null, CDTMiner.T_SCOPE_CONFIG_LOCATION, configLocation); |
| 531 |
args.add(configElement); |
| 532 |
|
| 533 |
// add in the filenames |
| 534 |
for(ICElement element : elements) { |
| 535 |
addElement(dataStore, args, element); |
| 536 |
} |
| 537 |
|
| 538 |
// execute the command |
| 539 |
DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot()); |
| 540 |
|
| 541 |
try |
| 542 |
{ |
| 543 |
smonitor.waitForUpdate(status, monitor); |
| 544 |
if (monitor.isCanceled()) |
| 545 |
{ |
| 546 |
cancelOperation(monitor, status.getParent()); |
| 547 |
} |
| 548 |
} |
| 549 |
catch (Exception e) |
| 550 |
{ |
| 551 |
} |
| 552 |
|
| 553 |
int i=0; |
| 554 |
i++; |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
} |
| 559 |
|
| 560 |
return Status.OK_STATUS; |
| 561 |
|
| 562 |
} |
| 563 |
|
| 564 |
/* |
| 565 |
* (non-Javadoc) |
| 566 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#reindexScope(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.ptp.internal.rdt.core.IRemoteIndexerInfoProvider, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ptp.internal.rdt.core.index.RemoteIndexerTask) |
| 567 |
*/ |
| 568 |
public IStatus reindexScope(Scope scope, IRemoteIndexerInfoProvider provider, String indexLocation, IProgressMonitor monitor, RemoteIndexerTask task) |
| 569 |
{ |
| 570 |
DataStore dataStore = getDataStore(); |
| 571 |
|
| 572 |
if (dataStore != null) |
| 573 |
{ |
| 574 |
|
| 575 |
DataElement result = getDataStore().createObject(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR, "index"); //$NON-NLS-1$ |
| 576 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 577 |
|
| 578 |
// int count = 0; |
| 579 |
// DataElement countCmd = dataStore.localDescriptorQuery(datastore.getDescriptorRoot(), CDTMiner.C_SCOPE_COUNT_ELEMENTS); |
| 580 |
// if (countCmd != null) |
| 581 |
// { |
| 582 |
// DataElement countStatus = dataStore.command(countCmd, result, true); |
| 583 |
// try |
| 584 |
// { |
| 585 |
// smonitor.waitForUpdate(countStatus, monitor, 5000); |
| 586 |
// if (monitor.isCanceled()) |
| 587 |
// { |
| 588 |
// cancelOperation(monitor, countStatus.getParent()); |
| 589 |
// } |
| 590 |
// } |
| 591 |
// catch (Exception e) |
| 592 |
// { |
| 593 |
// } |
| 594 |
// count = Integer.parseInt(countStatus.getSource()); |
| 595 |
// } |
| 596 |
// |
| 597 |
// monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.1"), count); //$NON-NLS-1$ |
| 598 |
|
| 599 |
monitor.beginTask("Rebuilding indexing...", 100); //$NON-NLS-1$ |
| 600 |
|
| 601 |
DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_INDEX_REINDEX); |
| 602 |
if (queryCmd != null) |
| 603 |
{ |
| 604 |
|
| 605 |
ArrayList<Object> args = new ArrayList<Object>(); |
| 606 |
|
| 607 |
// need to know the scope |
| 608 |
DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName()); |
| 609 |
args.add(scopeElement); |
| 610 |
|
| 611 |
String serializedProvider = null; |
| 612 |
try { |
| 613 |
serializedProvider = Serializer.serialize(provider); |
| 614 |
} catch (IOException e) { |
| 615 |
RDTLog.logError(e); |
| 616 |
} |
| 617 |
|
| 618 |
DataElement providerElement = dataStore.createObject(null, CDTMiner.T_INDEX_SCANNER_INFO_PROVIDER, serializedProvider); |
| 619 |
args.add(providerElement); |
| 620 |
|
| 621 |
// need to know the scope config location |
| 622 |
DataElement indexLocationElement = dataStore.createObject(null, CDTMiner.T_SCOPE_CONFIG_LOCATION, indexLocation); |
| 623 |
args.add(indexLocationElement); |
| 624 |
|
| 625 |
DataElement status = dataStore.command(queryCmd, args, result); |
| 626 |
|
| 627 |
//poll for progress information until the operation is done or canceled |
| 628 |
while (!status.getName().equals("done") && !status.getName().equals("cancelled") && !monitor.isCanceled()) { //$NON-NLS-1$ //$NON-NLS-2$ |
| 629 |
|
| 630 |
RemoteIndexerProgress progress = getIndexerProgress(status); |
| 631 |
task.updateProgressInformation(progress); |
| 632 |
try { |
| 633 |
Thread.sleep(100); |
| 634 |
} catch (InterruptedException e) { |
| 635 |
RDTLog.logError(e); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
try { |
| 640 |
smonitor.waitForUpdate(status, monitor); |
| 641 |
if (monitor.isCanceled()) |
| 642 |
cancelOperation(monitor, status.getParent()); |
| 643 |
} catch (Exception e) { |
| 644 |
RDTLog.logError(e); |
| 645 |
} |
| 646 |
|
| 647 |
monitor.done(); |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
return Status.OK_STATUS; |
| 652 |
|
| 653 |
} |
| 654 |
|
| 655 |
/* (non-Javadoc) |
| 656 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#removeIndexFile(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.core.runtime.IProgressMonitor) |
| 657 |
*/ |
| 658 |
public IStatus removeIndexFile(Scope scope, IProgressMonitor monitor) { |
| 659 |
sendRequest(CDTMiner.C_REMOVE_INDEX_FILE, new Object[] {scope}, monitor); |
| 660 |
return Status.OK_STATUS; |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
/* (non-Javadoc) |
| 665 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#runQuery(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.ptp.internal.rdt.core.search.RemoteSearchQuery, org.eclipse.core.runtime.IProgressMonitor) |
| 666 |
*/ |
| 667 |
@SuppressWarnings("unchecked") |
| 668 |
public List<RemoteSearchMatch> runQuery(Scope scope, RemoteSearchQuery query, IProgressMonitor monitor) { |
| 669 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.8") + query.getScopeDescription(), 100); //$NON-NLS-1$ |
| 670 |
Object result = sendRequest(CDTMiner.C_SEARCH_RUN_QUERY, new Object[] { scope, getBaseURI(), query }, null); |
| 671 |
if (result == null) { |
| 672 |
return Collections.emptyList(); |
| 673 |
} |
| 674 |
return (List<RemoteSearchMatch>) result; |
| 675 |
} |
| 676 |
|
| 677 |
/** |
| 678 |
* @param requestType |
| 679 |
* @param arguments |
| 680 |
* @param monitor |
| 681 |
* @return |
| 682 |
*/ |
| 683 |
public Object sendRequest(String requestType, Object[] arguments, IProgressMonitor monitor) { |
| 684 |
return sendRequest(requestType, arguments, monitor, true); |
| 685 |
} |
| 686 |
|
| 687 |
/** |
| 688 |
* @param requestType |
| 689 |
* @param arguments |
| 690 |
* @param monitor |
| 691 |
* @return |
| 692 |
*/ |
| 693 |
public String sendRequestStringResult(String requestType, Object[] arguments, IProgressMonitor monitor) { |
| 694 |
return (String) sendRequest(requestType, arguments, monitor, false); |
| 695 |
} |
| 696 |
|
| 697 |
/* (non-Javadoc) |
| 698 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#startIndexOfScope(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.core.runtime.IProgressMonitor) |
| 699 |
*/ |
| 700 |
public IStatus startIndexOfScope(Scope scope, IRemoteIndexerInfoProvider provider, IProgressMonitor monitor) |
| 701 |
{ |
| 702 |
DataStore dataStore = getDataStore(); |
| 703 |
|
| 704 |
if (dataStore != null) |
| 705 |
{ |
| 706 |
|
| 707 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 708 |
|
| 709 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.0"), 100); //$NON-NLS-1$ |
| 710 |
|
| 711 |
DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_INDEX_START); |
| 712 |
if (queryCmd != null) |
| 713 |
{ |
| 714 |
|
| 715 |
ArrayList<Object> args = new ArrayList<Object>(); |
| 716 |
|
| 717 |
// need to know the scope |
| 718 |
DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName()); |
| 719 |
args.add(scopeElement); |
| 720 |
|
| 721 |
String serializedProvider = null; |
| 722 |
try { |
| 723 |
serializedProvider = Serializer.serialize(provider); |
| 724 |
} catch (IOException e) { |
| 725 |
RDTLog.logError(e); |
| 726 |
} |
| 727 |
|
| 728 |
DataElement providerElement = dataStore.createObject(null, CDTMiner.T_INDEX_SCANNER_INFO_PROVIDER, serializedProvider); |
| 729 |
args.add(providerElement); |
| 730 |
|
| 731 |
|
| 732 |
// execute the command |
| 733 |
//DataElement status = dataStore.command(queryCmd, dataStore.getDescriptorRoot(), true); |
| 734 |
DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot()); |
| 735 |
|
| 736 |
try |
| 737 |
{ |
| 738 |
smonitor.waitForUpdate(status, monitor); |
| 739 |
if (monitor.isCanceled()) |
| 740 |
{ |
| 741 |
cancelOperation(monitor, status.getParent()); |
| 742 |
} |
| 743 |
} |
| 744 |
catch (Exception e) |
| 745 |
{ |
| 746 |
} |
| 747 |
|
| 748 |
} |
| 749 |
|
| 750 |
} |
| 751 |
|
| 752 |
return Status.OK_STATUS; |
| 753 |
|
| 754 |
} |
| 755 |
|
| 756 |
/* (non-Javadoc) |
| 757 |
* @see org.eclipse.ptp.internal.rdt.core.subsystems.ICIndexSubsystem#unregisterScope(org.eclipse.ptp.internal.rdt.core.model.Scope, org.eclipse.core.runtime.IProgressMonitor) |
| 758 |
*/ |
| 759 |
public IStatus unregisterScope(Scope scope, IProgressMonitor monitor) { |
| 760 |
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(scope.getName()); |
| 761 |
fInitializedProjects.remove(project); |
| 762 |
|
| 763 |
DataStore dataStore = getDataStore(); |
| 764 |
|
| 765 |
if (dataStore != null) |
| 766 |
{ |
| 767 |
|
| 768 |
// DataElement result = dataStore.createObject(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR, name); |
| 769 |
// DataElement statusDescriptor = dataStore.createObjectDescriptor(null, CDTMiner.T_INDEX_STATUS_DESCRIPTOR); |
| 770 |
|
| 771 |
// result.setDescriptor(statusDescriptor); |
| 772 |
|
| 773 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 774 |
|
| 775 |
monitor.beginTask(Messages.getString("RemoteCIndexSubsystem.4"), 100); //$NON-NLS-1$ |
| 776 |
|
| 777 |
DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), CDTMiner.C_SCOPE_UNREGISTER); |
| 778 |
if (queryCmd != null) |
| 779 |
{ |
| 780 |
|
| 781 |
ArrayList<Object> args = new ArrayList<Object>(); |
| 782 |
|
| 783 |
// need to know the scope |
| 784 |
DataElement scopeElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, scope.getName()); |
| 785 |
args.add(scopeElement); |
| 786 |
|
| 787 |
|
| 788 |
// execute the command |
| 789 |
//DataElement status = dataStore.command(queryCmd, dataStore.getDescriptorRoot(), true); |
| 790 |
DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot()); |
| 791 |
|
| 792 |
try |
| 793 |
{ |
| 794 |
smonitor.waitForUpdate(status, monitor); |
| 795 |
if (monitor.isCanceled()) |
| 796 |
{ |
| 797 |
cancelOperation(monitor, status.getParent()); |
| 798 |
} |
| 799 |
} |
| 800 |
catch (Exception e) |
| 801 |
{ |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
} |
| 809 |
|
| 810 |
return Status.OK_STATUS; |
| 811 |
} |
| 812 |
|
| 813 |
private DataElement createSerializableElement(DataStore dataStore, Object object) { |
| 814 |
try { |
| 815 |
String serialized = Serializer.serialize(object); |
| 816 |
return dataStore.createObject(null, CDTMiner.T_INDEX_STRING_DESCRIPTOR, serialized); |
| 817 |
} catch (IOException e) { |
| 818 |
RDTLog.logError(e); |
| 819 |
return null; |
| 820 |
} |
| 821 |
} |
| 822 |
|
| 823 |
private RemoteIndexerProgress getIndexerProgress(DataElement status) { |
| 824 |
int num = status.getNestedSize(); |
| 825 |
if (num > 0) { |
| 826 |
DataElement element = status.get(num-1); |
| 827 |
String data = element.getName(); |
| 828 |
try |
| 829 |
{ |
| 830 |
Object result = Serializer.deserialize(data); |
| 831 |
if (result == null || !(result instanceof RemoteIndexerProgress)) |
| 832 |
{ |
| 833 |
return null; |
| 834 |
} |
| 835 |
RemoteIndexerProgress info = (RemoteIndexerProgress) result; |
| 836 |
return info; |
| 837 |
} catch (IOException e) { |
| 838 |
RDTLog.logError(e); |
| 839 |
} catch (ClassNotFoundException e) { |
| 840 |
RDTLog.logError(e); |
| 841 |
} |
| 842 |
} |
| 843 |
return null; |
| 844 |
} |
| 845 |
|
| 846 |
private void initializeScope(IProject project, IProgressMonitor monitor) throws CoreException { |
| 847 |
// get the service model configuration for this project |
| 848 |
final ServiceModelManager serviceModelManager = ServiceModelManager.getInstance(); |
| 849 |
IServiceConfiguration config = serviceModelManager.getActiveConfiguration(project); |
| 850 |
|
| 851 |
// is the indexing service associated with our service provider? |
| 852 |
IService service = serviceModelManager.getService(RemoteCIndexServiceProvider2.SERVICE_ID); |
| 853 |
IServiceProvider provider = config.getServiceProvider(service); |
| 854 |
|
| 855 |
|
| 856 |
// if so, initialize a scope for the project consisting of all |
| 857 |
// its translation units |
| 858 |
final List<ICElement> cElements = new LinkedList<ICElement>(); |
| 859 |
|
| 860 |
IResourceVisitor fileCollector = new IResourceVisitor() { |
| 861 |
|
| 862 |
public boolean visit(IResource resource) throws CoreException { |
| 863 |
if (resource instanceof IFile) { |
| 864 |
// add the path |
| 865 |
ITranslationUnit tu = CoreModelUtil.findTranslationUnit((IFile) resource); |
| 866 |
if (tu != null) { |
| 867 |
cElements.add(tu); |
| 868 |
return false; |
| 869 |
} |
| 870 |
} |
| 871 |
return true; |
| 872 |
} |
| 873 |
}; |
| 874 |
|
| 875 |
// collect the translation units |
| 876 |
project.accept(fileCollector); |
| 877 |
|
| 878 |
String configLocation = ((IIndexServiceProvider)provider).getIndexLocation(); |
| 879 |
Scope scope = new Scope(project.getName()); |
| 880 |
|
| 881 |
// unregister the scope if there already is one |
| 882 |
unregisterScope(scope, monitor); |
| 883 |
|
| 884 |
// register the new scope |
| 885 |
registerScope(scope, cElements, configLocation, monitor); |
| 886 |
|
| 887 |
fInitializedProjects.add(project); |
| 888 |
|
| 889 |
} |
| 890 |
|
| 891 |
/** |
| 892 |
* Sends a request in a set format of arguments. |
| 893 |
* |
| 894 |
* @param deserializeResult If true the result will be deserialized, if false it will treat the result as a raw string. |
| 895 |
*/ |
| 896 |
private Object sendRequest(String requestType, Object[] arguments, IProgressMonitor monitor, boolean deserializeResult) { |
| 897 |
DataStore dataStore = getDataStore(); |
| 898 |
if (dataStore == null) |
| 899 |
return null; |
| 900 |
|
| 901 |
DataElement queryCmd = dataStore.localDescriptorQuery(dataStore.getDescriptorRoot(), requestType); |
| 902 |
if (queryCmd == null) |
| 903 |
return null; |
| 904 |
|
| 905 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 906 |
ArrayList<Object> args = new ArrayList<Object>(); |
| 907 |
|
| 908 |
for (Object argument : arguments) { |
| 909 |
if (argument instanceof Scope) { |
| 910 |
DataElement dataElement = dataStore.createObject(null, CDTMiner.T_SCOPE_SCOPENAME_DESCRIPTOR, ((Scope) argument).getName()); |
| 911 |
args.add(dataElement); |
| 912 |
} else if (argument instanceof String) { |
| 913 |
DataElement dataElement = dataStore.createObject(null, CDTMiner.T_INDEX_STRING_DESCRIPTOR, (String) argument); |
| 914 |
args.add(dataElement); |
| 915 |
} else if (argument instanceof Integer |
| 916 |
|| argument instanceof Boolean |
| 917 |
|| argument instanceof Character |
| 918 |
|| argument instanceof Double |
| 919 |
|| argument instanceof Float) { |
| 920 |
DataElement dataElement = dataStore.createObject(null, CDTMiner.T_INDEX_STRING_DESCRIPTOR, argument.toString()); |
| 921 |
args.add(dataElement); |
| 922 |
} else { |
| 923 |
args.add(createSerializableElement(dataStore, argument)); |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
// execute the command |
| 928 |
DataElement status = dataStore.command(queryCmd, args, dataStore.getDescriptorRoot()); |
| 929 |
|
| 930 |
try |
| 931 |
{ |
| 932 |
monitor = monitor == null ? new NullProgressMonitor() : monitor; |
| 933 |
smonitor.waitForUpdate(status, monitor); |
| 934 |
if (monitor.isCanceled()) { |
| 935 |
cancelOperation(monitor, status.getParent()); |
| 936 |
} |
| 937 |
} |
| 938 |
catch (Exception e) { |
| 939 |
RDTLog.logError(e); |
| 940 |
} |
| 941 |
|
| 942 |
DataElement element = status.get(0); |
| 943 |
if (element == null) { |
| 944 |
return null; |
| 945 |
} |
| 946 |
|
| 947 |
if(DataStoreResources.model_error.equals(element.getType())) { // Error occurred on the server |
| 948 |
RDTLog.logError(status.getValue()); // prints the server error stack trace to the log |
| 949 |
return null; |
| 950 |
} |
| 951 |
|
| 952 |
String data = element.getName(); |
| 953 |
if(!deserializeResult) |
| 954 |
return data; |
| 955 |
|
| 956 |
try |
| 957 |
{ |
| 958 |
Object result = Serializer.deserialize(data); |
| 959 |
return result; |
| 960 |
} catch (IOException e) { |
| 961 |
RDTLog.logError(e); |
| 962 |
} catch (ClassNotFoundException e) { |
| 963 |
RDTLog.logError(e); |
| 964 |
} |
| 965 |
return null; |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
/** |
| 971 |
* @param dataStore |
| 972 |
* @param args |
| 973 |
* @param filePath |
| 974 |
* @param element |
| 975 |
*/ |
| 976 |
protected void addElement(DataStore dataStore, ArrayList<Object> args, ICElement element) { |
| 977 |
|
| 978 |
String filePath = null; |
| 979 |
|
| 980 |
// if it's a translation unit, we can just add it |
| 981 |
if(element instanceof ITranslationUnit) { |
| 982 |
filePath = convertURIToRemotePath(element.getLocationURI()); |
| 983 |
} |
| 984 |
|
| 985 |
else { |
| 986 |
// if it's a container or a project, add the child elements |
| 987 |
if(element instanceof ICContainer || element instanceof ICProject) { |
| 988 |
try { |
| 989 |
ICElement[] children = ((IParent) element).getChildren(); |
| 990 |
|
| 991 |
for(int k = 0; k < children.length; k++) |
| 992 |
addElement(dataStore, args, children[k]); |
| 993 |
|
| 994 |
} catch (CModelException e) { |
| 995 |
RDTLog.logError(e); |
| 996 |
} |
| 997 |
} |
| 998 |
|
| 999 |
} |
| 1000 |
|
| 1001 |
if (filePath != null) { |
| 1002 |
DataElement fileElement = dataStore.createObject(null, |
| 1003 |
CDTMiner.T_INDEX_FILENAME_DESCRIPTOR, filePath); |
| 1004 |
args.add(fileElement); |
| 1005 |
} |
| 1006 |
} |
| 1007 |
|
| 1008 |
protected void cancelOperation(IProgressMonitor monitor, DataElement cmd) throws InvocationTargetException, InterruptedException |
| 1009 |
{ |
| 1010 |
DataStore dataStore = cmd.getDataStore(); |
| 1011 |
DataElement commandDescriptor = dataStore.findCommandDescriptor(DataStoreSchema.C_CANCEL); |
| 1012 |
if (commandDescriptor != null) |
| 1013 |
{ |
| 1014 |
dataStore.command(commandDescriptor, cmd, false, true); |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
protected URI convertRemotePathToURI(String path) throws URISyntaxException { |
| 1019 |
return fProvider.getRemoteServices().getFileManager(fProvider.getRemoteConnection()).toURI(path); |
| 1020 |
} |
| 1021 |
|
| 1022 |
protected String convertURIToRemotePath(URI locationURI) { |
| 1023 |
return fProvider.getRemoteServices().getFileManager(fProvider.getRemoteConnection()).toPath(locationURI).toString(); |
| 1024 |
} |
| 1025 |
|
| 1026 |
protected String getBaseURI() { |
| 1027 |
try { |
| 1028 |
return convertRemotePathToURI("/").toString(); //$NON-NLS-1$ |
| 1029 |
} catch (URISyntaxException e) { |
| 1030 |
throw new AssertionFailedException(e.getLocalizedMessage()); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
protected DataStore getDataStore() { |
| 1035 |
DataStore dataStore = null; |
| 1036 |
if (fDataStoreRunner == null) { |
| 1037 |
fDataStoreRunner = DStoreServerManager.getInstance().getServer(fProvider.getRemoteServices(), fProvider.getRemoteConnection()); |
| 1038 |
fDataStoreRunner.setWorkDir(fProvider.getDStoreLocation()); |
| 1039 |
fDataStoreRunner.setCommand(fProvider.getDStoreCommand()); |
| 1040 |
fDataStoreRunner.setEnv(fProvider.getDStoreEnv()); |
| 1041 |
} |
| 1042 |
dataStore = fDataStoreRunner.getDataStore(); |
| 1043 |
if (!dataStore.isConnected()) { |
| 1044 |
if (fDataStoreRunner.startServer()) { |
| 1045 |
DataElement status = dataStore.activateMiner("org.eclipse.ptp.internal.rdt.core.miners.CDTMiner"); //$NON-NLS-1$ |
| 1046 |
StatusMonitor smonitor = StatusMonitor.getStatusMonitorFor(fProvider.getRemoteConnection(), dataStore); |
| 1047 |
try { |
| 1048 |
smonitor.waitForUpdate(status, new NullProgressMonitor()); |
| 1049 |
} catch (InterruptedException e) { |
| 1050 |
// Data store will be disconnected if error occurs |
| 1051 |
} |
| 1052 |
} |
| 1053 |
} |
| 1054 |
return dataStore; |
| 1055 |
} |
| 1056 |
|
| 1057 |
} |